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

2014/4/12

how do i do powerups

GamesGrinder1998 GamesGrinder1998

2014/4/12

#
how would i implement power ups in my game, i have 3 types; one that gives you more points, one that gives you a shield and another that can shoot multiple bullets at one time...how would i write the code considering that it would only last for a few seconds and that to only apppear at certain times, not all at once???plz can someone help, much appreciation if you can
danpost danpost

2014/4/12

#
First, you will need a timer int field which can be set to a value plus a random value (for example: '300+Greenfoot.getRandomNumber(300)' which would be between about 5 and 10 seconds in a scenario running at normal speed). The first '300' gives the minimum time before spawning a powerup; the random one adds up to twice as much time. These values can be adjusted as needed. Then, when the timer reaches zero (decrement it in your act method), you will need another random number to determine which powerup to spawn. Set up a local 'Actor' variable and assign it a value depending on the random number (you can use a 'switch' or a bunch of 'if's). Add the actor to the world and reset the timer. Your powerup classes should probably all extend a Powerup class that extends Actor. It (the Powerup class) should contain the life timer and remove the object from the world when the timer expires.
GamesGrinder1998 GamesGrinder1998

2014/4/12

#
danpost wrote...
First, you will need a timer int field which can be set to a value plus a random value (for example: '300+Greenfoot.getRandomNumber(300)' which would be between about 5 and 10 seconds in a scenario running at normal speed). The first '300' gives the minimum time before spawning a powerup; the random one adds up to twice as much time. These values can be adjusted as needed. Then, when the timer reaches zero (decrement it in your act method), you will need another random number to determine which powerup to spawn. Set up a local 'Actor' variable and assign it a value depending on the random number (you can use a 'switch' or a bunch of 'if's). Add the actor to the world and reset the timer. Your powerup classes should probably all extend a Powerup class that extends Actor. It (the Powerup class) should contain the life timer and remove the object from the world when the timer expires.
thanks danpost but i'm very new to greenfoot, how would the code be written, if you don't mind typing it
danpost danpost

2014/4/12

#
Creating classes and writing code is not something that will change because you are in greenfoot. If it is Java that is new to you, then maybe you should review the Java tutorial on Learning the Java language. You can pick and choose from your weaknesses, and work on those particular pages. In other words, if you are totally unfamiliar with the language itself, 'Language Basics' would be the place to go; if you are not clear on how to create classes and methods, 'Classes and Objects' might be the answer.
You need to login to post a reply.