Coin Counter added
This commit is contained in:
parent
3e99a2ebc2
commit
e818037d75
|
@ -1,6 +1,6 @@
|
|||
package main.HUD;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -8,26 +8,42 @@ import javax.imageio.ImageIO;
|
|||
|
||||
import ea.Knoten;
|
||||
import ea.Ticker;
|
||||
import main.Main;
|
||||
import main.entities.player.PlayerInventory;
|
||||
|
||||
public class Inventory extends Knoten implements Ticker {
|
||||
|
||||
private static final int SCALE = 50;
|
||||
private BufferedImage inventory;
|
||||
private BufferedImage inventoryFrame;
|
||||
private BufferedImage coinCounterIcon;
|
||||
private PlayerInventory inventory;
|
||||
|
||||
public Inventory() {
|
||||
inventory = Main.instance.getWorld().getPlayer().getInventory();
|
||||
try {
|
||||
inventory = ImageIO.read(HUD.class.getResourceAsStream("/res/images/inventory.png"));
|
||||
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) {
|
||||
g.drawImage(inventory, 0, 0, SCALE * 2, SCALE * 2, null);
|
||||
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,SCALE,SCALE/2,null);
|
||||
}
|
||||
|
||||
// wird alle 50ms ausgeführt:
|
||||
// wird alle 50ms ausgef<EFBFBD>hrt:
|
||||
public void tick() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package main.entities;
|
||||
|
||||
import main.Main;
|
||||
import main.SheetLoader;
|
||||
import main.entities.player.Player;
|
||||
|
||||
|
@ -36,6 +37,7 @@ public class Coin extends AnimatedEntity {
|
|||
public void onEntityCollision(Entity e) {
|
||||
if (e instanceof Player) {
|
||||
deleteEntity();
|
||||
Main.instance.getWorld().getPlayer().getInventory().addCoins(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ public class Player extends LivingEntity {
|
|||
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() {
|
||||
loader.generateFigures(64, 32, new int[] { 5, 8, 7, 6, 2, 5, 4, 7 });
|
||||
|
@ -27,18 +28,21 @@ public class Player extends LivingEntity {
|
|||
posY = 5.5f;
|
||||
|
||||
// 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
|
||||
|
@ -46,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)) {
|
||||
|
||||
|
@ -113,6 +117,10 @@ public class Player extends LivingEntity {
|
|||
}
|
||||
}
|
||||
|
||||
public PlayerInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDeathAnimationName() {
|
||||
return "die";
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 250 B |
Loading…
Reference in New Issue