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