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

2016/11/12

Codes for the Menu Bar and Level to Level

lolitsme lolitsme

2016/11/12

#
Hello! I am currently trying to make a zombie game for our computer class, but I am having a hard to find in which codes can help me have a menu "world class" that when you click game it will appear to the level 1 "world class. Also, what codes can help me make my player enter a secret door or passage where in it once you enter that you will proceed to the next level. Please help me, I'm really having an hard time. Thank you and God bless!
Super_Hippo Super_Hippo

2016/11/12

#
Create an actor (like a button for the game) in the menu world, save a reference to it, give it an image and add it to the world. Check for mouse clicks on it from the world's act method and change the world when a click is detected. For the second thing, you could have code in the player's act method to check if it is touching the secret door and if it is, change the world.
lolitsme lolitsme

2016/11/12

#
Hi!! Do you have codes for those? Sorry I am very new to this.
Super_Hippo Super_Hippo

2016/11/12

#
It could look like this:
//at the beginning, outside methods
private Actor startButton = new Actor();

//when creating the world
addObject(startButton, 50, 50);
startButton.setImage(new GreenfootImage("Start Game", 14, null, null));

//in act method
if (Greenfoot.mousePressed(startButton)) Greenfoot.setWorld(new Level1());
You need to login to post a reply.