import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Spike here. * * @author (your name) * @version (a version number or a date) */ public class Spike extends Actor { int speed; public Spike(int pSpeed) { speed=pSpeed; } /** * Act - do whatever the Spike 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. if(this.isTouching(Player.class)) { Greenfoot.setWorld(new GameOverWorld()); } this.bewege(); } public void loescheMich() { MyWorld theWorld= (MyWorld) this.getWorld(); theWorld.removeObject(this); } public void bewege() { this.setLocation(this.getX(), this.getY()+speed); MyWorld theWorld= (MyWorld) this.getWorld(); if(this.getY()>=theWorld.getHeight()-5) { this.loescheMich(); } } }