Compare commits

..

30 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
61 changed files with 825 additions and 505 deletions

1
.gitignore vendored
View File

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

Binary file not shown.

View File

@@ -2,7 +2,7 @@ package main;
import ea.Ticker;
import main.entities.player.Player;
import main.maps.ImageMap;
import main.maps.Map;
public class DoorTile extends Tile implements Ticker {
@@ -13,11 +13,11 @@ public class DoorTile extends Tile implements Ticker {
private int side;
private DoorTile connected;
private ImageMap map;
private Map map;
private boolean waitForLeave;
public DoorTile(float x, float y, ImageMap map) {
super(Tile.DOOR, x, y);
public DoorTile(int id, float x, float y, Map map) {
super(id, x, y);
this.map = map;
}
@@ -28,8 +28,9 @@ public class DoorTile extends Tile implements Ticker {
float dist = player.dist(posX + 0.5f, posY + 0.5f);
if (dist < 0.5f) {
if (!waitForLeave) {
if (connected != null) {
Main.instance.getWorld().changeMap(this);
waitForLeave = true;
}
}
} else {
waitForLeave = false;
@@ -53,7 +54,7 @@ public class DoorTile extends Tile implements Ticker {
return connected;
}
public ImageMap getMap() {
public Map getMap() {
return map;
}
@@ -62,10 +63,15 @@ public class DoorTile extends Tile implements Ticker {
}
@Override
public Tile clone() {
DoorTile t = new DoorTile(posX, posY, map);
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,32 +1,35 @@
package main;
package main.HUD;
import ea.BoundingRechteck;
import ea.Knoten;
import ea.Ticker;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
public class HUD extends Knoten implements Ticker {
import javax.imageio.ImageIO;
import ea.Knoten;
import ea.Ticker;
import main.Main;
public class Herzen extends Knoten implements Ticker{
private final static int SCALE = 50;
private BufferedImage volles_Herz;
private BufferedImage halbes_Herz;
private BufferedImage leeres_Herz;
private BufferedImage inventory;
private BufferedImage hauptBild;
private BufferedImage[] HPLeiste;
private final static int SCALE = 50;
private boolean shakingSwitch;
private float HPVel;
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
HPLeiste = new BufferedImage[3];
Main.instance.manager.anmelden(this, 200);
HPLeiste = new BufferedImage[5];
HPLeisteY = new int [HPLeiste.length];
try {
hauptBild = ImageIO.read(HUD.class.getResourceAsStream("/res/images/icons.png"));
inventory = ImageIO.read(HUD.class.getResourceAsStream("/res/images/inventory.png"));
} catch (IOException e) {
e.printStackTrace();
}
@@ -45,26 +48,37 @@ public class HUD extends Knoten implements Ticker {
HPLeiste[2] = volles_Herz;
}
private int changeY () {
int y = 0;
if(Main.instance.getWorld().getPlayer().getHP() < 0.33f) {
private int shakeY() {
shakingSwitch = !shakingSwitch;
if(shakingSwitch == true) {
return y+=3;
if (shakingSwitch == true) {
return 3;
}
}
if(HPVel > 0) {
}
return y;
return 0;
}
//wird alle 200ms ausgeführt:
@Override
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() {
// 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,
// halb oder leer ist (BIG BRAIN):
HPVel = Main.instance.getWorld().getPlayer().getHP() - lastHP;
lastHP = Main.instance.getWorld().getPlayer().getHP();
float localeHP;
for (int i = 0; i < HPLeiste.length; i++) {
localeHP = Main.instance.getWorld().getPlayer().getHP();
@@ -77,15 +91,24 @@ public class HUD extends Knoten implements Ticker {
HPLeiste[i] = volles_Herz;
}
}
}
//Zeichnet alle Herzen im Array HPLeiste[] auf den Bildschirm
@Override
public void zeichnen(Graphics2D g, BoundingRechteck r) {
if(Main.instance.getWorld().getPlayer().getHP() < 0.33f) {
y = shakeY();
} else {
for (int i = 0; i < HPLeiste.length; i++) {
g.drawImage(HPLeiste[i], (i+2) * SCALE, changeY(), SCALE, SCALE, null);
}
g.drawImage(inventory,0,0,SCALE*2,SCALE*2,null);
HPLeisteY[i] = regenY();
}
}
}
// 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,6 +1,10 @@
package main;
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.
@@ -8,24 +12,32 @@ import ea.Game;
public class Main extends Game {
public static Main instance;
public static boolean SHOW_DEBUG = false;
private World world;
private HUD hud;
private Sounds sounds;
public Main() {
super(World.SCALE * 15, World.SCALE * 11, 16);
instance = this;
// Welt initialisieren und Spieler hinzufügen
world = new World();
hud = new HUD();
// die Welt zu EA hinzufügen
// Welt initialisieren und Spieler hinzufügen und die Welt zu EA hinzufügen
world = new TestWorld();
manager.anmelden(world.getPlayer(), 20);
world.start();
wurzel.add(world);
hud = new HUD();
wurzel.add(hud);
// sounds = new Sounds();
// sounds.playSound(2);
}
@Override
public void tasteReagieren(int code) {
if (code == Taste.O) {
SHOW_DEBUG = !SHOW_DEBUG;
}
}
public World getWorld() {

View File

@@ -12,20 +12,26 @@ import ea.internal.gra.PixelFeld;
public class SheetLoader {
private Figur[] figures;
private BufferedImage sheet;
/**
* Macht aus einem Spritesheet Figuren.
*
* @param path - Der pfad zum 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
*/
public SheetLoader(String path, int width, int height, int[] frames) {
public SheetLoader(String path) {
try {
// Bild laden
BufferedImage sheet = ImageIO.read(Tile.class.getResourceAsStream(path));
sheet = ImageIO.read(Tile.class.getResourceAsStream(path));
} catch (IOException e) {
e.printStackTrace();
}
}
public void generateFigures(int width, int height, int[] frames) {
// Anzahl der Animationen
int rows = frames.length;
@@ -44,10 +50,6 @@ public class SheetLoader {
fig.animationSetzen(sprites[i]);
figures[i] = fig;
}
} catch (IOException e) {
e.printStackTrace();
}
}
public Figur getFigur(int 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.Knoten;
import main.worlds.World;
/**
* Ein feld auf der Map
@@ -21,10 +22,13 @@ public class Tile extends Knoten {
public static final int STONE_WALL = 3;
public static final int STONE_WALL_BOTTOM = 4;
public static final int STONE_FLOOR = 5;
public static final int DOOR = 6;
public static final int STONE_FLOOR_SHADOW_LEFT = 7;
public static final int DOOR_LEFT_BOTTOM = 8;
public static final int DOOR_LEFT_TOP = 9;
public static final int STONE_FLOOR_SHADOW_LEFT = 6;
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 int id; // Die id dises Tiles//
@@ -50,17 +54,17 @@ public class Tile extends Knoten {
if (id != VOID) {
img = images[id].clone();
img.positionSetzen(posX * World.SCALE, posY * World.SCALE);
// Bild zu EA hinzufügen.
// Bild zu EA hinzuf<EFBFBD>gen.
add(img);
}
}
private static void loadImages() {
images = new Bild[10];
images = new Bild[13];
for (int i = 0; i < images.length; i++) {
try {
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.
if (i == GRASS) {
buff = buff.getSubimage(16 * (int) (Math.random() * 8), 0, 16, 16);
@@ -76,7 +80,7 @@ public class Tile extends Knoten {
}
/**
* @return den Pfad der zu der Id gehört.
* @return den Pfad der zu der Id gehoert.
*/
private static String getPathFromId(int id) {
switch (id) {
@@ -87,25 +91,31 @@ public class Tile extends Knoten {
case WALL_BOTTOM:
return "/res/images/tiles/wall_bottom.png";
case STONE_WALL:
return "/res/images/tiles/test.png";
return "/res/images/tiles/stone_wall.png";
case STONE_WALL_BOTTOM:
return "/res/images/tiles/stone_wall_bottom.png";
case STONE_FLOOR:
return "/res/images/tiles/TestTest.png";
case DOOR:
return "/res/images/tiles/door_left_bottom.png";
return "/res/images/tiles/stone_floor.png";
case STONE_FLOOR_SHADOW_LEFT:
return "/res/images/tiles/stone_floor_shadow_left.png";
case DOOR_LEFT_BOTTOM:
return "/res/images/tiles/door_left_bottom.png";
case DOOR_LEFT_TOP:
return "/res/images/tiles/door_left_top.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 die Größe der Textur
* @return die Groesse der Textur
*/
private static int getSize() {
return 16;
@@ -115,34 +125,34 @@ public class Tile extends Knoten {
* @return ob man durch das Tile durchgehen kann
*/
public boolean isCollidable() {
// Alle Tiles durch die man nicht laufen soll müssen hier true zurückgeben,
// sonst werden sie bei der Collisiondetection nicht berücksichtigt.
// Alle Tiles durch die man nicht laufen soll muessen hier true zurueckgeben,
// sonst werden sie bei der Collisiondetection nicht ber<EFBFBD>cksichtigt.
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() {
return positionY();
}
/**
* Kleine Hifsmethode un die koordinate der Bottom-Kante rurückzugenben.
* Kleine Hifsmethode um die Koordinate der Bottom-Kante zurueckzugenben.
*/
public int getBottom() {
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() {
return positionX();
}
/**
* Kleine Hifsmethode un die koordinate der Right-Kante rurückzugenben.
* Kleine Hifsmethode um die Koordinate der Right-Kante zurueckzugenben.
*/
public int getRight() {
return positionX() + getSize();
@@ -152,6 +162,14 @@ public class Tile extends Knoten {
return id;
}
public float getPosX() {
return posX;
}
public float getPosY() {
return posY;
}
@Override
public Tile clone() {
return new Tile(id, posX, posY);

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 width = 1f, height = 1f; // Breite und Höhe der Hitbox.
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)
@Override
@@ -49,12 +51,16 @@ public abstract class Entity implements Ticker {
/**
* 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 y = (int) (posY - 2); y < posY + 2; y++) {
if (x >= 0 && x < map.getWidth() && y >= 0 && y < map.getHeight()) {
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 distE = Math.abs((x + 1 + width / 2) - posX);
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.
*/
@@ -123,9 +160,10 @@ public abstract class Entity implements Ticker {
* Generiert einen vektor von diesm Entity zu einem anderen
*/
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) {
return new Vektor(0.0000001f, 0.0000001f);
return new Vektor(0.001f, 0.001f);
}
return v;
}
@@ -152,6 +190,7 @@ public abstract class Entity implements Ticker {
/**
* Gibt den velX Wert zurück.
*
* @return gibt den velX Wert als float zurück.
*/
public float getVelX() {
@@ -160,6 +199,7 @@ public abstract class Entity implements Ticker {
/**
* Gibt den velY Wert zurück.
*
* @return gibt den velY Wert als float zurück.
*/
public float getVelY() {
@@ -168,6 +208,7 @@ public abstract class Entity implements Ticker {
/**
* Setzt eine neue velX velocity.
*
* @param velX neuer float velX Wert.
*/
public void setVelX(float velX) {
@@ -176,6 +217,7 @@ public abstract class Entity implements Ticker {
/**
* Setzt eine neue Y velocity.
*
* @param velY neuer float velY Wert.
*/
public void setVelY(float velY) {
@@ -195,6 +237,14 @@ public abstract class Entity implements Ticker {
posY = y;
}
public float getPosX() {
return posX;
}
public float getPosY() {
return posY;
}
public void deleteEntity() {
deleteEntity = true;
}
@@ -202,4 +252,12 @@ public abstract class Entity implements Ticker {
public boolean isReadyToDelete() {
return deleteEntity;
}
public float getWidth() {
return width;
}
public float getHeight() {
return height;
}
}

View File

@@ -1,76 +1,34 @@
package main.entities;
import ea.ActionFigur;
import ea.Figur;
import main.World;
/*
* 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
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 mirrored; // true = gespiegelt, false = nicht
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
protected void update() {
// Prüft zu welcher seite man guckt
if (velX < 0) {
side = true;
side = !mirrored;
} else if (velX > 0) {
side = false;
side = mirrored;
}
if (hp <= 0) {
actionFigur.zustandSetzen(getDeathAnimationName());
velX = 0;
velY = 0;
if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length - 1) {
if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length - 1 && !isReadyToDelete()) {
deleteEntity();
onDeath();
}
}
// 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);
super.update();
}
/**
* 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() {
return hp;
}
@@ -83,4 +41,7 @@ public abstract class LivingEntity extends Entity {
public abstract String getDeathAnimationName();
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 {
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");
private float damage = 0.1f;
private boolean attackOnce;
public Snake() {
super(loader.getFigur(0), "idle");
loader.generateFigures(32, 32, new int[] { 10, 10, 10, 10, 13, 8 });
posX = 9f;
posY = 9f;
accelleration = 0.006f;
@@ -21,6 +22,7 @@ public class Snake extends LivingEntity {
height = 0.8f;
mirrored = true;
actionFigur.neuerZustand(loader.getFigur(0), "idle");
actionFigur.neuerZustand(loader.getFigur(1), "lost_sight");
actionFigur.neuerZustand(loader.getFigur(2), "walk");
actionFigur.neuerZustand(loader.getFigur(3), "attack");
@@ -38,6 +40,14 @@ public class Snake extends LivingEntity {
if (lineOfSightClear(player)) {
if (dist(player) < 1f) {
zustandSetzen("attack");
if (actionFigur.aktuelleFigur().aktuellesBild() == 6) {
if (!attackOnce) {
attackOnce = true;
player.takeDamage(damage, this);
}
} else {
attackOnce = false;
}
} else {
Vektor toPlayer = vectorToEntity(player).normiert();
velX += toPlayer.x * accelleration;
@@ -47,7 +57,8 @@ public class Snake extends LivingEntity {
} else {
if (!actionFigur.aktuellesVerhalten().equals("idle")) {
zustandSetzen("lost_sight");
if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length - 1) {
if (actionFigur.aktuelleFigur().aktuellesBild() == actionFigur.aktuelleFigur().animation().length
- 1) {
zustandSetzen("idle");
}
}
@@ -57,7 +68,6 @@ public class Snake extends LivingEntity {
zustandSetzen("walk");
}
}
this.checkTileCollisions(Main.instance.getWorld().getCurrentMap());
super.update();
}
@@ -70,4 +80,16 @@ public class Snake extends LivingEntity {
public String getDamageAnimationName() {
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 {
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() {
super(loader.getFigur(0), "idle");
loader.generateFigures(32, 32, new int[] { 5, 3, 6, 9, 9, 8 });
width = 0.7f;
height = 0.8f;
@@ -20,6 +20,7 @@ public class Spider extends LivingEntity {
posY = 4f;
mirrored = true;
actionFigur.neuerZustand(loader.getFigur(0), "idle");
actionFigur.neuerZustand(loader.getFigur(1), "lost_sight");
actionFigur.neuerZustand(loader.getFigur(2), "walk");
actionFigur.neuerZustand(loader.getFigur(3), "attack");
@@ -55,7 +56,6 @@ public class Spider extends LivingEntity {
zustandSetzen("walk");
}
}
this.checkTileCollisions(Main.instance.getWorld().getCurrentMap());
super.update();
}

View File

@@ -11,13 +11,13 @@ import main.entities.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");
private boolean onlyAttackOnceTrigger;
private float range = 1.2f; // die reichweite der Attacke
private PlayerInventory inventory;
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
width = 0.7f;
@@ -27,22 +27,22 @@ public class Player extends LivingEntity {
posX = 7.5f;
posY = 5.5f;
// XXX
accelleration = 0.05f;
// unterschiedliche Animationsgeschwindigkeiten
// für idle
// f<EFBFBD>r idle
loader.getFigur(0).animationsGeschwindigkeitSetzen(200);
// fürs laufen
// f<EFBFBD>rs laufen
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(1), "walk");
actionFigur.neuerZustand(loader.getFigur(2), "strike");
actionFigur.neuerZustand(loader.getFigur(3), "swipe");
actionFigur.neuerZustand(loader.getFigur(6), getDamageAnimationName());
actionFigur.neuerZustand(loader.getFigur(7), getDeathAnimationName());
//Spieler Inventar
inventory = new PlayerInventory(5);
}
@Override
@@ -50,7 +50,7 @@ public class Player extends LivingEntity {
// Bei dieser animation bleibt man sofort stehen.
if (!((actionFigur.aktuellesVerhalten().equals("strike"))
&& 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()
.aktuellesBild() < actionFigur.aktuelleFigur().animation().length - 1)) {
@@ -87,9 +87,6 @@ public class Player extends LivingEntity {
}
onlyAttackOnceTrigger = false;
}
// auf Kollisionen prüfen
checkTileCollisions(Main.instance.getWorld().getCurrentMap());
// LivingEntity auch updaten lassen
super.update();
} else {
@@ -97,9 +94,7 @@ public class Player extends LivingEntity {
velY = 0;
}
// auf Kollisionen prüfen
checkTileCollisions(Main.instance.getWorld().getCurrentMap());
if (!actionFigur.aktuellesVerhalten().equals(getDamageAnimationName())) {
if (!onlyAttackOnceTrigger && actionFigur.aktuellesVerhalten().equals("swipe")
&& actionFigur.aktuelleFigur().aktuellesBild() == 1) {
onlyAttackOnceTrigger = true;
@@ -120,6 +115,11 @@ public class Player extends LivingEntity {
}
}
}
}
public PlayerInventory getInventory() {
return inventory;
}
@Override
public String getDeathAnimationName() {

View File

@@ -32,7 +32,12 @@ public class Corridor extends Map {
}
}
}
}
registerEntities();
@Override
public Map clone() {
Corridor c = new Corridor();
c.cloneTiles(this);
return c;
}
}

View File

@@ -3,38 +3,26 @@ 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.Main;
import main.Tile;
public class ImageMap extends Map {
//Erstellung der abzulesenden Tiles (einem Tile wird eine farbe zugewiesen)
// Erstellung der abzulesenden Tiles (einem Tile wird eine Farbe zugewiesen)
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)), new PixelTile(Tile.DOOR_LEFT_TOP, new Color(255, 150, 0)) ,
new PixelTile(Tile.DOOR_LEFT_BOTTOM, new Color(69, 150, 0)), new PixelTile(Tile.STONE_WALL_BOTTOM, new Color(145, 145, 145)),
new PixelTile(Tile.STONE_FLOOR_SHADOW_LEFT, new Color(251, 251, 129))};
public DoorTile topDoor;
public DoorTile leftDoor;
public DoorTile rightDoor;
public DoorTile bottomDoor;
private static ImageMap[] maps;
static {
maps = new ImageMap[8];
for (int i = 0; i < maps.length; i++) {
System.out.println("/res/images/maps/map" + (i + 1) + "a.png");
maps[i] = new ImageMap("/res/images/maps/map" + (i + 1) + "a.png");
}
}
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_LEFT, new Color(255, 150, 0)),
new PixelTile(Tile.DOOR_RIGHT, new Color(69, 150, 0)),
new PixelTile(Tile.DOOR_BOTTOM, new Color(150, 150, 0)),
new PixelTile(Tile.DOOR_TOP, new Color(0, 147, 150)),
new PixelTile(Tile.STONE_WALL_BOTTOM, new Color(145, 145, 145)),
new PixelTile(Tile.STONE_FLOOR_SHADOW_LEFT, new Color(251, 251, 129)) };
public ImageMap(String path) {
super(15, 11);
@@ -54,37 +42,40 @@ public class ImageMap extends Map {
break;
}
}
if (id == Tile.DOOR_LEFT_BOTTOM) {
DoorTile door = new DoorTile(x, y, this);
tiles[x][y] = door;
if (id == Tile.DOOR_LEFT) {
DoorTile door = new DoorTile(id, x, y, this);
leftDoor = door;
door.setSide(DoorTile.LEFT);
}
if (id == Tile.DOOR ) {
DoorTile door = new DoorTile(x, y, this);
tiles[x][y] = door;
if (x == 7) {
if (y < 5) {
topDoor = door;
door.setSide(DoorTile.TOP);
} else {
bottomDoor = door;
door.setSide(DoorTile.BOTTOM);
add(tiles[x][y]);
continue;
}
}
if (y == 5) {
if (x < 7) {
leftDoor = door;
door.setSide(DoorTile.LEFT);
} else {
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;
}
} else {
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]);
}
}
@@ -95,28 +86,7 @@ public class ImageMap extends Map {
public ImageMap(ImageMap map) {
super(map.getWidth(), map.getHeight());
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];
switch (dt.getSide()) {
case DoorTile.TOP:
topDoor = dt;
break;
case DoorTile.BOTTOM:
bottomDoor = dt;
break;
case DoorTile.LEFT:
leftDoor = dt;
break;
case DoorTile.RIGHT:
rightDoor = dt;
break;
}
}
}
}
cloneTiles(map);
}
private static class PixelTile {
@@ -129,107 +99,8 @@ public class ImageMap extends Map {
}
}
public void generate(ArrayList<ImageMap> dungeon, int fromSide) {
if (topDoor != null && fromSide != DoorTile.TOP) {
ImageMap map = nextMap(DoorTile.BOTTOM);
connectDoors(topDoor, map.bottomDoor);
dungeon.add(map);
map.generate(dungeon, DoorTile.BOTTOM);
}
if (bottomDoor != null && fromSide != DoorTile.BOTTOM) {
ImageMap map = nextMap(DoorTile.TOP);
connectDoors(bottomDoor, map.topDoor);
dungeon.add(map);
map.generate(dungeon, DoorTile.TOP);
}
if (leftDoor != null && fromSide != DoorTile.LEFT) {
ImageMap map = nextMap(DoorTile.RIGHT);
connectDoors(leftDoor, map.rightDoor);
dungeon.add(map);
map.generate(dungeon, DoorTile.RIGHT);
}
if (rightDoor != null && fromSide != DoorTile.RIGHT) {
ImageMap map = nextMap(DoorTile.LEFT);
connectDoors(rightDoor, map.leftDoor);
dungeon.add(map);
map.generate(dungeon, DoorTile.LEFT);
}
}
private ImageMap nextMap(int entrySide) {
float r = 1f;
if (r < 0.1f) {
return maps[0].clone();
}
if (r < 0.2f) {
return maps[1].clone();
}
if (r < 0.6f) {
ImageMap map;
do {
map = maps[(int) (Math.random() * 2) + 2];
} while (!map.hasEntry(entrySide));
return map.clone();
} else {
ImageMap map;
do {
map = maps[(int) (Math.random() * 4) + 4];
} while (!map.hasEntry(entrySide));
return map.clone();
}
}
private boolean hasEntry(int entrySide) {
switch (entrySide) {
case DoorTile.TOP:
return topDoor != null;
case DoorTile.BOTTOM:
return bottomDoor != null;
case DoorTile.LEFT:
return leftDoor != null;
case DoorTile.RIGHT:
return rightDoor != null;
}
return false;
}
private void connectDoors(DoorTile door, DoorTile door2) {
door.setConnectedDoor(door2);
door2.setConnectedDoor(door);
}
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);
}
}
@Override
protected ImageMap clone() {
public ImageMap clone() {
return new ImageMap(this);
}
}

View File

@@ -4,10 +4,12 @@ import java.util.ArrayList;
import ea.Knoten;
import ea.Ticker;
import main.DoorTile;
import main.Main;
import main.Tile;
import main.entities.AnimatedEntity;
import main.entities.Entity;
import main.entities.LivingEntity;
import main.entities.player.Player;
/**
* Auf der Map sind alle Entities, sowie die Tiles gespiechert.
@@ -16,7 +18,12 @@ public abstract class Map extends Knoten implements Ticker {
protected Tile[][] tiles; // Die Tiles der map in einem 2D Array.
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) {
tiles = new Tile[width][height];
@@ -42,8 +49,8 @@ public abstract class Map extends Knoten implements Ticker {
for (int i = 0; i < entities.size(); i++) {
Entity e = entities.get(i);
if (e.isReadyToDelete()) {
if (e instanceof LivingEntity) {
entfernen(((LivingEntity) e).actionFigur);
if (e instanceof AnimatedEntity) {
entfernen(((AnimatedEntity) e).actionFigur);
}
Main.instance.manager.abmelden(e);
entities.remove(e);
@@ -63,9 +70,88 @@ public abstract class Map extends Knoten implements Ticker {
return entities;
}
public void registerEntities() {
for (Entity e : getEntities()) {
public void addAnimatedEntity(AnimatedEntity e) {
entities.add(e);
add(e.actionFigur);
if (started) {
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 < tiles.length; x++) {
for (int y = 0; y < tiles[0].length; y++) {
//Wand
if((x == 4 || y == 9 || x == 10) && x > 3 && y > 0 && x < 11 && y < 10 && x != 7 ) {
tiles[x][y] = new Tile(3, x, y);
add(tiles[x][y]);
}
//Boden
else if(x > 3 && y > 0 && x < 11 && y < 10) {
tiles[x][y] = new Tile(5, x, y);
add(tiles[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 < tiles.length; x++) {
for (int y = 0; y < tiles[0].length; y++) {
// Wand
if (y == 0 || x == 0 || y == 10 || x == 14) {
// Übergang, Tür
if (y == 10) {
if (x > 4 && x < 10) {
tiles[x][y] = new Tile(5, x, y);
add(tiles[x][y]);
continue;
}
}
tiles[x][y] = new Tile(3, x, y);
add(tiles[x][y]);
}
// 3D-Wand
else if(y == 1 ) {
tiles[x][y] = new Tile(4, x, y);
add(tiles[x][y]);
}
// Steinboden
else {
tiles[x][y] = new Tile(5, x, y);
add(tiles[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 < tiles.length; x++) {
for (int y = 0; y < tiles[0].length; y++) {
tiles[x][y] = new Tile(Math.random() * 5 < 1 ? 1 : 0, x, y);
add(tiles[x][y]);
}
}
}
}

View File

@@ -28,17 +28,14 @@ public class TutorialMap extends Map {
}
}
// und Spinnen auch
Spider spider = new Spider();
add(spider.actionFigur);
getEntities().add(spider);
addAnimatedEntity(new Spider());
addAnimatedEntity(new Snake());
}
//und
Snake snake = new Snake();
add(snake.actionFigur);
getEntities().add(snake);
// Alle Entities als ticker registrieren (triggert dann die update methoden)
registerEntities();
@Override
public Map clone() {
TutorialMap c = new TutorialMap();
c.cloneTiles(this);
return c;
}
}

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

@@ -1,45 +1,43 @@
package main;
package main.worlds;
import ea.Knoten;
import main.DoorTile;
import main.entities.player.Player;
import main.maps.ImageMap;
import main.maps.Map;
import java.util.ArrayList;
/**
* Hier werden alle Maps gespeichert.
*/
public class World extends Knoten {
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 ImageMap currentMap; // Die Map die aktuell angezeigt werden soll.
private ArrayList<ImageMap> dungeon;
private Map currentMap; // Die Map die aktuell angezeigt werden soll.
private Player player;
public World() {
protected static Map[] maps;
dungeon = new ArrayList<>(50);
ImageMap start = new ImageMap("/res/images/maps/map2a.png");
dungeon.add(start);
currentMap = start;
currentMap.start();
start.generate(dungeon, DoorTile.BOTTOM);
System.out.println("generated!");
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();
currentMap.getEntities().add(player);
currentMap.add(player.actionFigur);
Main.instance.manager.anmelden(player, 20);
add(currentMap);
}
public Map getCurrentMap() {
@@ -55,10 +53,15 @@ public class World extends Knoten {
currentMap.entfernen(player.actionFigur);
entfernen(currentMap);
currentMap = door.getConnectedDoor().getMap();
currentMap.add(player.actionFigur);
add(currentMap);
currentMap.add(player.actionFigur);
currentMap.start();
player.setPos(door.getConnectedDoor().getPosX() + 0.5f, door.getConnectedDoor().getPosY() + 0.5f);
door.getConnectedDoor().waitForLeave();
player.setPos(door.getConnectedDoor().posX + 0.5f, door.getConnectedDoor().posY + 0.5f);
}
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

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.

Before

Width:  |  Height:  |  Size: 223 B

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.

Before

Width:  |  Height:  |  Size: 234 B

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 181 B

After

Width:  |  Height:  |  Size: 171 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 217 B

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.

Before

Width:  |  Height:  |  Size: 208 B

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.

Before

Width:  |  Height:  |  Size: 190 B

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.

Before

Width:  |  Height:  |  Size: 193 B

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.

Before

Width:  |  Height:  |  Size: 203 B

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 444 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 523 B

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 535 B

After

Width:  |  Height:  |  Size: 243 B

View File

Before

Width:  |  Height:  |  Size: 502 B

After

Width:  |  Height:  |  Size: 502 B

View File

Before

Width:  |  Height:  |  Size: 137 B

After

Width:  |  Height:  |  Size: 137 B

View File

Before

Width:  |  Height:  |  Size: 230 B

After

Width:  |  Height:  |  Size: 230 B