Compare commits
2 Commits
5da7c43edf
...
54458293ba
| Author | SHA1 | Date | |
|---|---|---|---|
|
54458293ba
|
|||
|
ce8a97c0cc
|
@@ -49,7 +49,7 @@ public class KeyHandler implements KeyListener {
|
||||
case KeyEvent.VK_A, KeyEvent.VK_LEFT -> leftPressed = true;
|
||||
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> rightPressed = true;
|
||||
case KeyEvent.VK_SPACE -> spacePressed = true;
|
||||
case KeyEvent.VK_F -> shotKeyPressed = true;
|
||||
//case KeyEvent.VK_F -> shotKeyPressed = true;
|
||||
|
||||
// DEBUG OPTIONS
|
||||
case KeyEvent.VK_T -> debug = !debug;
|
||||
|
||||
@@ -87,15 +87,7 @@ public class Entity {
|
||||
panel.collisionH.checkEntity(this, panel.monster);
|
||||
boolean contactPlayer = panel.collisionH.checkPlayer(this);
|
||||
|
||||
if(this.type == EntityType.MONSTER && contactPlayer) {
|
||||
if(panel.player.invincible) return;
|
||||
panel.playSE(6);
|
||||
|
||||
int damage = attack - panel.player.defense;
|
||||
panel.player.life -= Math.max(damage, 0);
|
||||
|
||||
panel.player.invincible = true;
|
||||
}
|
||||
if(this.type == EntityType.MONSTER && contactPlayer) damagePlayer(attack);
|
||||
|
||||
if(!collisionOn) {
|
||||
switch (direction) {
|
||||
@@ -168,6 +160,15 @@ public class Entity {
|
||||
// INTERACTION
|
||||
public void setAction() {}
|
||||
public void damageReaction() {}
|
||||
public void damagePlayer(int attack) {
|
||||
if(panel.player.invincible) return;
|
||||
panel.playSE(6);
|
||||
|
||||
int damage = attack - panel.player.defense;
|
||||
panel.player.life -= Math.max(damage, 0);
|
||||
|
||||
panel.player.invincible = true;
|
||||
}
|
||||
public void speak() {
|
||||
if(dialogue[dialogueIndex] == null) dialogueIndex = 0;
|
||||
panel.ui.currentDialogue = dialogue[dialogueIndex];
|
||||
|
||||
@@ -4,6 +4,7 @@ import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.enums.Direction;
|
||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||
import de.miaurizius.jgame2d.entity.Entity;
|
||||
import de.miaurizius.jgame2d.entity.projectile.RockObj;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@@ -19,6 +20,7 @@ public class GreenSlimeMON extends Entity {
|
||||
attack = 5;
|
||||
defense = 0;
|
||||
exp = 2;
|
||||
projectile = new RockObj(panel);
|
||||
|
||||
solidArea.x = 3;
|
||||
solidArea.y = 18;
|
||||
@@ -33,14 +35,22 @@ public class GreenSlimeMON extends Entity {
|
||||
// INTERACTION
|
||||
public void setAction() {
|
||||
actionLock++;
|
||||
if(actionLock != 120) return; //lock action for x frames
|
||||
Random rand = new Random();
|
||||
int i = rand.nextInt(100)+1; //Generate number between 1 and 100
|
||||
if(i <= 25) direction = Direction.UP;
|
||||
if(i > 25 && i <= 50) direction = Direction.DOWN;
|
||||
if(i > 50 && i <= 75) direction = Direction.LEFT;
|
||||
if(i > 75) direction = Direction.RIGHT;
|
||||
actionLock = 0;
|
||||
|
||||
if(actionLock == 120) { //lock action for x frames
|
||||
Random rand = new Random();
|
||||
int i = rand.nextInt(100)+1; //Generate number between 1 and 100
|
||||
if(i <= 25) direction = Direction.UP;
|
||||
if(i > 25 && i <= 50) direction = Direction.DOWN;
|
||||
if(i > 50 && i <= 75) direction = Direction.LEFT;
|
||||
if(i > 75) direction = Direction.RIGHT;
|
||||
actionLock = 0;
|
||||
}
|
||||
|
||||
// int i = new Random().nextInt(100)+1;
|
||||
// if(i > 99 && !projectile.alive) {
|
||||
// projectile.set(worldX, worldY, direction, true, this);
|
||||
// panel.projectileList.add(projectile);
|
||||
// }
|
||||
}
|
||||
public void damageReaction() {
|
||||
actionLock = 0;
|
||||
|
||||
@@ -33,7 +33,10 @@ public class Projectile extends Entity {
|
||||
}
|
||||
|
||||
if(user.type == EntityType.MONSTER) {
|
||||
|
||||
if(!panel.player.invincible && panel.collisionH.checkPlayer(this)) {
|
||||
damagePlayer(attack);
|
||||
alive = false;
|
||||
}
|
||||
}
|
||||
|
||||
switch(direction) {
|
||||
|
||||
36
src/de/miaurizius/jgame2d/entity/projectile/RockObj.java
Normal file
36
src/de/miaurizius/jgame2d/entity/projectile/RockObj.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package de.miaurizius.jgame2d.entity.projectile;
|
||||
|
||||
import de.miaurizius.jgame2d.core.GamePanel;
|
||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||
|
||||
public class RockObj extends Projectile {
|
||||
|
||||
GamePanel panel;
|
||||
|
||||
public RockObj(GamePanel panel) {
|
||||
super(panel);
|
||||
this.panel = panel;
|
||||
|
||||
name = "Rock";
|
||||
type = EntityType.PROJECTILE;
|
||||
|
||||
speed = 5;
|
||||
maxLife = 80;
|
||||
life = maxLife;
|
||||
attack = 2;
|
||||
useCost = 1;
|
||||
alive = false;
|
||||
|
||||
// INITIALISATION OF IMAGES
|
||||
String defaultSprite = "/projectile/rock_down_1";
|
||||
up1 = initEntitySprites(defaultSprite);
|
||||
up2 = initEntitySprites(defaultSprite);
|
||||
down1 = initEntitySprites(defaultSprite);
|
||||
down2 = initEntitySprites(defaultSprite);
|
||||
left1 = initEntitySprites(defaultSprite);
|
||||
left2 = initEntitySprites(defaultSprite);
|
||||
right1 = initEntitySprites(defaultSprite);
|
||||
right2 = initEntitySprites(defaultSprite);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user