Compare commits
3 Commits
c035253790
...
f386ef49f6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f386ef49f6 | ||
|
|
3a65c74546 | ||
|
|
e643ec092d |
@@ -1,6 +1,7 @@
|
||||
package main;
|
||||
|
||||
import ea.Game;
|
||||
import ea.Taste;
|
||||
import main.HUD.HUD;
|
||||
import main.worlds.TestWorld;
|
||||
import main.worlds.World;
|
||||
@@ -11,6 +12,7 @@ import main.worlds.World;
|
||||
public class Main extends Game {
|
||||
|
||||
public static Main instance;
|
||||
public static boolean SHOW_DEBUG = false;
|
||||
|
||||
private World world;
|
||||
private HUD hud;
|
||||
@@ -27,12 +29,15 @@ public class Main extends Game {
|
||||
wurzel.add(world);
|
||||
hud = new HUD();
|
||||
wurzel.add(hud);
|
||||
sounds = new Sounds();
|
||||
sounds.playSound(2);
|
||||
// sounds = new Sounds();
|
||||
// sounds.playSound(2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tasteReagieren(int code) {
|
||||
if (code == Taste.O) {
|
||||
SHOW_DEBUG = !SHOW_DEBUG;
|
||||
}
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
|
||||
77
Zoelda/src/main/entities/AnimatedEntity.java
Normal file
77
Zoelda/src/main/entities/AnimatedEntity.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Zoelda/src/main/entities/Coin.java
Normal file
27
Zoelda/src/main/entities/Coin.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package main.entities;
|
||||
|
||||
import main.SheetLoader;
|
||||
|
||||
public class Coin extends AnimatedEntity {
|
||||
|
||||
private static SheetLoader loader = new SheetLoader("/res/images/coins.png");
|
||||
|
||||
public Coin() {
|
||||
loader.generateFigures(8, 8, new int[] {8, 8, 1});
|
||||
actionFigur.neuerZustand(loader.getFigur(0), "gold");
|
||||
actionFigur.neuerZustand(loader.getFigur(1), "silver");
|
||||
actionFigur.neuerZustand(loader.getFigur(2), "bronze");
|
||||
zustandSetzen("gold");
|
||||
|
||||
posX = 4f;
|
||||
posY = 4f;
|
||||
width = 0.375f;
|
||||
height = 0.25f;
|
||||
spriteOffsetY = -0.1f;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void update() {
|
||||
super.update();
|
||||
}
|
||||
}
|
||||
@@ -1,63 +1,20 @@
|
||||
package main.entities;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import ea.ActionFigur;
|
||||
import ea.Figur;
|
||||
import ea.internal.gra.PixelFeld;
|
||||
import main.Main;
|
||||
import main.worlds.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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param figur - erstes (standart) Sprite
|
||||
* @param name - name des Zustands
|
||||
*/
|
||||
public LivingEntity() {
|
||||
actionFigur = new ActionFigur(noTexture, "undefined") {
|
||||
// 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) {
|
||||
@@ -68,29 +25,9 @@ public abstract class LivingEntity extends Entity {
|
||||
deleteEntity();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ 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;
|
||||
@@ -69,7 +70,7 @@ public abstract class Map extends Knoten implements Ticker {
|
||||
return entities;
|
||||
}
|
||||
|
||||
public void addLivingEntity(LivingEntity e) {
|
||||
public void addAnimatedEntity(AnimatedEntity e) {
|
||||
entities.add(e);
|
||||
add(e.actionFigur);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ public class TutorialMap extends Map {
|
||||
}
|
||||
}
|
||||
|
||||
addLivingEntity(new Spider());
|
||||
addLivingEntity(new Snake());
|
||||
addAnimatedEntity(new Spider());
|
||||
addAnimatedEntity(new Snake());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package main.worlds;
|
||||
|
||||
import main.entities.Coin;
|
||||
import main.entities.Snake;
|
||||
import main.maps.Map;
|
||||
|
||||
@@ -14,8 +15,10 @@ public class TestWorld extends World {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Snake s = new Snake();
|
||||
s.setPosX((float) (Math.random() * 5 + 2));
|
||||
getCurrentMap().addLivingEntity(s);
|
||||
getCurrentMap().addAnimatedEntity(s);
|
||||
}
|
||||
|
||||
getCurrentMap().addAnimatedEntity(new Coin());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public abstract class World extends Knoten {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
currentMap.addLivingEntity(player);
|
||||
currentMap.addAnimatedEntity(player);
|
||||
currentMap.start();
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Zoelda/src/res/images/coins.png
Normal file
BIN
Zoelda/src/res/images/coins.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 414 B |
Reference in New Issue
Block a user