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

2016/4/12

How to continue Counter score to different worlds and make a leaderboard score when win or lose?

1
2
danpost danpost

2016/4/13

#
Sir_brandon_ wrote...
k fixed it but now when i compile the worlds it wont let me open them and the boxes in both actor and world have lines like this ///////// through them
Are you getting any type of error message? if so, what? Can you manually create a Playerx1 object?
Sir_brandon_ Sir_brandon_

2016/4/13

#
no im getting no error messages, everything is playing but the boxes have lines through them and i cant click on new (what ever the worlds called)() or new (what ever the Actors called)() because it is saying i need to compile it but i compile it and it wont let me select the world to change worlds (from what i said at the begining About - i cant click on new (what ever the worlds called)() or new (what ever the Actors called)() - ). Edit: also cant manually create new Playerx1() or new Player_p1()
Sir_brandon_ Sir_brandon_

2016/4/13

#
don't worry all fixed i just reset greenfoot
Sir_brandon_ Sir_brandon_

2016/4/13

#
just to make sure everything is correct heres my world
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Playerx1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Playerx1 extends World
{
    public Counter counter; //save the counter in a field to get access from outside
    /**
     * Constructor for objects of class CrabWorld.
     * 
     */
    public Playerx1()
    { 
        super(1000, 660, 1);
        prepare();

    }

    public void act()
    {
        if (getObjects(Player_p1.class).isEmpty()){
            Greenfoot.setWorld(new GameOverScreen());
        }
        if (getObjects(Peasant.class).isEmpty()){
            Greenfoot.setWorld(new level_2(counter));
        }
    }

    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepare()
    {

        //when creating
        counter = new Counter();
        addObject(counter, 54, 624);

        Player_p1 player_p1 = new Player_p1(counter);
        addObject(player_p1, 240, 304);
heres my Player
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

public class Player_p1 extends Actor
{
    private Counter counter;

    public Player_p1(Counter pointCounter)
    {
        counter = pointCounter;
    }

    public void act() 
    {
        moveAndTurn();
        eat();

    }

    public void moveAndTurn()
    {
        if (Greenfoot.isKeyDown("a"))
        {
            turn(-7);
        } 
        if (Greenfoot.isKeyDown("d"))
        {
            turn(7);
        }
        if (Greenfoot.isKeyDown("w"))
        {
            move(7);
        }
        if (Greenfoot.isKeyDown("s"))
        {
            move(-7);
        }
    }

    public void eat()
    {
        Actor peasant;
        peasant = getOneObjectAtOffset(0, 0, Peasant.class);
        if (peasant != null)
        {
            World world;
            world = getWorld();
            world.removeObject(peasant);
            counter.add(1);
            Greenfoot.playSound("eating.wav");
        }
    }
}
You need to login to post a reply.
1
2