Hi there,
I am trying something daring (for me)
What I am trying to do is, when the imput is shift I would like to transfer to another level (Level0). I want to place the player in the same coords as in Level1. And when shift is pressed again, I would like to return to Level1.
So what I think i need is:
-2 world
-shift input goes to Level0(if in Level1) or Level1(if in level0) and no shift input stays in the current world.
-Remember coords.
Sofar I have this
My character has:
If the input is shift, I transport to another world on given coords (setLocation in Level0)
So if I want to teleport back to Level1, what would be the way to go.
Make a shift counter and every shift teleports to the other world or does anybody have another idea?
public class Level1 extends SWorld
{
public Level1()
{
this (new Alice());
}
public Level1(Alice alice)
{
super(800, 400, 1, 2400);
//Player
setMainActor(new Alice(),10,340);
mainActor.setLocation(200, 340);
//Background
GreenfootImage bg = new GreenfootImage("Test.jpg");
setScrollingBackground(bg);
//Counter
addObject(new Score(), 30, 10, false);
addObject(new ShroomScore(), 130, 10, false);
//Level blocks
for(int i=1;i<75;i++)
{
addObject(new Block(), i*30-15, 384,true);
}
}public class Level0 extends SWorld
{
public Level0()
{
this (new Alice());
}
public Level0(Alice alice)
{
super(600, 400, 1, 2400);
setMainActor(new Alice(),600,340);
mainActor.setLocation(200, 340);
//Background
GreenfootImage bg = new GreenfootImage("Forest.jpg");
setScrollingBackground(bg);
//Counter
addObject(new Score(), 30, 10, false);
addObject(new ShroomScore(), 130, 10, false);
//Blocks
for(int i=1;i<75;i++)
{
addObject(new Block(), i*30-15, 384,true);
}
}
}private int level;
public void act()
{
checkKeys();
checkFall();
CheckCollisionBlock();
}
private void checkKeys()
{
if (Greenfoot.isKeyDown("shift") )
{
if (level != 1) {
level = 0;
Greenfoot.setWorld(new Level1a(this));
}
else {
level = 1;
getWorld().removeObject(this);
Greenfoot.setWorld(new Level1(this));
}
}
private void checkFall()
{
if (onGround()) {
setVSpeed(0);
}
else {
fall();
}
}
public void CheckCollisionBlock()
{
// check below the actor
while(getOneObjectAtOffset(0, getImage().getHeight()/2+1, Block.class)!=null)
{
setLocation(getX(), getY()-1);
onGround=true;
vSpeed=0;
}
// check above the actor
while(getOneObjectAtOffset(0, -getImage().getHeight()/2-1, Block.class)!=null)
{
setLocation(getX(), getY()+1);
vSpeed = 0;
}
// check to right of actor
while(getOneObjectAtOffset(getImage().getWidth()/2+1, 0, Block.class)!=null)
{
setLocation(getX()-1, getY());
vSpeed = 0;
}
// check to left of actor
while(getOneObjectAtOffset(-getImage().getWidth()/2-1, 0, Block.class)!=null)
{
setLocation(getX()+1, getY());
vSpeed = 0;
}
}


