31 lines
724 B
Java
31 lines
724 B
Java
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.
|
|
this.setLocation(this.getX(), this.getY()+speed);
|
|
if(this.isTouching(Player.class))
|
|
{
|
|
Greenfoot.setWorld(new GameOverWorld());
|
|
}
|
|
}
|
|
}
|