snake fix
This commit is contained in:
@@ -64,7 +64,10 @@ public abstract class LivingEntity extends Entity {
|
||||
*/
|
||||
protected void zustandSetzen(String name) {
|
||||
actionFigur.spiegelXSetzen(mirrored ? !side : side);
|
||||
if (!actionFigur.aktuellesVerhalten().equals(name)) {
|
||||
actionFigur.zustandSetzen(name);
|
||||
actionFigur.aktuelleFigur().animationsBildSetzen(0);
|
||||
}
|
||||
}
|
||||
|
||||
protected float getHealthPoints() {
|
||||
@@ -72,7 +75,8 @@ public abstract class LivingEntity extends Entity {
|
||||
}
|
||||
|
||||
public void takeDamage(float damage, Entity e) {
|
||||
actionFigur.zustandSetzen(getDamageAnimationName());
|
||||
zustandSetzen(getDamageAnimationName());
|
||||
actionFigur.aktuelleFigur().animationsBildSetzen(0);
|
||||
hp -= damage;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package main.entities;
|
||||
|
||||
import ea.Vektor;
|
||||
import main.Main;
|
||||
import main.SheetLoader;
|
||||
import main.entities.player.Player;
|
||||
|
||||
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 static SheetLoader loader = new SheetLoader("/res/images/snake_spritesheet_calciumtrice.png", 32, 32,
|
||||
new int[] { 10, 10, 10, 10, 13, 8 });
|
||||
|
||||
public Snake() {
|
||||
super(loader.getFigur(0), "idle");
|
||||
@@ -32,7 +34,29 @@ public class Snake extends LivingEntity {
|
||||
@Override
|
||||
protected void update() {
|
||||
Player player = Main.instance.getWorld().getCurrentMap().getPlayer();
|
||||
|
||||
if (!actionFigur.aktuellesVerhalten().equals(getDamageAnimationName())) {
|
||||
if (lineOfSightClear(player)) {
|
||||
if (dist(player) < 1f) {
|
||||
zustandSetzen("attack");
|
||||
} else {
|
||||
Vektor toPlayer = vectorToEntity(player).normiert();
|
||||
velX += toPlayer.x * accelleration;
|
||||
velY += toPlayer.y * accelleration;
|
||||
zustandSetzen("walk");
|
||||
}
|
||||
} else {
|
||||
if (!actionFigur.aktuellesVerhalten().equals("idle")) {
|
||||
zustandSetzen("lost_sight");
|
||||
if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length - 1) {
|
||||
zustandSetzen("idle");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length - 1) {
|
||||
zustandSetzen("walk");
|
||||
}
|
||||
}
|
||||
this.checkTileCollisions(Main.instance.getWorld().getCurrentMap());
|
||||
super.update();
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ public class Player extends LivingEntity {
|
||||
if ((toE.x > 0 && !side) || (toE.x <= 0 && side)) {
|
||||
le.setVelX(le.getVelX() + toE.x * 0.05f);
|
||||
le.setVelY(le.getVelY() + toE.y * 0.05f);
|
||||
le.takeDamage(0.4f, this);
|
||||
le.takeDamage(0.1f, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user