mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-04-14 14:43:33 +02:00
Beispiel Raindops OOP
Raindrops OOP ist die objektorientierte Umsetzung eines kleines Spiels, bei dem Regentropfen mit einem Eimer gefangen werden müssen. Das Beispiel zeigt die Umsetzung eines etwas komplexeren Spiels mittels des ShapesLayer. Eine nicht-objektorientierte Variante, die den DrawingLayer nutzt, wird im Beispiel zm_raindrops zu finden sein.
This commit is contained in:
45
examples/zm_raindrops_oop/Drop.java
Normal file
45
examples/zm_raindrops_oop/Drop.java
Normal file
@@ -0,0 +1,45 @@
|
||||
import schule.ngb.zm.Updatable;
|
||||
import schule.ngb.zm.shapes.Picture;
|
||||
|
||||
public class Drop extends Picture implements Updatable {
|
||||
|
||||
public static final double SPEED_PIXELPERSECOND = 100.0;
|
||||
|
||||
public static final double SPEED_INCREASE = 1.2;
|
||||
|
||||
public static final int START_Y = 40;
|
||||
|
||||
|
||||
private double speed = SPEED_PIXELPERSECOND;
|
||||
|
||||
private boolean active = false;
|
||||
|
||||
public Drop() {
|
||||
super(0, 0, "raindrop.png");
|
||||
hide();
|
||||
}
|
||||
|
||||
public void increaseSpeed() {
|
||||
this.speed *= SPEED_INCREASE;
|
||||
}
|
||||
|
||||
public void activate() {
|
||||
this.active = true;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
moveTo(random(Raindrops.GAME_BORDER, Raindrops.GAME_WIDTH - Raindrops.GAME_BORDER), START_Y);
|
||||
show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( double delta ) {
|
||||
y += speed * delta;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user