This commit is contained in:
Max 2021-07-01 11:00:34 +02:00
commit b85a36bf14
3 changed files with 28 additions and 8 deletions

View File

@ -10,6 +10,7 @@ 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 {
@ -26,21 +27,22 @@ public class Inventory extends Knoten implements Ticker {
} catch (IOException e) {
e.printStackTrace();
}
coinCounterIcon = coinCounterIcon.getSubimage(0,20,7,4);
coinCounterIcon = coinCounterIcon.getSubimage(0, 20, 7, 4);
}
public void style(Graphics2D g){
public void style(Graphics2D g) {
Font currentFont = g.getFont();
Font newFont = currentFont.deriveFont(Font.BOLD,20);
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,SCALE,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<EFBFBD>hrt:

View File

@ -7,6 +7,9 @@ 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 });
@ -31,13 +34,24 @@ public class Coin extends AnimatedEntity {
@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) {
deleteEntity();
Main.instance.getWorld().getPlayer().getInventory().addCoins(1);
if (e instanceof Player && !moveToCounterAnimation) {
moveToCounterAnimation = true;
enableTileCollisions = false;
}
}
}

View File

@ -19,6 +19,7 @@ public abstract class Entity implements Ticker {
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
@ -51,6 +52,9 @@ public abstract class Entity implements Ticker {
* Checkt collision mit tiles von der map. Fertig, clean, nie wieder ändern.
*/
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()) {