player can take damage
This commit is contained in:
parent
0b521ca667
commit
f36c861726
|
@ -1,6 +1,7 @@
|
|||
package main;
|
||||
|
||||
import ea.Knoten;
|
||||
import main.entities.Snake;
|
||||
import main.entities.player.Player;
|
||||
import main.maps.ImageMap;
|
||||
import main.maps.Map;
|
||||
|
@ -34,7 +35,11 @@ public class World extends Knoten {
|
|||
player = new Player();
|
||||
currentMap.getEntities().add(player);
|
||||
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);
|
||||
|
||||
|
|
|
@ -10,6 +10,9 @@ public class Snake extends LivingEntity {
|
|||
private static SheetLoader loader = new SheetLoader("/res/images/snake_spritesheet_calciumtrice.png", 32, 32,
|
||||
new int[] { 10, 10, 10, 10, 13, 8 });
|
||||
|
||||
private float damage = 0.1f;
|
||||
private boolean attackOnce;
|
||||
|
||||
public Snake() {
|
||||
super(loader.getFigur(0), "idle");
|
||||
|
||||
|
@ -38,6 +41,14 @@ public class Snake extends LivingEntity {
|
|||
if (lineOfSightClear(player)) {
|
||||
if (dist(player) < 1f) {
|
||||
zustandSetzen("attack");
|
||||
if (actionFigur.aktuelleFigur().aktuellesBild() == 6) {
|
||||
if (!attackOnce) {
|
||||
attackOnce = true;
|
||||
player.takeDamage(damage, this);
|
||||
}
|
||||
} else {
|
||||
attackOnce = false;
|
||||
}
|
||||
} else {
|
||||
Vektor toPlayer = vectorToEntity(player).normiert();
|
||||
velX += toPlayer.x * accelleration;
|
||||
|
@ -47,7 +58,8 @@ public class Snake extends LivingEntity {
|
|||
} else {
|
||||
if (!actionFigur.aktuellesVerhalten().equals("idle")) {
|
||||
zustandSetzen("lost_sight");
|
||||
if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length - 1) {
|
||||
if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length
|
||||
- 1) {
|
||||
zustandSetzen("idle");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,9 +26,6 @@ public class Player extends LivingEntity {
|
|||
spriteScale = 0.8f;
|
||||
posX = 7.5f;
|
||||
posY = 5.5f;
|
||||
|
||||
// XXX
|
||||
accelleration = 0.05f;
|
||||
|
||||
// unterschiedliche Animationsgeschwindigkeiten
|
||||
// für idle
|
||||
|
@ -100,20 +97,22 @@ public class Player extends LivingEntity {
|
|||
// auf Kollisionen prüfen
|
||||
checkTileCollisions(Main.instance.getWorld().getCurrentMap());
|
||||
|
||||
if (!onlyAttackOnceTrigger && actionFigur.aktuellesVerhalten().equals("swipe")
|
||||
&& actionFigur.aktuelleFigur().aktuellesBild() == 1) {
|
||||
onlyAttackOnceTrigger = true;
|
||||
ArrayList<Entity> entities = Main.instance.getWorld().getCurrentMap().getEntities();
|
||||
for (Entity e : entities) {
|
||||
if (e instanceof LivingEntity && e != this && e.dist(this) <= range) {
|
||||
LivingEntity le = (LivingEntity) e;
|
||||
if (le.getHP() > 0) {
|
||||
Vektor toE = vectorToEntity(le);
|
||||
toE = toE.normiert();
|
||||
if ((toE.x > 0 && !side) || (toE.x <= 0 && side)) {
|
||||
le.setVelX(le.getVelX() + toE.x * 0.1f);
|
||||
le.setVelY(le.getVelY() + toE.y * 0.1f);
|
||||
le.takeDamage(0.1f, this);
|
||||
if (!actionFigur.aktuellesVerhalten().equals(getDamageAnimationName())) {
|
||||
if (!onlyAttackOnceTrigger && actionFigur.aktuellesVerhalten().equals("swipe")
|
||||
&& actionFigur.aktuelleFigur().aktuellesBild() == 1) {
|
||||
onlyAttackOnceTrigger = true;
|
||||
ArrayList<Entity> entities = Main.instance.getWorld().getCurrentMap().getEntities();
|
||||
for (Entity e : entities) {
|
||||
if (e instanceof LivingEntity && e != this && e.dist(this) <= range) {
|
||||
LivingEntity le = (LivingEntity) e;
|
||||
if (le.getHP() > 0) {
|
||||
Vektor toE = vectorToEntity(le);
|
||||
toE = toE.normiert();
|
||||
if ((toE.x > 0 && !side) || (toE.x <= 0 && side)) {
|
||||
le.setVelX(le.getVelX() + toE.x * 0.1f);
|
||||
le.setVelY(le.getVelY() + toE.y * 0.1f);
|
||||
le.takeDamage(0.1f, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue