Compare commits

..

38 Commits

Author SHA1 Message Date
Max
865b5e0c52 animationspeed of rick edited 2021-07-01 11:39:33 +02:00
Max
d28a29df45 Spider anzahl fixed 2021-07-01 11:02:17 +02:00
Max
b85a36bf14 Merge branch 'master' of https://git.ngb.schule/Tim/Zoelda 2021-07-01 11:00:34 +02:00
Max
66d36c4ea2 Rick added 2021-07-01 11:00:27 +02:00
Tim
d46d25115e Merge branch 'master' of https://git.ngb.schule/Tim/Zoelda 2021-07-01 10:58:44 +02:00
Tim
5f0b827fab better coin alignment 2021-07-01 10:58:42 +02:00
Tim
ca40e4c01a Coin collect animation 2021-07-01 10:47:37 +02:00
Max
21790ecd7a Create rick_sprite_sheet.png 2021-07-01 10:40:17 +02:00
Max
da5c5571b2 Rickroll added 2021-07-01 10:37:24 +02:00
Tim
af51d3776e door colors on maps 2021-07-01 10:23:46 +02:00
e818037d75 Coin Counter added 2021-07-01 08:41:45 +02:00
Malin.sieckmann
3e99a2ebc2 door textures finally added! WOOP WOOP 2021-06-30 19:05:06 +02:00
Malin.sieckmann
dc9a08c9ee Added DoorTiles Textures 2021-06-30 19:05:05 +02:00
Asecave
58a41725eb Snakes drop coins now 2021-06-30 19:01:57 +02:00
Asecave
d440ad8f67 Coins can be collected 2021-06-30 18:03:47 +02:00
Asecave
f386ef49f6 added coin entity 2021-06-30 17:14:43 +02:00
Asecave
3a65c74546 Show boundingbox info/debug with 'o' 2021-06-30 17:08:57 +02:00
Asecave
e643ec092d added class AnimatedEntity between LivingEntity and Entity 2021-06-30 17:06:29 +02:00
Asecave
c035253790 Entity vs Entity collision 2021-06-30 15:47:17 +02:00
a5eed792e7 Merge branch 'master' of https://git.ngb.schule/Tim/Zoelda 2021-06-30 13:33:45 +02:00
cbc30b0ac5 class Sounds and sounds with ids added 2021-06-30 13:33:22 +02:00
Max
d150a613c4 Merge branch 'master' of https://git.ngb.schule/Tim/Zoelda 2021-06-30 13:33:20 +02:00
Max
ec74176426 Disco sprite sheet added 2021-06-30 13:32:26 +02:00
Tim
28b9404fe9 added default texture 2021-06-30 13:32:05 +02:00
Asecave
b7da4535d7 new map structure 2021-06-29 15:37:26 +02:00
Asecave
f36c861726 player can take damage 2021-06-28 23:04:39 +02:00
0b521ca667 Merge branch 'master' of https://git.ngb.schule/Tim/Zoelda 2021-06-28 22:56:58 +02:00
1f1f5bbc68 Added special classes for Inventory and Herzen 2021-06-28 22:56:52 +02:00
Asecave
12c57e1c3c Merge branch 'master' of https://git.ngb.schule/Tim/Zoelda 2021-06-28 22:28:04 +02:00
Asecave
52a59d2808 doors always lead to other rooms 2021-06-28 22:27:58 +02:00
Malin.sieckmann
657c7bab9e left door added/ improved, 3D wall added, shadow added 2021-06-28 21:45:51 +02:00
Asecave
23eba51e5c performance fix 2021-06-28 15:45:48 +02:00
Tim
1555acd781 Merge branch 'master' of https://git.ngb.schule/Tim/Zoelda 2021-06-28 09:49:41 +02:00
Tim
4f76c1eaa8 performace 2021-06-28 09:49:21 +02:00
08a67a8a24 Merge branch 'master' of https://git.ngb.schule/Tim/Zoelda 2021-06-28 09:38:20 +02:00
595b9b26d9 Shaking Hearts added 2021-06-28 09:37:25 +02:00
a0f632608a Merge remote-tracking branch 'origin/master' 2021-06-28 09:37:18 +02:00
fc17421e0b Inventory HUD Implementation 2021-06-28 09:37:08 +02:00
63 changed files with 927 additions and 520 deletions

1
.gitignore vendored
View File

@@ -8,3 +8,4 @@
/.idea/ /.idea/
/out/ /out/
/Zoelda.iml /Zoelda.iml
/bin/

Binary file not shown.

View File

@@ -2,10 +2,10 @@ package main;
import ea.Ticker; import ea.Ticker;
import main.entities.player.Player; import main.entities.player.Player;
import main.maps.ImageMap; import main.maps.Map;
public class DoorTile extends Tile implements Ticker { public class DoorTile extends Tile implements Ticker {
public static final int TOP = 0; public static final int TOP = 0;
public static final int BOTTOM = 1; public static final int BOTTOM = 1;
public static final int LEFT = 2; public static final int LEFT = 2;
@@ -13,11 +13,11 @@ public class DoorTile extends Tile implements Ticker {
private int side; private int side;
private DoorTile connected; private DoorTile connected;
private ImageMap map; private Map map;
private boolean waitForLeave; private boolean waitForLeave;
public DoorTile(float x, float y, ImageMap map) { public DoorTile(int id, float x, float y, Map map) {
super(Tile.DOOR, x, y); super(id, x, y);
this.map = map; this.map = map;
} }
@@ -28,8 +28,9 @@ public class DoorTile extends Tile implements Ticker {
float dist = player.dist(posX + 0.5f, posY + 0.5f); float dist = player.dist(posX + 0.5f, posY + 0.5f);
if (dist < 0.5f) { if (dist < 0.5f) {
if (!waitForLeave) { if (!waitForLeave) {
Main.instance.getWorld().changeMap(this); if (connected != null) {
waitForLeave = true; Main.instance.getWorld().changeMap(this);
}
} }
} else { } else {
waitForLeave = false; waitForLeave = false;
@@ -44,20 +45,33 @@ public class DoorTile extends Tile implements Ticker {
public void setSide(int side) { public void setSide(int side) {
this.side = side; this.side = side;
} }
public void setConnectedDoor(DoorTile door) { public void setConnectedDoor(DoorTile door) {
connected = door; connected = door;
} }
public DoorTile getConnectedDoor() { public DoorTile getConnectedDoor() {
return connected; return connected;
} }
public ImageMap getMap() { public Map getMap() {
return map; return map;
} }
public void waitForLeave() { public void waitForLeave() {
waitForLeave = true; waitForLeave = true;
} }
@Override
public DoorTile clone() {
DoorTile t = new DoorTile(getID(), posX, posY, map);
t.setConnectedDoor(connected);
t.side = side;
t.map = map;
return t;
}
public void setMap(Map map) {
this.map = map;
}
} }

View File

@@ -0,0 +1,28 @@
package main.HUD;
import java.awt.Graphics2D;
import ea.BoundingRechteck;
import ea.Knoten;
import main.Main;
public class HUD extends Knoten{
public final Herzen herzen;
public final Inventory inventory;
public HUD() {
herzen = new Herzen();
inventory = new Inventory();
add(herzen);
add(inventory);
Main.instance.manager.anmelden(herzen, 60);
Main.instance.manager.anmelden(inventory, 50);
}
@Override
public void zeichnen(Graphics2D g, BoundingRechteck r) {
herzen.zeichnen(g);
inventory.zeichnen(g);
}
}

View File

@@ -1,25 +1,33 @@
package main; package main.HUD;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import ea.BoundingRechteck;
import ea.Knoten; import ea.Knoten;
import ea.Ticker; import ea.Ticker;
import main.Main;
public class HUD extends Knoten implements Ticker { public class Herzen extends Knoten implements Ticker{
private final static int SCALE = 50;
private BufferedImage volles_Herz; private BufferedImage volles_Herz;
private BufferedImage halbes_Herz; private BufferedImage halbes_Herz;
private BufferedImage leeres_Herz; private BufferedImage leeres_Herz;
private BufferedImage hauptBild; private BufferedImage hauptBild;
private BufferedImage[] HPLeiste; private BufferedImage[] HPLeiste;
private final static int SCALE = 50; private boolean shakingSwitch;
private float HPVel = 0.3f;
private int counter = 0;
private float lastHP;
private int y;
private int HPLeisteY[];
public HUD() { public Herzen() {
// inizialisieren der Variablen, laden der Bilder und für den ticker anmelden // inizialisieren der Variablen, laden der Bilder und für den ticker anmelden
HPLeiste = new BufferedImage[3]; HPLeiste = new BufferedImage[5];
Main.instance.manager.anmelden(this, 50); HPLeisteY = new int [HPLeiste.length];
try { try {
hauptBild = ImageIO.read(HUD.class.getResourceAsStream("/res/images/icons.png")); hauptBild = ImageIO.read(HUD.class.getResourceAsStream("/res/images/icons.png"));
} catch (IOException e) { } catch (IOException e) {
@@ -40,16 +48,40 @@ public class HUD extends Knoten implements Ticker {
HPLeiste[2] = volles_Herz; HPLeiste[2] = volles_Herz;
} }
//wird alle 50ms ausgeführt: private int shakeY() {
@Override shakingSwitch = !shakingSwitch;
if (shakingSwitch == true) {
return 3;
}
return 0;
}
private int regenY() {
if (HPVel > 0) {
if (counter < HPLeiste.length + 1) {
counter++;
if (counter * 4 < HPLeiste.length + 1) {
return 3;
} else {
return 0;
}
} else {
counter = 0;
}
}
return 0;
}
// wird alle 200ms ausgeführt:
public void tick() { public void tick() {
// teilt den Wert der HP in Teile auf, welche der Anzahl der Herzen entspricht // teilt den Wert der HP in Teile auf, welche der Anzahl der Herzen entspricht
// und prüft dann für den eigenen Teil des Herzens, ob das jeweilige Herz voll, // und prüft dann für den eigenen Teil des Herzens, ob das jeweilige Herz voll,
// halb oder leer ist (BIG BRAIN): // halb oder leer ist (BIG BRAIN):
HPVel = Main.instance.getWorld().getPlayer().getHP() - lastHP;
lastHP = Main.instance.getWorld().getPlayer().getHP();
float localeHP; float localeHP;
for (int i = 0; i < HPLeiste.length; i++) { for (int i = 0; i < HPLeiste.length; i++) {
localeHP = Main.instance.getWorld().getPlayer().getHP(); localeHP = Main.instance.getWorld().getPlayer().getHP();
;
localeHP -= ((float) i) * (1f / HPLeiste.length); localeHP -= ((float) i) * (1f / HPLeiste.length);
if (localeHP <= 0f) { if (localeHP <= 0f) {
HPLeiste[i] = leeres_Herz; HPLeiste[i] = leeres_Herz;
@@ -59,14 +91,24 @@ public class HUD extends Knoten implements Ticker {
HPLeiste[i] = volles_Herz; HPLeiste[i] = volles_Herz;
} }
} }
} if(Main.instance.getWorld().getPlayer().getHP() < 0.33f) {
y = shakeY();
} else {
for (int i = 0; i < HPLeiste.length; i++) {
HPLeisteY[i] = regenY();
}
//Zeichnet alle Herzen im Array HPLeiste[] auf den Bildschirm
@Override
public void zeichnen(Graphics2D g, BoundingRechteck r) {
for (int i = 0; i < HPLeiste.length; i++) {
g.drawImage(HPLeiste[i], i * SCALE, 0, SCALE, SCALE, null);
} }
} }
// Zeichnet alle Herzen im Array HPLeiste[] auf den Bildschirm
public void zeichnen(Graphics2D g) {
for (int i = 0; i < HPLeiste.length; i++) {
if(Main.instance.getWorld().getPlayer().getHP() < 0.33f) {
g.drawImage(HPLeiste[i], (i + 2) * SCALE, y , SCALE, SCALE, null);
} else {
g.drawImage(HPLeiste[i], (i + 2) * SCALE, HPLeisteY[i] , SCALE, SCALE, null);
}
}
}
} }

View File

@@ -0,0 +1,51 @@
package main.HUD;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import ea.Knoten;
import ea.Ticker;
import main.Main;
import main.entities.player.PlayerInventory;
import main.worlds.World;
public class Inventory extends Knoten implements Ticker {
private static final int SCALE = 50;
private BufferedImage inventoryFrame;
private BufferedImage coinCounterIcon;
private PlayerInventory inventory;
public Inventory() {
inventory = Main.instance.getWorld().getPlayer().getInventory();
try {
inventoryFrame = ImageIO.read(HUD.class.getResourceAsStream("/res/images/inventory.png"));
coinCounterIcon = ImageIO.read(HUD.class.getResourceAsStream("/res/images/coins.png"));
} catch (IOException e) {
e.printStackTrace();
}
coinCounterIcon = coinCounterIcon.getSubimage(0, 20, 7, 4);
}
public void style(Graphics2D g) {
Font currentFont = g.getFont();
Font newFont = currentFont.deriveFont(Font.BOLD, 20);
g.setFont(newFont);
}
public void zeichnen(Graphics2D g) {
style(g);
g.drawImage(inventoryFrame, 0, 0, SCALE * 2, SCALE * 2, null);
g.drawString(String.valueOf(inventory.getCoins()), SCALE + 10, 145);
g.drawImage(coinCounterIcon, 0, 125, coinCounterIcon.getWidth() * World.SCALE_FACTOR,
coinCounterIcon.getHeight() * World.SCALE_FACTOR, null);
}
// wird alle 50ms ausgef<65>hrt:
public void tick() {
}
}

View File

@@ -1,31 +1,43 @@
package main; package main;
import ea.Game; import ea.Game;
import ea.Taste;
import main.HUD.HUD;
import main.worlds.TestWorld;
import main.worlds.World;
/** /**
* Von hier wird alles initialisiert. Das ist die höchste Klasse. * Von hier wird alles initialisiert. Das ist die höchste Klasse.
*/ */
public class Main extends Game { public class Main extends Game {
public static Main instance; public static Main instance;
public static boolean SHOW_DEBUG = false;
private World world; private World world;
private HUD hud; private HUD hud;
private Sounds sounds;
public Main() { public Main() {
super(World.SCALE * 15, World.SCALE * 11, 16); super(World.SCALE * 15, World.SCALE * 11, 16);
instance = this; instance = this;
// Welt initialisieren und Spieler hinzufügen // Welt initialisieren und Spieler hinzufügen und die Welt zu EA hinzufügen
world = new World(); world = new TestWorld();
hud = new HUD(); manager.anmelden(world.getPlayer(), 20);
// die Welt zu EA hinzufügen world.start();
wurzel.add(world); wurzel.add(world);
hud = new HUD();
wurzel.add(hud); wurzel.add(hud);
// sounds = new Sounds();
// sounds.playSound(2);
} }
@Override @Override
public void tasteReagieren(int code) { public void tasteReagieren(int code) {
if (code == Taste.O) {
SHOW_DEBUG = !SHOW_DEBUG;
}
} }
public World getWorld() { public World getWorld() {

View File

@@ -12,44 +12,46 @@ import ea.internal.gra.PixelFeld;
public class SheetLoader { public class SheetLoader {
private Figur[] figures; private Figur[] figures;
private BufferedImage sheet;
/** /**
* Macht aus einem Spritesheet Figuren. * Macht aus einem Spritesheet Figuren.
* @param path - Der pfad zum sheet *
* @param width - die Breite von einem Bild * @param path - Der pfad zum sheet
* @param height - die Höhe von einem Bild (nicht das ganze sheet) * @param width - die Breite von einem Bild
* @param height - die Höhe von einem Bild (nicht das ganze sheet)
* @param lengths - die Anzahl der Frames der verschiedenen Animationen * @param lengths - die Anzahl der Frames der verschiedenen Animationen
*/ */
public SheetLoader(String path, int width, int height, int[] frames) { public SheetLoader(String path) {
try { try {
// Bild laden // Bild laden
BufferedImage sheet = ImageIO.read(Tile.class.getResourceAsStream(path)); sheet = ImageIO.read(Tile.class.getResourceAsStream(path));
// Anzahl der Animationen
int rows = frames.length;
// Sprites anordnen *magie*
PixelFeld[][] sprites = new PixelFeld[rows][];
for (int i = 0; i < frames.length; i++) {
sprites[i] = new PixelFeld[frames[i]];
}
for (int i = 0; i < sprites.length; i++) {
loadSprites(sprites[i], i, width, height, sheet);
}
Figur fig;
figures = new Figur[rows];
for (int i = 0; i < figures.length; i++) {
fig = new Figur();
fig.animationSetzen(sprites[i]);
figures[i] = fig;
}
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void generateFigures(int width, int height, int[] frames) {
// Anzahl der Animationen
int rows = frames.length;
// Sprites anordnen *magie*
PixelFeld[][] sprites = new PixelFeld[rows][];
for (int i = 0; i < frames.length; i++) {
sprites[i] = new PixelFeld[frames[i]];
}
for (int i = 0; i < sprites.length; i++) {
loadSprites(sprites[i], i, width, height, sheet);
}
Figur fig;
figures = new Figur[rows];
for (int i = 0; i < figures.length; i++) {
fig = new Figur();
fig.animationSetzen(sprites[i]);
figures[i] = fig;
}
}
public Figur getFigur(int y) { public Figur getFigur(int y) {
return figures[y]; return figures[y];
} }

View File

@@ -0,0 +1,45 @@
package main;
import ea.Sound;
public class Sounds {
private Sound[] sounds;
public Sounds() {
sounds = new Sound[6];
for(int i = 0; i < sounds.length; i++) {
sounds[i] = new Sound(getPathFromId(i));
}
}
public void playSound(int id) {
sounds[id].play();
}
public void loopSound(int id) {
sounds[id].loop();
}
public void stopSound(int id) {
sounds[id].stop();
}
private String getPathFromId(int id) {
switch(id) {
case 0:
return "/res/sounds/Water-Balloon-Maniacs.mp3";
case 1:
return "/res/sounds/Runaway-Food-Truck.mp3";
case 2:
return "/res/sounds/Hypnotic-Puzzle2.mp3" ;
case 3:
return "/res/sounds/Game-Menu_v001.mp3" ;
case 4:
return "/res/sounds/Blob-Monsters-on-the-Loose.mp3";
case 5:
return "/res/sounds/And-the-Machines-Came-at-Midnight.mp3";
default:
return null;
}
}
}

View File

@@ -7,6 +7,7 @@ import javax.imageio.ImageIO;
import ea.Bild; import ea.Bild;
import ea.Knoten; import ea.Knoten;
import main.worlds.World;
/** /**
* Ein feld auf der Map * Ein feld auf der Map
@@ -14,18 +15,26 @@ import ea.Knoten;
public class Tile extends Knoten { public class Tile extends Knoten {
// IDs der Tiles // IDs der Tiles
public static final int VOID = -1;
public static final int GRASS = 0; public static final int GRASS = 0;
public static final int WALL_TOP = 1; public static final int WALL_TOP = 1;
public static final int WALL_BOTTOM = 2; public static final int WALL_BOTTOM = 2;
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 STONE_FLOOR_SHADOW_LEFT = 6;
public static final int DOOR = 7; public static final int DOOR_LEFT = 7;
public static final int DOOR_RIGHT_LEFT_TOP = 8;
public static final int DISCO = 9;
public static final int DOOR_RIGHT = 10;
public static final int DOOR_TOP = 11;
public static final int DOOR_BOTTOM = 12;
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 protected float posX, posY; // Position dieses Tiles
private static Bild[] images;
/** /**
* @param id * @param id
@@ -33,40 +42,47 @@ public class Tile extends Knoten {
* @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) {
if (images == null) {
loadImages();
}
this.id = id; this.id = id;
posX = x; posX = x;
posY = y; posY = y;
if (id != VOID) { if (id != VOID) {
// Das Bild laden img = images[id].clone();
img.positionSetzen(posX * World.SCALE, posY * World.SCALE);
// Bild zu EA hinzuf<75>gen.
add(img);
}
}
private static void loadImages() {
images = new Bild[13];
for (int i = 0; i < images.length; i++) {
try { try {
BufferedImage buff = ImageIO.read(Tile.class.getResourceAsStream(getPathFromId(id))); BufferedImage buff = ImageIO.read(Tile.class.getResourceAsStream(getPathFromId(i)));
// Gras hat 8 verschiedene Texturen von denen eine zufällig ausgewählt werden // Gras hat 8 verschiedene Texturen von denen eine zufaellig ausgewaehlt werden
// muss. // muss.
if (id == GRASS) { if (i == GRASS) {
buff = buff.getSubimage(16 * (int) (Math.random() * 8), 0, 16, 16); 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 // Skalieren
BufferedImage scaled = new BufferedImage(World.SCALE, World.SCALE, BufferedImage.TYPE_INT_RGB); BufferedImage scaled = new BufferedImage(World.SCALE, World.SCALE, BufferedImage.TYPE_INT_RGB);
scaled.getGraphics().drawImage(buff, 0, 0, World.SCALE, World.SCALE, null); scaled.getGraphics().drawImage(buff, 0, 0, World.SCALE, World.SCALE, null);
img = new Bild(x * World.SCALE, y * World.SCALE, scaled); images[i] = new Bild(0, 0, scaled);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
// Bild zu EA hinzufügen.
add(img);
} }
} }
/** /**
* @return den Pfad der zu der Id gehört. * @return den Pfad der zu der Id gehoert.
*/ */
private String getPathFromId(int id) { private static String getPathFromId(int id) {
switch (id) { switch (id) {
case GRASS: case GRASS:
return "/res/images/tiles/grass.png"; return "/res/images/tiles/grass.png";
@@ -75,21 +91,33 @@ public class Tile extends Knoten {
case WALL_BOTTOM: case WALL_BOTTOM:
return "/res/images/tiles/wall_bottom.png"; return "/res/images/tiles/wall_bottom.png";
case STONE_WALL: case STONE_WALL:
return "/res/images/tiles/test.png"; return "/res/images/tiles/stone_wall.png";
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/TestTest.png"; return "/res/images/tiles/stone_floor.png";
case DOOR: case STONE_FLOOR_SHADOW_LEFT:
return "/res/images/tiles/door.png"; return "/res/images/tiles/stone_floor_shadow_left.png";
case DOOR_LEFT:
return "/res/images/tiles/door_left.png";
case DOOR_RIGHT_LEFT_TOP:
return "/res/images/tiles/door_right_left_top.png";
case DISCO:
return "/res/images/tiles/disco_sprite_sheet.png";
case DOOR_RIGHT:
return "/res/images/tiles/door_right.png";
case DOOR_TOP:
return "/res/images/tiles/door_top.png";
case DOOR_BOTTOM:
return "/res/images/tiles/door_bottom.png";
} }
return null; return null;
} }
/** /**
* @return die Größe der Textur * @return die Groesse der Textur
*/ */
public static int getSize() { private static int getSize() {
return 16; return 16;
} }
@@ -97,34 +125,34 @@ public class Tile extends Knoten {
* @return ob man durch das Tile durchgehen kann * @return ob man durch das Tile durchgehen kann
*/ */
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 muessen hier true zurueckgeben,
// sonst werden sie bei der Collisiondetection nicht berücksichtigt. // sonst werden sie bei der Collisiondetection nicht ber<EFBFBD>cksichtigt.
return id == WALL_TOP || id == STONE_WALL; return id == WALL_TOP || id == STONE_WALL;
} }
/** /**
* Kleine Hifsmethode un die koordinate der Top-Kante rurückzugenben. * Kleine Hifsmethode um die Koordinate der Top-Kante zurueckzugenben.
*/ */
public int getTop() { public int getTop() {
return positionY(); return positionY();
} }
/** /**
* Kleine Hifsmethode un die koordinate der Bottom-Kante rurückzugenben. * Kleine Hifsmethode um die Koordinate der Bottom-Kante zurueckzugenben.
*/ */
public int getBottom() { public int getBottom() {
return positionY() + getSize(); return positionY() + getSize();
} }
/** /**
* Kleine Hifsmethode un die koordinate der Left-Kante rurückzugenben. * Kleine Hifsmethode um die Koordinate der Left-Kante zurueckzugenben.
*/ */
public int getLeft() { public int getLeft() {
return positionX(); return positionX();
} }
/** /**
* Kleine Hifsmethode un die koordinate der Right-Kante rurückzugenben. * Kleine Hifsmethode um die Koordinate der Right-Kante zurueckzugenben.
*/ */
public int getRight() { public int getRight() {
return positionX() + getSize(); return positionX() + getSize();
@@ -133,4 +161,17 @@ public class Tile extends Knoten {
public int getID() { public int getID() {
return id; return id;
} }
public float getPosX() {
return posX;
}
public float getPosY() {
return posY;
}
@Override
public Tile clone() {
return new Tile(id, posX, posY);
}
} }

View File

@@ -1,63 +0,0 @@
package main;
import java.util.ArrayList;
import ea.Knoten;
import main.entities.player.Player;
import main.maps.ImageMap;
import main.maps.Map;
/**
* Hier werden alle Maps gespeichert.
*/
public class World extends Knoten {
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
private ImageMap currentMap; // Die Map die aktuell angezeigt werden soll.
private ArrayList<ImageMap> dungeon;
private Player player;
public World() {
dungeon = new ArrayList<>(50);
ImageMap start = new ImageMap("/res/images/maps/map2.png");
dungeon.add(start);
currentMap = start;
currentMap.start();
start.generate(dungeon, DoorTile.BOTTOM);
player = new Player();
currentMap.getEntities().add(player);
currentMap.add(player.actionFigur);
Main.instance.manager.anmelden(player, 20);
add(currentMap);
}
public Map getCurrentMap() {
return currentMap;
}
public Player getPlayer() {
return player;
}
public void changeMap(DoorTile door) {
currentMap.stop();
currentMap.entfernen(player.actionFigur);
entfernen(currentMap);
currentMap = door.getConnectedDoor().getMap();
currentMap.add(player.actionFigur);
add(currentMap);
currentMap.start();
door.getConnectedDoor().waitForLeave();
player.setPos(door.getConnectedDoor().posX + 0.5f, door.getConnectedDoor().posY + 0.5f);
}
}

View File

@@ -0,0 +1,77 @@
package main.entities;
import java.awt.Color;
import java.awt.Graphics2D;
import ea.ActionFigur;
import ea.BoundingRechteck;
import ea.Figur;
import ea.internal.gra.PixelFeld;
import main.Main;
import main.worlds.World;
public abstract class AnimatedEntity extends Entity {
public ActionFigur actionFigur; // Sprite des Entities
protected float spriteScale = 1f; // Skalierung des Sprites
protected float spriteOffsetX, spriteOffsetY; // Offset des Sprites. Hier kann man die relative render-Position
// nachjustieren.
protected boolean side;
private static Figur noTexture = new Figur();
static {
PixelFeld[] img = new PixelFeld[1];
img[0] = new PixelFeld(16, 16, 1);
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
img[0].farbeSetzen(x, y, Color.MAGENTA);
}
}
noTexture.animationSetzen(img);
}
public AnimatedEntity() {
actionFigur = new ActionFigur(noTexture, "undefined") {
// DEBUG: render boxes
@Override
public void zeichnen(Graphics2D g, BoundingRechteck r) {
super.zeichnen(g, r);
if (Main.SHOW_DEBUG) {
g.setColor(Color.CYAN);
g.drawRect((int) actionFigur.positionX(), (int) actionFigur.positionY(),
(int) actionFigur.getBreite(), (int) actionFigur.getHoehe());
g.setColor(Color.GREEN);
g.drawRect((int) ((posX - width / 2) * World.SCALE), (int) ((posY - height / 2) * World.SCALE),
(int) (width * World.SCALE), (int) (height * World.SCALE));
}
}
};
}
@Override
protected void update() {
checkTileCollision(Main.instance.getWorld().getCurrentMap());
checkEntityCollision(Main.instance.getWorld().getCurrentMap());
// Packt das Sprite an die richtige Stelle
actionFigur.faktorSetzen((int) (spriteScale * World.SCALE_FACTOR));
float offsetX = width / 2 + spriteOffsetX - width / 2;
float offsetY = height / 2 + spriteOffsetY - height / 2;
actionFigur.positionSetzen((posX + offsetX) * World.SCALE - actionFigur.getBreite() / 2,
(posY + offsetY) * World.SCALE - actionFigur.getHoehe() / 2);
}
/**
* Spiegelt die figur autmatisch, wenn nötig.
*/
protected void zustandSetzen(String name) {
actionFigur.spiegelXSetzen(side);
if (!actionFigur.aktuellesVerhalten().equals(name)) {
actionFigur.zustandSetzen(name);
actionFigur.aktuelleFigur().animationsBildSetzen(0);
}
}
}

View File

@@ -0,0 +1,57 @@
package main.entities;
import main.Main;
import main.SheetLoader;
import main.entities.player.Player;
public class Coin extends AnimatedEntity {
private static SheetLoader loader = new SheetLoader("/res/images/coins.png");
private boolean moveToCounterAnimation;
private float animationDestX = 0.2f;
private float animationDestY = 2.0f;
public Coin() {
loader.generateFigures(8, 8, new int[] { 8, 8, 1 });
loader.getFigur(0).animationsGeschwindigkeitSetzen(100);
loader.getFigur(1).animationsGeschwindigkeitSetzen(100);
loader.getFigur(2).animationsGeschwindigkeitSetzen(100);
actionFigur.neuerZustand(loader.getFigur(0), "gold");
actionFigur.neuerZustand(loader.getFigur(1), "silver");
actionFigur.neuerZustand(loader.getFigur(2), "bronze");
zustandSetzen("bronze");
posX = 4f;
posY = 4f;
width = 0.375f;
height = 0.25f;
spriteOffsetY = -0.1f;
enablePushBack = false;
}
@Override
protected void update() {
super.update();
if (moveToCounterAnimation) {
float distX = animationDestX - posX;
float distY = animationDestY - posY;
posX += distX / 10f;
posY += distY / 10f;
if (distX < 0.05f && distX > -0.05f && distY < 0.05f && distY > -0.05f) {
deleteEntity();
Main.instance.getWorld().getPlayer().getInventory().addCoins(1);
}
}
}
@Override
public void onEntityCollision(Entity e) {
if (e instanceof Player && !moveToCounterAnimation) {
moveToCounterAnimation = true;
enableTileCollisions = false;
}
}
}

View File

@@ -18,6 +18,8 @@ public abstract class Entity implements Ticker {
protected float friction = 0.2f; // Entschleunigung des entities in gameunits pro frame. protected float friction = 0.2f; // Entschleunigung des entities in gameunits pro frame.
protected float width = 1f, height = 1f; // Breite und Höhe der Hitbox. protected float width = 1f, height = 1f; // Breite und Höhe der Hitbox.
private boolean deleteEntity; // Wenn true wird dieses Entity von der map gelöscht private boolean deleteEntity; // Wenn true wird dieses Entity von der map gelöscht
protected boolean enablePushBack = true; // Ob das Entity von anderen Entities weggedrückt werden kann.
protected boolean enableTileCollisions = true; // Ob das Entity von Wänden abprallen soll
// Das ist die Ticker-Methode von ea; wird jeden frame ausgeführt (frameloop) // Das ist die Ticker-Methode von ea; wird jeden frame ausgeführt (frameloop)
@Override @Override
@@ -49,12 +51,16 @@ public abstract class Entity implements Ticker {
/** /**
* Checkt collision mit tiles von der map. Fertig, clean, nie wieder ändern. * Checkt collision mit tiles von der map. Fertig, clean, nie wieder ändern.
*/ */
public void checkTileCollisions(Map map) { public void checkTileCollision(Map map) {
if (!enableTileCollisions) {
return;
}
for (int x = (int) (posX - 2); x < posX + 2; x++) { for (int x = (int) (posX - 2); x < posX + 2; x++) {
for (int y = (int) (posY - 2); y < posY + 2; y++) { for (int y = (int) (posY - 2); y < posY + 2; y++) {
if (x >= 0 && x < map.getWidth() && y >= 0 && y < map.getHeight()) { if (x >= 0 && x < map.getWidth() && y >= 0 && y < map.getHeight()) {
if (map.getTile(x, y).isCollidable()) { if (map.getTile(x, y).isCollidable()) {
if (posY + height / 2 > y && posY - height / 2 < y + 1 && posX + width / 2 > x && posX - width / 2 < x + 1) { if (posY + height / 2 > y && posY - height / 2 < y + 1 && posX + width / 2 > x
&& posX - width / 2 < x + 1) {
float distN = Math.abs((y + 1 + height / 2) - posY); float distN = Math.abs((y + 1 + height / 2) - posY);
float distE = Math.abs((x + 1 + width / 2) - posX); float distE = Math.abs((x + 1 + width / 2) - posX);
float distS = Math.abs((y - height / 2) - posY); float distS = Math.abs((y - height / 2) - posY);
@@ -75,6 +81,37 @@ public abstract class Entity implements Ticker {
} }
} }
public void checkEntityCollision(Map map) {
for (int i = 0; i < map.getEntities().size(); i++) {
Entity e = map.getEntities().get(i);
if (e != this) {
float esize = (e.getWidth() + e.getHeight()) / 2;
float size = (width + height) / 2;
float dist = dist(e);
float sizes = esize / 2 + size / 2;
if (dist < sizes) {
if (enablePushBack && e.enablePushBack) {
float overlap = dist - sizes;
float xDist = e.posX - posX;
float yDist = e.posY - posY;
if (xDist == 0f) {
xDist = (float) (Math.random() - 0.5f) * 0.01f;
}
if (yDist == 0f) {
yDist = (float) (Math.random() - 0.5f) * 0.01f;
}
posX += (overlap * xDist);
posY += (overlap * yDist);
}
onEntityCollision(e);
}
}
}
}
public void onEntityCollision(Entity e) {
}
/** /**
* Gehört mit zur collision detection. Hier werden kollisionen aufgelöst. * Gehört mit zur collision detection. Hier werden kollisionen aufgelöst.
*/ */
@@ -104,32 +141,33 @@ public abstract class Entity implements Ticker {
posX = blockX - width / 2; posX = blockX - width / 2;
} }
} }
/** /**
* @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 - 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 * @return die entifernung zu dieser Koordinate
*/ */
public float dist(float x, float y) { public float dist(float x, float y) {
return (float) Math.sqrt((x - posX) * (x - posX) + (y - posY) * (y - posY)); 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) {
Vektor v = 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) { if (v.x == 0 && v.y == 0) {
return new Vektor(0.0000001f, 0.0000001f); return new Vektor(0.001f, 0.001f);
} }
return v; return v;
} }
protected boolean lineOfSightClear(Entity e) { protected boolean lineOfSightClear(Entity e) {
Vektor direct = vectorToEntity(e).normiert(); Vektor direct = vectorToEntity(e).normiert();
direct = direct.teilen(4f); direct = direct.teilen(4f);
@@ -152,6 +190,7 @@ public abstract class Entity implements Ticker {
/** /**
* Gibt den velX Wert zurück. * Gibt den velX Wert zurück.
*
* @return gibt den velX Wert als float zurück. * @return gibt den velX Wert als float zurück.
*/ */
public float getVelX() { public float getVelX() {
@@ -160,6 +199,7 @@ public abstract class Entity implements Ticker {
/** /**
* Gibt den velY Wert zurück. * Gibt den velY Wert zurück.
*
* @return gibt den velY Wert als float zurück. * @return gibt den velY Wert als float zurück.
*/ */
public float getVelY() { public float getVelY() {
@@ -168,6 +208,7 @@ public abstract class Entity implements Ticker {
/** /**
* Setzt eine neue velX velocity. * Setzt eine neue velX velocity.
*
* @param velX neuer float velX Wert. * @param velX neuer float velX Wert.
*/ */
public void setVelX(float velX) { public void setVelX(float velX) {
@@ -176,30 +217,47 @@ public abstract class Entity implements Ticker {
/** /**
* Setzt eine neue Y velocity. * Setzt eine neue Y velocity.
*
* @param velY neuer float velY Wert. * @param velY neuer float velY Wert.
*/ */
public void setVelY(float velY) { public void setVelY(float velY) {
this.velY = velY; this.velY = velY;
} }
public void setPosX(float x) { public void setPosX(float x) {
posX = x; posX = x;
} }
public void setPosY(float y) { public void setPosY(float y) {
posY = y; posY = y;
} }
public void setPos(float x, float y) { public void setPos(float x, float y) {
posX = x; posX = x;
posY = y; posY = y;
} }
public float getPosX() {
return posX;
}
public float getPosY() {
return posY;
}
public void deleteEntity() { public void deleteEntity() {
deleteEntity = true; deleteEntity = true;
} }
public boolean isReadyToDelete() { public boolean isReadyToDelete() {
return deleteEntity; return deleteEntity;
} }
public float getWidth() {
return width;
}
public float getHeight() {
return height;
}
} }

View File

@@ -1,76 +1,34 @@
package main.entities; package main.entities;
import ea.ActionFigur;
import ea.Figur;
import main.World;
/* /*
* Alles was zustände hat und sich Bewegen kann, ist ein LivingEntity. * Alles was zustände hat und sich Bewegen kann, ist ein LivingEntity.
*/ */
public abstract class LivingEntity extends Entity { public abstract class LivingEntity extends AnimatedEntity {
protected boolean side; // true = gespiegelt, false = nicht protected boolean mirrored; // true = gespiegelt, false = nicht
public ActionFigur actionFigur; // Sprite des Entities
protected float spriteScale = 1f; // Skalierung des Sprites
protected float spriteOffsetX, spriteOffsetY; // Offset des Sprites. Hier kann man die relative render-Position nachjustieren.
protected float hp = 1f; //hp des Entitys protected float hp = 1f; //hp des Entitys
protected boolean mirrored;
/**
* @param figur - erstes (standart) Sprite
* @param name - name des Zustands
*/
public LivingEntity(Figur figur, String name) {
actionFigur = new ActionFigur(figur, name) {
// DEBUG: render boxes
// @Override
// public void zeichnen(Graphics2D g, BoundingRechteck r) {
// g.setColor(Color.GREEN);
// g.drawRect((int) actionFigur.positionX(), (int) actionFigur.positionY(), (int) actionFigur.getBreite(), (int) actionFigur.getHoehe());
// g.drawRect((int) ((posX - width / 2) * World.SCALE), (int) ((posY - height / 2) * World.SCALE), (int) (width * World.SCALE), (int) (height * World.SCALE));
// super.zeichnen(g, r);
// }
};
}
@Override @Override
protected void update() { protected void update() {
// Prüft zu welcher seite man guckt // Prüft zu welcher seite man guckt
if (velX < 0) { if (velX < 0) {
side = true; side = !mirrored;
} else if (velX > 0) { } else if (velX > 0) {
side = false; side = mirrored;
} }
if (hp <= 0) { if (hp <= 0) {
actionFigur.zustandSetzen(getDeathAnimationName()); actionFigur.zustandSetzen(getDeathAnimationName());
velX = 0; velX = 0;
velY = 0; velY = 0;
if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length - 1) { if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length - 1 && !isReadyToDelete()) {
deleteEntity(); deleteEntity();
onDeath();
} }
} }
super.update();
// Packt das Sprite an die richtige Stelle
actionFigur.faktorSetzen((int) (spriteScale * World.SCALE_FACTOR));
float offsetX = width / 2 + spriteOffsetX - width / 2;
float offsetY = height / 2 + spriteOffsetY - height / 2;
actionFigur.positionSetzen((posX + offsetX) * World.SCALE - actionFigur.getBreite() / 2, (posY + offsetY) * World.SCALE - actionFigur.getHoehe() / 2);
} }
/**
* Spiegelt die figur autmatisch, wenn nötig.
*/
protected void zustandSetzen(String name) {
actionFigur.spiegelXSetzen(mirrored ? !side : side);
if (!actionFigur.aktuellesVerhalten().equals(name)) {
actionFigur.zustandSetzen(name);
actionFigur.aktuelleFigur().animationsBildSetzen(0);
}
}
public float getHP() { public float getHP() {
return hp; return hp;
} }
@@ -83,4 +41,7 @@ public abstract class LivingEntity extends Entity {
public abstract String getDeathAnimationName(); public abstract String getDeathAnimationName();
public abstract String getDamageAnimationName(); public abstract String getDamageAnimationName();
protected void onDeath() {
}
} }

View File

@@ -0,0 +1,36 @@
package main.entities;
import main.SheetLoader;
public class Rick extends LivingEntity{
private static SheetLoader loader = new SheetLoader("/res/images/rick_sprite_sheet.png");
public Rick() {
loader.generateFigures(24, 24, new int[] {4});
width = 0.7f;
height = 0.8f;
spriteOffsetY = -0.14f;
spriteScale = 0.8f;
posX = 4f;
posY = 4f;
mirrored = true;
loader.getFigur(0).animationsGeschwindigkeitSetzen(265);
actionFigur.neuerZustand(loader.getFigur(0), "dancin");
zustandSetzen("dancin");
}
@Override
public String getDeathAnimationName() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getDamageAnimationName() {
// TODO Auto-generated method stub
return null;
}
}

View File

@@ -7,12 +7,13 @@ 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, private static SheetLoader loader = new SheetLoader("/res/images/snake_spritesheet_calciumtrice.png");
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"); loader.generateFigures(32, 32, new int[] { 10, 10, 10, 10, 13, 8 });
posX = 9f; posX = 9f;
posY = 9f; posY = 9f;
accelleration = 0.006f; accelleration = 0.006f;
@@ -21,6 +22,7 @@ public class Snake extends LivingEntity {
height = 0.8f; height = 0.8f;
mirrored = true; mirrored = true;
actionFigur.neuerZustand(loader.getFigur(0), "idle");
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");
actionFigur.neuerZustand(loader.getFigur(3), "attack"); actionFigur.neuerZustand(loader.getFigur(3), "attack");
@@ -38,6 +40,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 +57,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");
} }
} }
@@ -57,7 +68,6 @@ public class Snake extends LivingEntity {
zustandSetzen("walk"); zustandSetzen("walk");
} }
} }
this.checkTileCollisions(Main.instance.getWorld().getCurrentMap());
super.update(); super.update();
} }
@@ -70,4 +80,16 @@ public class Snake extends LivingEntity {
public String getDamageAnimationName() { public String getDamageAnimationName() {
return "damage"; return "damage";
} }
@Override
protected void onDeath() {
int count = (int) (Math.random() * 3);
for (int i = 0; i < count; i++) {
Coin c = new Coin();
float x = posX + (float) Math.random() * width - width / 2;
float y = posY + (float) Math.random() * height - height / 2;
c.setPos(x, y);
Main.instance.getWorld().getCurrentMap().addAnimatedEntity(c);
}
}
} }

View File

@@ -7,10 +7,10 @@ import main.entities.player.Player;
public class Spider extends LivingEntity { public class Spider extends LivingEntity {
private static SheetLoader loader = new SheetLoader("/res/images/spider_sprite_sheet.png", 32, 32, new int[] { 5, 3, 6, 9, 9, 8 }); private static SheetLoader loader = new SheetLoader("/res/images/spider_sprite_sheet.png");
public Spider() { public Spider() {
super(loader.getFigur(0), "idle"); loader.generateFigures(32, 32, new int[] { 5, 3, 6, 9, 9, 8 });
width = 0.7f; width = 0.7f;
height = 0.8f; height = 0.8f;
@@ -19,7 +19,8 @@ public class Spider extends LivingEntity {
posX = 4f; posX = 4f;
posY = 4f; posY = 4f;
mirrored = true; mirrored = true;
actionFigur.neuerZustand(loader.getFigur(0), "idle");
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");
actionFigur.neuerZustand(loader.getFigur(3), "attack"); actionFigur.neuerZustand(loader.getFigur(3), "attack");
@@ -55,7 +56,6 @@ public class Spider extends LivingEntity {
zustandSetzen("walk"); zustandSetzen("walk");
} }
} }
this.checkTileCollisions(Main.instance.getWorld().getCurrentMap());
super.update(); super.update();
} }

View File

@@ -11,13 +11,13 @@ 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, private static SheetLoader loader = new SheetLoader("/res/images/player_sprite_sheet.png");
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 private float range = 1.2f; // die reichweite der Attacke
private PlayerInventory inventory;
public Player() { public Player() {
super(loader.getFigur(0), "idle"); loader.generateFigures(64, 32, new int[] { 5, 8, 7, 6, 2, 5, 4, 7 });
// Entity-Eigenschaften werden festgelegt // Entity-Eigenschaften werden festgelegt
width = 0.7f; width = 0.7f;
@@ -26,23 +26,23 @@ public class Player extends LivingEntity {
spriteScale = 0.8f; spriteScale = 0.8f;
posX = 7.5f; posX = 7.5f;
posY = 5.5f; posY = 5.5f;
// XXX
accelleration = 0.05f;
// unterschiedliche Animationsgeschwindigkeiten // unterschiedliche Animationsgeschwindigkeiten
// für idle // f<EFBFBD>r idle
loader.getFigur(0).animationsGeschwindigkeitSetzen(200); loader.getFigur(0).animationsGeschwindigkeitSetzen(200);
// fürs laufen // f<EFBFBD>rs laufen
loader.getFigur(1).animationsGeschwindigkeitSetzen(50); loader.getFigur(1).animationsGeschwindigkeitSetzen(50);
// Zustände werden hinzugefügt // Zust<EFBFBD>nde werden hinzugef<EFBFBD>gt
actionFigur.neuerZustand(loader.getFigur(0), "idle"); actionFigur.neuerZustand(loader.getFigur(0), "idle");
actionFigur.neuerZustand(loader.getFigur(1), "walk"); actionFigur.neuerZustand(loader.getFigur(1), "walk");
actionFigur.neuerZustand(loader.getFigur(2), "strike"); actionFigur.neuerZustand(loader.getFigur(2), "strike");
actionFigur.neuerZustand(loader.getFigur(3), "swipe"); actionFigur.neuerZustand(loader.getFigur(3), "swipe");
actionFigur.neuerZustand(loader.getFigur(6), getDamageAnimationName()); actionFigur.neuerZustand(loader.getFigur(6), getDamageAnimationName());
actionFigur.neuerZustand(loader.getFigur(7), getDeathAnimationName()); actionFigur.neuerZustand(loader.getFigur(7), getDeathAnimationName());
//Spieler Inventar
inventory = new PlayerInventory(5);
} }
@Override @Override
@@ -50,7 +50,7 @@ public class Player extends LivingEntity {
// Bei dieser animation bleibt man sofort stehen. // Bei dieser animation bleibt man sofort stehen.
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<EFBFBD>nnen aber weiter rutschen
if (!((actionFigur.aktuellesVerhalten().equals("swipe")) && actionFigur.aktuelleFigur() if (!((actionFigur.aktuellesVerhalten().equals("swipe")) && actionFigur.aktuelleFigur()
.aktuellesBild() < actionFigur.aktuelleFigur().animation().length - 1)) { .aktuellesBild() < actionFigur.aktuelleFigur().animation().length - 1)) {
@@ -87,9 +87,6 @@ public class Player extends LivingEntity {
} }
onlyAttackOnceTrigger = false; onlyAttackOnceTrigger = false;
} }
// auf Kollisionen prüfen
checkTileCollisions(Main.instance.getWorld().getCurrentMap());
// LivingEntity auch updaten lassen // LivingEntity auch updaten lassen
super.update(); super.update();
} else { } else {
@@ -97,23 +94,22 @@ public class Player extends LivingEntity {
velY = 0; velY = 0;
} }
// auf Kollisionen prüfen if (!actionFigur.aktuellesVerhalten().equals(getDamageAnimationName())) {
checkTileCollisions(Main.instance.getWorld().getCurrentMap()); if (!onlyAttackOnceTrigger && actionFigur.aktuellesVerhalten().equals("swipe")
&& actionFigur.aktuelleFigur().aktuellesBild() == 1) {
if (!onlyAttackOnceTrigger && actionFigur.aktuellesVerhalten().equals("swipe") onlyAttackOnceTrigger = true;
&& actionFigur.aktuelleFigur().aktuellesBild() == 1) { ArrayList<Entity> entities = Main.instance.getWorld().getCurrentMap().getEntities();
onlyAttackOnceTrigger = true; for (Entity e : entities) {
ArrayList<Entity> entities = Main.instance.getWorld().getCurrentMap().getEntities(); if (e instanceof LivingEntity && e != this && e.dist(this) <= range) {
for (Entity e : entities) { LivingEntity le = (LivingEntity) e;
if (e instanceof LivingEntity && e != this && e.dist(this) <= range) { if (le.getHP() > 0) {
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.1f);
if ((toE.x > 0 && !side) || (toE.x <= 0 && side)) { le.setVelY(le.getVelY() + toE.y * 0.1f);
le.setVelX(le.getVelX() + toE.x * 0.1f); le.takeDamage(0.1f, this);
le.setVelY(le.getVelY() + toE.y * 0.1f); }
le.takeDamage(0.1f, this);
} }
} }
} }
@@ -121,6 +117,10 @@ public class Player extends LivingEntity {
} }
} }
public PlayerInventory getInventory() {
return inventory;
}
@Override @Override
public String getDeathAnimationName() { public String getDeathAnimationName() {
return "die"; return "die";

View File

@@ -7,32 +7,37 @@ public class Corridor extends Map {
public Corridor() { public Corridor() {
super(15, 11); super(15, 11);
for (int x = 0; x < map.length; x++) { for (int x = 0; x < tiles.length; x++) {
for (int y = 0; y < map[0].length; y++) { for (int y = 0; y < tiles[0].length; y++) {
// Wand // Wand
if ((y == 0 || x == 5 || y == 10 || x == 9) && x != 7 && x >= 5 && x <= 9) { if ((y == 0 || x == 5 || y == 10 || x == 9) && x != 7 && x >= 5 && x <= 9) {
map[x][y] = new Tile(Tile.STONE_WALL, x, y); tiles[x][y] = new Tile(Tile.STONE_WALL, x, y);
add(map[x][y]); add(tiles[x][y]);
} }
// 3D-Wand // 3D-Wand
else if (y == 1 && (x != 0 || x != 4) && x != 7 && x >= 6 && x <= 8) { else if (y == 1 && (x != 0 || x != 4) && x != 7 && x >= 6 && x <= 8) {
map[x][y] = new Tile(Tile.STONE_WALL_BOTTOM, x, y); tiles[x][y] = new Tile(Tile.STONE_WALL_BOTTOM, x, y);
add(map[x][y]); add(tiles[x][y]);
} }
// Steinboden // Steinboden
else if (x >= 6 && x <= 8) { else if (x >= 6 && x <= 8) {
if (x == 7 && (y == 0 || y == map[0].length - 1)) { if (x == 7 && (y == 0 || y == tiles[0].length - 1)) {
} else { } else {
map[x][y] = new Tile(Tile.STONE_FLOOR, x, y); tiles[x][y] = new Tile(Tile.STONE_FLOOR, x, y);
add(map[x][y]); add(tiles[x][y]);
} }
} else { } else {
map[x][y] = new Tile(Tile.VOID, x, y); tiles[x][y] = new Tile(Tile.VOID, x, y);
add(map[x][y]); add(tiles[x][y]);
} }
} }
} }
}
registerEntities();
@Override
public Map clone() {
Corridor c = new Corridor();
c.cloneTiles(this);
return c;
} }
} }

View File

@@ -3,35 +3,26 @@ package main.maps;
import java.awt.Color; import java.awt.Color;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import main.DoorTile; import main.DoorTile;
import main.Main;
import main.Tile; import main.Tile;
public class ImageMap extends Map { public class ImageMap extends Map {
// Erstellung der abzulesenden Tiles (einem Tile wird eine Farbe zugewiesen)
private static PixelTile[] pixels = { private static PixelTile[] pixels = {
new PixelTile(Tile.STONE_WALL, new Color(100, 100, 100)), new PixelTile(Tile.STONE_WALL, new Color(100, 100, 100)),
new PixelTile(Tile.STONE_FLOOR, new Color(127, 127, 127)), new PixelTile(Tile.STONE_FLOOR, new Color(127, 127, 127)),
new PixelTile(Tile.VOID, new Color(0, 0, 0)), new PixelTile(Tile.VOID, new Color(0, 0, 0)),
new PixelTile(Tile.DOOR, new Color(255, 0, 0)) }; new PixelTile(Tile.DOOR_LEFT, new Color(255, 150, 0)),
new PixelTile(Tile.DOOR_RIGHT, new Color(69, 150, 0)),
public DoorTile topDoor; new PixelTile(Tile.DOOR_BOTTOM, new Color(150, 150, 0)),
public DoorTile leftDoor; new PixelTile(Tile.DOOR_TOP, new Color(0, 147, 150)),
public DoorTile rightDoor; new PixelTile(Tile.STONE_WALL_BOTTOM, new Color(145, 145, 145)),
public DoorTile bottomDoor; new PixelTile(Tile.STONE_FLOOR_SHADOW_LEFT, new Color(251, 251, 129)) };
private static ImageMap[] maps;
static {
maps = new ImageMap[8];
for (int i = 0; i < maps.length; i++) {
maps[i] = new ImageMap("/res/images/maps/map" + (i + 1) + ".png");
}
}
public ImageMap(String path) { public ImageMap(String path) {
super(15, 11); super(15, 11);
@@ -51,31 +42,41 @@ public class ImageMap extends Map {
break; break;
} }
} }
if (id == Tile.DOOR) { if (id == Tile.DOOR_LEFT) {
DoorTile door = new DoorTile(x, y, this); DoorTile door = new DoorTile(id, x, y, this);
map[x][y] = door; leftDoor = door;
if (x == 7) { door.setSide(DoorTile.LEFT);
if (y < 5) { tiles[x][y] = door;
topDoor = door; add(tiles[x][y]);
door.setSide(DoorTile.TOP); continue;
} 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]); if (id == Tile.DOOR_RIGHT ) {
DoorTile door = new DoorTile(id, x, y, this);
rightDoor = door;
door.setSide(DoorTile.RIGHT);
tiles[x][y] = door;
add(tiles[x][y]);
continue;
}
if (id == Tile.DOOR_TOP) {
DoorTile door = new DoorTile(id, x, y, this);
topDoor = door;
door.setSide(DoorTile.TOP);
tiles[x][y] = door;
add(tiles[x][y]);
continue;
}
if (id == Tile.DOOR_BOTTOM) {
DoorTile door = new DoorTile(id, x, y, this);
bottomDoor = door;
door.setSide(DoorTile.BOTTOM);
tiles[x][y] = door;
add(tiles[x][y]);
continue;
}
tiles[x][y] = new Tile(id, x, y);
add(tiles[x][y]);
} }
} }
} catch (IOException e) { } catch (IOException e) {
@@ -83,6 +84,11 @@ public class ImageMap extends Map {
} }
} }
public ImageMap(ImageMap map) {
super(map.getWidth(), map.getHeight());
cloneTiles(map);
}
private static class PixelTile { private static class PixelTile {
public final int c; public final int c;
public final int id; public final int id;
@@ -93,107 +99,8 @@ public class ImageMap extends Map {
} }
} }
public void generate(ArrayList<ImageMap> dungeon, int fromSide) { @Override
if (topDoor != null && fromSide != DoorTile.TOP) { public ImageMap clone() {
ImageMap map; return new ImageMap(this);
do {
map = nextMap();
} while (!connectDoors(topDoor, map));
dungeon.add(map);
map.generate(dungeon, DoorTile.BOTTOM);
}
if (bottomDoor != null && fromSide != DoorTile.BOTTOM) {
ImageMap map;
do {
map = nextMap();
} while (!connectDoors(bottomDoor, map));
dungeon.add(map);
map.generate(dungeon, DoorTile.TOP);
}
if (leftDoor != null && fromSide != DoorTile.LEFT) {
ImageMap map;
do {
map = nextMap();
} while (!connectDoors(leftDoor, map));
dungeon.add(map);
map.generate(dungeon, DoorTile.RIGHT);
}
if (rightDoor != null && fromSide != DoorTile.RIGHT) {
ImageMap map;
do {
map = nextMap();
} while (!connectDoors(rightDoor, map));
dungeon.add(map);
map.generate(dungeon, DoorTile.LEFT);
}
System.out.println();
}
private ImageMap nextMap() {
return new ImageMap("/res/images/maps/map" + ((int) (Math.random() * 6) + 3) + ".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;
}
public void start() {
if (topDoor != null) {
Main.instance.manager.anmelden(topDoor, 50);
}
if (bottomDoor != null) {
Main.instance.manager.anmelden(bottomDoor, 50);
}
if (leftDoor != null) {
Main.instance.manager.anmelden(leftDoor, 50);
}
if (rightDoor != null) {
Main.instance.manager.anmelden(rightDoor, 50);
}
}
public void stop() {
if (topDoor != null) {
Main.instance.manager.abmelden(topDoor);
}
if (bottomDoor != null) {
Main.instance.manager.abmelden(bottomDoor);
}
if (leftDoor != null) {
Main.instance.manager.abmelden(leftDoor);
}
if (rightDoor != null) {
Main.instance.manager.abmelden(rightDoor);
}
} }
} }

View File

@@ -4,22 +4,29 @@ import java.util.ArrayList;
import ea.Knoten; import ea.Knoten;
import ea.Ticker; import ea.Ticker;
import main.DoorTile;
import main.Main; import main.Main;
import main.Tile; import main.Tile;
import main.entities.AnimatedEntity;
import main.entities.Entity; import main.entities.Entity;
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.
*/ */
public abstract class Map extends Knoten implements Ticker { public abstract class Map extends Knoten implements Ticker {
protected Tile[][] map; // Die Tiles der map in einem 2D Array. protected Tile[][] tiles; // Die Tiles der map in einem 2D Array.
private ArrayList<Entity> entities; private ArrayList<Entity> entities;
private boolean started;
public DoorTile topDoor;
public DoorTile leftDoor;
public DoorTile rightDoor;
public DoorTile bottomDoor;
public Map(int width, int height) { public Map(int width, int height) {
map = new Tile[width][height]; tiles = new Tile[width][height];
entities = new ArrayList<>(100); entities = new ArrayList<>(100);
@@ -31,8 +38,8 @@ public abstract class Map extends Knoten implements Ticker {
* existiert) * existiert)
*/ */
public Tile getTile(int x, int y) { public Tile getTile(int x, int y) {
if (x >= 0 && x < map.length && y >= 0 && y < map[0].length) { if (x >= 0 && x < tiles.length && y >= 0 && y < tiles[0].length) {
return map[x][y]; return tiles[x][y];
} }
return null; return null;
} }
@@ -42,8 +49,8 @@ public abstract class Map extends Knoten implements Ticker {
for (int i = 0; i < entities.size(); i++) { for (int i = 0; i < entities.size(); i++) {
Entity e = entities.get(i); Entity e = entities.get(i);
if (e.isReadyToDelete()) { if (e.isReadyToDelete()) {
if (e instanceof LivingEntity) { if (e instanceof AnimatedEntity) {
entfernen(((LivingEntity) e).actionFigur); entfernen(((AnimatedEntity) e).actionFigur);
} }
Main.instance.manager.abmelden(e); Main.instance.manager.abmelden(e);
entities.remove(e); entities.remove(e);
@@ -52,20 +59,99 @@ public abstract class Map extends Knoten implements Ticker {
} }
public int getWidth() { public int getWidth() {
return map.length; return tiles.length;
} }
public int getHeight() { public int getHeight() {
return map[0].length; return tiles[0].length;
} }
public ArrayList<Entity> getEntities() { public ArrayList<Entity> getEntities() {
return entities; return entities;
} }
public void registerEntities() { public void addAnimatedEntity(AnimatedEntity e) {
for (Entity e : getEntities()) { entities.add(e);
add(e.actionFigur);
if (started) {
Main.instance.manager.anmelden(e, 20); Main.instance.manager.anmelden(e, 20);
} }
} }
public abstract Map clone();
public void cloneTiles(Map map) {
for (int x = 0; x < map.getWidth(); x++) {
for (int y = 0; y < map.getHeight(); y++) {
tiles[x][y] = map.getTile(x, y).clone();
if (tiles[x][y] instanceof DoorTile) {
DoorTile dt = (DoorTile) tiles[x][y];
if (dt.getSide() == DoorTile.TOP) {
topDoor = dt;
topDoor.setMap(this);
}
if (dt.getSide() == DoorTile.BOTTOM) {
bottomDoor = dt;
bottomDoor.setMap(this);
}
if (dt.getSide() == DoorTile.LEFT) {
leftDoor = dt;
leftDoor.setMap(this);
}
if (dt.getSide() == DoorTile.RIGHT) {
rightDoor = dt;
rightDoor.setMap(this);
}
}
add(tiles[x][y]);
}
}
}
public void start() {
if (topDoor != null) {
Main.instance.manager.anmelden(topDoor, 50);
}
if (bottomDoor != null) {
Main.instance.manager.anmelden(bottomDoor, 50);
}
if (leftDoor != null) {
Main.instance.manager.anmelden(leftDoor, 50);
}
if (rightDoor != null) {
Main.instance.manager.anmelden(rightDoor, 50);
}
for (Entity e : entities) {
if (!(e instanceof Player)) {
Main.instance.manager.anmelden(e, 20);
}
}
started = true;
}
public void stop() {
if (topDoor != null) {
Main.instance.manager.abmelden(topDoor);
}
if (bottomDoor != null) {
Main.instance.manager.abmelden(bottomDoor);
}
if (leftDoor != null) {
Main.instance.manager.abmelden(leftDoor);
}
if (rightDoor != null) {
Main.instance.manager.abmelden(rightDoor);
}
for (Entity e : entities) {
if (!(e instanceof Player)) {
Main.instance.manager.abmelden(e);
}
}
started = false;
}
public void connectDoors(DoorTile door, DoorTile door2) {
door.setConnectedDoor(door2);
door2.setConnectedDoor(door);
}
} }

View File

@@ -1,25 +0,0 @@
package main.maps;
import main.Tile;
public class Map01 extends Map {
public Map01 () {
super (15,11);
for (int x = 0; x < map.length; x++) {
for (int y = 0; y < map[0].length; y++) {
//Wand
if((x == 4 || y == 9 || x == 10) && x > 3 && y > 0 && x < 11 && y < 10 && x != 7 ) {
map[x][y] = new Tile(3, x, y);
add(map[x][y]);
}
//Boden
else if(x > 3 && y > 0 && x < 11 && y < 10) {
map[x][y] = new Tile(5, x, y);
add(map[x][y]);
}
}
}
}
}

View File

@@ -1,38 +0,0 @@
package main.maps;
import main.Tile;
public class Map02 extends Map {
public Map02() {
super(15, 11);
for (int x = 0; x < map.length; x++) {
for (int y = 0; y < map[0].length; y++) {
// Wand
if (y == 0 || x == 0 || y == 10 || x == 14) {
// Übergang, Tür
if (y == 10) {
if (x > 4 && x < 10) {
map[x][y] = new Tile(5, x, y);
add(map[x][y]);
continue;
}
}
map[x][y] = new Tile(3, x, y);
add(map[x][y]);
}
// 3D-Wand
else if(y == 1 ) {
map[x][y] = new Tile(4, x, y);
add(map[x][y]);
}
// Steinboden
else {
map[x][y] = new Tile(5, x, y);
add(map[x][y]);
}
}
}
}
}

View File

@@ -1,17 +0,0 @@
package main.maps;
import main.Tile;
public class TestMap extends Map {
public TestMap() {
super(15, 11);
for (int x = 0; x < map.length; x++) {
for (int y = 0; y < map[0].length; y++) {
map[x][y] = new Tile(Math.random() * 5 < 1 ? 1 : 0, x, y);
add(map[x][y]);
}
}
}
}

View File

@@ -8,37 +8,34 @@ public class TutorialMap extends Map {
public TutorialMap() { public TutorialMap() {
super(15, 11); super(15, 11);
for (int x = 0; x < map.length; x++) { for (int x = 0; x < tiles.length; x++) {
for (int y = 0; y < map[0].length; y++) { for (int y = 0; y < tiles[0].length; y++) {
//Wand, Sichtschutz //Wand, Sichtschutz
if (y == 0 ||y == map[0].length - 1 || x == 0 || x == map.length - 1 || ((y == 4|| y == 5) && x == 10 )) { if (y == 0 ||y == tiles[0].length - 1 || x == 0 || x == tiles.length - 1 || ((y == 4|| y == 5) && x == 10 )) {
map[x][y] = new Tile (1, x, y); tiles[x][y] = new Tile (1, x, y);
add(map [x][y]); add(tiles [x][y]);
} }
//3D-Wand, 3F-Sichtschutz //3D-Wand, 3F-Sichtschutz
else if(y == 1 || ( y == 6 && x == 10)) { else if(y == 1 || ( y == 6 && x == 10)) {
map[x][y] = new Tile (2, x, y); tiles[x][y] = new Tile (2, x, y);
add(map [x][y]); add(tiles [x][y]);
} }
//Grasboden //Grasboden
else{ else{
map[x][y] = new Tile(0, x, y); tiles[x][y] = new Tile(0, x, y);
add(map[x][y]); add(tiles[x][y]);
} }
} }
} }
// und Spinnen auch addAnimatedEntity(new Spider());
Spider spider = new Spider(); addAnimatedEntity(new Snake());
add(spider.actionFigur); }
getEntities().add(spider);
@Override
//und public Map clone() {
Snake snake = new Snake(); TutorialMap c = new TutorialMap();
add(snake.actionFigur); c.cloneTiles(this);
getEntities().add(snake); return c;
// Alle Entities als ticker registrieren (triggert dann die update methoden)
registerEntities();
} }
} }

View File

@@ -0,0 +1,41 @@
package main.worlds;
import main.entities.Coin;
import main.entities.Rick;
import main.entities.Snake;
import main.entities.Spider;
import main.maps.Map;
public class TestWorld extends World {
public TestWorld() {
super(4);
Map m2 = maps[3].clone();
getCurrentMap().connectDoors(getCurrentMap().bottomDoor, m2.topDoor);
for (int i = 0; i < 15; i++) {
Coin c = new Coin();
c.setPosX(i * 0.5f + 4);
getCurrentMap().addAnimatedEntity(c);
}
for (int i = 0; i < 2; i++) {
Snake s = new Snake();
s.setPosX((float) (Math.random() * 5 + 2));
getCurrentMap().addAnimatedEntity(s);
}
for (int i = 0; i < 3; i++) {
Spider spooda = new Spider();
spooda.setPosX((float) (Math.random() * 5 + 2));
getCurrentMap().addAnimatedEntity(spooda);
}
for (int i = 0; i < 1; i++) {
Rick astley = new Rick();
astley.setPosX((float) (Math.random() * 5 + 2));
getCurrentMap().addAnimatedEntity(astley);
}
}
}

View File

@@ -0,0 +1,67 @@
package main.worlds;
import ea.Knoten;
import main.DoorTile;
import main.entities.player.Player;
import main.maps.ImageMap;
import main.maps.Map;
/**
* Hier werden alle Maps gespeichert.
*/
public abstract class World extends Knoten {
public static final int SCALE_FACTOR = 4; // Der Basis Zoomfaktor
public static final int SCALE = SCALE_FACTOR * 16; // Eine Gameunit ist so viele pixel lang
private Map currentMap; // Die Map die aktuell angezeigt werden soll.
private Player player;
protected static Map[] maps;
public World(int startMap) {
if (maps == null) {
maps = new ImageMap[8];
for (int i = 0; i < maps.length; i++) {
maps[i] = new ImageMap("/res/images/maps/map" + i + "a.png");
}
}
init(maps[startMap]);
}
public World(Map startMap) {
init(startMap);
}
private void init(Map startMap) {
currentMap = startMap;
player = new Player();
add(currentMap);
}
public Map getCurrentMap() {
return currentMap;
}
public Player getPlayer() {
return player;
}
public void changeMap(DoorTile door) {
currentMap.stop();
currentMap.entfernen(player.actionFigur);
entfernen(currentMap);
currentMap = door.getConnectedDoor().getMap();
add(currentMap);
currentMap.add(player.actionFigur);
currentMap.start();
player.setPos(door.getConnectedDoor().getPosX() + 0.5f, door.getConnectedDoor().getPosY() + 0.5f);
door.getConnectedDoor().waitForLeave();
}
public void start() {
currentMap.addAnimatedEntity(player);
currentMap.start();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

View File

Before

Width:  |  Height:  |  Size: 116 B

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 168 B

After

Width:  |  Height:  |  Size: 169 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 169 B

After

Width:  |  Height:  |  Size: 181 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 181 B

After

Width:  |  Height:  |  Size: 171 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 171 B

After

Width:  |  Height:  |  Size: 162 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 162 B

After

Width:  |  Height:  |  Size: 166 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 166 B

After

Width:  |  Height:  |  Size: 164 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 B

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 444 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 502 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

View File

Before

Width:  |  Height:  |  Size: 137 B

After

Width:  |  Height:  |  Size: 137 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 B

View File

Before

Width:  |  Height:  |  Size: 230 B

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 545 B

After

Width:  |  Height:  |  Size: 450 B