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

2017/4/23

I NEED IMMEDIATE HELP

7
8
9
10
11
Xmin_Terminator Xmin_Terminator

2017/5/4

#
I may need some help on a congratulations screen when you finish, last time I tried putting that, I got java out of memory and the scenario lagged to a consistent 2 acts a second roughly, even when changing the speed. the congratulations would also come up instant and not when I wanted it to. and for the co-ords, I used
addObject(new Wall(55, false), (2+55)*25/2, 12+0*25);
addObject(new Wall(55, false), (-1+56)*25/2, 12+31*25);
addObject(new Wall(31, true), 12+0*25, (0+31)*25/2);
addObject(new Wall(31, true), 12+55*25, (1+32)*25/2);
I think I just went the different direction to line them up if you know what I mean...
Xmin_Terminator Xmin_Terminator

2017/5/4

#
How do I get my score int to another actor, which is my Your Score actor.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class YourScore here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class YourScore extends Actor
{
    public int score;
    /**
     * Act - do whatever the YourScore wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        setImage(new GreenfootImage(" Your Score : " + score,60, Color.RED, Color.YELLOW));
    }    
}
This is what I used, but I need to do something like what you have done to get the int to another actor. My score always comes as 0 with this.
danpost danpost

2017/5/4

#
Replace 11 through 19 with this: and create the object with this (from Player class I presume):
YourScore yourScore = new YourScore(((Background1)getWorld()).getScoreCounter().getScore());
Xmin_Terminator Xmin_Terminator

2017/5/4

#
I am setting the image in the Your Score class, where I create it with text
Xmin_Terminator Xmin_Terminator

2017/5/4

#
I am setting the image in the actor class YourScore, but adding it through the world class. How do I do it like this? I want to add it inside the world class as I also have something that detects when the player hits the end there, but to set the image I have
setImage(new GreenfootImage(" Your Score : " + score,100, Color.RED, Color.YELLOW));
Which means that I need to state what the score is at the end of the maze so that it will display that, I am unsure on how to connect it up to this, all I need is to let the actor know what the score is at that given moment, so it will display the score.
danpost danpost

2017/5/5

#
My last post did not display properly. It was:
danpost wrote...
Replace 11 through 19 with this:
public YourScore(int score)
{
    setImage(new GreenfootImage(" Your Score : " + score,60, Color.RED, Color.YELLOW));
}
and create the object with this (from Player class I presume):
YourScore yourScore = new YourScore(((Background1)getWorld()).getScoreCounter().getScore());
If you are creating the YourScore object from the world class, then it will just be this:
YourScore yourScore = new YourScore(getScoreCounter().getScore());
Xmin_Terminator Xmin_Terminator

2017/5/5

#
Ok I believe that is all I need, Then I just neaten up the adding actors, and tile them to reduce the amount of actors to prevent errors, thanks, I will try this code as soon as I get home.
Xmin_Terminator Xmin_Terminator

2017/5/5

#
Error underlining .getScore() cannot find symbol - method getScore()
danpost danpost

2017/5/5

#
Xmin_Terminator wrote...
Error underlining .getScore() cannot find symbol - method getScore()
Show your ScoreCounter class codes.
Xmin_Terminator Xmin_Terminator

2017/5/5

#
public class ScoreCounter extends Actor
{
    public int score = 0;
    /**
     * Act - do whatever the ScoreCounter wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        setImage(new GreenfootImage("Score : " + score,60, Color.GREEN, Color.YELLOW));
    } 
    
    public void addScore()
    {
        score++;
    }
    
    public void loseScore()
    {
        score--;
    }
}
danpost danpost

2017/5/5

#
Add the following method to the ScoreCounter class:
public int getScore()
{
    return score;
}
Xmin_Terminator Xmin_Terminator

2017/5/6

#
Can you explain how this code works so that I can annotate it
public Wall(int count, boolean inverted) 
    {
        GreenfootImage tile = getImage(); 
        tile.scale(25, 25); 
        int x = 1, y = 1;        
        if (inverted) y = count; else x = count; 
        GreenfootImage image = new GreenfootImage(x*25, y*25);
        for (int j=0; j<y; j++) for (int i=0; i<x; i++) image.drawImage(tile, i*25, j*25);
        setImage(image);
    
Xmin_Terminator Xmin_Terminator

2017/5/6

#
This is how I think it works but I still can't understand the full thing
public Wall(int count, boolean inverted) // Creates an integer and boolean called count inverted, this code is to tile the actor to reduce the amount of actors in the world
    {
        GreenfootImage tile = getImage(); // Creates a variable called tile which represents the Image
        tile.scale(25, 25); // Sets the scale of the tile to 25 by 25 pixels in height and width
        int x = 1, y = 1; // Creates two integers which are x and y, both being 1 as of now
        if (inverted) y = count; else x = count; // If the boolean = inverted, set y to the same value as count but if boolean doesn't = inverted, set x to the same value as count
        GreenfootImage image = new GreenfootImage(x*25, y*25); // 
        for (int j=0; j<y; j++) for (int i=0; i<x; i++) image.drawImage(tile, i*25, j*25);
        setImage(image);
    
Xmin_Terminator Xmin_Terminator

2017/5/6

#
Also this code I can' really put into words for annotating
private LaserWall laser;
    public LaserButton(LaserWall actor)
    {
        laser = actor;
    }
    
    /**
     * Act - do whatever the LaserButton wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if(laser.getWorld() != null && isTouching (Player.class))
        {
            getWorld().removeObject(laser);
        }
    }
Xmin_Terminator Xmin_Terminator

2017/5/6

#
Is this annotated correctly?
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
 * The Player is what the person playing the game plays as.
 * It can Move Forwards, Backwards, Left and Right.
 * Its speed is 3 pixels an act.
 * The image is a Lobster
 * 
 * Daniel Pereira 
 * @version (a version number or a date)
 */
public class Player extends Actor
{
   public int stopMoving = 0; // A public integer that tells when the player reaches the end
   public void endTheGame()
   {
       Actor EndPad = getOneObjectInFront(EndPad.class); // Actor EndPad is set to null, and is not null when the Player has touched the EndPad
       if(EndPad != null) // If the EndPad is not null, meaning the Player has touched the EndPad
       {
          stopMoving = 1; // The public int stopMoving is now 1, which indicates the Player has touched the EndPad, to be used later
       }
   }
   
   public void act() // What methods are applied when the senario runs 
   {
       movement(); // The code to move the Player
       getPoints(); // The code to give Player points 
       endTheGame(); // The code to check if the Player has reached the End of the Maze
   }
    
   public Player() // Re-sizes the Player actors image so that it can fit inside the Maze
   {
        GreenfootImage myImage = getImage(); // Gets the Image and dimentions of the Image of the Player
        int myNewHeight = (int)myImage.getHeight()/3; // Creating a new integer that represents the new height, which is a third of the Image's original height
        int myNewWidth = (int)myImage.getWidth()/3; // Creating a new integer that represents the new width, which is a third of the Image's original width
        myImage.scale(myNewWidth, myNewHeight); // The Image is set to the new width and height, which has the dimetions a third of the original Image
   }
    
   public void movement() // Sets the keys to move in the different directions 
   {
       if(Greenfoot.isKeyDown("right")) // If the right arrow key is pressed
       {
          setRotation(0); // Set the rotation of the Player to 0, which is East
          if(getOneObjectInFront(Wall.class)==null) // Make sure there are no Walls infront of the Player before moving, otherwise the Player is not aloud to move
          if(getOneObjectInFront(Maze.class)==null) // Make sure there are no Maze walls infront of the Player before moving, otherwise the Player is not aloud to move
          if(getOneObjectInFront(LaserWall.class)==null) // Make sure there are no Lasers infront of the Player before moving, otherwise the Player is not aloud to move
          if(stopMoving == 0) // Make sure the Player has not reached the End, if the Player had reached the end then stopMoving == 1
          move(3); // Move in the direction set 3 pixels forward in this act
       }
       if(Greenfoot.isKeyDown("left")) // If the left arrow key is pressed
       {
          setRotation(180); // Set the rotation of the Player to 180, which is West
          if(getOneObjectInFront(Wall.class)==null) // Make sure there are no Walls infront of the Player before moving, otherwise the Player is not aloud to move
          if(getOneObjectInFront(Maze.class)==null) // Make sure there are no Maze walls infront of the Player before moving, otherwise the Player is not aloud to move
          if(getOneObjectInFront(LaserWall.class)==null) // Make sure there are no Lasers infront of the Player before moving, otherwise the Player is not aloud to move
          if(stopMoving == 0) // Make sure the Player has not reached the End, if the Player had reached the end then stopMoving == 1
          move(3); // Move in the direction set 3 pixels forward in this act
       }
       if(Greenfoot.isKeyDown("up"))
       {
          setRotation(270); // Set the rotation of the Player to 270, which is North
          if(getOneObjectInFront(Wall.class)==null) // Make sure there are no Walls infront of the Player before moving, otherwise the Player is not aloud to move
          if(getOneObjectInFront(Maze.class)==null) // Make sure there are no Maze walls infront of the Player before moving, otherwise the Player is not aloud to move
          if(getOneObjectInFront(LaserWall.class)==null) // Make sure there are no Lasers infront of the Player before moving, otherwise the Player is not aloud to move
          if(stopMoving == 0)// Make sure the Player has not reached the End, if the Player had reached the end then stopMoving == 1
          move(3); // Move in the direction set 3 pixels forward in this act
       }
       if(Greenfoot.isKeyDown("down"))
       {
          setRotation(90); // Set the rotation of the Player to 90, which is South
          if(getOneObjectInFront(Wall.class)==null) // Make sure there are no Walls infront of the Player before moving, otherwise the Player is not aloud to move
          if(getOneObjectInFront(Maze.class)==null) // Make sure there are no Maze walls infront of the Player before moving, otherwise the Player is not aloud to move
          if(getOneObjectInFront(LaserWall.class)==null) // Make sure there are no Lasers infront of the Player before moving, otherwise the Player is not aloud to move
          // The Player will not be able to move past the Mae actor anyway, so it is ok to let the player go down so that they can go fully on top of the EndPad actor
          move(3); // Move in the direction set 3 pixels forward in this act
       }
   }
   
   private Actor getOneObjectInFront(Class c) // A method that checks if there is any Actors infront of another Actor
   {
       GreenfootImage myImage = getImage(); // Gets the Player's image to be set as the variable myImage
       int distanceToFront = myImage.getWidth(); // Creates a new integer called distanceToFront which is the Image's width
       int xOffset = (int)Math.ceil(distanceToFront*Math.cos(Math.toRadians(getRotation()))); // I am unsure how exactly these lines work, I used help from a youtube video
       int yOffset = (int)Math.ceil(distanceToFront*Math.sin(Math.toRadians(getRotation()))); // The video was by Jim Stewart, @ mrstewartslessons.com
       return (getOneObjectAtOffset(xOffset, yOffset, c)); // reurns a certain offset that checks if there is an Object infront
   }
   
   public void getPoints() // Gives the Player Points when the Player runs over them
    {
       Actor Points = getOneIntersectingObject(Points.class); // Actor Points is set to null, and is not null when the Player has touched the EndPad
       if(Points != null) // If the Player has touched Points
       {
          World myWorld = getWorld(); // Gets commands that can only be used in a World class, so they can be used here in this Actor class, such as addObject or removeObject
          myWorld.removeObject(Points); // myWorld is the variable to get the World commands and this removes the Object Points when Player comes in contact with it
          Background1 background1 = (Background1)myWorld; // Gets Background1 so the variabls in this World class can be used, such as ScoreCounter 
          ScoreCounter scoreCounter = background1.getScoreCounter(); // Gets the ScoreCounter from the background so that it can be used to add Score to the Player
          scoreCounter.addScore(); // Adds 1 Score to the ScoreCounter
       }
   }  
}
There are more replies on the next page.
7
8
9
10
11