made projectile usage available for monsters
This commit is contained in:
@@ -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,14 +35,22 @@ public class GreenSlimeMON extends Entity {
|
|||||||
// INTERACTION
|
// INTERACTION
|
||||||
public void setAction() {
|
public void setAction() {
|
||||||
actionLock++;
|
actionLock++;
|
||||||
if(actionLock != 120) return; //lock action for x frames
|
|
||||||
Random rand = new Random();
|
if(actionLock == 120) { //lock action for x frames
|
||||||
int i = rand.nextInt(100)+1; //Generate number between 1 and 100
|
Random rand = new Random();
|
||||||
if(i <= 25) direction = Direction.UP;
|
int i = rand.nextInt(100)+1; //Generate number between 1 and 100
|
||||||
if(i > 25 && i <= 50) direction = Direction.DOWN;
|
if(i <= 25) direction = Direction.UP;
|
||||||
if(i > 50 && i <= 75) direction = Direction.LEFT;
|
if(i > 25 && i <= 50) direction = Direction.DOWN;
|
||||||
if(i > 75) direction = Direction.RIGHT;
|
if(i > 50 && i <= 75) direction = Direction.LEFT;
|
||||||
actionLock = 0;
|
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() {
|
public void damageReaction() {
|
||||||
actionLock = 0;
|
actionLock = 0;
|
||||||
|
|||||||
@@ -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