This is the code from myWorld.
This is the code from the Score.
This is the code from Man.
I hope you can help me.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MyWorld extends World
{
int started=0;
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(800, 600, 1);
prepare();
spawnObjects();
spawnBoxes();
}
public int game=1;
public void start()
{
if(game==1)
{
started=1;
addObject(new spawner(), 0, 0);
addObject(new Score(), 400, 100);
}
}
public void Game1()
{
game=0;
addObject(new Boss1(), 400, 300);
}
public void Boss1()
{
addObject(new Thief1(), 750, 489);
}
public void GameOver()
{
End end = new End();
addObject(end,400,250);
}
private void prepare()
{
Line line = new Line();
addObject(line,352,596);
line.setLocation(352,589);
Mans mans = new Mans();
addObject(mans,155,496);
mans.setLocation(400,489);
}
public void spawnObjects()
{
addObject(new Toutorial(), 400, 100);
}
int x;
public void spawnBoxes()
{
if (started==1)
{
x = Greenfoot.getRandomNumber(30);
if (x==0)
{
addObject(new Boxes(), 550, 550);
addObject(new Walls(), 650, 532);
addObject(new Walls(), 750, 532);
}
if (x==1)
{
addObject(new Boxes(), 750, 550);
}
if (x==2)
{
addObject(new Boxes(), 650, 550);
addObject(new Walls(), 750, 532);
}
if (x==3)
{
addObject(new BadBoxes(), 750, 550);
}
if (x==4)
{
addObject(new Boxes(), 550, 550);
addObject(new BadWalls(), 650, 532);
addObject(new BadWalls(), 750, 532);
}
if (x==5)
{
addObject(new BadBoxes(), 550, 550);
addObject(new BadWalls(), 650, 532);
addObject(new BadWalls(), 750, 532);
}
if (x==6)
{
addObject(new BadBoxes(), 550, 550);
addObject(new Walls(), 650, 532);
addObject(new Walls(), 750, 532);
}
if (x==7)
{
addObject(new BadBoxes(), 550, 550);
addObject(new BadWalls(), 650, 532);
addObject(new Walls(), 750, 532);
}
if (x==8)
{
addObject(new BadBoxes(), 550, 550);
addObject(new Walls(), 650, 532);
addObject(new BadWalls(), 750, 532);
}
if (x==9)
{
addObject(new Boxes(), 550, 550);
addObject(new BadWalls(), 650, 532);
addObject(new Walls(), 750, 532);
}
if (x==10)
{
addObject(new Boxes(), 550, 550);
addObject(new Walls(), 650, 532);
addObject(new BadWalls(), 750, 532);
}
if (x==11)
{
addObject(new BadBoxes(), 650, 550);
addObject(new BadWalls(), 750, 532);
}
if (x==12)
{
addObject(new BadBoxes(), 650, 550);
addObject(new Walls(), 750, 532);
}
if (x==13)
{
addObject(new Boxes(), 650, 550);
addObject(new BadWalls(), 750, 532);
}
if (x==14)
{
addObject(new Boxes(), 650, 550);
addObject(new Boxes(), 750, 550);
}
if (x==15)
{
addObject(new BadBoxes(), 650, 550);
addObject(new BadBoxes(), 750, 550);
}
if (x==16)
{
addObject(new BadBoxes(), 650, 550);
addObject(new Boxes(), 750, 550);
}
if (x==17)
{
addObject(new Boxes(), 650, 550);
addObject(new BadBoxes(), 750, 550);
}
if (x==18)
{
addObject(new Coin(), 750, 325);
}
if (x==19)
{
addObject(new Barrels(), 716,487);
}
if (x==20)
{
addObject(new Barrels(), 716,487);
addObject(new Barrels(), 716,319);
}
if (x==21)
{
addObject(new Barrels(), 714,490);
addObject(new Barrels(), 586,490);
addObject(new Barrels(), 619,322);
}
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Score here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Score extends Actor
{
/**
* Act - do whatever the Score wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
this.countScore();
}
public int score=0;
public int start=1;
public void countScore()
{
if (start==1)
{
score++;
}
setImage(new GreenfootImage("Score: " + score, 48, Color.WHITE, Color.BLACK));
if(score==2000)
{
MyWorld m = (MyWorld) getWorld();
m.Game1();
start=0;
}
}
}
import greenfoot.*;
public class Mans extends Actor
{
public int ySpeed;
public int groundLevel=489;
private boolean pressed;
public void act()
{
boolean onGround = false;
ySpeed++;
setLocation(getX(), getY()+ySpeed);
// at ground level
if (getY() > groundLevel)
{
ySpeed = 0;
setLocation(getX(), groundLevel);
onGround = true;
}
// hitting box
Actor object = getOneIntersectingObject(Objects.class);
if (object != null)
{
int yDir = (int)Math.signum(ySpeed);
setLocation(getX(), object.getY()-yDir*((object.getImage().getHeight()+getImage().getHeight())/2+1));
ySpeed = 0;
if (yDir > 0) onGround = true;
}
// jumping
if (onGround && Greenfoot.isKeyDown("up"))
{
ySpeed = -15;
}
// firing weapon
if (pressed == Greenfoot.isKeyDown("space"))
{
pressed = !pressed;
if (pressed) getWorld().addObject(new Weapons(), getX()+80, getY()-25);
}
//die
if (this.isAtEdge())
{ this.removeTouching(Objects.class);
this.setImage("Mans3.png");
this.setLocation(400, 400);
Greenfoot.playSound("game-over.wav");
Greenfoot.stop();
MyWorld m = (MyWorld) getWorld();
m.GameOver();
}
//get a Coin
if(this.isTouching(Coin.class))
{
this.removeTouching(Coin.class);
this.setLocation(400, 350);
Greenfoot.playSound("pop.wav");
}
//start Boss Battle
if(this.isTouching(Boss1.class))
{
this.removeTouching(Boss1.class);
this.setLocation(400, 350);
MyWorld m = (MyWorld) getWorld();
m.Boss1();
}
}
}
