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/earrape.mp3
Normal file
BIN
core/assets/sound/earrape.mp3
Normal file
Binary file not shown.
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;
|
||||
@@ -76,13 +78,13 @@ public class MainGame extends ApplicationAdapter {
|
||||
|
||||
String[] strings = new String[]{
|
||||
"#########################",
|
||||
"#xxxx #",
|
||||
"# x #",
|
||||
"# xxxx xxxxx #",
|
||||
"# xxxx xxxxx #",
|
||||
"# xxxx xx xx #",
|
||||
"# x xxxxx #",
|
||||
"# x xxxx #",
|
||||
"#xxxx # #",
|
||||
"# x # #",
|
||||
"# xxxx #xxxx #",
|
||||
"# xxxx #xxxx #",
|
||||
"# xxxx #x xx #",
|
||||
"# x #xxxx #",
|
||||
"# x #xxx #",
|
||||
"# x #",
|
||||
"# xxxxxx #",
|
||||
"# x #",
|
||||
@@ -113,22 +115,31 @@ 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();
|
||||
|
||||
|
||||
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"));
|
||||
mapRenderer.getGameTiles()[3][i].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));
|
||||
|
||||
}
|
||||
@@ -136,12 +147,11 @@ public class MainGame extends ApplicationAdapter {
|
||||
|
||||
private void playSong() {
|
||||
// play music
|
||||
Music music = Gdx.audio.newMusic(Gdx.files.getFileHandle("core/assets/music.mp3", Files.FileType.Internal));
|
||||
Music music = Gdx.audio.newMusic(Gdx.files.getFileHandle("core/assets/earrape.mp3", Files.FileType.Internal));
|
||||
music.setVolume(.1f);
|
||||
music.play();
|
||||
music.setLooping(true);
|
||||
|
||||
connectToServer();
|
||||
}
|
||||
|
||||
|
||||
@@ -195,9 +205,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) {
|
||||
@@ -61,4 +67,11 @@ public class Team {
|
||||
}
|
||||
return dead >= this.members.getSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Team{" +
|
||||
"members=" + members +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ public class GameInputProcessor implements InputProcessor {
|
||||
|
||||
camera.zoom = MathUtils.clamp(camera.zoom, 1.5f, 1.8f);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public boolean isWPressed() {
|
||||
@@ -124,8 +125,10 @@ public class GameInputProcessor implements InputProcessor {
|
||||
System.out.println("HACKER");
|
||||
mainGame.setChosenFaction(Faction.HACKER);
|
||||
mainGame.initCharacters();
|
||||
camera.translate(-400, 0);
|
||||
mainGame.setGamestate(GAMESTATE.PLAYING);
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -148,21 +151,31 @@ public class GameInputProcessor implements InputProcessor {
|
||||
GameTile gameTile = mainGame.mapRenderer.getGameTiles()[row][col];
|
||||
if (gameTile.contains(touchPoint.x, touchPoint.y)) {
|
||||
if (button == Input.Buttons.LEFT) {
|
||||
// System.out.println(gameTile + " row: " + row + ", col: " + col);
|
||||
|
||||
// moving selected character
|
||||
if (mainGame.hasCharacterSelected() && !gameTile.containsCharacter()) {
|
||||
// System.out.println(mainGame.getSelectedCharacter());
|
||||
|
||||
if (gameTile.getSymbol() != '#' && mainGame.mapRenderer.getSurroundedTilesOfCurrentCharacter().contains(gameTile)) {
|
||||
removeCharacterFromTile(mainGame.getSelectedCharacter());
|
||||
gameTile.visit(mainGame.getSelectedCharacter());
|
||||
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
||||
}
|
||||
}
|
||||
// clicking on enemy
|
||||
if (mainGame.hasCharacterSelected() && gameTile.containsCharacter() && gameTile.getCharacter().getFaction() != mainGame.getChosenFaction()) {
|
||||
if (mainGame.mapRenderer.getSurroundedTilesOfCurrentCharacter().contains(gameTile)) {
|
||||
gameTile.getCharacter().damage(10);
|
||||
|
||||
}
|
||||
}
|
||||
// set selected character
|
||||
if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) {
|
||||
if (gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) {
|
||||
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
||||
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
||||
}
|
||||
}
|
||||
// switch character
|
||||
if (gameTile.containsCharacter()
|
||||
&& !mainGame.getSelectedCharacter().equals(gameTile.getCharacter())
|
||||
&& gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) {
|
||||
|
||||
@@ -26,6 +26,7 @@ public class MapRenderer implements Renderable {
|
||||
private MainGame mainGame;
|
||||
private Texture square;
|
||||
private Texture square2;
|
||||
private Texture hitMarker;
|
||||
|
||||
|
||||
public static TextureRegion FLOOR_TILE;
|
||||
@@ -61,9 +62,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);
|
||||
@@ -117,10 +120,17 @@ 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);
|
||||
// System.out.println("character " + character.getName() + " showing: " + character.isShowingAnimation());
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,102 +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;
|
||||
}
|
||||
|
||||
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 false;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (this.timeout != -1) {
|
||||
// Only update when timer is not aborted
|
||||
this.time += deltaTime;
|
||||
if (this.time >= this.wait) {
|
||||
// timeout occurred
|
||||
this.time -= this.wait;
|
||||
this.timeout++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -19,6 +20,8 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
|
||||
protected TextureRegion textureRegion;
|
||||
protected int health;
|
||||
protected List<GameTile> allowedToMove;
|
||||
protected boolean damageAnimation;
|
||||
protected double hitTimout = 0;
|
||||
|
||||
public GameCharacter(String name, Faction faction, TextureRegion textureRegion, Ability... abilities) {
|
||||
super();
|
||||
@@ -28,6 +31,7 @@ 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<>();
|
||||
}
|
||||
|
||||
@@ -58,7 +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;
|
||||
|
||||
System.out.println("OUCH character " + name + " was damaged for " + amount + ", animation: " + this.isShowingAnimation());
|
||||
}
|
||||
|
||||
public boolean isDead() {
|
||||
@@ -89,6 +99,17 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
|
||||
Objects.equals(abilities, character.abilities);
|
||||
}
|
||||
|
||||
public void update(double deltaTime) {
|
||||
if (this.damageAnimation) {
|
||||
this.hitTimout += deltaTime;
|
||||
}
|
||||
if (this.hitTimout >= 0.4) {
|
||||
this.damageAnimation = false;
|
||||
this.hitTimout = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, faction, abilities, override);
|
||||
@@ -96,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
|
||||
@@ -120,4 +141,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user