Snakes drop coins now

This commit is contained in:
Asecave
2021-06-30 19:01:57 +02:00
parent d440ad8f67
commit 58a41725eb
7 changed files with 38 additions and 8 deletions

Binary file not shown.

View File

@@ -17,7 +17,7 @@ public class Coin extends AnimatedEntity {
actionFigur.neuerZustand(loader.getFigur(0), "gold"); actionFigur.neuerZustand(loader.getFigur(0), "gold");
actionFigur.neuerZustand(loader.getFigur(1), "silver"); actionFigur.neuerZustand(loader.getFigur(1), "silver");
actionFigur.neuerZustand(loader.getFigur(2), "bronze"); actionFigur.neuerZustand(loader.getFigur(2), "bronze");
zustandSetzen("gold"); zustandSetzen("bronze");
posX = 4f; posX = 4f;
posY = 4f; posY = 4f;

View File

@@ -233,6 +233,14 @@ public abstract class Entity implements Ticker {
posY = y; posY = y;
} }
public float getPosX() {
return posX;
}
public float getPosY() {
return posY;
}
public void deleteEntity() { public void deleteEntity() {
deleteEntity = true; deleteEntity = true;
} }

View File

@@ -21,8 +21,9 @@ public abstract class LivingEntity extends AnimatedEntity {
actionFigur.zustandSetzen(getDeathAnimationName()); actionFigur.zustandSetzen(getDeathAnimationName());
velX = 0; velX = 0;
velY = 0; velY = 0;
if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length - 1) { if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length - 1 && !isReadyToDelete()) {
deleteEntity(); deleteEntity();
onDeath();
} }
} }
super.update(); super.update();
@@ -40,4 +41,7 @@ public abstract class LivingEntity extends AnimatedEntity {
public abstract String getDeathAnimationName(); public abstract String getDeathAnimationName();
public abstract String getDamageAnimationName(); public abstract String getDamageAnimationName();
protected void onDeath() {
}
} }

View File

@@ -80,4 +80,16 @@ public class Snake extends LivingEntity {
public String getDamageAnimationName() { public String getDamageAnimationName() {
return "damage"; 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);
}
}
} }

View File

@@ -18,6 +18,7 @@ public abstract class Map extends Knoten implements Ticker {
protected Tile[][] tiles; // Die Tiles der map in einem 2D Array. protected Tile[][] tiles; // Die Tiles der map in einem 2D Array.
private ArrayList<Entity> entities; private ArrayList<Entity> entities;
private boolean started;
public DoorTile topDoor; public DoorTile topDoor;
public DoorTile leftDoor; public DoorTile leftDoor;
@@ -72,6 +73,9 @@ public abstract class Map extends Knoten implements Ticker {
public void addAnimatedEntity(AnimatedEntity e) { public void addAnimatedEntity(AnimatedEntity e) {
entities.add(e); entities.add(e);
add(e.actionFigur); add(e.actionFigur);
if (started) {
Main.instance.manager.anmelden(e, 20);
}
} }
public abstract Map clone(); public abstract Map clone();
@@ -122,6 +126,7 @@ public abstract class Map extends Knoten implements Ticker {
Main.instance.manager.anmelden(e, 20); Main.instance.manager.anmelden(e, 20);
} }
} }
started = true;
} }
public void stop() { public void stop() {
@@ -142,6 +147,7 @@ public abstract class Map extends Knoten implements Ticker {
Main.instance.manager.abmelden(e); Main.instance.manager.abmelden(e);
} }
} }
started = false;
} }
public void connectDoors(DoorTile door, DoorTile door2) { public void connectDoors(DoorTile door, DoorTile door2) {

View File

@@ -12,16 +12,16 @@ public class TestWorld extends World {
Map m2 = maps[3].clone(); Map m2 = maps[3].clone();
getCurrentMap().connectDoors(getCurrentMap().leftDoor, m2.leftDoor); 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++) { for (int i = 0; i < 15; i++) {
Coin c = new Coin(); Coin c = new Coin();
c.setPosX(i * 0.5f + 4); c.setPosX(i * 0.5f + 4);
getCurrentMap().addAnimatedEntity(c); getCurrentMap().addAnimatedEntity(c);
} }
for (int i = 0; i < 5; i++) {
Snake s = new Snake();
s.setPosX((float) (Math.random() * 5 + 2));
getCurrentMap().addAnimatedEntity(s);
}
} }
} }