This site requires JavaScript, please enable it in your browser!
Greenfoot back
itslit
itslit wrote ...

2017/4/11

Multiple Actors Added

itslit itslit

2017/4/11

#
Hi, I am developing this mini game right now but I'm having an issue with my main menu screen. I've added a button ("start") and everything the user does click start, it starts the game. I'm also using a switch and cases to switch between each "screen". However, when ever I click start, there are multiple rockets and bullets coming out - almost as if the game is lagging. I'm not quite sure what the issue is.
danpost danpost

2017/4/11

#
itslit wrote...
I'm also using a switch and cases to switch between each "screen"
This is vague. Show the class code.
when ever I click start, there are multiple rockets and bullets coming out - almost as if the game is lagging. I'm not quite sure what the issue is.
Need to see class code of game world.
itslit itslit

2017/4/14

#
This code is placed in the act section of the world.
MouseInfo mouse = Greenfoot.getMouseInfo();
        switch(gameState) {
            case 0:
                    currentButton = new Start();
                    addObject (currentButton, 280, 150);
                    
                    currentButton2 = new Instructions();
                    addObject(currentButton2, 280, 200);
                    gameState = 1;
                    
            
            
            case 1:
                    // initialization of start screen 
                     if (Greenfoot.mouseClicked(currentButton)) {
                        gameState = 3;
                        removeObject(currentButton);
                        removeObject(currentButton2);
                        
                        }
                    
                    if (Greenfoot.mouseClicked(currentButton2)) {
                        gameState = 2;
                        removeObject(currentButton2);
                        removeObject(currentButton);
                    
                    }
        
                    break;
                    
            case 2: 
                    // will add instructions here later 
                    break;
            
            
            case 3: 
                    addObject(new Rocket(),308,360);
                    counter = new Counter();
                 
                    addObject(counter,84,32);
                    
                    
                    if(Greenfoot.getRandomNumber(100) < 2)
                    {       
                          addObject(new Alien(), Greenfoot.getRandomNumber(500) + 50, 50);  

                    }
                    
                    break;
        }

   
danpost danpost

2017/4/14

#
Insert the following at line 42:
    gameState = 4;
    break;
case 4:
Or, as an alternative, move lines 37 through 40 to line 19.
itslit itslit

2017/4/14

#
Thank you! One more thing, I'm trying to add a score for each level so that if a user passes a certain score, they can move on to the next level. I'm using the standard Counter method by returning the score in the world. However, I'm kind of stuck on how I would implement that with the cases. For example, I wanted to do something like this: case 3: addObject(new Rocket(),308,360); counter = new Counter(); addObject(counter,84,32); if(Greenfoot.getRandomNumber(100) < 2) { addObject(new Alien(), Greenfoot.getRandomNumber(500) + 50, 50); } if (timer = 0) { if (counter = 0) { Greenfoot.stop(); } }
Yehuda Yehuda

2017/4/14

#
With your last if's your assigning ('=') timer to 0 and counter which is an instance of Counter to 0 (instead of '=='), so that won't work. You have to use 1 instance of counter for that whole level (or game), not create a new one every act cycle. Then, if the level is over and the score value of that counter is 0 then it's game over.
You need to login to post a reply.