added knockback to monsters
This commit is contained in:
@@ -4,7 +4,6 @@ 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.enums.Map;
|
||||
import de.miaurizius.jgame2d.core.handlers.KeyHandler;
|
||||
import de.miaurizius.jgame2d.entity.item.ShieldWoodObj;
|
||||
import de.miaurizius.jgame2d.entity.item.SwordNormalObj;
|
||||
@@ -95,18 +94,18 @@ public class Player extends Entity {
|
||||
if(keyH.spacePressed && !attackCancel) {
|
||||
panel.playSE(7);
|
||||
attacking = true;
|
||||
spriteCounter = 0;
|
||||
spriteCount = 0;
|
||||
}
|
||||
|
||||
attackCancel = false;
|
||||
panel.keyH.spacePressed = false;
|
||||
|
||||
spriteCounter++;
|
||||
if(spriteCounter > 12) {
|
||||
spriteCount++;
|
||||
if(spriteCount > 12) {
|
||||
if(spriteNum == 1) spriteNum = 2;
|
||||
else if(spriteNum == 2) spriteNum = 1;
|
||||
else spriteNum = 0;
|
||||
spriteCounter = 0;
|
||||
spriteCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,9 +167,9 @@ public class Player extends Entity {
|
||||
}
|
||||
public void attacking() {
|
||||
if(attackCancel) return;
|
||||
spriteCounter++;
|
||||
if(spriteCounter <= 5) spriteNum = 1;
|
||||
if(spriteCounter > 5 && spriteCounter <= 25) {
|
||||
spriteCount++;
|
||||
if(spriteCount <= 5) spriteNum = 1;
|
||||
if(spriteCount > 5 && spriteCount <= 25) {
|
||||
spriteNum = 2;
|
||||
int currentWorldX = worldX;
|
||||
int currentWorldY = worldY;
|
||||
@@ -187,7 +186,7 @@ public class Player extends Entity {
|
||||
solidArea.height = attackArea.height;
|
||||
|
||||
int monsterIndex = panel.collisionH.checkEntity(this, panel.monster[panel.currentMap.getIndex()]);
|
||||
damageMonster(monsterIndex, attack);
|
||||
damageMonster(monsterIndex, attack, currentWeapon.knockbackVal);
|
||||
|
||||
int iTileIndex = panel.collisionH.checkEntity(this, panel.iTile[panel.currentMap.getIndex()]);
|
||||
interactTile(iTileIndex);
|
||||
@@ -198,13 +197,13 @@ public class Player extends Entity {
|
||||
solidArea.height = solidAreaHeight;
|
||||
|
||||
}
|
||||
if(spriteCounter > 25) {
|
||||
if(spriteCount > 25) {
|
||||
spriteNum = 1;
|
||||
spriteCounter = 0;
|
||||
spriteCount = 0;
|
||||
attacking = false;
|
||||
}
|
||||
}
|
||||
public void damageMonster(int index, int attack) {
|
||||
public void damageMonster(int index, int attack, int knockbackVal) {
|
||||
if(index == 999) return;
|
||||
if(panel.monster[panel.currentMap.getIndex()][index].invincible) return;
|
||||
|
||||
@@ -212,6 +211,7 @@ public class Player extends Entity {
|
||||
|
||||
if(damage > 0) {
|
||||
panel.playSE(5);
|
||||
if(knockbackVal > 0) knockback(panel.monster[panel.currentMap.getIndex()][index], knockbackVal);
|
||||
panel.monster[panel.currentMap.getIndex()][index].life -= damage;
|
||||
panel.monster[panel.currentMap.getIndex()][index].invincible = true;
|
||||
}
|
||||
@@ -224,6 +224,12 @@ public class Player extends Entity {
|
||||
checkLevelUp();
|
||||
}
|
||||
}
|
||||
public void knockback(Entity entity, int knockbackVal) {
|
||||
entity.direction = direction;
|
||||
entity.speed += knockbackVal;
|
||||
entity.knockback = true;
|
||||
}
|
||||
|
||||
public void interactTile(int index) {
|
||||
if(index == 999 || !panel.iTile[panel.currentMap.getIndex()][index].destructible || panel.iTile[panel.currentMap.getIndex()][index].invincible) return;
|
||||
if(!panel.iTile[panel.currentMap.getIndex()][index].meetItemReq(this)) return;
|
||||
@@ -294,11 +300,8 @@ public class Player extends Entity {
|
||||
worldX = panel.tileSize * 23;
|
||||
worldY = panel.tileSize * 21;
|
||||
|
||||
// worldX = panel.tileSize * 12;
|
||||
// worldY = panel.tileSize * 12;
|
||||
// panel.currentMap = Map.HUT;
|
||||
|
||||
speed = 4;
|
||||
defaultSpeed = 4;
|
||||
speed = defaultSpeed;
|
||||
direction = Direction.DOWN;
|
||||
|
||||
// PLAYER STATUS (1 heart = 2 lives)
|
||||
|
||||
Reference in New Issue
Block a user