Merge branch 'master' of https://git.ngb.schule/Tim/Zoelda
51
Zoelda/src/main/DoorTile.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package main;
|
||||||
|
|
||||||
|
import ea.Ticker;
|
||||||
|
import main.entities.player.Player;
|
||||||
|
import main.maps.ImageMap;
|
||||||
|
|
||||||
|
public class DoorTile extends Tile implements Ticker {
|
||||||
|
|
||||||
|
public static final int TOP = 0;
|
||||||
|
public static final int BOTTOM = 1;
|
||||||
|
public static final int LEFT = 2;
|
||||||
|
public static final int RIGHT = 3;
|
||||||
|
|
||||||
|
private int side;
|
||||||
|
private DoorTile connected;
|
||||||
|
private ImageMap map;
|
||||||
|
|
||||||
|
public DoorTile(float x, float y, ImageMap map) {
|
||||||
|
super(Tile.DOOR, x, y);
|
||||||
|
this.map = map;
|
||||||
|
|
||||||
|
Main.instance.tickerAnmelden(this, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (Main.instance.getWorld() != null) {
|
||||||
|
Player player = Main.instance.getWorld().getPlayer();
|
||||||
|
float dist = player.dist(posX + 0.5f, posY + 0.5f);
|
||||||
|
if (dist < 0.5f) {
|
||||||
|
Main.instance.getWorld().changeMap(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSide() {
|
||||||
|
return side;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSide(int side) {
|
||||||
|
this.side = side;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnectedDoor(DoorTile door) {
|
||||||
|
connected = door;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageMap getMap() {
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,7 +31,7 @@ public class HUD extends Knoten implements Ticker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
float localHp = Main.instance.getWorld().getCurrentMap().getPlayer().getHealthPoints();
|
float localHp = Main.instance.getWorld().getPlayer().getHP();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class Main extends Game {
|
|||||||
private HUD hud;
|
private HUD hud;
|
||||||
|
|
||||||
public Main() {
|
public Main() {
|
||||||
super(World.SCALE * 15, World.SCALE * 11);
|
super(World.SCALE * 15, World.SCALE * 11, 16);
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
// Welt initialisieren und Spieler hinzufügen
|
// Welt initialisieren und Spieler hinzufügen
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import ea.internal.gra.PixelFeld;
|
|||||||
|
|
||||||
public class SheetLoader {
|
public class SheetLoader {
|
||||||
|
|
||||||
private static Figur[] figures;
|
private Figur[] figures;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Macht aus einem Spritesheet Figuren.
|
* Macht aus einem Spritesheet Figuren.
|
||||||
|
|||||||
@@ -20,37 +20,46 @@ public class Tile extends Knoten {
|
|||||||
public static final int STONE_WALL = 3;
|
public static final int STONE_WALL = 3;
|
||||||
public static final int STONE_WALL_BOTTOM = 4;
|
public static final int STONE_WALL_BOTTOM = 4;
|
||||||
public static final int STONE_FLOOR = 5;
|
public static final int STONE_FLOOR = 5;
|
||||||
|
public static final int VOID = 6;
|
||||||
|
public static final int DOOR = 7;
|
||||||
|
|
||||||
private Bild img; // Bild, das gerendert wird
|
private Bild img; // Bild, das gerendert wird
|
||||||
private int id; // Die id dises Tiles
|
private int id; // Die id dises Tiles
|
||||||
|
protected float posX, posY; // Position dieses Tiles
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id
|
* @param id
|
||||||
* @param x - X-Koordinate in units
|
* @param x - X-Koordinate in units
|
||||||
* @param y - Y-Koordinate in units
|
* @param y - Y-Koordinate in units
|
||||||
*/
|
*/
|
||||||
public Tile(int id, float x, float y) {
|
public Tile(int id, float x, float y) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
posX = x;
|
||||||
|
posY = y;
|
||||||
|
|
||||||
// Das Bild laden
|
if (id == VOID) {
|
||||||
try {
|
BufferedImage buff = new BufferedImage(World.SCALE, World.SCALE, BufferedImage.TYPE_INT_RGB);
|
||||||
BufferedImage buff = ImageIO.read(Tile.class.getResourceAsStream(getPathFromId(id)));
|
img = new Bild(x * World.SCALE, y * World.SCALE, buff);
|
||||||
// Gras hat 8 verschiedene Texturen von denen eine zufällig ausgewählt werden
|
} else {
|
||||||
// muss.
|
// Das Bild laden
|
||||||
if (id == GRASS) {
|
try {
|
||||||
buff = buff.getSubimage(16 * (int) (Math.random() * 8), 0, 16, 16);
|
BufferedImage buff = ImageIO.read(Tile.class.getResourceAsStream(getPathFromId(id)));
|
||||||
|
// Gras hat 8 verschiedene Texturen von denen eine zufällig ausgewählt werden
|
||||||
|
// muss.
|
||||||
|
if (id == GRASS) {
|
||||||
|
buff = buff.getSubimage(16 * (int) (Math.random() * 8), 0, 16, 16);
|
||||||
|
}
|
||||||
|
// if (id == STONE_FLOOR) {
|
||||||
|
// buff = buff.getSubimage(16 * (int) (Math.random() * 10), 0, 16, 16);
|
||||||
|
// }
|
||||||
|
// Skalieren
|
||||||
|
BufferedImage scaled = new BufferedImage(World.SCALE, World.SCALE, BufferedImage.TYPE_INT_RGB);
|
||||||
|
scaled.getGraphics().drawImage(buff, 0, 0, World.SCALE, World.SCALE, null);
|
||||||
|
img = new Bild(x * World.SCALE, y * World.SCALE, scaled);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (id == STONE_FLOOR) {
|
|
||||||
buff = buff.getSubimage(16 * (int) (Math.random() * 10), 0, 16, 16);
|
|
||||||
}
|
|
||||||
// Skalieren
|
|
||||||
BufferedImage scaled = new BufferedImage(World.SCALE, World.SCALE, BufferedImage.TYPE_INT_RGB);
|
|
||||||
scaled.getGraphics().drawImage(buff, 0, 0, World.SCALE, World.SCALE, null);
|
|
||||||
img = new Bild(x * World.SCALE, y * World.SCALE, scaled);
|
|
||||||
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
// Bild zu EA hinzufügen.
|
// Bild zu EA hinzufügen.
|
||||||
add(img);
|
add(img);
|
||||||
@@ -72,7 +81,9 @@ public class Tile extends Knoten {
|
|||||||
case STONE_WALL_BOTTOM:
|
case STONE_WALL_BOTTOM:
|
||||||
return "/res/images/tiles/stone_wall_bottom.png";
|
return "/res/images/tiles/stone_wall_bottom.png";
|
||||||
case STONE_FLOOR:
|
case STONE_FLOOR:
|
||||||
return "/res/images/tiles/Stone_floor.png";
|
return "/res/images/tiles/TestTest.png";
|
||||||
|
case DOOR:
|
||||||
|
return "/res/images/tiles/door.png";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -90,7 +101,7 @@ public class Tile extends Knoten {
|
|||||||
public boolean isCollidable() {
|
public boolean isCollidable() {
|
||||||
// Alle Tiles durch die man nicht laufen soll müssen hier true zurückgeben,
|
// Alle Tiles durch die man nicht laufen soll müssen hier true zurückgeben,
|
||||||
// sonst werden sie bei der Collisiondetection nicht berücksichtigt.
|
// sonst werden sie bei der Collisiondetection nicht berücksichtigt.
|
||||||
return id == WALL_TOP || id == STONE_WALL ;
|
return id == WALL_TOP || id == STONE_WALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,4 +131,8 @@ public class Tile extends Knoten {
|
|||||||
public int getRight() {
|
public int getRight() {
|
||||||
return positionX() + getSize();
|
return positionX() + getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getID() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,58 @@
|
|||||||
package main;
|
package main;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import ea.Knoten;
|
import ea.Knoten;
|
||||||
|
import main.entities.player.Player;
|
||||||
|
import main.maps.ImageMap;
|
||||||
import main.maps.Map;
|
import main.maps.Map;
|
||||||
import main.maps.TutorialMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hier werden alle Maps gespeichert.
|
* Hier werden alle Maps gespeichert.
|
||||||
*/
|
*/
|
||||||
public class World extends Knoten {
|
public class World extends Knoten {
|
||||||
|
|
||||||
public static final int SCALE_FACTOR = 4; // Der Basis Zoomfaktor
|
public static final int SCALE_FACTOR = 6; // 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.
|
||||||
|
private ArrayList<ImageMap> dungeon;
|
||||||
|
|
||||||
|
private Player player;
|
||||||
|
|
||||||
public World() {
|
public World() {
|
||||||
|
|
||||||
// Map initialisieren
|
dungeon = new ArrayList<>(50);
|
||||||
currentMap = new TutorialMap();
|
|
||||||
// Map zu EA hinzufügen
|
ImageMap start = new ImageMap("/res/images/maps/map1.png");
|
||||||
|
dungeon.add(start);
|
||||||
|
currentMap = start;
|
||||||
|
|
||||||
|
start.generate(dungeon);
|
||||||
|
|
||||||
|
|
||||||
|
player = new Player();
|
||||||
|
currentMap.getEntities().add(player);
|
||||||
|
currentMap.add(player.actionFigur);
|
||||||
|
Main.instance.manager.anmelden(player, 20);
|
||||||
|
|
||||||
add(currentMap);
|
add(currentMap);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getCurrentMap() {
|
public Map getCurrentMap() {
|
||||||
return currentMap;
|
return currentMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changeMap(DoorTile door) {
|
||||||
|
entfernen(currentMap);
|
||||||
|
currentMap = door.getMap();
|
||||||
|
currentMap.add(player.actionFigur);
|
||||||
|
add(currentMap);
|
||||||
|
player.setPos(7, 5);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,11 +112,22 @@ public abstract class Entity implements Ticker {
|
|||||||
return (float) Math.sqrt((e.posX - posX) * (e.posX - posX) + (e.posY - posY) * (e.posY - posY));
|
return (float) Math.sqrt((e.posX - posX) * (e.posX - posX) + (e.posY - posY) * (e.posY - posY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return die entifernung zu dieser Koordinate
|
||||||
|
*/
|
||||||
|
public float dist(float x, float y) {
|
||||||
|
return (float) Math.sqrt((x - posX) * (x - posX) + (y - posY) * (y - posY));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generiert einen vektor von diesm Entity zu einem anderen
|
* Generiert einen vektor von diesm Entity zu einem anderen
|
||||||
*/
|
*/
|
||||||
public Vektor vectorToEntity(Entity e) {
|
public Vektor vectorToEntity(Entity e) {
|
||||||
return new Vektor(e.posX - posX, e.posY - posY);
|
Vektor v = new Vektor(e.posX - posX, e.posY - posY);;
|
||||||
|
if (v.x == 0 && v.y == 0) {
|
||||||
|
return new Vektor(0.0000001f, 0.0000001f);
|
||||||
|
}
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean lineOfSightClear(Entity e) {
|
protected boolean lineOfSightClear(Entity e) {
|
||||||
@@ -171,6 +182,19 @@ public abstract class Entity implements Ticker {
|
|||||||
this.velY = velY;
|
this.velY = velY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPosX(float x) {
|
||||||
|
posX = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosY(float y) {
|
||||||
|
posY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPos(float x, float y) {
|
||||||
|
posX = x;
|
||||||
|
posY = y;
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteEntity() {
|
public void deleteEntity() {
|
||||||
deleteEntity = true;
|
deleteEntity = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,15 +64,20 @@ public abstract class LivingEntity extends Entity {
|
|||||||
*/
|
*/
|
||||||
protected void zustandSetzen(String name) {
|
protected void zustandSetzen(String name) {
|
||||||
actionFigur.spiegelXSetzen(mirrored ? !side : side);
|
actionFigur.spiegelXSetzen(mirrored ? !side : side);
|
||||||
actionFigur.zustandSetzen(name);
|
if (!actionFigur.aktuellesVerhalten().equals(name)) {
|
||||||
|
actionFigur.zustandSetzen(name);
|
||||||
|
actionFigur.aktuelleFigur().animationsBildSetzen(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getHealthPoints() {
|
|
||||||
|
public float getHP() {
|
||||||
return hp;
|
return hp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void takeDamage(float damage, Entity e) {
|
public void takeDamage(float damage, Entity e) {
|
||||||
actionFigur.zustandSetzen(getDamageAnimationName());
|
zustandSetzen(getDamageAnimationName());
|
||||||
|
actionFigur.aktuelleFigur().animationsBildSetzen(0);
|
||||||
hp -= damage;
|
hp -= damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
package main.entities;
|
package main.entities;
|
||||||
|
|
||||||
|
import ea.Vektor;
|
||||||
import main.Main;
|
import main.Main;
|
||||||
import main.SheetLoader;
|
import main.SheetLoader;
|
||||||
import main.entities.player.Player;
|
import main.entities.player.Player;
|
||||||
|
|
||||||
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, 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() {
|
public Snake() {
|
||||||
super(loader.getFigur(0), "idle");
|
super(loader.getFigur(0), "idle");
|
||||||
@@ -26,13 +28,35 @@ public class Snake extends LivingEntity {
|
|||||||
actionFigur.neuerZustand(loader.getFigur(5), getDamageAnimationName());
|
actionFigur.neuerZustand(loader.getFigur(5), getDamageAnimationName());
|
||||||
|
|
||||||
loader.getFigur(3).animationsGeschwindigkeitSetzen(80);
|
loader.getFigur(3).animationsGeschwindigkeitSetzen(80);
|
||||||
loader.getFigur(5).animationsGeschwindigkeitSetzen(40);
|
loader.getFigur(5).animationsGeschwindigkeitSetzen(60);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void update() {
|
protected void update() {
|
||||||
Player player = Main.instance.getWorld().getCurrentMap().getPlayer();
|
Player player = Main.instance.getWorld().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());
|
this.checkTileCollisions(Main.instance.getWorld().getCurrentMap());
|
||||||
super.update();
|
super.update();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package main.entities;
|
package main.entities;
|
||||||
|
|
||||||
|
import ea.Vektor;
|
||||||
import main.Main;
|
import main.Main;
|
||||||
import main.SheetLoader;
|
import main.SheetLoader;
|
||||||
import main.entities.player.Player;
|
import main.entities.player.Player;
|
||||||
@@ -17,6 +18,7 @@ public class Spider extends LivingEntity {
|
|||||||
spriteScale = 0.8f;
|
spriteScale = 0.8f;
|
||||||
posX = 4f;
|
posX = 4f;
|
||||||
posY = 4f;
|
posY = 4f;
|
||||||
|
mirrored = true;
|
||||||
|
|
||||||
actionFigur.neuerZustand(loader.getFigur(1), "lost_sight");
|
actionFigur.neuerZustand(loader.getFigur(1), "lost_sight");
|
||||||
actionFigur.neuerZustand(loader.getFigur(2), "walk");
|
actionFigur.neuerZustand(loader.getFigur(2), "walk");
|
||||||
@@ -30,10 +32,31 @@ public class Spider extends LivingEntity {
|
|||||||
|
|
||||||
protected void update() {
|
protected void update() {
|
||||||
Player player = Main.instance.getWorld().getCurrentMap().getPlayer();
|
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());
|
this.checkTileCollisions(Main.instance.getWorld().getCurrentMap());
|
||||||
super.update();
|
super.update();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ import main.entities.LivingEntity;
|
|||||||
|
|
||||||
public class Player extends LivingEntity {
|
public class Player extends LivingEntity {
|
||||||
|
|
||||||
private static SheetLoader loader = new SheetLoader("/res/images/player_sprite_sheet.png", 64, 32, new int[] { 5, 8, 7, 6, 2, 5, 4, 7 });
|
private static SheetLoader loader = new SheetLoader("/res/images/player_sprite_sheet.png", 64, 32,
|
||||||
|
new int[] { 5, 8, 7, 6, 2, 5, 4, 7 });
|
||||||
private boolean onlyAttackOnceTrigger;
|
private boolean onlyAttackOnceTrigger;
|
||||||
|
private float range = 1.2f; // die reichweite der Attacke
|
||||||
|
|
||||||
public Player() {
|
public Player() {
|
||||||
super(loader.getFigur(0), "idle");
|
super(loader.getFigur(0), "idle");
|
||||||
@@ -22,8 +24,8 @@ public class Player extends LivingEntity {
|
|||||||
height = 0.8f;
|
height = 0.8f;
|
||||||
spriteOffsetY = -0.14f;
|
spriteOffsetY = -0.14f;
|
||||||
spriteScale = 0.8f;
|
spriteScale = 0.8f;
|
||||||
posX = 4f;
|
posX = 7.5f;
|
||||||
posY = 4f;
|
posY = 5.5f;
|
||||||
|
|
||||||
// unterschiedliche Animationsgeschwindigkeiten
|
// unterschiedliche Animationsgeschwindigkeiten
|
||||||
// für idle
|
// für idle
|
||||||
@@ -46,8 +48,8 @@ public class Player extends LivingEntity {
|
|||||||
if (!((actionFigur.aktuellesVerhalten().equals("strike"))
|
if (!((actionFigur.aktuellesVerhalten().equals("strike"))
|
||||||
&& actionFigur.aktuelleFigur().aktuellesBild() < actionFigur.aktuelleFigur().animation().length - 1)) {
|
&& actionFigur.aktuelleFigur().aktuellesBild() < actionFigur.aktuelleFigur().animation().length - 1)) {
|
||||||
// Bei diser soll man sich nicht bewegen können aber weiter rutschen
|
// Bei diser soll man sich nicht bewegen können aber weiter rutschen
|
||||||
if (!((actionFigur.aktuellesVerhalten().equals("swipe"))
|
if (!((actionFigur.aktuellesVerhalten().equals("swipe")) && actionFigur.aktuelleFigur()
|
||||||
&& actionFigur.aktuelleFigur().aktuellesBild() < actionFigur.aktuelleFigur().animation().length - 1)) {
|
.aktuellesBild() < actionFigur.aktuelleFigur().animation().length - 1)) {
|
||||||
|
|
||||||
// wasd movement
|
// wasd movement
|
||||||
if (Main.instance.tasteGedrueckt(Taste.A)) {
|
if (Main.instance.tasteGedrueckt(Taste.A)) {
|
||||||
@@ -95,18 +97,21 @@ public class Player extends LivingEntity {
|
|||||||
// auf Kollisionen prüfen
|
// auf Kollisionen prüfen
|
||||||
checkTileCollisions(Main.instance.getWorld().getCurrentMap());
|
checkTileCollisions(Main.instance.getWorld().getCurrentMap());
|
||||||
|
|
||||||
if (!onlyAttackOnceTrigger && actionFigur.aktuellesVerhalten().equals("swipe") && actionFigur.aktuelleFigur().aktuellesBild() == 1) {
|
if (!onlyAttackOnceTrigger && actionFigur.aktuellesVerhalten().equals("swipe")
|
||||||
|
&& actionFigur.aktuelleFigur().aktuellesBild() == 1) {
|
||||||
onlyAttackOnceTrigger = true;
|
onlyAttackOnceTrigger = true;
|
||||||
ArrayList<Entity> entities = Main.instance.getWorld().getCurrentMap().getEntities();
|
ArrayList<Entity> entities = Main.instance.getWorld().getCurrentMap().getEntities();
|
||||||
for (Entity e : entities) {
|
for (Entity e : entities) {
|
||||||
if (e instanceof LivingEntity && e != this && e.dist(this) <= 1f) {
|
if (e instanceof LivingEntity && e != this && e.dist(this) <= range) {
|
||||||
LivingEntity le = (LivingEntity) e;
|
LivingEntity le = (LivingEntity) e;
|
||||||
Vektor toE = vectorToEntity(le);
|
if (le.getHP() > 0) {
|
||||||
toE = toE.normiert();
|
Vektor toE = vectorToEntity(le);
|
||||||
if ((toE.x > 0 && !side) || (toE.x <= 0 && side)) {
|
toE = toE.normiert();
|
||||||
le.setVelX(le.getVelX() + toE.x * 0.05f);
|
if ((toE.x > 0 && !side) || (toE.x <= 0 && side)) {
|
||||||
le.setVelY(le.getVelY() + toE.y * 0.05f);
|
le.setVelX(le.getVelX() + toE.x * 0.1f);
|
||||||
le.takeDamage(0.4f, this);
|
le.setVelY(le.getVelY() + toE.y * 0.1f);
|
||||||
|
le.takeDamage(0.1f, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ public class Item {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getIconPath(){
|
public String getIconPath(){
|
||||||
TODO:
|
// TODO:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,31 +2,37 @@ package main.maps;
|
|||||||
|
|
||||||
import main.Tile;
|
import main.Tile;
|
||||||
|
|
||||||
import main.entities.Snake;
|
|
||||||
|
|
||||||
public class Corridor extends Map {
|
public class Corridor extends Map {
|
||||||
|
|
||||||
public Corridor() {
|
public Corridor() {
|
||||||
super(5, 10);
|
super(15, 11);
|
||||||
|
|
||||||
for (int x = 0; x < map.length; x++) {
|
for (int x = 0; x < map.length; x++) {
|
||||||
for (int y = 0; y < map[0].length; y++) {
|
for (int y = 0; y < map[0].length; y++) {
|
||||||
//Wand
|
// Wand
|
||||||
if((y == 0 || x == 0 || y == 9 || x == 4) && x != 2 ) {
|
if ((y == 0 || x == 5 || y == 10 || x == 9) && x != 7 && x >= 5 && x <= 9) {
|
||||||
map[x][y] = new Tile(3, x, y);
|
map[x][y] = new Tile(Tile.STONE_WALL, x, y);
|
||||||
add(map[x][y]);
|
add(map[x][y]);
|
||||||
}
|
}
|
||||||
//3D-Wand
|
// 3D-Wand
|
||||||
else if(y == 1 && (x != 0 || x != 4)&& x != 2 ) {
|
else if (y == 1 && (x != 0 || x != 4) && x != 7 && x >= 6 && x <= 8) {
|
||||||
map[x][y] = new Tile(4, x, y);
|
map[x][y] = new Tile(Tile.STONE_WALL_BOTTOM, x, y);
|
||||||
add(map[x][y]);
|
add(map[x][y]);
|
||||||
}
|
}
|
||||||
//Steinboden
|
// Steinboden
|
||||||
else {
|
else if (x >= 6 && x <= 8) {
|
||||||
map[x][y] = new Tile(5, x, y);
|
if (x == 7 && (y == 0 || y == map[0].length - 1)) {
|
||||||
|
} else {
|
||||||
|
map[x][y] = new Tile(Tile.STONE_FLOOR, x, y);
|
||||||
|
add(map[x][y]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
map[x][y] = new Tile(Tile.VOID, x, y);
|
||||||
add(map[x][y]);
|
add(map[x][y]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerEntities();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
152
Zoelda/src/main/maps/ImageMap.java
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
package main.maps;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
import main.DoorTile;
|
||||||
|
import main.Tile;
|
||||||
|
|
||||||
|
public class ImageMap extends Map {
|
||||||
|
|
||||||
|
private static PixelTile[] pixels = { new PixelTile(Tile.STONE_WALL, new Color(100, 100, 100)),
|
||||||
|
new PixelTile(Tile.STONE_FLOOR, new Color(127, 127, 127)), new PixelTile(Tile.VOID, new Color(0, 0, 0)),
|
||||||
|
new PixelTile(Tile.DOOR, new Color(255, 0, 0)) };
|
||||||
|
|
||||||
|
public DoorTile topDoor;
|
||||||
|
public DoorTile leftDoor;
|
||||||
|
public DoorTile rightDoor;
|
||||||
|
public DoorTile bottomDoor;
|
||||||
|
|
||||||
|
public ImageMap(String path) {
|
||||||
|
super(15, 11);
|
||||||
|
|
||||||
|
try {
|
||||||
|
BufferedImage img = ImageIO.read(ImageMap.class.getResourceAsStream(path));
|
||||||
|
if (img.getWidth() != 15 || img.getHeight() != 11) {
|
||||||
|
System.err.println("Odd map size! Use 15x11");
|
||||||
|
}
|
||||||
|
for (int x = 0; x < img.getWidth(); x++) {
|
||||||
|
for (int y = 0; y < img.getHeight(); y++) {
|
||||||
|
int id = Tile.VOID;
|
||||||
|
int rgb = img.getRGB(x, y);
|
||||||
|
for (PixelTile t : pixels) {
|
||||||
|
if (t.c == rgb) {
|
||||||
|
id = t.id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (id == Tile.DOOR) {
|
||||||
|
DoorTile door = new DoorTile(x, y, this);
|
||||||
|
map[x][y] = door;
|
||||||
|
if (x == 7) {
|
||||||
|
if (y < 5) {
|
||||||
|
topDoor = door;
|
||||||
|
door.setSide(DoorTile.TOP);
|
||||||
|
} else {
|
||||||
|
bottomDoor = door;
|
||||||
|
door.setSide(DoorTile.BOTTOM);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (y == 5) {
|
||||||
|
if (x < 7) {
|
||||||
|
leftDoor = door;
|
||||||
|
door.setSide(DoorTile.LEFT);
|
||||||
|
} else {
|
||||||
|
rightDoor = door;
|
||||||
|
door.setSide(DoorTile.RIGHT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
map[x][y] = new Tile(id, x, y);
|
||||||
|
}
|
||||||
|
add(map[x][y]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class PixelTile {
|
||||||
|
public final int c;
|
||||||
|
public final int id;
|
||||||
|
|
||||||
|
public PixelTile(int id, Color c) {
|
||||||
|
this.c = c.getRGB();
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generate(ArrayList<ImageMap> dungeon) {
|
||||||
|
if (topDoor != null) {
|
||||||
|
ImageMap map;
|
||||||
|
do {
|
||||||
|
map = nextMap();
|
||||||
|
} while (!connectDoors(topDoor, map));
|
||||||
|
dungeon.add(map);
|
||||||
|
}
|
||||||
|
if (bottomDoor != null) {
|
||||||
|
ImageMap map;
|
||||||
|
do {
|
||||||
|
map = nextMap();
|
||||||
|
} while (!connectDoors(bottomDoor, map));
|
||||||
|
dungeon.add(map);
|
||||||
|
}
|
||||||
|
if (leftDoor != null) {
|
||||||
|
ImageMap map;
|
||||||
|
do {
|
||||||
|
map = nextMap();
|
||||||
|
} while (!connectDoors(leftDoor, map));
|
||||||
|
dungeon.add(map);
|
||||||
|
}
|
||||||
|
if (rightDoor != null) {
|
||||||
|
ImageMap map;
|
||||||
|
do {
|
||||||
|
map = nextMap();
|
||||||
|
} while (!connectDoors(rightDoor, map));
|
||||||
|
dungeon.add(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImageMap nextMap() {
|
||||||
|
return new ImageMap("/res/images/maps/map" + ((int) (Math.random() * 7) + 1) + ".png");
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean connectDoors(DoorTile door, ImageMap otherMap) {
|
||||||
|
switch (door.getSide()) {
|
||||||
|
case DoorTile.TOP:
|
||||||
|
if (otherMap.bottomDoor == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
door.setConnectedDoor(otherMap.bottomDoor);
|
||||||
|
otherMap.bottomDoor.setConnectedDoor(door);
|
||||||
|
return true;
|
||||||
|
case DoorTile.BOTTOM:
|
||||||
|
if (otherMap.topDoor == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
door.setConnectedDoor(otherMap.topDoor);
|
||||||
|
otherMap.topDoor.setConnectedDoor(door);
|
||||||
|
return true;
|
||||||
|
case DoorTile.LEFT:
|
||||||
|
if (otherMap.rightDoor == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
door.setConnectedDoor(otherMap.rightDoor);
|
||||||
|
otherMap.rightDoor.setConnectedDoor(door);
|
||||||
|
return true;
|
||||||
|
case DoorTile.RIGHT:
|
||||||
|
if (otherMap.leftDoor == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
door.setConnectedDoor(otherMap.leftDoor);
|
||||||
|
otherMap.leftDoor.setConnectedDoor(door);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,6 @@ import main.Main;
|
|||||||
import main.Tile;
|
import main.Tile;
|
||||||
import main.entities.Entity;
|
import main.entities.Entity;
|
||||||
import main.entities.LivingEntity;
|
import main.entities.LivingEntity;
|
||||||
import main.entities.player.Player;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auf der Map sind alle Entities, sowie die Tiles gespiechert.
|
* Auf der Map sind alle Entities, sowie die Tiles gespiechert.
|
||||||
@@ -17,7 +16,7 @@ public abstract class Map extends Knoten implements Ticker {
|
|||||||
|
|
||||||
protected Tile[][] map; // Die Tiles der map in einem 2D Array.
|
protected Tile[][] map; // Die Tiles der map in einem 2D Array.
|
||||||
private ArrayList<Entity> entities;
|
private ArrayList<Entity> entities;
|
||||||
private Player player;
|
|
||||||
|
|
||||||
public Map(int width, int height) {
|
public Map(int width, int height) {
|
||||||
map = new Tile[width][height];
|
map = new Tile[width][height];
|
||||||
@@ -64,14 +63,6 @@ public abstract class Map extends Knoten implements Ticker {
|
|||||||
return entities;
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayer() {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlayer(Player player) {
|
|
||||||
this.player = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerEntities() {
|
public void registerEntities() {
|
||||||
for (Entity e : getEntities()) {
|
for (Entity e : getEntities()) {
|
||||||
Main.instance.manager.anmelden(e, 20);
|
Main.instance.manager.anmelden(e, 20);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package main.maps;
|
|||||||
import main.Tile;
|
import main.Tile;
|
||||||
import main.entities.Snake;
|
import main.entities.Snake;
|
||||||
import main.entities.Spider;
|
import main.entities.Spider;
|
||||||
import main.entities.player.Player;
|
|
||||||
|
|
||||||
public class TutorialMap extends Map {
|
public class TutorialMap extends Map {
|
||||||
|
|
||||||
@@ -29,10 +28,6 @@ public class TutorialMap extends Map {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = new Player();
|
|
||||||
add(player.actionFigur);
|
|
||||||
getEntities().add(player);
|
|
||||||
|
|
||||||
// und Spinnen auch
|
// und Spinnen auch
|
||||||
Spider spider = new Spider();
|
Spider spider = new Spider();
|
||||||
add(spider.actionFigur);
|
add(spider.actionFigur);
|
||||||
@@ -43,8 +38,6 @@ public class TutorialMap extends Map {
|
|||||||
add(snake.actionFigur);
|
add(snake.actionFigur);
|
||||||
getEntities().add(snake);
|
getEntities().add(snake);
|
||||||
|
|
||||||
setPlayer(player);
|
|
||||||
|
|
||||||
// Alle Entities als ticker registrieren (triggert dann die update methoden)
|
// Alle Entities als ticker registrieren (triggert dann die update methoden)
|
||||||
registerEntities();
|
registerEntities();
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Zoelda/src/res/images/maps/map1.png
Normal file
|
After Width: | Height: | Size: 168 B |
BIN
Zoelda/src/res/images/maps/map2.png
Normal file
|
After Width: | Height: | Size: 169 B |
BIN
Zoelda/src/res/images/maps/map3.png
Normal file
|
After Width: | Height: | Size: 181 B |
BIN
Zoelda/src/res/images/maps/map4.png
Normal file
|
After Width: | Height: | Size: 171 B |
BIN
Zoelda/src/res/images/maps/map5.png
Normal file
|
After Width: | Height: | Size: 162 B |
BIN
Zoelda/src/res/images/maps/map6.png
Normal file
|
After Width: | Height: | Size: 166 B |
BIN
Zoelda/src/res/images/maps/map7.png
Normal file
|
After Width: | Height: | Size: 164 B |
BIN
Zoelda/src/res/images/maps/map8.png
Normal file
|
After Width: | Height: | Size: 160 B |
BIN
Zoelda/src/res/images/tiles/TestTest.png
Normal file
|
After Width: | Height: | Size: 137 B |
BIN
Zoelda/src/res/images/tiles/door.png
Normal file
|
After Width: | Height: | Size: 302 B |
|
Before Width: | Height: | Size: 574 B |
|
Before Width: | Height: | Size: 481 B |
|
Before Width: | Height: | Size: 540 B After Width: | Height: | Size: 545 B |