Skip to content
Snippets Groups Projects
Commit 3f3bd445 authored by Scherbaum Maximilian's avatar Scherbaum Maximilian
Browse files

update: timer for attacks and bombs, I-Frames for Player #90

parent e3610d72
No related branches found
No related tags found
4 merge requests!74V1,!73Initial commit,!71Merge DataBase into Development,!33Update: Items, spawn locations of items, hit rate, i-frames
......@@ -151,8 +151,8 @@ public class GameSceneController implements Initializable {
}
private void updateContent() {
player.updateEntityMovement(this);
enemy.updateEntityMovement(this);
player.updateEntity(this);
enemy.updateEntity(this);
player.attack(enemy, graphicsContext2D);
enemy.attack(player, graphicsContext2D);
updateGameplayObjects();
......
......@@ -52,7 +52,7 @@ public class Bomb implements IEntity {
}
@Override
public void updateEntityMovement(GameSceneController gameScene) {
public void updateEntity(GameSceneController gameScene) {
}
......
......@@ -48,7 +48,7 @@ public class Explosion implements IEntity {
}
@Override
public void updateEntityMovement(GameSceneController gameScene) {
public void updateEntity(GameSceneController gameScene) {
}
......
......@@ -45,7 +45,7 @@ public class Heart implements IEntity {
}
@Override
public void updateEntityMovement(GameSceneController gameScene) {
public void updateEntity(GameSceneController gameScene) {
}
......
......@@ -12,7 +12,7 @@ public interface IEntity {
void loadEntitySprites();
void updateEntityMovement(GameSceneController gameScene);
void updateEntity(GameSceneController gameScene);
//checks collision with GameplayObjects by iterating through GameplayObjects list
void checkGameplayObjectInteraction(IEntity entity, GraphicsContext graphicsContext);
......
......@@ -34,7 +34,7 @@ class NetworkPlayerTwo implements IEntity{
}
@Override
public void updateEntityMovement(GameSceneController gameScene) {
public void updateEntity(GameSceneController gameScene) {
}
......
......@@ -72,6 +72,9 @@ class Player implements IEntity {
private int health;
private int maxPlayerHealth;
private int damage;
private int iFrameCounter = 0;
private int attackRate = 0;
private int bombPlacementRate = 0;
public Player(GraphicsContext gameScene, InputHandler inputHandler, EntityClass entityClass,
GameSceneController gameSceneController, PlayerMode PLAYER_MODE) {
......@@ -200,8 +203,11 @@ class Player implements IEntity {
}
@Override
public void updateEntityMovement(GameSceneController gameScene) {
public void updateEntity(GameSceneController gameScene) {
if (PLAYER_MODE == PlayerMode.PLAYER_ONE) {
updateInvincibility();
updateAttackRate();
updateBombPlacementRate();
if (inputHandler.isMoveUp() || inputHandler.isMoveDown() || inputHandler.isMoveLeft() || inputHandler.isMoveRight()) {
if (inputHandler.isMoveUp()) {
playerDirection = EntityDirection.UP;
......@@ -225,6 +231,9 @@ class Player implements IEntity {
updateEntityWalkAnimation();
}
} else if (PLAYER_MODE == PlayerMode.PLAYER_TWO) {
updateInvincibility();
updateAttackRate();
updateBombPlacementRate();
if (inputHandler.isSdMoveUp() || inputHandler.isSdMoveDown() || inputHandler.isSdMoveLeft() || inputHandler.isSdMoveRight()) {
if (inputHandler.isSdMoveUp()) {
playerDirection = EntityDirection.UP;
......@@ -250,6 +259,24 @@ class Player implements IEntity {
}
}
private void updateInvincibility() {
if (iFrameCounter > 0) {
iFrameCounter--;
}
}
private void updateAttackRate() {
if (attackRate > 0) {
attackRate--;
}
}
private void updateBombPlacementRate() {
if (bombPlacementRate > 0) {
bombPlacementRate--;
}
}
private void performEntityMovement(boolean isWalkableTile) {
lastMapPosX = mapPosX;
lastMapPosY = mapPosY;
......@@ -315,8 +342,9 @@ class Player implements IEntity {
@Override
public void placeBomb(IEntity entity, IEntity entity2, GraphicsContext graphicsContext) {
if (inputHandler.isBomb() && PLAYER_MODE == PlayerMode.PLAYER_ONE ||
inputHandler.isSdBomb() && PLAYER_MODE == PlayerMode.PLAYER_TWO) {
if (inputHandler.isBomb() && PLAYER_MODE == PlayerMode.PLAYER_ONE && bombPlacementRate == 0 ||
inputHandler.isSdBomb() && PLAYER_MODE == PlayerMode.PLAYER_TWO && bombPlacementRate == 0) {
bombPlacementRate = 100;
//int extrapixelpadding = 2; //Could this fix the wrong Tile because of the Player??
int xTile = mapPosX / scaledTileSize;
int yTile = mapPosY / scaledTileSize;
......@@ -433,6 +461,7 @@ class Player implements IEntity {
}
}
}
public boolean checkTilePlacing(int y, int x) { //Change it with a DestructionHandler like CollisionHandler //tileSet[xTile].getDestruction();
return TileManager.tileMap[y][x] >= 20 || TileManager.tileMap[y][x] <= 9;
}
......@@ -453,6 +482,7 @@ class Player implements IEntity {
}
}
}
public void spawnExplosion(int spawnCordX, int spawnCordY, GraphicsContext graphicsContext){
List<IEntity> gameplayObjects = runtimeInfo.getGameplayObjects();
IEntity explosion = EntityFactory.createGameplayObject(ObjectType.EXPLOSION, spawnCordY * scaledTileSize, spawnCordX * scaledTileSize, graphicsContext);
......@@ -461,6 +491,7 @@ class Player implements IEntity {
log.info("explosion placed");
changeCheckedTileDestructable(graphicsContext);
}
public void spawnHeart(int x, int y,GraphicsContext graphicsContext){
double dropChance = 0.1;
double randomDropChance = Math.random() * 1;
......@@ -483,8 +514,9 @@ class Player implements IEntity {
int attackRange = 30;
int attackWidth = 10;
if (inputHandler.isAttack() && PLAYER_MODE == PlayerMode.PLAYER_ONE ||
inputHandler.isSdAttack() && PLAYER_MODE == PlayerMode.PLAYER_TWO) {
if (inputHandler.isAttack() && PLAYER_MODE == PlayerMode.PLAYER_ONE && attackRate == 0 ||
inputHandler.isSdAttack() && PLAYER_MODE == PlayerMode.PLAYER_TWO && attackRate == 0) {
attackRate = 15;
if (playerDirection == EntityDirection.UP) {
hitBox = new BoundingBox(mapPosX + playerWidth, mapPosY - 10, attackWidth, attackRange);
graphicsContext.strokeRect(mapPosX + playerWidth, mapPosY - 10, attackWidth, attackRange);
......@@ -582,13 +614,16 @@ class Player implements IEntity {
@Override
public void gotHit(int damageDone) {
int damagedHealth = health - damageDone;
if(damagedHealth > 0){
health -= damageDone;
}else{
health = 0;
log.info("Dead");
if (iFrameCounter == 0) {
if(damagedHealth > 0){
health -= damageDone;
iFrameCounter = 10;
}else{
health = 0;
log.info("Dead");
}
log.info("DamageTaken, current Health: " + health);
}
log.info("DamageTaken, current Health: " + health);
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment