Compare commits
3 Commits
21790ecd7a
...
d46d25115e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d46d25115e | ||
|
|
5f0b827fab | ||
|
|
ca40e4c01a |
@@ -10,6 +10,7 @@ import ea.Knoten;
|
|||||||
import ea.Ticker;
|
import ea.Ticker;
|
||||||
import main.Main;
|
import main.Main;
|
||||||
import main.entities.player.PlayerInventory;
|
import main.entities.player.PlayerInventory;
|
||||||
|
import main.worlds.World;
|
||||||
|
|
||||||
public class Inventory extends Knoten implements Ticker {
|
public class Inventory extends Knoten implements Ticker {
|
||||||
|
|
||||||
@@ -40,7 +41,8 @@ public class Inventory extends Knoten implements Ticker {
|
|||||||
style(g);
|
style(g);
|
||||||
g.drawImage(inventoryFrame, 0, 0, SCALE * 2, SCALE * 2, null);
|
g.drawImage(inventoryFrame, 0, 0, SCALE * 2, SCALE * 2, null);
|
||||||
g.drawString(String.valueOf(inventory.getCoins()), SCALE + 10, 145);
|
g.drawString(String.valueOf(inventory.getCoins()), SCALE + 10, 145);
|
||||||
g.drawImage(coinCounterIcon,0,125,SCALE,SCALE/2,null);
|
g.drawImage(coinCounterIcon, 0, 125, coinCounterIcon.getWidth() * World.SCALE_FACTOR,
|
||||||
|
coinCounterIcon.getHeight() * World.SCALE_FACTOR, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// wird alle 50ms ausgef<65>hrt:
|
// wird alle 50ms ausgef<65>hrt:
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import main.entities.player.Player;
|
|||||||
public class Coin extends AnimatedEntity {
|
public class Coin extends AnimatedEntity {
|
||||||
|
|
||||||
private static SheetLoader loader = new SheetLoader("/res/images/coins.png");
|
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() {
|
public Coin() {
|
||||||
loader.generateFigures(8, 8, new int[] { 8, 8, 1 });
|
loader.generateFigures(8, 8, new int[] { 8, 8, 1 });
|
||||||
@@ -31,13 +34,24 @@ public class Coin extends AnimatedEntity {
|
|||||||
@Override
|
@Override
|
||||||
protected void update() {
|
protected void update() {
|
||||||
super.update();
|
super.update();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (moveToCounterAnimation) {
|
||||||
public void onEntityCollision(Entity e) {
|
float distX = animationDestX - posX;
|
||||||
if (e instanceof Player) {
|
float distY = animationDestY - posY;
|
||||||
|
posX += distX / 10f;
|
||||||
|
posY += distY / 10f;
|
||||||
|
if (distX < 0.05f && distX > -0.05f && distY < 0.05f && distY > -0.05f) {
|
||||||
deleteEntity();
|
deleteEntity();
|
||||||
Main.instance.getWorld().getPlayer().getInventory().addCoins(1);
|
Main.instance.getWorld().getPlayer().getInventory().addCoins(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEntityCollision(Entity e) {
|
||||||
|
if (e instanceof Player && !moveToCounterAnimation) {
|
||||||
|
moveToCounterAnimation = true;
|
||||||
|
enableTileCollisions = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public abstract class Entity implements Ticker {
|
|||||||
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 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
|
||||||
@@ -51,6 +52,9 @@ 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 checkTileCollision(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()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user