Hi, i don't know how to make my smiley to teleport between two pipe classes/image(leftpipe and rightpipe).
I want my smiley when it goes/touch leftpipe it will transport to rightpipe and reverse.
I would be glad with some help.
I have came this far.
I will put here my world and my smiley. leftpipe and rightpipe are emty.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class escaper here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Smiley extends Actor
{
/**
* Act - do whatever the escaper wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public int x = 1;
public int y = 0;
public void act()
{
move();
if(Greenfoot.isKeyDown("left"))
{
x = -1;
y = 0;
}
if(Greenfoot.isKeyDown("right"))
{
x = 1;
y = 0;
}
if(Greenfoot.isKeyDown("up") )
{
y = -1;
x = 0;
}
if(Greenfoot.isKeyDown("down"))
{
y = 1;
x = 0;
}
}
public void move()
{
setLocation(getX()+x,getY()+y);
}
}
and
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Back here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Back extends World
{
public Back()
{
// Create a new world with 20x20 cells with a cell size of 10x10 pixels.
super(295, 200, 2);
addObject(new Smiley(), 20, 100);
addObject(new Rightpipe(), 20, Greenfoot.getRandomNumber(200));
addObject(new Leftpipe(), 280, Greenfoot.getRandomNumber(200));
}
}