add death animation to dying monsters
This commit is contained in:
@@ -100,7 +100,13 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
case PLAY:
|
case PLAY:
|
||||||
player.update();
|
player.update();
|
||||||
for(Entity entity : npc) if(entity != null) entity.update();
|
for(Entity entity : npc) if(entity != null) entity.update();
|
||||||
for(Entity entity : monster) if(entity != null) entity.update();
|
for(int i = 0; i < monster.length; i++) {
|
||||||
|
Entity m = monster[i];
|
||||||
|
if(m != null) {
|
||||||
|
if(m.alive && !m.dying) m.update();
|
||||||
|
if(!m.alive) monster[i] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case PAUSE:
|
case PAUSE:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ public class Entity {
|
|||||||
public boolean collisionOn;
|
public boolean collisionOn;
|
||||||
public boolean invincible;
|
public boolean invincible;
|
||||||
boolean attacking;
|
boolean attacking;
|
||||||
boolean alive = true;
|
public boolean alive = true;
|
||||||
boolean dying;
|
public boolean dying;
|
||||||
|
|
||||||
// COUNTER
|
// COUNTER
|
||||||
public int spriteCounter;
|
public int spriteCounter;
|
||||||
@@ -103,9 +103,9 @@ public class Entity {
|
|||||||
worldY + panel.tileSize > panel.player.worldY - panel.player.screenY &&
|
worldY + panel.tileSize > panel.player.worldY - panel.player.screenY &&
|
||||||
worldY - panel.tileSize < panel.player.worldY + panel.player.screenY
|
worldY - panel.tileSize < panel.player.worldY + panel.player.screenY
|
||||||
) {
|
) {
|
||||||
if(invincible) {
|
if(invincible) graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
|
||||||
graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
|
|
||||||
}
|
if(dying) dyingAnimation(graphics2d);
|
||||||
|
|
||||||
// only modify sprite render position for player because I dont know yet how monster attack sprite are gonna look
|
// only modify sprite render position for player because I dont know yet how monster attack sprite are gonna look
|
||||||
if(type == EntityType.PLAYER) {
|
if(type == EntityType.PLAYER) {
|
||||||
@@ -120,6 +120,7 @@ public class Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// INTERACTION
|
// INTERACTION
|
||||||
|
public void setAction() {}
|
||||||
public void speak() {
|
public void speak() {
|
||||||
if(dialogue[dialogueIndex] == null) dialogueIndex = 0;
|
if(dialogue[dialogueIndex] == null) dialogueIndex = 0;
|
||||||
panel.ui.currentDialogue = dialogue[dialogueIndex];
|
panel.ui.currentDialogue = dialogue[dialogueIndex];
|
||||||
@@ -132,7 +133,22 @@ public class Entity {
|
|||||||
case RIGHT -> direction = Direction.LEFT;
|
case RIGHT -> direction = Direction.LEFT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void setAction() {}
|
public void dyingAnimation(Graphics2D graphics2d) {
|
||||||
|
dyingCount++;
|
||||||
|
int incr = 5;
|
||||||
|
if(dyingCount <= incr) changeOpacity(graphics2d, 0f);
|
||||||
|
if(dyingCount > incr && dyingCount <= incr*2) changeOpacity(graphics2d, 1f);
|
||||||
|
if(dyingCount > incr*2 && dyingCount <= incr*3) changeOpacity(graphics2d, 0f);
|
||||||
|
if(dyingCount > incr*3 && dyingCount <= incr*4) changeOpacity(graphics2d, 1f);
|
||||||
|
if(dyingCount > incr*4 && dyingCount <= incr*5) changeOpacity(graphics2d, 0f);
|
||||||
|
if(dyingCount > incr*5 && dyingCount <= incr*6) changeOpacity(graphics2d, 1f);
|
||||||
|
if(dyingCount > incr*6 && dyingCount <= incr*7) changeOpacity(graphics2d, 0f);
|
||||||
|
if(dyingCount > incr*7 && dyingCount <= incr*8) changeOpacity(graphics2d, 1f);
|
||||||
|
if(dyingCount > incr*8) {
|
||||||
|
dying = false;
|
||||||
|
alive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SETTING THINGS UP
|
// SETTING THINGS UP
|
||||||
BufferedImage parseSprite() {
|
BufferedImage parseSprite() {
|
||||||
@@ -167,5 +183,8 @@ public class Entity {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
public void changeOpacity(Graphics2D graphics2d, float opacity) {
|
||||||
|
graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import java.awt.*;
|
|||||||
public class Player extends Entity {
|
public class Player extends Entity {
|
||||||
|
|
||||||
KeyHandler keyH;
|
KeyHandler keyH;
|
||||||
|
|
||||||
public final int screenX;
|
public final int screenX;
|
||||||
public final int screenY;
|
public final int screenY;
|
||||||
|
|
||||||
@@ -156,7 +155,7 @@ public class Player extends Entity {
|
|||||||
panel.monster[index].life -= 1;
|
panel.monster[index].life -= 1;
|
||||||
panel.playSE(5);
|
panel.playSE(5);
|
||||||
panel.monster[index].invincible = true;
|
panel.monster[index].invincible = true;
|
||||||
if(panel.monster[index].life <= 0) panel.monster[index] = null;
|
if(panel.monster[index].life <= 0) panel.monster[index].dying = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void interactNPC(int index) {
|
public void interactNPC(int index) {
|
||||||
|
|||||||
Reference in New Issue
Block a user