corrent dist method
This commit is contained in:
@@ -11,8 +11,8 @@ public class Main extends Game {
|
|||||||
|
|
||||||
private World world;
|
private World world;
|
||||||
|
|
||||||
public static final int WIDTH = 1440; // Fensterbreite
|
public static final int WIDTH = 1000; // Fensterbreite
|
||||||
public static final int HEIGHT = 1056; // Fensterhöhe
|
public static final int HEIGHT = 800; // Fensterhöhe
|
||||||
|
|
||||||
public Main() {
|
public Main() {
|
||||||
super(WIDTH, HEIGHT);
|
super(WIDTH, HEIGHT);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import main.entities.Entity;
|
|||||||
import main.entities.Player;
|
import main.entities.Player;
|
||||||
import main.entities.Snake;
|
import main.entities.Snake;
|
||||||
import main.entities.Spider;
|
import main.entities.Spider;
|
||||||
import main.maps.Corridor;
|
|
||||||
import main.maps.Map;
|
import main.maps.Map;
|
||||||
import main.maps.TestMap;
|
import main.maps.TestMap;
|
||||||
|
|
||||||
@@ -14,7 +13,7 @@ import main.maps.TestMap;
|
|||||||
*/
|
*/
|
||||||
public class World extends Knoten {
|
public class World extends Knoten {
|
||||||
|
|
||||||
public static final int SCALE_FACTOR = 6; // Der Basis Zoomfaktor
|
public static final int SCALE_FACTOR = 4; // Der Basis Zoomfaktor
|
||||||
public static final int SCALE = SCALE_FACTOR * Tile.getSize(); // Eine Gameunit ist so viele pixel lang
|
public static final int SCALE = SCALE_FACTOR * Tile.getSize(); // Eine Gameunit ist so viele pixel lang
|
||||||
|
|
||||||
private Map currentMap; // Die Map die aktuell angezeigt werden soll.
|
private Map currentMap; // Die Map die aktuell angezeigt werden soll.
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public abstract class Entity implements Ticker {
|
|||||||
* @return die entifernung zu diesem Entity
|
* @return die entifernung zu diesem Entity
|
||||||
*/
|
*/
|
||||||
public float dist(Entity e) {
|
public float dist(Entity e) {
|
||||||
return (float) Math.sqrt(e.posX * e.posX + posY * posY);
|
return (float) Math.sqrt((e.posX - posX) * (e.posX - posX) + (e.posY - posY) * (e.posY - posY));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package main.entities;
|
package main.entities;
|
||||||
|
|
||||||
import ea.Farbe;
|
|
||||||
import ea.Taste;
|
import ea.Taste;
|
||||||
import main.Main;
|
import main.Main;
|
||||||
import main.SheetLoader;
|
import main.SheetLoader;
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ import main.Tile;
|
|||||||
|
|
||||||
public class Snake extends LivingEntity {
|
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, 10 });
|
private static SheetLoader loader = new SheetLoader("/res/images/snake_spritesheet_calciumtrice.png", 32, 32,
|
||||||
|
new int[] { 10, 10, 10, 10, 10 });
|
||||||
|
|
||||||
public Snake() {
|
public Snake() {
|
||||||
super(loader.getFigur(0), "idle");
|
super(loader.getFigur(0), "idle");
|
||||||
@@ -40,17 +41,24 @@ public class Snake extends LivingEntity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nearestPlayer != null && lineOfSightClear(nearestPlayer)) {
|
if (nearestPlayer != null && lineOfSightClear(nearestPlayer)) {
|
||||||
|
if (dist(nearestPlayer) < 1f) {
|
||||||
|
zustandSetzen("attack");
|
||||||
|
} else {
|
||||||
Vektor toPlayer = new Vektor(nearestPlayer.posX - posX, nearestPlayer.posY - posY);
|
Vektor toPlayer = new Vektor(nearestPlayer.posX - posX, nearestPlayer.posY - posY);
|
||||||
toPlayer = toPlayer.normiert();
|
toPlayer = toPlayer.normiert();
|
||||||
velX += toPlayer.x * accelleration;
|
velX += toPlayer.x * accelleration;
|
||||||
velY += toPlayer.y * accelleration;
|
velY += toPlayer.y * accelleration;
|
||||||
zustandSetzen("walk");
|
zustandSetzen("walk");
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
} else
|
||||||
|
|
||||||
|
{
|
||||||
if (actionFigur.aktuellesVerhalten().equals("walk")) {
|
if (actionFigur.aktuellesVerhalten().equals("walk")) {
|
||||||
zustandSetzen("lost_sight");
|
zustandSetzen("lost_sight");
|
||||||
}
|
}
|
||||||
if (actionFigur.aktuellesVerhalten().equals("lost_sight")
|
if (actionFigur.aktuellesVerhalten().equals("lost_sight") && actionFigur.aktuelleFigur()
|
||||||
&& actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length - 1) {
|
.aktuellesBild() == actionFigur.aktuelleFigur().animation().length - 1) {
|
||||||
actionFigur.aktuelleFigur().animationsBildSetzen(0);
|
actionFigur.aktuelleFigur().animationsBildSetzen(0);
|
||||||
zustandSetzen("idle");
|
zustandSetzen("idle");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user