From 35a93d3ecbdafc3b894e59f85d0b10667a28b5ee Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Sat, 6 Jun 2020 22:42:43 +0200 Subject: [PATCH] hit timer --- .../src/netwerkprog/game/client/MainGame.java | 23 ++-- .../game/client/game/characters/Team.java | 7 ++ .../game/client/game/map/MapRenderer.java | 2 +- .../game/util/application/Timer.java | 106 ------------------ .../game/util/game/GameCharacter.java | 33 +++--- core/src/netwerkprog/game/util/tree/BST.java | 15 +++ 6 files changed, 55 insertions(+), 131 deletions(-) delete mode 100644 core/src/netwerkprog/game/util/application/Timer.java diff --git a/core/src/netwerkprog/game/client/MainGame.java b/core/src/netwerkprog/game/client/MainGame.java index 1b6b858..63e3bbf 100644 --- a/core/src/netwerkprog/game/client/MainGame.java +++ b/core/src/netwerkprog/game/client/MainGame.java @@ -117,22 +117,29 @@ public class MainGame extends ApplicationAdapter { this.team = new Team(); this.enemyTeam = new Team(); + + System.out.println(this.chosenFaction); for (int i = 1; i <= 5; i++) { GameCharacter temp = new Hacker("hacker" + i, characters[5][0], new BodySwap("test")); mapRenderer.getGameTiles()[1][i].visit(temp); + + GameCharacter temp2 = new Agent("Agent" + i, characters[11][0], new BodySwap("Test")); + int width = mapRenderer.getGameTiles()[0].length; + mapRenderer.getGameTiles()[3][width - (i + 1)].visit(temp2); + if (chosenFaction == Faction.HACKER) { + System.out.println("adding " + temp); this.team.addMember(temp); + this.enemyTeam.addMember(temp2); + } if (chosenFaction == Faction.MEGACORPORATION) { + System.out.println("adding " + temp2); + this.team.addMember(temp2); + this.enemyTeam.addMember(temp); } } - for (int i = 1; i <= 5; i++) { - GameCharacter temp = new Agent("Agent" + i, characters[11][0], new BodySwap("Test")); - int width = mapRenderer.getGameTiles()[0].length; - mapRenderer.getGameTiles()[3][width - (i + 1)].visit(temp); - if (chosenFaction == Faction.MEGACORPORATION) { - this.team.addMember(temp); - } - } + System.out.println(this.team); + System.out.println(this.enemyTeam); this.setSelectedCharacter(this.team.get(0)); } diff --git a/core/src/netwerkprog/game/client/game/characters/Team.java b/core/src/netwerkprog/game/client/game/characters/Team.java index caf9145..c419d3d 100644 --- a/core/src/netwerkprog/game/client/game/characters/Team.java +++ b/core/src/netwerkprog/game/client/game/characters/Team.java @@ -67,4 +67,11 @@ public class Team { } return dead >= this.members.getSize(); } + + @Override + public String toString() { + return "Team{" + + "members=" + members + + '}'; + } } diff --git a/core/src/netwerkprog/game/client/game/map/MapRenderer.java b/core/src/netwerkprog/game/client/game/map/MapRenderer.java index 0e69407..ada9960 100644 --- a/core/src/netwerkprog/game/client/game/map/MapRenderer.java +++ b/core/src/netwerkprog/game/client/game/map/MapRenderer.java @@ -6,7 +6,6 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; import netwerkprog.game.client.MainGame; -import netwerkprog.game.util.application.Timer; import netwerkprog.game.util.game.GameCharacter; import netwerkprog.game.util.graphics.Renderable; @@ -123,6 +122,7 @@ public class MapRenderer implements Renderable { if (cur.containsCharacter()) { GameCharacter character = cur.getCharacter(); batch.draw(character.getTextureRegion(), cur.x, cur.y); +// System.out.println("character " + character.getName() + " showing: " + character.isShowingAnimation()); if (character.isShowingAnimation()) { // System.out.println("animation"); batch.draw(hitMarker,cur.x,cur.y); diff --git a/core/src/netwerkprog/game/util/application/Timer.java b/core/src/netwerkprog/game/util/application/Timer.java deleted file mode 100644 index 2d8174f..0000000 --- a/core/src/netwerkprog/game/util/application/Timer.java +++ /dev/null @@ -1,106 +0,0 @@ -package netwerkprog.game.util.application; - -public class Timer implements Updatable { - private double wait; - private double time; - private boolean loop; - private int timeout; - - /** - * makes a new timer that doesnt start automatically and doesnt loop - * @param wait the time in ms to wait - */ - public Timer(double wait) { - this(wait, false, false); - } - - /** - * makes a new timer with the given parameters - * @param wait the wait time in ms - * @param autoStart whether the timer should start automatically - */ - public Timer(double wait, boolean autoStart) { - this(wait, autoStart, false); - } - - /** - * makes a new timer with the given parameters - * @param wait the wait time in ms - * @param autoStart wether the timer should start automatically - * @param loop if this timer should loop - */ - public Timer(double wait, boolean autoStart, boolean loop) { - this.wait = wait; - this.loop = loop; - this.time = 0.0; - this.timeout = autoStart ? 0 : -1; - } - - public void start() { - this.timeout = 0; - System.out.println("starting timer for " + wait + ", timeout is " + this.timeout); - } - - public void stop() { - this.timeout = -1; - } - - /** - * Get whether the timer has timed out. - * Timeouts will stack and will not be reset when this method has been called, - * instead the timeout will decrease by one. - * - * @return timeout occurred - */ - public boolean timeout() { - if (this.timeout == -1) { - // timeout has occurred and is not looped - return true; - } - - if (this.timeout - 1 < 0) { - // timeout has not occurred - this.timeout = 0; - return false; - } - - if (this.loop) { - // when looped, decrease by one - this.timeout -= 1; - } else { - // else abort the timer - this.timeout = -1; - } - - return true; - } - - /** - * sets the time until the timeout. - * @param wait the new timeout time - */ - public void setWait(double wait) { - this.wait = wait; - } - - - public double getWait() { - return this.wait; - } - - @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++; - } - } - } -} diff --git a/core/src/netwerkprog/game/util/game/GameCharacter.java b/core/src/netwerkprog/game/util/game/GameCharacter.java index 0eb629c..34fbd67 100644 --- a/core/src/netwerkprog/game/util/game/GameCharacter.java +++ b/core/src/netwerkprog/game/util/game/GameCharacter.java @@ -5,7 +5,6 @@ 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; @@ -21,8 +20,8 @@ public abstract class GameCharacter extends Actor implements Comparable allowedToMove; - protected boolean damageAnimation = false; - protected Timer hitAnimationTimer; + protected boolean damageAnimation; + protected double hitTimout = 0; public GameCharacter(String name, Faction faction, TextureRegion textureRegion, Ability... abilities) { super(); @@ -32,8 +31,8 @@ public abstract class GameCharacter extends Actor implements Comparable(); - this.hitAnimationTimer = new Timer(5000); } public String getName() { @@ -63,10 +62,13 @@ public abstract class GameCharacter extends Actor implements Comparable= 0.4) { + this.damageAnimation = false; + this.hitTimout = 0; + } -// if (this.isShowingAnimation()) { -// System.out.println("showing"); - if (this.hitAnimationTimer.timeout()) { - System.out.println("timout"); - this.damageAnimation = false; - this.hitAnimationTimer.stop(); - } } @Override @@ -116,7 +117,7 @@ public abstract class GameCharacter extends Actor implements Comparable> extends AbstractTree { protected TreeNode root; protected int size = 0; @@ -323,6 +325,19 @@ public class BST> extends AbstractTree { size = 0; } + @Override + public String toString() { + String res = ""; + for (E e : this) { + res += e.toString(); + } + return "BST{" + + "root=" + root + + ", size=" + size + + ", " + res + + '}'; + } + // if (tree == null) { // return false; // }