Compare commits
7 Commits
21790ecd7a
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
865b5e0c52 | ||
|
|
d28a29df45 | ||
|
|
b85a36bf14 | ||
|
|
66d36c4ea2 | ||
|
|
d46d25115e | ||
|
|
5f0b827fab | ||
|
|
ca40e4c01a |
@@ -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<65>hrt:
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
36
Zoelda/src/main/entities/Rick.java
Normal file
36
Zoelda/src/main/entities/Rick.java
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
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 {
|
||||
@@ -18,10 +20,22 @@ public class TestWorld extends World {
|
||||
getCurrentMap().addAnimatedEntity(c);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 444 B After Width: | Height: | Size: 444 B |
Reference in New Issue
Block a user