61 lines
1.5 KiB
Java
61 lines
1.5 KiB
Java
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
|
|
|
/**
|
|
* Write a description of class SpikedPlattform here.
|
|
*
|
|
* @author (your name)
|
|
* @version (a version number or a date)
|
|
*/
|
|
public class SpikedPlattform extends Plattform
|
|
{
|
|
int SpikeCountdown;
|
|
boolean spikesActivated=false;
|
|
boolean isSpiked=false;
|
|
Spike[] hasSpikes= new Spike[5];
|
|
/**
|
|
* Act - do whatever the SpikedPlattform wants to do. This method is called whenever
|
|
* the 'Act' or 'Run' button gets pressed in the environment.
|
|
*/
|
|
public void act(int pSpikeCountdown)
|
|
{
|
|
// Add your action code here.
|
|
if(this.PlayerOnPlattform() && spikesActivated== false)
|
|
{
|
|
this.activateSpikes();
|
|
}
|
|
if(spikesActivated)
|
|
{
|
|
SpikeCountdown--;
|
|
}
|
|
if(SpikeCountdown==0)
|
|
{
|
|
this.spikeTheSurface();
|
|
}
|
|
if(isSpiked && this.PlayerOnPlattform())
|
|
{
|
|
Greenfoot.setWorld(new GameOverWorld());
|
|
}
|
|
super.act();
|
|
}
|
|
|
|
public void activateSpikes()
|
|
{
|
|
spikesActivated=true;
|
|
//Sound
|
|
//setImage
|
|
|
|
}
|
|
|
|
public void spikeTheSurface()
|
|
{
|
|
isSpiked=true;
|
|
MyWorld theWorld= (MyWorld) this.getWorld();
|
|
for(int i=0; i<3; i++)
|
|
{
|
|
theWorld.addObject(new Spike(2), this.getX()-this.getImage().getWidth()+ i*this.getImage().getWidth()/3, this.getX()-this.getImage().getHeight()/2);
|
|
}
|
|
//Sound
|
|
//setImage
|
|
}
|
|
|
|
} |