53 lines
1.2 KiB
Java
53 lines
1.2 KiB
Java
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
|
|
|
/**
|
|
* Write a description of class MovingPlattform here.
|
|
*
|
|
* @author (your name)
|
|
* @version (a version number or a date)
|
|
*/
|
|
public class MovingPlattform extends Plattform
|
|
{
|
|
int speed;
|
|
|
|
public MovingPlattform(int pSpeed)
|
|
{
|
|
speed= pSpeed;
|
|
}
|
|
|
|
/**
|
|
* Act - do whatever the MovingPlattform wants to do. This method is called whenever
|
|
* the 'Act' or 'Run' button gets pressed in the environment.
|
|
*/
|
|
public void act()
|
|
{
|
|
// Add your action code here.
|
|
this.bewege();
|
|
this.bewegeSpielerMit();
|
|
super.act();
|
|
}
|
|
|
|
public void bewege()
|
|
{
|
|
MyWorld theWorld= (MyWorld) this.getWorld();
|
|
this.setLocation(this.getX()+speed, this.getY());
|
|
if(this.getX()<5 || this.getX()>=theWorld.getWidth()-5)
|
|
{
|
|
speed=speed*(-1);
|
|
}
|
|
|
|
}
|
|
|
|
public void bewegeSpielerMit()
|
|
{
|
|
if(this.PlayerOnPlattform())
|
|
{
|
|
Actor DerSpieler = this.getOneObjectAtOffset(0, -40, Player.class);
|
|
if(DerSpieler!=null)
|
|
{
|
|
DerSpieler.setLocation(DerSpieler.getX()+speed, DerSpieler.getY());
|
|
}
|
|
}
|
|
}
|
|
}
|