Question

I'm in the process of creating my pinball game - and i feel the game is a bit bland, because it's a prototype i have only set 4 bumpers in the whole game, and each bumper giving 10,000 points. I am wondering how i can add a difficulty setting to easy medium and hard.

easy giving 10,000 per hit medium giving 5,000 per hit and hard giving 2,500 per hit.

This is my code associated with the scoring system and the bumpers (For testing purposes i have set the event handler as a click - but i will be changing it to when the ball touches it to allow the points and rebound in the opposite direction).

    for(var i=0;i<bumpersArray.length;i++){
    bumpersArray[i].addEventListener(MouseEvent.CLICK,add_score);
}

    function add_score(e:MouseEvent){
    myScore.add(10000);
}

I would assume you would need an if statement linked to a button created after you push start so something like

if (easy_btn.addEventListener(MouseEvent.CLICK, easyGame))
{

        for(var i=0;i<bumpersArray.length;i++){
        bumpersArray[i].addEventListener(MouseEvent.CLICK,add_score);
    }

        function add_score(e:MouseEvent){
        myScore.add(10000);
    }
}

That's just a wild guess - but yes. Thank You. :)

Was it helpful?

Solution

Its simple,

step 1: you just define the scoreIterator value based on the level like so:

var scoreIterator:Number;

switch (difficulty) {
case "easy" :
    scoreIterator = 10000;
    break;
case "medium" :
    scoreIterator = 5000;
    break;
case "hard" :
    scoreIterator = 2500;
    break;
default :
    break;
}

Then your function becomes this:

if (easy_btn.addEventListener(MouseEvent.CLICK, easyGame))
{

    for(var i=0;i<bumpersArray.length;i++){
        bumpersArray[i].addEventListener(MouseEvent.CLICK,add_score);
    }

    function add_score(e:MouseEvent){
        myScore.add(scoreIterator);      //<-- this is now dynamic
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top