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

2012/3/11

power ups?

1
2
3
4
5
6
danpost danpost

2014/4/17

#
GamesGrinder1998 wrote...
thanks if i want different types of powerups, would this code be able to be used for others (such as a shield or two bullets fired at one) and will i need to fill in anything myself or add stuff??? P.SSS sorry if i'm taking too much of your time or asking too many questions
Yes. I already have it set up for three different types of powerups (for the purpose of example). The ONLY thing you will need to change (that is, after making the correction given in my previous post) in the Powerup class are the 'static final' fields. The names of the images are also for the purpose of example and, obviously, do not refer to any actual images. You will have to supply the appropriate image names for any types of powerups you implement.
GamesGrinder1998 GamesGrinder1998

2014/4/17

#
danpost wrote...
I was about to edit my code when you posted. Change 'powerup' on line 15 to 'puType'.
so what parts do i use from you and the other code
GamesGrinder1998 GamesGrinder1998

2014/4/17

#
danpost wrote...
GamesGrinder1998 wrote...
thanks if i want different types of powerups, would this code be able to be used for others (such as a shield or two bullets fired at one) and will i need to fill in anything myself or add stuff??? P.SSS sorry if i'm taking too much of your time or asking too many questions
Yes. I already have it set up for three different types of powerups (for the purpose of example). The ONLY thing you will need to change (that is, after making the correction given in my previous post) in the Powerup class are the 'static final' fields. The names of the images are also for the purpose of example and, obviously, do not refer to any actual images. You will have to supply the appropriate image names for any types of powerups you implement.
also what is the purpose of drag and Ammo
danpost danpost

2014/4/17

#
GamsGrinder1998 wrote...
so what parts do I use from you and the other code
Like I stated above, the only thing (after making the correction) that you should change in the Powerup class code are the 'static final' fields. The 'static final int' fields give each different type of powerup you will use a unique number. The 'static final GreenfootImage' array will hold the images to use for each different type in numbered order. That is it. Anything else will be dealt with in the classes of the objects that will receive the powerup abilities.
also what is the purpose of drag and Ammo
. drag is the opposite of 'Speed' (like a negative powerup -- one you might want to avoid) and Ammo is for restocking your arsenal. Like I stated above, these are just for example and can be removed or changed to whatever type of powerup you wish to implement.
GamesGrinder1998 GamesGrinder1998

2014/4/17

#
danpost wrote...
GamsGrinder1998 wrote...
so what parts do I use from you and the other code
Like I stated above, the only thing (after making the correction) that you should change in the Powerup class code are the 'static final' fields. The 'static final int' fields give each different type of powerup you will use a unique number. The 'static final GreenfootImage' array will hold the images to use for each different type in numbered order. That is it. Anything else will be dealt with in the classes of the objects that will receive the powerup abilities.
also what is the purpose of drag and Ammo
. drag is the opposite of 'Speed' (like a negative powerup -- one you might want to avoid) and Ammo is for restocking your arsenal. Like I stated above, these are just for example and can be removed or changed to whatever type of powerup you wish to implement.
ok i'll put in the code to see what happens
GamesGrinder1998 GamesGrinder1998

2014/4/17

#
danpost wrote...
GamsGrinder1998 wrote...
so what parts do I use from you and the other code
Like I stated above, the only thing (after making the correction) that you should change in the Powerup class code are the 'static final' fields. The 'static final int' fields give each different type of powerup you will use a unique number. The 'static final GreenfootImage' array will hold the images to use for each different type in numbered order. That is it. Anything else will be dealt with in the classes of the objects that will receive the powerup abilities.
also what is the purpose of drag and Ammo
. drag is the opposite of 'Speed' (like a negative powerup -- one you might want to avoid) and Ammo is for restocking your arsenal. Like I stated above, these are just for example and can be removed or changed to whatever type of powerup you wish to implement.
is the basic universal code a class extended from the actor and then all the different types of powerups extend form the basic universal class??
danpost danpost

2014/4/17

#
GamesGrinder1998 wrote...
is the basic universal code a class extended from the actor and then all the different types of powerups extend form the basic universal class??
No. Nothing needs to extend the Powerup class. It, by itself, has everything you need for ANY powerup.
danpost danpost

2014/4/17

#
You mentioned 'Shield' and 'DoubleFire' as possible powerups. Then your static fields would be, if you kept the 'Speed' powerup as well:
static final int SPEED_PU = 0, SHIELD_PU = 1, DOUBLE_FIRE_PU = 2;
static final String[] images = { "speedPU.png", "shieldPU.png", "doubleFirePU.png" };
(this is assuming you had images with those names) and you would create one of each with (from your subclass of World, probably)
Powerup speedPU = new Powerup(Powerup.SPEED_PU);
Powerup shieldPU = new Powerup(Powerup.SHIELD_PU); // and
Powerup doubleFirePU = new Powerup(Powerup.DOUBLE_FIRE_PU);
But, not all at once, like this ^^ (unless you really wanted to add all three into your world at one time). You could actually have one randomly chosen to be placed in the world with this:
Powerup pu = new Powerup(Greenfoot.getRandomNumber(Powerup.images.length));
danpost danpost

2014/4/17

#
Another correction: on line 6 of the Powerup class, change 'GreenfootImage' to 'String'.
danpost danpost

2014/4/17

#
I decided to re-post the class with the corrections -- a basic universal Powerup class could look something like this:
import greenfoot.*;

public class Powerup extends Actor
{
    static final int SPEED_PU = 0, DRAG_PU = 1, AMMO_PU = 2; // add as needed giving unique number to each different type of powerup
    static final String[] images = { "speedPU.png", "dragPU.png", "ammoPU.png" }; // add as needed; keep the same order as the static final int fields above

    int puType; // a value from the list of static final ints above
    int lifespan = 300; // about 5 to 6 seconds

    // a Powerup object can be created with 'new Powerup(Powerup.SPEED_PU)' or similar
    public Powerup(int type)
    {
        puType = type;
        setImage(images[puType]);
    }

    public void act()
    {
        lifespan--;
        if (lifespan == 0) getWorld().removeObject(this);
    }

    public int getType()
    {
        return puType;
    }
}
GamesGrinder1998 GamesGrinder1998

2014/4/17

#
danpost wrote...
I decided to re-post the class with the corrections -- a basic universal Powerup class could look something like this:
import greenfoot.*;

public class Powerup extends Actor
{
    static final int SPEED_PU = 0, DRAG_PU = 1, AMMO_PU = 2; // add as needed giving unique number to each different type of powerup
    static final String[] images = { "speedPU.png", "dragPU.png", "ammoPU.png" }; // add as needed; keep the same order as the static final int fields above

    int puType; // a value from the list of static final ints above
    int lifespan = 300; // about 5 to 6 seconds

    // a Powerup object can be created with 'new Powerup(Powerup.SPEED_PU)' or similar
    public Powerup(int type)
    {
        puType = type;
        setImage(images[puType]);
    }

    public void act()
    {
        lifespan--;
        if (lifespan == 0) getWorld().removeObject(this);
    }

    public int getType()
    {
        return puType;
    }
}
so do i use any code from the matt guy
danpost danpost

2014/4/17

#
You will need code similar to what he posted for each different type of powerup. The big change is in determining which powerup was encountered (like I stated above). Each powerup may require a different method of implementation. For example, the shield will require a new Actor or a change in the image of the starfighter object. The doubleFire implementation will only need a boolean field to be changed. But, that boolean field needs to be checked when creating a shot so the proper image can be used on the shot fired. The speed changes the value of the int 'speed' and also sets a boolean. Each type will require a separate timer field to track their lifespans as each effect is temporary. For something like an Ammo powerup, one that adds a specific number of rounds that can be fired, no timer would be necessary (it just adds so many rounds to the arsenal).
GamesGrinder1998 GamesGrinder1998

2014/4/17

#
danpost wrote...
You will need code similar to what he posted for each different type of powerup. The big change is in determining which powerup was encountered (like I stated above). Each powerup may require a different method of implementation. For example, the shield will require a new Actor or a change in the image of the starfighter object. The doubleFire implementation will only need a boolean field to be changed. But, that boolean field needs to be checked when creating a shot so the proper image can be used on the shot fired. The speed changes the value of the int 'speed' and also sets a boolean. Each type will require a separate timer field to track their lifespans as each effect is temporary. For something like an Ammo powerup, one that adds a specific number of rounds that can be fired, no timer would be necessary (it just adds so many rounds to the arsenal).
so all i need is one class for the powerups and can you tell me which ones i need from the matt guy
danpost danpost

2014/4/17

#
GamesGrinder1998 wrote...
< Quote Omitted > so all I need is one class for the powerups and can you tell me which ones i need from the matt guy
That, which you quoted, gave you that information.
GamesGrinder1998 GamesGrinder1998

2014/4/17

#
danpost wrote...
GamesGrinder1998 wrote...
< Quote Omitted > so all I need is one class for the powerups and can you tell me which ones i need from the matt guy
That, which you quoted, gave you that information.
ok so to clear things up cos there is so much text im a bit confused about what to write, can you please state exactly which code i need for the powerup to work and tell me if i need to fill in anything
There are more replies on the next page.
1
2
3
4
5
6