Damage character #11

Merged
SemvdH merged 5 commits from damage-character into master 2020-06-06 20:43:07 +00:00
6 changed files with 55 additions and 131 deletions
Showing only changes of commit 35a93d3ecb - Show all commits

View File

@@ -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));
}

View File

@@ -67,4 +67,11 @@ public class Team {
}
return dead >= this.members.getSize();
}
@Override
public String toString() {
return "Team{" +
"members=" + members +
'}';
}
}

View File

@@ -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);

View File

@@ -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++;
}
}
}
}

View File

@@ -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<GameChar
protected TextureRegion textureRegion;
protected int health;
protected List<GameTile> 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<GameChar
this.override = false;
this.textureRegion = textureRegion;
this.health = 100;
this.damageAnimation = false;
this.allowedToMove = new ArrayList<>();
this.hitAnimationTimer = new Timer(5000);
}
public String getName() {
@@ -63,10 +62,13 @@ 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);
System.out.println("OUCH character " + name + " was damaged for " + amount + ", animation: " + this.isShowingAnimation());
}
public boolean isDead() {
@@ -98,15 +100,14 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
}
public void update(double deltaTime) {
this.hitAnimationTimer.update(deltaTime);
if (this.damageAnimation) {
this.hitTimout += deltaTime;
}
if (this.hitTimout >= 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<GameChar
@Override
public int compareTo(GameCharacter o) {
return this.health - o.health;
return (this.health - o.health) + this.name.compareTo(o.name) + this.faction.compareTo(o.faction);
}
@Override

View File

@@ -1,5 +1,7 @@
package netwerkprog.game.util.tree;
import java.util.Iterator;
public class BST<E extends Comparable<E>> extends AbstractTree<E> {
protected TreeNode<E> root;
protected int size = 0;
@@ -323,6 +325,19 @@ public class BST<E extends Comparable<E>> extends AbstractTree<E> {
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;
// }