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_A, KeyEvent.VK_LEFT -> leftPressed = true;
|
||||||
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> rightPressed = true;
|
case KeyEvent.VK_D, KeyEvent.VK_RIGHT -> rightPressed = true;
|
||||||
case KeyEvent.VK_SPACE -> spacePressed = true;
|
case KeyEvent.VK_SPACE -> spacePressed = true;
|
||||||
case KeyEvent.VK_F -> shotKeyPressed = true;
|
//case KeyEvent.VK_F -> shotKeyPressed = true;
|
||||||
|
|
||||||
// DEBUG OPTIONS
|
// DEBUG OPTIONS
|
||||||
case KeyEvent.VK_T -> debug = !debug;
|
case KeyEvent.VK_T -> debug = !debug;
|
||||||
|
|||||||
@@ -87,15 +87,7 @@ public class Entity {
|
|||||||
panel.collisionH.checkEntity(this, panel.monster);
|
panel.collisionH.checkEntity(this, panel.monster);
|
||||||
boolean contactPlayer = panel.collisionH.checkPlayer(this);
|
boolean contactPlayer = panel.collisionH.checkPlayer(this);
|
||||||
|
|
||||||
if(this.type == EntityType.MONSTER && contactPlayer) {
|
if(this.type == EntityType.MONSTER && contactPlayer) damagePlayer(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!collisionOn) {
|
if(!collisionOn) {
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
@@ -168,6 +160,15 @@ public class Entity {
|
|||||||
// INTERACTION
|
// INTERACTION
|
||||||
public void setAction() {}
|
public void setAction() {}
|
||||||
public void damageReaction() {}
|
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() {
|
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];
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import de.miaurizius.jgame2d.core.GamePanel;
|
|||||||
import de.miaurizius.jgame2d.core.enums.Direction;
|
import de.miaurizius.jgame2d.core.enums.Direction;
|
||||||
import de.miaurizius.jgame2d.core.enums.EntityType;
|
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||||
import de.miaurizius.jgame2d.entity.Entity;
|
import de.miaurizius.jgame2d.entity.Entity;
|
||||||
|
import de.miaurizius.jgame2d.entity.projectile.RockObj;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ public class GreenSlimeMON extends Entity {
|
|||||||
attack = 5;
|
attack = 5;
|
||||||
defense = 0;
|
defense = 0;
|
||||||
exp = 2;
|
exp = 2;
|
||||||
|
projectile = new RockObj(panel);
|
||||||
|
|
||||||
solidArea.x = 3;
|
solidArea.x = 3;
|
||||||
solidArea.y = 18;
|
solidArea.y = 18;
|
||||||
@@ -33,7 +35,8 @@ public class GreenSlimeMON extends Entity {
|
|||||||
// INTERACTION
|
// INTERACTION
|
||||||
public void setAction() {
|
public void setAction() {
|
||||||
actionLock++;
|
actionLock++;
|
||||||
if(actionLock != 120) return; //lock action for x frames
|
|
||||||
|
if(actionLock == 120) { //lock action for x frames
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
int i = rand.nextInt(100)+1; //Generate number between 1 and 100
|
int i = rand.nextInt(100)+1; //Generate number between 1 and 100
|
||||||
if(i <= 25) direction = Direction.UP;
|
if(i <= 25) direction = Direction.UP;
|
||||||
@@ -42,6 +45,13 @@ public class GreenSlimeMON extends Entity {
|
|||||||
if(i > 75) direction = Direction.RIGHT;
|
if(i > 75) direction = Direction.RIGHT;
|
||||||
actionLock = 0;
|
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() {
|
public void damageReaction() {
|
||||||
actionLock = 0;
|
actionLock = 0;
|
||||||
direction = panel.player.direction;
|
direction = panel.player.direction;
|
||||||
|
|||||||
@@ -33,7 +33,10 @@ public class Projectile extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(user.type == EntityType.MONSTER) {
|
if(user.type == EntityType.MONSTER) {
|
||||||
|
if(!panel.player.invincible && panel.collisionH.checkPlayer(this)) {
|
||||||
|
damagePlayer(attack);
|
||||||
|
alive = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(direction) {
|
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