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

2014/4/21

Can't get powerup to appear on screen

1
2
3
GamesGrinder1998 GamesGrinder1998

2014/4/22

#
danpost wrote...
Change line 25 in the Fireball class to this:
Powerup pu = (Powerup)getOneIntersectingObject(Powerup.class);
Also, I noticed something else, change line 27 (also in the Fireball class) to this:
if (pu.getType() == Powerup.SPEED_PU)
i was thinking that the world doesn't know that if a fireball hits it, to remove it and act (increase speed by 5)???
danpost danpost

2014/4/22

#
danpost wrote...
Finally, remove line 28 from the Starfighter class (the call to 'getSpeedBoost' in the 'act' method)
You did not do this.
danpost danpost

2014/4/23

#
GamesGrinder1998 wrote...
i was thinking that the world doesn't know that if a fireball hits it, to remove it and act (increase speed by 5)???
I sense confusion; but, I do not understand your question (if there is one).
GamesGrinder1998 GamesGrinder1998

2014/4/23

#
danpost wrote...
danpost wrote...
Finally, remove line 28 from the Starfighter class (the call to 'getSpeedBoost' in the 'act' method)
You did not do this.
i did that but it still doesn't work, my starfighters speed doesn't increase by 5
danpost danpost

2014/4/23

#
Well, the powerup does need to be removed when contacting the fireball. Change the Fireball 'checkSpeedPU' method to this:
private void checkSpeedPU()
{ 
    Powerup pu = (Powerup)getOneIntersectingObject(Powerup.class); 
    if (pu == null) return;
    if (pu.getType() == Powerup.SPEED_PU)
    {
        starfighter.getSpeedBoost();
        getWorld().removeObject(pu);
        getWorld().removeObject(this);
    }    
}
danpost danpost

2014/4/23

#
In your Starfighter 'checkKeys' method, change '5' to 'Speed' and '-5' to '-Speed'.
GamesGrinder1998 GamesGrinder1998

2014/4/23

#
danpost wrote...
In your Starfighter 'checkKeys' method, change '5' to 'Speed' and '-5' to '-Speed'.
thank you so much, it does work now....how long does the powerup stay long for
danpost danpost

2014/4/23

#
With a 'lifespan' of 400, maybe about 7 to 8 seconds, if your scenario is running at normal speeds (about midway on the speed slider).
GamesGrinder1998 GamesGrinder1998

2014/4/23

#
danpost wrote...
With a 'lifespan' of 400, maybe about 7 to 8 seconds, if your scenario is running at normal speeds (about midway on the speed slider).
ok, if i want to implement a shield powerup, can i just use setImage a new image if a fireball collects it and then the shield starfighter can just eat the enemies bullet, if so, what could the code look like
GamesGrinder1998 GamesGrinder1998

2014/4/23

#
danpost wrote...
With a 'lifespan' of 400, maybe about 7 to 8 seconds, if your scenario is running at normal speeds (about midway on the speed slider).
also about the shield powerup, how to make the starfighter return to the normal starfighter
danpost danpost

2014/4/23

#
GamesGrinder1998 wrote...
danpost wrote...
With a 'lifespan' of 400, maybe about 7 to 8 seconds, if your scenario is running at normal speeds (about midway on the speed slider).
ok, if i want to implement a shield powerup, can i just use setImage a new image if a fireball collects it and then the shield starfighter can just eat the enemies bullet, if so, what could the code look like
It would make more sense to have a separate actor for the shield. The starfighter object should have a field to reference it when it is active (null when not). If the collision code between the starfighter and enemy bullets is in the class of the enemy bullet, have the bullet check for shield before starfighter; if, it is in the class of the starfighter, the starfighter can check the value of the field to determine whether damage should be taken or not.
GamesGrinder1998 wrote...
danpost wrote...
With a 'lifespan' of 400, maybe about 7 to 8 seconds, if your scenario is running at normal speeds (about midway on the speed slider).
also about the shield powerup, how to make the starfighter return to the normal starfighter
You should have an int timer field for the shield ability (similar to the speed ability timer) and when it runs out, remove the shield and set the field referring to it to null. The movement of the shield should also be done in the starfighter class; not in the shield class -- if (shield != null) shield.setLocation(getX(), getY());
GamesGrinder1998 GamesGrinder1998

2014/4/23

#
danpost wrote...
GamesGrinder1998 wrote...
danpost wrote...
With a 'lifespan' of 400, maybe about 7 to 8 seconds, if your scenario is running at normal speeds (about midway on the speed slider).
ok, if i want to implement a shield powerup, can i just use setImage a new image if a fireball collects it and then the shield starfighter can just eat the enemies bullet, if so, what could the code look like
It would make more sense to have a separate actor for the shield. The starfighter object should have a field to reference it when it is active (null when not). If the collision code between the starfighter and enemy bullets is in the class of the enemy bullet, have the bullet check for shield before starfighter; if, it is in the class of the starfighter, the starfighter can check the value of the field to determine whether damage should be taken or not.
GamesGrinder1998 wrote...
danpost wrote...
With a 'lifespan' of 400, maybe about 7 to 8 seconds, if your scenario is running at normal speeds (about midway on the speed slider).
also about the shield powerup, how to make the starfighter return to the normal starfighter
You should have an int timer field for the shield ability (similar to the speed ability timer) and when it runs out, remove the shield and set the field referring to it to null. The movement of the shield should also be done in the starfighter class; not in the shield class -- if (shield != null) shield.setLocation(getX(), getY());
is it possible if you can type a basic format of the code and where it needs to go
danpost danpost

2014/4/23

#
GamesGrinder1998 wrote...
is it possible if you can type a basic format of the code and where it needs to go
You already have the basic format -- in how the other powerup is set up. The only difference is in what ability is applied when the powerup is picked up (and I gave you pretty much what you needed there in my last post.
GamesGrinder1998 GamesGrinder1998

2014/4/24

#
danpost wrote...
GamesGrinder1998 wrote...
is it possible if you can type a basic format of the code and where it needs to go
You already have the basic format -- in how the other powerup is set up. The only difference is in what ability is applied when the powerup is picked up (and I gave you pretty much what you needed there in my last post.
sorry this question is about a totally different question, my darkpower (enemies bullet) isn't still being removed at the edge, i asked you this a few weeks ago and i did what you told me but it doesn't work still, can you see a problem in my code and how can you fix it???
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class DarkPower here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DarkPower extends Actor
{
    public DarkPower(int rotation)
    {
        setRotation(rotation);
    }

    /**
     * Act - do whatever the DarkPower wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(2);
        tryToEat(); 
        atWorldEdge();
    }

    public void tryToEat()
    {
        if (canSee(Starfighter.class) )
        {
            eat(Starfighter.class);
            gameOver();
        }
        if (canSee(Starfighter2.class) )
        {
            eat(Starfighter2.class);
            gameOver();
            Label1 label1 = new Label1();
            getWorld().addObject(label1, 450, 350);
        } 
        if (canSee(Starfighter3.class) )
        {
            eat(Starfighter3.class);
            gameOver();
            Label2 label2 = new Label2();
            getWorld().addObject(label2, 450, 350);
        } 
    }

    public void gameOver()
    {
        Greenfoot.stop();
        GameOver gameover = new GameOver();
        getWorld().addObject(gameover, getWorld().getWidth()/2, getWorld().getHeight()/2);
        Greenfoot.playSound("gameover.wav");
        Greenfoot.stop();
        GameOver2 gameover2 = new GameOver2();
        getWorld().addObject(gameover2, getWorld().getWidth()/2, getWorld().getHeight()/2);
        Greenfoot.playSound("gameover.wav");
    }

    public boolean atWorldEdge()
    {
        if(getX() < 10 || getX() > getWorld().getWidth() + 10)
            return true;
        if(getY() < 10 || getY() > getWorld().getHeight() + 10)
            return true;
        else
            return false;
    }

    public boolean canSee(Class clss)
    {
        Actor actor = getOneObjectAtOffset(0, 0, clss);
            return actor != null;        
    }

    public void eat(Class clss)
    {
        Actor actor = getOneObjectAtOffset(0, 0, clss);
        if(actor != null) {
            getWorld().removeObject(actor);
        }
    }
}    
danpost danpost

2014/4/24

#
GamesGrinder1998 wrote...
i asked you this a few weeks ago and i did what you told me but it doesn't work still, can you see a problem in my code and how can you fix it???
Look at line 24. Can you tell me what that line is doing?
There are more replies on the next page.
1
2
3