[Disallowed URL] Hi guys,
I'm working on a schoolproject.
I have a problem I have made a game with 3 levels. In level1 I have on player. In level 2 I have 2 players. I want to get from level 2 tot level 3, so I need the 2players in level2 tot get tot a house where they then get to level 3, But It's not working fyi I have 1class with 2 id (id==1 and id==2).
I want it to be like fireboy & watergirl, but use the same house instead of 2
At the bottom is the code which will get me to level 3.
.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class LittleRedcap here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class LittleRedCap extends BaseClass
{
private int speed=3;
private int id;
public LittleRedCap (int idParameter)
{
this.id=idParameter;
if(id==2)
{
GreenfootImage myImage = getImage();
int myNewHeight = (int) myImage.getHeight()/2;
int myNewWidth = (int) myImage.getWidth()/2;
myImage.scale (myNewWidth, myNewHeight);
}
if(id==3)
{
GreenfootImage myImage = getImage();
int myNewHeight = (int) myImage.getHeight()/2;
int myNewWidth = (int) myImage.getWidth()/2;
myImage.scale (myNewWidth, myNewHeight);
}
}
public void act()
{
keys();
pickFlowers();
Announcement();
nextLevel(2);
nextLevel(3);
}
public void pickFlowers()
{
if(canSee(Flower.class))
{
ScoreBoard scoreboard = (ScoreBoard) getWorld().getObjects(ScoreBoard.class).get(0);
super.score=scoreboard.getScore();
Flower flower = (Flower) getOneObjectAtOffset(0, 0, Flower.class);
if(flower.getPoisonous())
{
super.score = super.score-5;
}else {
super.score++;
}
removeObject(Flower.class);
World world = getWorld();
world.removeObjects(world.getObjects(ScoreBoard.class));
world.addObject (new ScoreBoard(super.score), 85,25);
}
}
public void Announcement()
{
if(this.score<0)
{World world = getWorld();
world.addObject (new Announcement("Game Over"), 300,300);
Greenfoot.stop();
}
}
/**
* With the arrow keys, you are able to control Little Redcap
*/
public void keys()
{
if (this.id==1)
{
if (Greenfoot.isKeyDown("left"))
{
setLocation(getX() - speed, getY());
setImage("redcapleft.gif");
}
if (Greenfoot.isKeyDown("right"))
{
setLocation(getX() + speed, getY());
setImage("redcapright.gif");
}
if (Greenfoot.isKeyDown("up"))
{
setLocation(getX(), getY() - speed);
setImage("redcapbehind.gif");
}
if (Greenfoot.isKeyDown("down"))
{
setLocation(getX(), getY() + speed);
setImage("redcapfront.gif");
}
}
if (this.id==2)
{
if (Greenfoot.isKeyDown("a"))
{
setLocation(getX() - speed, getY());
setImage("redcapleft.gif");
GreenfootImage myImage = getImage();
int myNewHeight = (int) myImage.getHeight()/2;
int myNewWidth = (int) myImage.getWidth()/2;
myImage.scale (myNewWidth, myNewHeight);
}
if (Greenfoot.isKeyDown("d"))
{
setLocation(getX() + speed, getY());
setImage("redcapright.gif");
GreenfootImage myImage = getImage();
int myNewHeight = (int) myImage.getHeight()/2;
int myNewWidth = (int) myImage.getWidth()/2;
myImage.scale (myNewWidth, myNewHeight);
}
if (Greenfoot.isKeyDown("w"))
{
setLocation(getX(), getY() - speed);
setImage("redcapbehind.gif");
GreenfootImage myImage = getImage();
int myNewHeight = (int) myImage.getHeight()/2;
int myNewWidth = (int) myImage.getWidth()/2;
myImage.scale (myNewWidth, myNewHeight);
}
if (Greenfoot.isKeyDown("s"))
{
setLocation(getX(), getY() + speed);
setImage("redcapfront.gif");
GreenfootImage myImage = getImage();
int myNewHeight = (int) myImage.getHeight()/2;
int myNewWidth = (int) myImage.getWidth()/2;
myImage.scale (myNewWidth, myNewHeight);
}
}
if (this.id==3)
{
if (Greenfoot.isKeyDown("left"))
{
setLocation(getX() - speed, getY());
setImage("redcapleft.gif");
GreenfootImage myImage = getImage();
int myNewHeight = (int) myImage.getHeight()/2;
int myNewWidth = (int) myImage.getWidth()/2;
myImage.scale (myNewWidth, myNewHeight);
}
if (Greenfoot.isKeyDown("right"))
{
setLocation(getX() + speed, getY());
setImage("redcapright.gif");
GreenfootImage myImage = getImage();
int myNewHeight = (int) myImage.getHeight()/2;
int myNewWidth = (int) myImage.getWidth()/2;
myImage.scale (myNewWidth, myNewHeight);
}
if (Greenfoot.isKeyDown("up"))
{
setLocation(getX(), getY() - speed);
setImage("redcapbehind.gif");
GreenfootImage myImage = getImage();
int myNewHeight = (int) myImage.getHeight()/2;
int myNewWidth = (int) myImage.getWidth()/2;
myImage.scale (myNewWidth, myNewHeight);
}
if (Greenfoot.isKeyDown("down"))
{
setLocation(getX(), getY() + speed);
setImage("redcapfront.gif");
GreenfootImage myImage = getImage();
int myNewHeight = (int) myImage.getHeight()/2;
int myNewWidth = (int) myImage.getWidth()/2;
myImage.scale (myNewWidth, myNewHeight);
}
}
}
public void setLocation(int x, int y)
{
int oldX = getX();
int oldY = getY();
super.setLocation(x, y);
if(!getIntersectingObjects(Wall.class).isEmpty())
{
super.setLocation(oldX, oldY);
}
}
public int getId()
{
return this.id;
}
public void nextLevel (int levelParameter)
{
if(levelParameter ==2) {
if ((score ==10) && (canSee(House.class)))
{
World level2 = new Level2();
Greenfoot.setWorld(level2);
//setImage();
}
}
if(levelParameter ==3) {
if ((score==20) && (canSee(House.class)))
{
World level3 = new Level3();
Greenfoot.setWorld(level3);
//setImage();
}
}
}
}
