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

2012/11/29

Dance dance help!

poprocks38 poprocks38

2012/11/29

#
I want to make a dance dance revolution game. The problem is that i want the different arrows to come up at random and move across the screen like in the real game. I've already searched this, but all i keep finding is code to make the same picture how up in random locations. I want random pictures to show up in the same location. Please help!!
Morran Morran

2012/11/29

#
You could have it like this: Arrow arrow = new Arrow(); int random = Greenfoot.getRandomNumber(4); if(random == 0) arrow.setImage(firstimagename); else if(random == 1) arrow.setImage(secondimagename); else if(random == 2) arrow.setImage(thirdimagename); else if(random == 3) arrow.setImage(fourthimagename); And then do whatever code to set them in their random locations. Assuming you have a class named "Arrow" to act as the arrows in dance dance revolution.
poprocks38 poprocks38

2012/11/29

#
This was really helpful! Thanks!
poprocks38 poprocks38

2012/12/3

#
One more thing.. I'm not sure how to make the arrows actually appear.. public class MyCat extends Cat { public void act() { displayArrows(); playMusic(); } public void displayArrows() { if (Greenfoot.isKeyDown("1")) { Arrow arrow = new Arrow(); int random = Greenfoot.getRandomNumber(4); if(random == 0) { arrow.setLocation(15, 45); arrow.setImage("downArrow.png"); arrow.move(5); } else if(random == 1) { arrow.setLocation(15, 45); arrow.setImage("leftArrow.png"); arrow.move(5); } else if(random == 2) { arrow.setLocation(15, 45); arrow.setImage("rightArrow.png"); arrow.move(5); } else if(random == 3) { arrow.setLocation(15, 45); arrow.setImage("upArrow.png"); arrow.move(5); } } } public void playMusic(){ if(Greenfoot.mouseClicked("Cat.MyCat")){ Greenfoot.playSound("hooray.wav"); } This should make the arrows appear on the screen when the number one in being pressed, right? What i really want is for when the number 1 is pressed, a song should start, and then the arrows appear as the song is playing..
Morran Morran

2012/12/3

#
Poprocks, every time you create anything, and you want it to show up on screen, you need to add it to the world. You do that like this:
getWorld().addObject(objectYouJustMade, whereYouWantItX, whereYouWantItY);
I hope that this helps!
danpost danpost

2012/12/3

#
There are several elements missing or wrong in the code you are showing here. (1) nowhere are the new Arrow objects being added to the world; (2) Greenfoot.mouseClicked does not take a String argument; (3) the way it is coded, an arrow will be created on each run cycle of the scenario that the '1' key is pressed; and (4) the music will not start on the '1' keypress;
You need to login to post a reply.