danpost gave me code to do something, you can view the code above, we were working on the walls, where I used his code, maybe you can find a problem of how I put it in.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Player here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Player extends Actor
{
public int stopMoving = 0;
public void endTheGame()
{
Actor EndPad = getOneObjectInFront(EndPad.class);
if(EndPad != null)
{
stopMoving = 1;
}
}
public void act()
{
movement();
getPoints();
endTheGame();
}
public Player()
{
GreenfootImage myImage = getImage();
int myNewHeight = (int)myImage.getHeight()/3;
int myNewWidth = (int)myImage.getWidth()/3;
myImage.scale(myNewWidth, myNewHeight);
}
public void movement()
{
if(Greenfoot.isKeyDown("right"))
{
setRotation(0);
if(getOneObjectInFront(Wall.class)==null)
if(getOneObjectInFront(Maze.class)==null)
if(getOneObjectInFront(LaserWall.class)==null)
if(stopMoving == 0)
move(3);
}
if(Greenfoot.isKeyDown("left"))
{
setRotation(180);
if(getOneObjectInFront(Wall.class)==null)
if(getOneObjectInFront(Maze.class)==null)
if(getOneObjectInFront(LaserWall.class)==null)
if(stopMoving == 0)
move(3);
}
if(Greenfoot.isKeyDown("up"))
{
setRotation(270);
if(getOneObjectInFront(Wall.class)==null)
if(getOneObjectInFront(Maze.class)==null)
if(getOneObjectInFront(LaserWall.class)==null)
if(stopMoving == 0)
move(3);
}
if(Greenfoot.isKeyDown("down"))
{
setRotation(90);
if(getOneObjectInFront(Wall.class)==null)
if(getOneObjectInFront(Maze.class)==null)
if(getOneObjectInFront(LaserWall.class)==null)
move(3);
}
}
private Actor getOneObjectInFront(Class c)
{
GreenfootImage myImage = getImage();
int distanceToFront = myImage.getWidth();
int xOffset = (int)Math.ceil(distanceToFront*Math.cos(Math.toRadians(getRotation())));
int yOffset = (int)Math.ceil(distanceToFront*Math.sin(Math.toRadians(getRotation())));
return (getOneObjectAtOffset(xOffset, yOffset, c));
}
public void getPoints()
{
Actor Points = getOneIntersectingObject(Points.class);
if(Points != null)
{
World myWorld = getWorld();
myWorld.removeObject(Points);
Background1 background1 = (Background1)myWorld;
ScoreCounter scoreCounter = background1.getScoreCounter();
scoreCounter.addScore();
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Background1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Background1 extends World
{
ScoreCounter scoreCounter = new ScoreCounter();
public int stopMoving;
public int actCycles = -300;
public void countingCycles()
{
actCycles++;
if (actCycles == 30)
{
getScoreCounter().loseScore();
actCycles = 0;
if(stopMoving == 1)
{
actCycles = 31;
}
}
}
public void act()
{
countingCycles();
}
/**
* Adds objects for background1.
*/
public Background1()
{
super(1400, 800, 1);
outlineOfMaze();
mazeParts();
addLaserWalls();
prepare();
addCharacters();
addPoints();
}
public ScoreCounter getScoreCounter()
{
return scoreCounter;
}if (((Playeer)getObjects(Player.class).get(0)).stopMoving == 1)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Wall here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Wall extends Actor
{
public Wall()
{
GreenfootImage myImage = getImage();
int myNewHeight = (int)myImage.getHeight()/2;
int myNewWidth = (int)myImage.getWidth()/2;
myImage.scale(myNewWidth, myNewHeight);
}
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; x++) image.drawImage(tile, i*25, j*25);
setImage(image);
}
/**
* Act - do whatever the Wall wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
}
}private void outlineOfMaze()
{
addObject(new Wall(55, false), (0+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);
}/**
* Adds objects for background1.
*/
public Background1()
{
super(1400, 800, 1);
outlineOfMaze();
mazeParts();
addLaserWalls();
prepare();
addCharacters();
addPoints();
}public void outlineOfMaze()
{
addObject(new Wall(55, false), (0+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, (1+32)*25/2);
addObject(new Wall(31, true), 12+55*25, (0+31)*25/2);
}