diff --git a/src/de/miaurizius/jgame2d/core/handlers/Sound.java b/src/de/miaurizius/jgame2d/core/handlers/Sound.java index 141fdf8..4eb38e4 100644 --- a/src/de/miaurizius/jgame2d/core/handlers/Sound.java +++ b/src/de/miaurizius/jgame2d/core/handlers/Sound.java @@ -22,6 +22,8 @@ public class Sound { soundURL[2] = new File("assets/sounds/powerup.wav").toURI().toURL(); soundURL[3] = new File("assets/sounds/unlock.wav").toURI().toURL(); soundURL[4] = new File("assets/sounds/fanfare.wav").toURI().toURL(); + soundURL[5] = new File("assets/sounds/hitmonster.wav").toURI().toURL(); + soundURL[6] = new File("assets/sounds/receivedamage.wav").toURI().toURL(); } catch(MalformedURLException e) { Boot.logger.log(Level.SEVERE, e.getMessage()); } diff --git a/src/de/miaurizius/jgame2d/entity/Entity.java b/src/de/miaurizius/jgame2d/entity/Entity.java index c85b0cc..03dba40 100644 --- a/src/de/miaurizius/jgame2d/entity/Entity.java +++ b/src/de/miaurizius/jgame2d/entity/Entity.java @@ -82,6 +82,14 @@ public class Entity { else spriteNum = 0; spriteCounter = 0; } + + // INVINCIBLE COUNTER + if(!invincible) return; + invincibleCount++; + if(invincibleCount > 40) { + invincible = false; + invincibleCount = 0; + } } public void draw(Graphics2D graphics2d) { int screenX = worldX - panel.player.worldX + panel.player.screenX; @@ -92,7 +100,19 @@ public class Entity { worldY + panel.tileSize > panel.player.worldY - panel.player.screenY && worldY - panel.tileSize < panel.player.worldY + panel.player.screenY ) { - graphics2d.drawImage(parseSprite(), screenX, screenY, panel.tileSize, panel.tileSize, null); + if(invincible) { + graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f)); + } + + // only modify sprite render position for player because I dont know yet how monster attack sprite are gonna look + if(type == EntityType.PLAYER) { + if(attacking) graphics2d.drawImage(parseSpriteATK(), + (direction == Direction.LEFT) ? screenX - panel.tileSize : screenX, + (direction == Direction.UP) ? screenY - panel.tileSize : screenY, null); + else graphics2d.drawImage(parseSprite(), screenX, screenY, null); + } else graphics2d.drawImage(parseSprite(), screenX, screenY, null); + + graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f)); } } diff --git a/src/de/miaurizius/jgame2d/entity/OldManNPC.java b/src/de/miaurizius/jgame2d/entity/OldManNPC.java index 7f25ead..98fd566 100644 --- a/src/de/miaurizius/jgame2d/entity/OldManNPC.java +++ b/src/de/miaurizius/jgame2d/entity/OldManNPC.java @@ -2,6 +2,7 @@ package de.miaurizius.jgame2d.entity; import de.miaurizius.jgame2d.core.enums.Direction; import de.miaurizius.jgame2d.core.GamePanel; +import de.miaurizius.jgame2d.core.enums.EntityType; import java.util.Random; @@ -9,6 +10,7 @@ public class OldManNPC extends Entity { public OldManNPC(GamePanel panel) { super(panel); + type = EntityType.NPC; name = "oldman-npc"; direction = Direction.DOWN; diff --git a/src/de/miaurizius/jgame2d/entity/Player.java b/src/de/miaurizius/jgame2d/entity/Player.java index b558015..aeb7e93 100644 --- a/src/de/miaurizius/jgame2d/entity/Player.java +++ b/src/de/miaurizius/jgame2d/entity/Player.java @@ -2,6 +2,7 @@ package de.miaurizius.jgame2d.entity; import de.miaurizius.jgame2d.core.*; import de.miaurizius.jgame2d.core.enums.Direction; +import de.miaurizius.jgame2d.core.enums.EntityType; import de.miaurizius.jgame2d.core.enums.GameState; import de.miaurizius.jgame2d.core.handlers.KeyHandler; @@ -17,7 +18,9 @@ public class Player extends Entity { public Player(GamePanel panel, KeyHandler keyH) { super(panel); this.keyH = keyH; + name = "player"; + type = EntityType.PLAYER; screenX = panel.screenWidth/2 - panel.tileSize/2; screenY = panel.screenHeight/2 - panel.tileSize/2; @@ -91,6 +94,8 @@ public class Player extends Entity { spriteCounter = 0; } } + + // INVINCIBLE COUNTER if(!invincible) return; invincibleCount++; if(invincibleCount > 60) { @@ -98,21 +103,6 @@ public class Player extends Entity { invincibleCount = 0; } } - public void draw(Graphics2D graphics2d) { - int screenX = worldX - panel.player.worldX + panel.player.screenX; - int screenY = worldY - panel.player.worldY + panel.player.screenY; - - if(invincible) { - graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f)); - } - - if(attacking) graphics2d.drawImage(parseSpriteATK(), - (direction == Direction.LEFT) ? screenX - panel.tileSize : screenX, - (direction == Direction.UP) ? screenY - panel.tileSize : screenY, null); - else graphics2d.drawImage(parseSprite(), screenX, screenY, null); - - graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f)); - } // INTERACTION public void pickObject(int index) { @@ -123,6 +113,7 @@ public class Player extends Entity { if(index == 999) return; if(invincible) return; life -= 1; + panel.playSE(6); invincible = true; } public void attacking() { @@ -161,6 +152,11 @@ public class Player extends Entity { } public void damageMonster(int index) { if(index == 999) return; + if(panel.monster[index].invincible) return; + panel.monster[index].life -= 1; + panel.playSE(5); + panel.monster[index].invincible = true; + if(panel.monster[index].life <= 0) panel.monster[index] = null; } public void interactNPC(int index) {