I want to create something like an elevator, but I dont have an working idea yet. Can someone give me an example/ideas how to create it?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Elevator_Plattform here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Elevator_Plattform extends Ground
{
private int speed = 0;
private int count = 0;
boolean hitByProjectile = false;
private int direction = 1;
private int verticalSpeed = 3;
private int verticalSpeed2 = -3;
private int horizontalSpeed = 0;
/**
* Act - do whatever the Elevator_Plattform wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
moveAround(horizontalSpeed, verticalSpeed);
count++;
}
public void moveAround(int changeX, int changeY)
{
int x = getX();
int y = getY();
int newX = x + changeX;
int newY = y + changeY;
setLocation(newX,newY);
count = (count+1)%120;
if (count == 0) speed = -speed;
{
move(horizontalSpeed, verticalSpeed2);
}
}
public void move(int changeX, int changeY)
{
int x = getX();
int y = getY();
int newX = x + changeX;
int newY = y + changeY;
setLocation(newX,newY);
}
}
public class Elevator_Platform extends Ground
{
private int speed = 3;
public void act()
{
setLocation(getX(), getY()+speed);
count = (count+1)%120;
if (count == 0) speed = -speed;
}
}public class Elevator_Platform extends Ground
{
private int speed = 3;
public void act()
{
setLocation(getX(), getY()+speed);
Actor player = getOneIntersectingObject(Player.class);
if (player != null) player.setLocation(player.getX(), player.getY()+speed);
count = (count+1)%120;
if (count == 0) speed = -speed;
}
}