player can take damage
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package main;
|
package main;
|
||||||
|
|
||||||
import ea.Knoten;
|
import ea.Knoten;
|
||||||
|
import main.entities.Snake;
|
||||||
import main.entities.player.Player;
|
import main.entities.player.Player;
|
||||||
import main.maps.ImageMap;
|
import main.maps.ImageMap;
|
||||||
import main.maps.Map;
|
import main.maps.Map;
|
||||||
@@ -34,7 +35,11 @@ public class World extends Knoten {
|
|||||||
player = new Player();
|
player = new Player();
|
||||||
currentMap.getEntities().add(player);
|
currentMap.getEntities().add(player);
|
||||||
currentMap.add(player.actionFigur);
|
currentMap.add(player.actionFigur);
|
||||||
Main.instance.manager.anmelden(player, 20);
|
|
||||||
|
Snake s = new Snake();
|
||||||
|
currentMap.getEntities().add(s);
|
||||||
|
currentMap.add(s.actionFigur);
|
||||||
|
currentMap.registerEntities();
|
||||||
|
|
||||||
add(currentMap);
|
add(currentMap);
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ public class Snake extends LivingEntity {
|
|||||||
private static SheetLoader loader = new SheetLoader("/res/images/snake_spritesheet_calciumtrice.png", 32, 32,
|
private static SheetLoader loader = new SheetLoader("/res/images/snake_spritesheet_calciumtrice.png", 32, 32,
|
||||||
new int[] { 10, 10, 10, 10, 13, 8 });
|
new int[] { 10, 10, 10, 10, 13, 8 });
|
||||||
|
|
||||||
|
private float damage = 0.1f;
|
||||||
|
private boolean attackOnce;
|
||||||
|
|
||||||
public Snake() {
|
public Snake() {
|
||||||
super(loader.getFigur(0), "idle");
|
super(loader.getFigur(0), "idle");
|
||||||
|
|
||||||
@@ -38,6 +41,14 @@ public class Snake extends LivingEntity {
|
|||||||
if (lineOfSightClear(player)) {
|
if (lineOfSightClear(player)) {
|
||||||
if (dist(player) < 1f) {
|
if (dist(player) < 1f) {
|
||||||
zustandSetzen("attack");
|
zustandSetzen("attack");
|
||||||
|
if (actionFigur.aktuelleFigur().aktuellesBild() == 6) {
|
||||||
|
if (!attackOnce) {
|
||||||
|
attackOnce = true;
|
||||||
|
player.takeDamage(damage, this);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
attackOnce = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Vektor toPlayer = vectorToEntity(player).normiert();
|
Vektor toPlayer = vectorToEntity(player).normiert();
|
||||||
velX += toPlayer.x * accelleration;
|
velX += toPlayer.x * accelleration;
|
||||||
@@ -47,7 +58,8 @@ public class Snake extends LivingEntity {
|
|||||||
} else {
|
} else {
|
||||||
if (!actionFigur.aktuellesVerhalten().equals("idle")) {
|
if (!actionFigur.aktuellesVerhalten().equals("idle")) {
|
||||||
zustandSetzen("lost_sight");
|
zustandSetzen("lost_sight");
|
||||||
if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length - 1) {
|
if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length
|
||||||
|
- 1) {
|
||||||
zustandSetzen("idle");
|
zustandSetzen("idle");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,6 @@ public class Player extends LivingEntity {
|
|||||||
posX = 7.5f;
|
posX = 7.5f;
|
||||||
posY = 5.5f;
|
posY = 5.5f;
|
||||||
|
|
||||||
// XXX
|
|
||||||
accelleration = 0.05f;
|
|
||||||
|
|
||||||
// unterschiedliche Animationsgeschwindigkeiten
|
// unterschiedliche Animationsgeschwindigkeiten
|
||||||
// für idle
|
// für idle
|
||||||
loader.getFigur(0).animationsGeschwindigkeitSetzen(200);
|
loader.getFigur(0).animationsGeschwindigkeitSetzen(200);
|
||||||
@@ -100,6 +97,7 @@ public class Player extends LivingEntity {
|
|||||||
// auf Kollisionen prüfen
|
// auf Kollisionen prüfen
|
||||||
checkTileCollisions(Main.instance.getWorld().getCurrentMap());
|
checkTileCollisions(Main.instance.getWorld().getCurrentMap());
|
||||||
|
|
||||||
|
if (!actionFigur.aktuellesVerhalten().equals(getDamageAnimationName())) {
|
||||||
if (!onlyAttackOnceTrigger && actionFigur.aktuellesVerhalten().equals("swipe")
|
if (!onlyAttackOnceTrigger && actionFigur.aktuellesVerhalten().equals("swipe")
|
||||||
&& actionFigur.aktuelleFigur().aktuellesBild() == 1) {
|
&& actionFigur.aktuelleFigur().aktuellesBild() == 1) {
|
||||||
onlyAttackOnceTrigger = true;
|
onlyAttackOnceTrigger = true;
|
||||||
@@ -120,6 +118,7 @@ public class Player extends LivingEntity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDeathAnimationName() {
|
public String getDeathAnimationName() {
|
||||||
|
|||||||
Reference in New Issue
Block a user