Snakes drop coins now
This commit is contained in:
parent
d440ad8f67
commit
58a41725eb
Binary file not shown.
|
@ -17,7 +17,7 @@ public class Coin extends AnimatedEntity {
|
|||
actionFigur.neuerZustand(loader.getFigur(0), "gold");
|
||||
actionFigur.neuerZustand(loader.getFigur(1), "silver");
|
||||
actionFigur.neuerZustand(loader.getFigur(2), "bronze");
|
||||
zustandSetzen("gold");
|
||||
zustandSetzen("bronze");
|
||||
|
||||
posX = 4f;
|
||||
posY = 4f;
|
||||
|
|
|
@ -232,6 +232,14 @@ public abstract class Entity implements Ticker {
|
|||
posX = x;
|
||||
posY = y;
|
||||
}
|
||||
|
||||
public float getPosX() {
|
||||
return posX;
|
||||
}
|
||||
|
||||
public float getPosY() {
|
||||
return posY;
|
||||
}
|
||||
|
||||
public void deleteEntity() {
|
||||
deleteEntity = true;
|
||||
|
|
|
@ -21,8 +21,9 @@ public abstract class LivingEntity extends AnimatedEntity {
|
|||
actionFigur.zustandSetzen(getDeathAnimationName());
|
||||
velX = 0;
|
||||
velY = 0;
|
||||
if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length - 1) {
|
||||
if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length - 1 && !isReadyToDelete()) {
|
||||
deleteEntity();
|
||||
onDeath();
|
||||
}
|
||||
}
|
||||
super.update();
|
||||
|
@ -40,4 +41,7 @@ public abstract class LivingEntity extends AnimatedEntity {
|
|||
|
||||
public abstract String getDeathAnimationName();
|
||||
public abstract String getDamageAnimationName();
|
||||
|
||||
protected void onDeath() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,4 +80,16 @@ public class Snake extends LivingEntity {
|
|||
public String getDamageAnimationName() {
|
||||
return "damage";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeath() {
|
||||
int count = (int) (Math.random() * 3);
|
||||
for (int i = 0; i < count; i++) {
|
||||
Coin c = new Coin();
|
||||
float x = posX + (float) Math.random() * width - width / 2;
|
||||
float y = posY + (float) Math.random() * height - height / 2;
|
||||
c.setPos(x, y);
|
||||
Main.instance.getWorld().getCurrentMap().addAnimatedEntity(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ public abstract class Map extends Knoten implements Ticker {
|
|||
|
||||
protected Tile[][] tiles; // Die Tiles der map in einem 2D Array.
|
||||
private ArrayList<Entity> entities;
|
||||
private boolean started;
|
||||
|
||||
public DoorTile topDoor;
|
||||
public DoorTile leftDoor;
|
||||
|
@ -72,6 +73,9 @@ public abstract class Map extends Knoten implements Ticker {
|
|||
public void addAnimatedEntity(AnimatedEntity e) {
|
||||
entities.add(e);
|
||||
add(e.actionFigur);
|
||||
if (started) {
|
||||
Main.instance.manager.anmelden(e, 20);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Map clone();
|
||||
|
@ -122,6 +126,7 @@ public abstract class Map extends Knoten implements Ticker {
|
|||
Main.instance.manager.anmelden(e, 20);
|
||||
}
|
||||
}
|
||||
started = true;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
|
@ -142,6 +147,7 @@ public abstract class Map extends Knoten implements Ticker {
|
|||
Main.instance.manager.abmelden(e);
|
||||
}
|
||||
}
|
||||
started = false;
|
||||
}
|
||||
|
||||
public void connectDoors(DoorTile door, DoorTile door2) {
|
||||
|
|
|
@ -12,16 +12,16 @@ public class TestWorld extends World {
|
|||
Map m2 = maps[3].clone();
|
||||
getCurrentMap().connectDoors(getCurrentMap().leftDoor, m2.leftDoor);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Snake s = new Snake();
|
||||
s.setPosX((float) (Math.random() * 5 + 2));
|
||||
getCurrentMap().addAnimatedEntity(s);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 15; i++) {
|
||||
Coin c = new Coin();
|
||||
c.setPosX(i * 0.5f + 4);
|
||||
getCurrentMap().addAnimatedEntity(c);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Snake s = new Snake();
|
||||
s.setPosX((float) (Math.random() * 5 + 2));
|
||||
getCurrentMap().addAnimatedEntity(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue