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

2012/3/11

power ups?

4
5
6
7
8
9
GamesGrinder1998 GamesGrinder1998

2014/4/19

#
danpost wrote...
Are you using the Animal class also? If so, have them extend that class. When you moved the at world edge removal code from the 'tryToEat' method, you lost half the code to it. You no longer have an 'if' block or a 'getWorld().removeObject(this)' line anywhere.
do you mean extend Darkpower from Player which is extended from Actor, if so, i tried that without editing any code but it still does remove the object
danpost danpost

2014/4/19

#
What class are your 'canSee' and 'eat' methods in?
GamesGrinder1998 GamesGrinder1998

2014/4/19

#
danpost wrote...
What class are your 'canSee' and 'eat' methods in?
the starfighters
danpost danpost

2014/4/19

#
Copy/paste those methods into any class that uses them.
GamesGrinder1998 GamesGrinder1998

2014/4/19

#
danpost wrote...
Copy/paste those methods into any class that uses them.
sorry i meant the player, i did that but it doesn't seem to work, do i still put the darkpower under player which is extended from actor and what about my picture, do you have any other ideas to fix it
danpost danpost

2014/4/19

#
What errors are you getting now?
GamesGrinder1998 GamesGrinder1998

2014/4/19

#
danpost wrote...
What errors are you getting now?
for the darkpower to be removed at edge, it still didn't work, but it did compile. here is the code, i removed it so it wasn't under player but under Actor...Also abput the picture, it says it can't find the file speedPU.JPEG
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;        
    }

    /**
     * Try to eat an object of class 'clss'. This is only successful if there
     * is such an object where we currently are. Otherwise this method does
     * nothing.
     */
    public void eat(Class clss)
    {
        Actor actor = getOneObjectAtOffset(0, 0, clss);
        if(actor != null) {
            getWorld().removeObject(actor);
        }
    }
}    
danpost danpost

2014/4/20

#
Calling 'atWorldEdge()' by itself from the act method will do nothing but create a Boolean value that will be ignored. You need to supply the icons for your powerups and adjust the 'images' array to match their names.
GamesGrinder1998 GamesGrinder1998

2014/4/20

#
danpost wrote...
You need to supply the icons for your powerups and adjust the 'images' array to match their names.
what do you mean
GamesGrinder1998 GamesGrinder1998

2014/4/20

#
danpost wrote...
Calling 'atWorldEdge()' by itself from the act method will do nothing but create a Boolean value that will be ignored.
well i put it in the act method and it says method canSee in class DarkPower cannot be applied to given types; required: java.lang.Class; found: no arguments; reason: actual and formal arguments lists differ in length here is the edited code...
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();
        canSee();
        eat();
    }

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

2014/4/20

#
Look at line 74. The method canSee requires an argument, in this case a class. It returns a Boolean so it only makes sense to use it in an condition like 'if(canSee...)' like you have in tryToEat. With that, you don't need to call canSee in the act method alone. The "atWorldEdge" also returns a Boolean, so use it in a condition. For example turn if at world edge. Line 54 and 58 both stop the scenario. What is the reason?
danpost danpost

2014/4/20

#
GamesGrinder1998 wrote...
danpost wrote...
You need to supply the icons for your powerups and adjust the 'images' array to match their names.
what do you mean
I mean that the images for your powerups (the actor object that needs to be shot in order to acquire an ability, in your case) need to be added to your 'images' file and the names of those images need to be listed in the 'static final String images' array.
GamesGrinder1998 GamesGrinder1998

2014/4/20

#
Super_Hippo wrote...
Look at line 74. The method canSee requires an argument, in this case a class. It returns a Boolean so it only makes sense to use it in an condition like 'if(canSee...)' like you have in tryToEat. With that, you don't need to call canSee in the act method alone. The "atWorldEdge" also returns a Boolean, so use it in a condition. For example turn if at world edge. Line 54 and 58 both stop the scenario. What is the reason?
it stops because the game will still run in the background when it displays Gameover, do you know how to remove the objects
GamesGrinder1998 GamesGrinder1998

2014/4/20

#
Super_Hippo wrote...
Look at line 74. The method canSee requires an argument, in this case a class. It returns a Boolean so it only makes sense to use it in an condition like 'if(canSee...)' like you have in tryToEat. With that, you don't need to call canSee in the act method alone. The "atWorldEdge" also returns a Boolean, so use it in a condition. For example turn if at world edge. Line 54 and 58 both stop the scenario. What is the reason?
how would i write it?
GamesGrinder1998 GamesGrinder1998

2014/4/20

#
danpost wrote...
GamesGrinder1998 wrote...
danpost wrote...
You need to supply the icons for your powerups and adjust the 'images' array to match their names.
what do you mean
I mean that the images for your powerups (the actor object that needs to be shot in order to acquire an ability, in your case) need to be added to your 'images' file and the names of those images need to be listed in the 'static final String images' array.
i got it to work but how come up it didn't comeup on the screen, how long did i have to wait
There are more replies on the next page.
4
5
6
7
8
9