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

2012/3/11

power ups?

3
4
5
6
7
8
9
GamesGrinder1998 GamesGrinder1998

2014/4/19

#
danpost wrote...
I am not exactly sure what you are getting at. Are you saying that enemies will be killed (hopefully) by the starfighter on the side it is spawned on? can either ship fire at any enemy or only at those on its side? It might help if I had some context as to what you are trying to accomplish (in general, as well as specific to the issue).
well i put a wall in the middle of the world so each starfighter can't go to the other players side and each starfighter has the same amount of enemies to shoot, when i put that spawning code you told me it spawns in the other starfighters square; so when i used my starfighter2 to shoot enemies, some spawned in the other starfighter 1 box. do you get me, if so, how can i fix it
GamesGrinder1998 GamesGrinder1998

2014/4/19

#
danpost wrote...
GamesGrinder1998 wrote...
i deleted the fw from it but it still comes up with the message, do i write the png in caps
Renaming the file is not enough. The file must be saved into one of the supported formats. And yes, the way you write it must be consistent with the way the filename was saved for the file.
how would i save it in a supported format
danpost danpost

2014/4/19

#
What is the complete code you are using to get the x and y of where the enemies are spawned? What is your world size? What code are you using to initially place your enemy objects?
danpost danpost

2014/4/19

#
GamesGrinder1998 wrote...
how would i save it in a supported format
Fireworks may have a way to convert them into a PNG or JPEG. Load the file, and select 'File>Save As' and see what formats you can save in.
GamesGrinder1998 GamesGrinder1998

2014/4/19

#
danpost wrote...
What is the complete code you are using to get the x and y of where the enemies are spawned? What is your world size? What code are you using to initially place your enemy objects?
that is the complete code of the fireball and i used it to extend under player cos if i don't, for some reason my atWorldEdge, remove object won't work. Also my world size is 900 x 550
import greenfoot.*;  

public class Fireball extends Player
{
    private int direction, speed;  

    public Fireball(int dir)
    {
        direction = 270;
        speed = 7;
    }

    public void act() 
    {
        setRotation(direction);
        move(speed);
        disappear();
    }    

    public void disappear()
    {
        Actor BugEnemy;
        BugEnemy = getOneObjectAtOffset(0, 0, BugEnemy.class);
        Actor InsectEnemy;
        InsectEnemy = getOneObjectAtOffset(0, 0, InsectEnemy.class);
        Actor Bee;
        Bee = getOneObjectAtOffset(0, 0, Bee.class);
        Actor DarkPower;
        DarkPower = getOneObjectAtOffset(0, 0, DarkPower.class);
        if (BugEnemy != null)
        {
            World world;
            world = getWorld();
            MyGame mygame = (MyGame)world;
            Counter counter = mygame.getCounter();
            counter.addScore();
            world.removeObject(this);
            int x = 100+Greenfoot.getRandomNumber(500);  
            int y = 100+Greenfoot.getRandomNumber(300);  
            BugEnemy.setLocation(x, y); 
            return;
        }    

        if (InsectEnemy != null)
        {
            World world;
            world = getWorld();
            MyGame mygame = (MyGame)world;
            Counter counter = mygame.getCounter();
            counter.addScore();
            world.removeObject(this);
            int x = 100+Greenfoot.getRandomNumber(500);  
            int y = 100+Greenfoot.getRandomNumber(300);  
            InsectEnemy.setLocation(x, y); 
            return;
        } 

        if (Bee != null)
        {
            World world;
            world = getWorld();
            MyGame mygame = (MyGame)world;
            Counter counter = mygame.getCounter();
            counter.addScore();
            world.removeObject(this);
            int x = 100+Greenfoot.getRandomNumber(500);  
            int y = 100+Greenfoot.getRandomNumber(300);  
            Bee.setLocation(x, y); 
            return;
        } 

        if (DarkPower != null)
        {
            World world;
            world = getWorld();
            world.removeObject(DarkPower);
            world.removeObject(this);
            return;
        }  else {
            if (atWorldEdge())
            {
                getWorld().removeObject(this);
                return;
            } 
        }    
    } 

     
}    
GamesGrinder1998 GamesGrinder1998

2014/4/19

#
danpost wrote...
GamesGrinder1998 wrote...
how would i save it in a supported format
Fireworks may have a way to convert them into a PNG or JPEG. Load the file, and select 'File>Save As' and see what formats you can save in.
i tried that before you told me and it didn't work, i changed it to JPEG but it says couldn't find file
danpost danpost

2014/4/19

#
GamesGrinder1998 wrote...
that is the complete code of the fireball and i used it to extend under player cos if i don't, for some reason my atWorldEdge, remove object won't work. Also my world size is 900 x 550 < Code Omitted >
Since your fireballs are going straight up, you only need to check the top edge of the world. Change line 80 to 'if (getY()<=0)'. Then, have the class extend Actor.
GamesGrinder1998 GamesGrinder1998

2014/4/19

#
danpost wrote...
GamesGrinder1998 wrote...
that is the complete code of the fireball and i used it to extend under player cos if i don't, for some reason my atWorldEdge, remove object won't work. Also my world size is 900 x 550 < Code Omitted >
Since your fireballs are going straight up, you only need to check the top edge of the world. Change line 80 to 'if (getY()<=0)'. Then, have the class extend Actor.
thanks it did work but my enemies bullet is shooting down and it's also not removing the object at worlds edge, i input the code except change Y to X but it still doesn't work....here is the 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 Player
{
    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();
    }

    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);
        } else {
            if(getX()<=0)
            {
                getWorld().removeObject(this);
                return;
            }    
        }    
    } 

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

}    
danpost danpost

2014/4/19

#
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.
GamesGrinder1998 GamesGrinder1998

2014/4/19

#
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.
well i changed it back and it's still not removing it, here is the updated 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 Player
{
    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();
    }

    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);
        } else {
            if(atWorldEdge())
            {
                getWorld().removeObject(this);
                return;
            }    
        }    
    } 

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

}    
danpost danpost

2014/4/19

#
You need to copy/paste the 'atWorldEdge' method into this class.
GamesGrinder1998 GamesGrinder1998

2014/4/19

#
danpost wrote...
You need to copy/paste the 'atWorldEdge' method into this class.
i did and i changed it so it extends from actor, not player but it says cannot find symbol - method canSee (java.lang.class<Starfighter>), here is the updated 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();
    }

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

2014/4/19

#
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.
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.
i don't get it when you say "Are you using the Animal class also? If so, have them extend that class."
danpost danpost

2014/4/19

#
Well, what does the Player class extend? and if that answer is not the Actor class, what that that class extend? continue until the answer is the Actor class.
There are more replies on the next page.
3
4
5
6
7
8
9