Damage character #11
BIN
core/assets/hit.png
Normal file
BIN
core/assets/hit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
BIN
core/assets/sound/hit.mp3
Normal file
BIN
core/assets/sound/hit.mp3
Normal file
Binary file not shown.
@@ -12,6 +12,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import netwerkprog.game.client.game.GAMESTATE;
|
||||
import netwerkprog.game.client.game.characters.Agent;
|
||||
import netwerkprog.game.client.game.characters.Hacker;
|
||||
@@ -44,6 +45,7 @@ public class MainGame extends ApplicationAdapter {
|
||||
private GlyphLayout layout;
|
||||
private GAMESTATE gamestate;
|
||||
private Faction chosenFaction;
|
||||
private long lastTimeCounted = 0;
|
||||
|
||||
private Map map;
|
||||
public MapRenderer mapRenderer;
|
||||
@@ -101,7 +103,7 @@ public class MainGame extends ApplicationAdapter {
|
||||
// this.tree.insert(new Hacker(,new BodySwap()));
|
||||
|
||||
|
||||
playSong();
|
||||
// playSong();
|
||||
|
||||
|
||||
// connectToServer();
|
||||
@@ -113,6 +115,7 @@ public class MainGame extends ApplicationAdapter {
|
||||
Texture texture = assets.get("core/assets/characters.png");
|
||||
TextureRegion[][] characters = TextureRegion.split(texture, 32, 32);
|
||||
this.team = new Team();
|
||||
this.enemyTeam = new Team();
|
||||
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
GameCharacter temp = new Hacker("hacker" + i, characters[5][0], new BodySwap("test"));
|
||||
@@ -195,9 +198,12 @@ public class MainGame extends ApplicationAdapter {
|
||||
* update method that does all calculation before something is being drawn
|
||||
*/
|
||||
public void update() {
|
||||
|
||||
frameRate.update();
|
||||
camera.update();
|
||||
this.gameInputProcessor.update();
|
||||
this.team.update(Gdx.graphics.getDeltaTime());
|
||||
this.enemyTeam.update(Gdx.graphics.getDeltaTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -54,6 +54,12 @@ public class Team {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void update(double deltaTime) {
|
||||
for (GameCharacter character : this.members) {
|
||||
character.update(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDead() {
|
||||
int dead = 0;
|
||||
for (GameCharacter character : this.members) {
|
||||
|
||||
@@ -125,7 +125,7 @@ public class GameInputProcessor implements InputProcessor {
|
||||
System.out.println("HACKER");
|
||||
mainGame.setChosenFaction(Faction.HACKER);
|
||||
mainGame.initCharacters();
|
||||
camera.translate(-400,0);
|
||||
camera.translate(-400, 0);
|
||||
mainGame.setGamestate(GAMESTATE.PLAYING);
|
||||
}
|
||||
|
||||
@@ -163,8 +163,10 @@ public class GameInputProcessor implements InputProcessor {
|
||||
}
|
||||
// clicking on enemy
|
||||
if (mainGame.hasCharacterSelected() && gameTile.containsCharacter() && gameTile.getCharacter().getFaction() != mainGame.getChosenFaction()) {
|
||||
if (mainGame.mapRenderer.getSurroundedTilesOfCurrentCharacter().contains(gameTile))
|
||||
gameTile.getCharacter().damage(10);
|
||||
if (mainGame.mapRenderer.getSurroundedTilesOfCurrentCharacter().contains(gameTile)) {
|
||||
gameTile.getCharacter().damage(10);
|
||||
|
||||
}
|
||||
}
|
||||
// set selected character
|
||||
if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) {
|
||||
|
||||
@@ -27,6 +27,7 @@ public class MapRenderer implements Renderable {
|
||||
private MainGame mainGame;
|
||||
private Texture square;
|
||||
private Texture square2;
|
||||
private Texture hitMarker;
|
||||
|
||||
|
||||
public static TextureRegion FLOOR_TILE;
|
||||
@@ -62,9 +63,11 @@ public class MapRenderer implements Renderable {
|
||||
mainGame.assets.load("square.png", Texture.class);
|
||||
mainGame.assets.load("square2.png", Texture.class);
|
||||
mainGame.assets.load(tilePath, Texture.class);
|
||||
mainGame.assets.load("hit.png",Texture.class);
|
||||
mainGame.assets.finishLoading();
|
||||
square = mainGame.assets.get("square.png");
|
||||
square2 = mainGame.assets.get("square2.png");
|
||||
hitMarker = mainGame.assets.get("hit.png");
|
||||
|
||||
Texture texture = mainGame.assets.get(tilePath);
|
||||
TextureRegion[][] tileTextures = TextureRegion.split(texture, 32, 32);
|
||||
@@ -118,7 +121,13 @@ public class MapRenderer implements Renderable {
|
||||
batch.draw(cur.getTextureRegion(), cur.x, cur.y);
|
||||
|
||||
if (cur.containsCharacter()) {
|
||||
batch.draw(cur.getCharacter().getTextureRegion(), cur.x, cur.y);
|
||||
GameCharacter character = cur.getCharacter();
|
||||
batch.draw(character.getTextureRegion(), cur.x, cur.y);
|
||||
if (character.isShowingAnimation()) {
|
||||
// System.out.println("animation");
|
||||
batch.draw(hitMarker,cur.x,cur.y);
|
||||
}
|
||||
|
||||
|
||||
if (cur.getCharacter().equals(mainGame.getSelectedCharacter())) {
|
||||
batch.draw(square, cur.x, cur.y);
|
||||
|
||||
@@ -38,6 +38,7 @@ public class Timer implements Updatable {
|
||||
|
||||
public void start() {
|
||||
this.timeout = 0;
|
||||
System.out.println("starting timer for " + wait + ", timeout is " + this.timeout);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
@@ -54,7 +55,7 @@ public class Timer implements Updatable {
|
||||
public boolean timeout() {
|
||||
if (this.timeout == -1) {
|
||||
// timeout has occurred and is not looped
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.timeout - 1 < 0) {
|
||||
@@ -89,11 +90,14 @@ public class Timer implements Updatable {
|
||||
|
||||
@Override
|
||||
public void update(double deltaTime) {
|
||||
System.out.println("timeout: " + this.timeout);
|
||||
if (this.timeout != -1) {
|
||||
// Only update when timer is not aborted
|
||||
this.time += deltaTime;
|
||||
System.out.println("time is " + this.time);
|
||||
if (this.time >= this.wait) {
|
||||
// timeout occurred
|
||||
System.out.println("timeout occurred, time is " + this.time);
|
||||
this.time -= this.wait;
|
||||
this.timeout++;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package netwerkprog.game.util.game;
|
||||
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import netwerkprog.game.client.game.map.GameTile;
|
||||
import netwerkprog.game.util.application.Timer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -19,6 +21,8 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
|
||||
protected TextureRegion textureRegion;
|
||||
protected int health;
|
||||
protected List<GameTile> allowedToMove;
|
||||
protected boolean damageAnimation = false;
|
||||
protected Timer hitAnimationTimer;
|
||||
|
||||
public GameCharacter(String name, Faction faction, TextureRegion textureRegion, Ability... abilities) {
|
||||
super();
|
||||
@@ -29,6 +33,7 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
|
||||
this.textureRegion = textureRegion;
|
||||
this.health = 100;
|
||||
this.allowedToMove = new ArrayList<>();
|
||||
this.hitAnimationTimer = new Timer(5000);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -58,7 +63,9 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
|
||||
|
||||
public void damage(int amount) {
|
||||
this.health -= amount;
|
||||
if (this.health < 0) this. health = 0;
|
||||
if (this.health < 0) this.health = 0;
|
||||
this.damageAnimation = true;
|
||||
this.hitAnimationTimer.start();
|
||||
System.out.println("OUCH character " + name + " was damaged for " + amount);
|
||||
}
|
||||
|
||||
@@ -90,6 +97,18 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
|
||||
Objects.equals(abilities, character.abilities);
|
||||
}
|
||||
|
||||
public void update(double deltaTime) {
|
||||
this.hitAnimationTimer.update(deltaTime);
|
||||
|
||||
// if (this.isShowingAnimation()) {
|
||||
// System.out.println("showing");
|
||||
if (this.hitAnimationTimer.timeout()) {
|
||||
System.out.println("timout");
|
||||
this.damageAnimation = false;
|
||||
this.hitAnimationTimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, faction, abilities, override);
|
||||
@@ -121,4 +140,12 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
|
||||
public Faction getFaction() {
|
||||
return faction;
|
||||
}
|
||||
|
||||
public boolean isShowingAnimation() {
|
||||
return this.damageAnimation;
|
||||
}
|
||||
|
||||
public void setShowingDamageAnimation(boolean damageAnimation) {
|
||||
this.damageAnimation = damageAnimation;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user