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

2014/4/15

Shield

GamesGrinder1998 GamesGrinder1998

2014/4/15

#
How can i implement a shield in my game as a powerup and i need a timer for it to only last about 15 seconds? What is the code for this? also to just come up on the screen at random times
danpost danpost

2014/4/15

#

Sword

Create an Actor subclass for the Shield. Give it an instance 'int' field for the timer and assign some value (maybe 800) to it. Have the act method decrement the timer and check for zero for removal of object from world. That should give it a lifespan of about 15 seconds.
danpost danpost

2014/4/16

#
The powerup for a shield should be a different actor (from a different class). Your world class should control when and where it should be placed in the world. The class of the powerup should control its lifespan similar to how the shield does it. Again, 'Greenfoot.getRandomNumber(int)' should be used to set the timer that regulates the spawning of the powerup (and which powerup, if you have more than one kind).
GamesGrinder1998 GamesGrinder1998

2014/4/16

#
danpost wrote...
The powerup for a shield should be a different actor (from a different class). Your world class should control when and where it should be placed in the world. The class of the powerup should control its lifespan similar to how the shield does it. Again, 'Greenfoot.getRandomNumber(int)' should be used to set the timer that regulates the spawning of the powerup (and which powerup, if you have more than one kind).
Thanks but im have to create a game for an assingment and our teacher gave us no advice on how to make a powerup and it's my first year doing i.s.t so i don't really get this advanced stuff, do you mind writing out the code or explain it in simpler words
danpost danpost

2014/4/16

#
Sounds like you need to look over the first three section (skip over what you are already familiar with) of the Java tutorials. What I suggested above was fairly basic and if you are having trouble understanding it, you should review those sections.
You need to login to post a reply.