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
danpost danpost

2014/4/24

#
danpost wrote...
That is a totally different class you just posted. And it looks like these could move in any direction and could contact any edge of the world. Copy/paste the 'atWorldEdge' method from the other class into this one and change 'getX()<=0' back to 'atWorldEdge()'. The Fireball class is the one that can just use 'getX()<=0' from what I saw.
This quote is from the middle of this page from that discussion. My next post said to copy/paste the 'atWorldEdge' method into the class (which you did do). However, you change much more than that (and I am not talking about having it extend Actor) and that is where your problem lies (you removed an 'if' block from one of the methods and added line 24 above. My question is "why?" (I did not suggest you do that).
GamesGrinder1998 GamesGrinder1998

2014/4/25

#
danpost wrote...
danpost wrote...
That is a totally different class you just posted. And it looks like these could move in any direction and could contact any edge of the world. Copy/paste the 'atWorldEdge' method from the other class into this one and change 'getX()<=0' back to 'atWorldEdge()'. The Fireball class is the one that can just use 'getX()<=0' from what I saw.
This quote is from the middle of this page from that discussion. My next post said to copy/paste the 'atWorldEdge' method into the class (which you did do). However, you change much more than that (and I am not talking about having it extend Actor) and that is where your problem lies (you removed an 'if' block from one of the methods and added line 24 above. My question is "why?" (I did not suggest you do that).
so how should i fix it?
danpost danpost

2014/4/25

#
danpost wrote...
That is a totally different class you just posted. And it looks like these could move in any direction and could contact any edge of the world. Copy/paste the 'atWorldEdge' method from the other class into this one and change 'getX()<=0' back to 'atWorldEdge()'. The Fireball class is the one that can just use 'getX()<=0' from what I saw.
This quote is from the middle of this page from that discussion. My next post said to copy/paste the 'atWorldEdge' method into the class (which you did do). However, you change much more than that (and I am not talking about having it extend Actor) and that is where your problem lies (you removed an 'if' block from one of the methods and added line 24 above. My question is "why?" I did not suggest you do that).
GamesGrinder1998 GamesGrinder1998

2014/4/26

#
danpost wrote...
danpost wrote...
That is a totally different class you just posted. And it looks like these could move in any direction and could contact any edge of the world. Copy/paste the 'atWorldEdge' method from the other class into this one and change 'getX()<=0' back to 'atWorldEdge()'. The Fireball class is the one that can just use 'getX()<=0' from what I saw.
This quote is from the middle of this page from that discussion. My next post said to copy/paste the 'atWorldEdge' method into the class (which you did do). However, you change much more than that (and I am not talking about having it extend Actor) and that is where your problem lies (you removed an 'if' block from one of the methods and added line 24 above. My question is "why?" I did not suggest you do that).
i don't know if i did what you told me, here is the new code i
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(); 
        if(atWorldEdge())
        {
            getWorld().removeObject(this);
        }    
    }

    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);
        }
    }
}    
GamesGrinder1998 GamesGrinder1998

2014/4/27

#
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());
sorry i don't get most of it, what is the code for this???
You need to login to post a reply.
1
2
3