refactored character to game character
This commit is contained in:
@@ -15,7 +15,7 @@ import netwerkprog.game.client.game.characters.abilities.BodySwap;
|
||||
import netwerkprog.game.client.game.map.Map;
|
||||
import netwerkprog.game.client.game.map.MapRenderer;
|
||||
import netwerkprog.game.client.game.map.GameInputProcessor;
|
||||
import netwerkprog.game.util.game.Character;
|
||||
import netwerkprog.game.util.game.GameCharacter;
|
||||
import netwerkprog.game.util.graphics.FrameRate;
|
||||
import netwerkprog.game.util.tree.BST;
|
||||
|
||||
@@ -27,13 +27,13 @@ public class MainGame extends ApplicationAdapter {
|
||||
private Thread client;
|
||||
private OrthographicCamera camera;
|
||||
private GameInputProcessor gameInputProcessor;
|
||||
private Character selectedCharacter;
|
||||
private GameCharacter selectedCharacter;
|
||||
|
||||
private Map map;
|
||||
public MapRenderer mapRenderer;
|
||||
|
||||
private BST<Character> tree;
|
||||
public Character testCharacter;
|
||||
private BST<GameCharacter> tree;
|
||||
public GameCharacter testCharacter;
|
||||
|
||||
private static MainGame INSTANCE;
|
||||
|
||||
@@ -95,7 +95,7 @@ public class MainGame extends ApplicationAdapter {
|
||||
Texture texture = new Texture(Gdx.files.internal("core/assets/characters.png"));
|
||||
TextureRegion[][] characters = TextureRegion.split(texture, 32, 32);
|
||||
this.testCharacter = new Hacker("harry",characters[1][0], new BodySwap("test"));
|
||||
Character character2 = new Hacker("test2",characters[2][0], new BodySwap("test"));
|
||||
GameCharacter character2 = new Hacker("test2",characters[2][0], new BodySwap("test"));
|
||||
// this.tree.insert(testCharacter);
|
||||
// this.tree.insert(character2);
|
||||
// this.tree.insert(new Agent(characters[2][0], new Implant("test")));
|
||||
@@ -183,16 +183,16 @@ public class MainGame extends ApplicationAdapter {
|
||||
return map.getWidth();
|
||||
}
|
||||
|
||||
public BST<Character> getTree() {
|
||||
public BST<GameCharacter> getTree() {
|
||||
return tree;
|
||||
}
|
||||
|
||||
public void setSelectedCharacter(Character character) {
|
||||
public void setSelectedCharacter(GameCharacter character) {
|
||||
this.selectedCharacter = character;
|
||||
System.out.println("selected character set to : " + character);
|
||||
}
|
||||
|
||||
public Character getSelectedCharacter() {
|
||||
public GameCharacter getSelectedCharacter() {
|
||||
return selectedCharacter;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@ package netwerkprog.game.client.game.characters;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import netwerkprog.game.util.game.Ability;
|
||||
import netwerkprog.game.util.game.Character;
|
||||
import netwerkprog.game.util.game.Faction;
|
||||
import netwerkprog.game.util.game.GameCharacter;
|
||||
|
||||
public class Agent extends Character {
|
||||
public class Agent extends GameCharacter {
|
||||
public Agent(TextureRegion textureRegion, Ability... abilities) {
|
||||
super("Agent", Faction.MEGACORPORATION, textureRegion, abilities);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package netwerkprog.game.client.game.characters;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import netwerkprog.game.util.game.Ability;
|
||||
import netwerkprog.game.util.game.Character;
|
||||
import netwerkprog.game.util.game.Faction;
|
||||
import netwerkprog.game.util.game.GameCharacter;
|
||||
|
||||
public class Hacker extends Character {
|
||||
public class Hacker extends GameCharacter {
|
||||
public Hacker(String name, TextureRegion textureRegion, Ability... abilities) {
|
||||
super(name, Faction.HACKER, textureRegion, abilities);
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package netwerkprog.game.client.game.characters;
|
||||
|
||||
import netwerkprog.game.client.game.map.GameTile;
|
||||
import netwerkprog.game.util.game.Character;
|
||||
|
||||
public class SelectedCharacter {
|
||||
private Character character;
|
||||
private GameTile currentTile;
|
||||
|
||||
public SelectedCharacter(Character character, GameTile tile) {
|
||||
this.character = character;
|
||||
this.currentTile =tile;
|
||||
}
|
||||
|
||||
public Character getCharacter() {
|
||||
return character;
|
||||
}
|
||||
|
||||
public void setCharacter(Character character) {
|
||||
this.character = character;
|
||||
}
|
||||
|
||||
public GameTile getCurrentTile() {
|
||||
return currentTile;
|
||||
}
|
||||
|
||||
public void setCurrentTile(GameTile currentTile) {
|
||||
this.currentTile = currentTile;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import netwerkprog.game.client.MainGame;
|
||||
import netwerkprog.game.util.game.Character;
|
||||
import netwerkprog.game.util.game.GameCharacter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -148,7 +148,7 @@ public class GameInputProcessor implements InputProcessor {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void removeCharacterFromTile(Character character) {
|
||||
private void removeCharacterFromTile(GameCharacter character) {
|
||||
rowLoop:
|
||||
for (int row = 0; row < mainGame.mapRenderer.getGameTiles().length; row++) {
|
||||
for (int col = 0; col < mainGame.mapRenderer.getGameTiles()[0].length; col++) {
|
||||
|
||||
@@ -2,14 +2,14 @@ package netwerkprog.game.client.game.map;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import netwerkprog.game.util.game.Character;
|
||||
import netwerkprog.game.util.game.GameCharacter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class GameTile extends Rectangle {
|
||||
private TextureRegion textureRegion;
|
||||
private char symbol;
|
||||
private Character character;
|
||||
private GameCharacter character;
|
||||
|
||||
public GameTile(TextureRegion textureRegion, int xPos, int yPos, char symbol) {
|
||||
this.textureRegion = textureRegion;
|
||||
@@ -20,7 +20,7 @@ public class GameTile extends Rectangle {
|
||||
super.height = textureRegion.getRegionHeight();
|
||||
}
|
||||
|
||||
public Character getCharacter() {
|
||||
public GameCharacter getCharacter() {
|
||||
return character;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class GameTile extends Rectangle {
|
||||
* @param character the character to visit this tile
|
||||
* @return false if this tile already had a character on it.
|
||||
*/
|
||||
public boolean visit(Character character) {
|
||||
public boolean visit(GameCharacter character) {
|
||||
if (this.character != null) return false;
|
||||
this.character = character;
|
||||
return true;
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
package netwerkprog.game.util.game;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class Character implements Comparable<Character> {
|
||||
protected String name;
|
||||
protected Faction faction;
|
||||
protected HashSet<Ability> abilities;
|
||||
protected boolean override;
|
||||
protected TextureRegion textureRegion;
|
||||
protected SpriteBatch batch;
|
||||
|
||||
public Character(String name, Faction faction, TextureRegion textureRegion, Ability... abilities) {
|
||||
this.name = name;
|
||||
this.faction = faction;
|
||||
this.abilities = new HashSet<>(Arrays.asList(abilities));
|
||||
this.override = false;
|
||||
this.textureRegion = textureRegion;
|
||||
batch = new SpriteBatch();
|
||||
}
|
||||
|
||||
public void addAbilities(Ability ability) {
|
||||
this.abilities.add(ability);
|
||||
}
|
||||
|
||||
public void removeAbility(Ability ability) {
|
||||
this.abilities.remove(ability);
|
||||
}
|
||||
|
||||
public void changeControl() {
|
||||
this.override = !this.override;
|
||||
}
|
||||
|
||||
public TextureRegion getTextureRegion() {
|
||||
return textureRegion;
|
||||
}
|
||||
|
||||
public void setTextureRegion(TextureRegion textureRegion) {
|
||||
this.textureRegion = textureRegion;
|
||||
}
|
||||
|
||||
public void render(float x, float y) {
|
||||
batch.begin();
|
||||
batch.draw(this.textureRegion, x, y);
|
||||
batch.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null) return false;
|
||||
if (!(o instanceof Character)) return false;
|
||||
Character character = (Character) o;
|
||||
return override == character.override &&
|
||||
Objects.equals(name, character.name) &&
|
||||
faction == character.faction &&
|
||||
Objects.equals(abilities, character.abilities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, faction, abilities, override);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Character o) {
|
||||
return this.name.compareTo(o.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Character{" +
|
||||
"name='" + name + '\'' +
|
||||
", faction=" + faction +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user