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

2018/6/6

incompatible types: java.lang.Class<lifeboard> cannot be converted into greenfoot.Actor

1
2
3
4
5
ogy2014 ogy2014

2018/6/6

#
ill taake it out thats where i thought you wanted me to put it originally but i forgot to take it out
ogy2014 ogy2014

2018/6/6

#
it keeps on freezing whenever they get to the edge
ogy2014 ogy2014

2018/6/6

#
i just noticed that the freezing is just the game pausing but the error message still comes
danpost danpost

2018/6/6

#
ogy2014 wrote...
i just noticed that the freezing is just the game pausing but the error message still comes
Put the return statement where I suggested.
ogy2014 ogy2014

2018/6/6

#
it worked but you were telling me to do something on the unrevised version
ogy2014 ogy2014

2018/6/6

#
thank you for all the help i am almost finished
danpost danpost

2018/6/6

#
ogy2014 wrote...
it worked but you were telling me to do something on the unrevised version
You had not posted the revised version at that point.
ogy2014 ogy2014

2018/6/6

#
i had 37 minutes though
ogy2014 ogy2014

2018/6/6

#
i don't get this now for no reason my invader class has stopped working
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
 * Write a description of class Invader here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Invader extends Actor
{
    /**
     * Act - do whatever the Invader wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    { 
        Actor playermissile = getOneIntersectingObject(PlayerMissile.class);
        if (getY() == getWorld().getHeight() -1)
        {                       
            Space space = (Space) getWorld();
            Lifeboard lBoard = space.lifeboard;
            getWorld().removeObject(this);
            getWorld().removeObject(lBoard);
            setLocation(400,300);
            this.setImage("gameover.jpg");          
            Greenfoot.stop();
            return;
        }
        if(playermissile != null)
        {
            Space space = (Space) getWorld();
            Scoreboard sBoard = space.scoreboard; 
            space.scoreboard.add(10);
            getWorld().removeObject(playermissile);
            getWorld().removeObject(this);
        }
    }

    public boolean invaderBelow()
    {
        if(getOneObjectAtOffset(0, 60, Invader.class) == null)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
}
java.lang.NullPointerException at Invader.act(Invader.java:22) at greenfoot.core.Simulation.actActor(Simulation.java:604) at greenfoot.core.Simulation.runOneLoop(Simulation.java:562) at greenfoot.core.Simulation.runContent(Simulation.java:221) at greenfoot.core.Simulation.run(Simulation.java:211) this is the problematic line at Invader.act(Invader.java:22)
danpost danpost

2018/6/6

#
Do not use an Invader as a object for game over. Create a new class for a GameOver object. If you must, just remove line 21.
ogy2014 ogy2014

2018/6/7

#
Do i really need a gameover object, i get that it might be messier but i only have 3 instances where a gameover can take place, when life points hit zero, when you touch an invader and when an invader touches the bottom of the screen, i am open to tidying it up so if it will really help then i could just set the print order so that gameover is at the front and make a counter to test for all those and make it so when the counter increases by one the gameover pops up. Shouldn't it work just by removing the object at the front of the print order, setting the position to the centre and setting the image as gameover. Unfortunately i cant really do it now as my improved code is at home and i forgot my memory stick so i will check back after school.
danpost danpost

2018/6/7

#
ogy2014 wrote...
Do i really need a gameover object, i get that it might be messier but i only have 3 instances where a gameover can take place, when life points hit zero, when you touch an invader and when an invader touches the bottom of the screen, i am open to tidying it up so if it will really help then i could just set the print order so that gameover is at the front and make a counter to test for all those and make it so when the counter increases by one the gameover pops up. Shouldn't it work just by removing the object at the front of the print order, setting the position to the centre and setting the image as gameover. Unfortunately i cant really do it now as my improved code is at home and i forgot my memory stick so i will check back after school.
If you used an Invader object as a game over object, the other Invader objects may appear in front of it and that is something that paint order cannot change. Also, it is not a true behavior for an Invader type object to mutate into a game over object. As another point, if the Run button was clicked to resume the game afterwards, the game over object would then act like an Invader object. With a separate GameOver object, you can prevent the game from being resumed by overriding the started method of the World class:
public void started()
{
    if (!getObjects(GameOver.class).isEmpty()) Greenfoot.stop();
}
ogy2014 ogy2014

2018/6/7

#
I have the GameOver class but now i need the code i attempted to modify my scoreboard code but because of my lack of knowledge i only managed to do this (not sure what some of it does or if its only needed in a standard scoreboard).
import greenfoot.*;
 
public class GameOver extends Actor
{
    int score = 0;
    private GreenfootImage gameover;
    
    public GameOver()
    {
        updateBoard();
    }
     
    private void updateBoard()
    {
        if (score == 1)
        {
            setLocation(400,300);
            setImage(gameover);
            return;
        } 
    }   
     
    public void add(int addVal)
    {
        score += addVal; updateBoard();
    }
     
    public int getScore()
    {
        return score;
    }

    public void addedToWorld(World world)
    {
        gameover = new GreenfootImage("gameover.png");
    }
}
ogy2014 ogy2014

2018/6/7

#
i forgot the code to stop the game but i can add that in afterwards
ogy2014 ogy2014

2018/6/7

#
is this gameover code sufficient
        Actor playermissile = getOneIntersectingObject(PlayerMissile.class);
        if (getY() == getWorld().getHeight() -1)
        {                       
            Space space = (Space) getWorld();
            GameOver gBoard = space.gameover;
            getWorld().removeObject(this);
            space.gameover.add(1);
            return;
        }
There are more replies on the next page.
1
2
3
4
5