added test character drawing

This commit is contained in:
Sem van der Hoeven
2020-05-27 21:17:09 +02:00
parent 1f6e229d79
commit 9ddf94589b
11 changed files with 88 additions and 5 deletions

BIN
core/assets/characters.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

View File

@@ -6,11 +6,21 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import netwerkprog.game.client.game.characters.Agent;
import netwerkprog.game.client.game.characters.Hacker;
import netwerkprog.game.client.game.characters.abilities.BodySwap;
import netwerkprog.game.client.game.characters.abilities.Implant;
import netwerkprog.game.client.game.characters.abilities.Scrambler;
import netwerkprog.game.client.game.map.Map; import netwerkprog.game.client.game.map.Map;
import netwerkprog.game.client.game.map.MapRenderer; import netwerkprog.game.client.game.map.MapRenderer;
import netwerkprog.game.client.game.map.GameInputProcessor; import netwerkprog.game.client.game.map.GameInputProcessor;
import netwerkprog.game.util.game.Character;
import netwerkprog.game.util.graphics.FrameRate; import netwerkprog.game.util.graphics.FrameRate;
import netwerkprog.game.util.tree.BST;
public class MainGame extends ApplicationAdapter{ public class MainGame extends ApplicationAdapter{
SpriteBatch batch; SpriteBatch batch;
@@ -24,6 +34,9 @@ public class MainGame extends ApplicationAdapter{
private Map map; private Map map;
public MapRenderer mapRenderer; public MapRenderer mapRenderer;
private BST<Character> tree;
public Character testCharacter;
@Override @Override
@@ -58,6 +71,9 @@ public class MainGame extends ApplicationAdapter{
camera.viewportWidth = screenWidth / 2; camera.viewportWidth = screenWidth / 2;
camera.viewportHeight = screenHeight / 2; camera.viewportHeight = screenHeight / 2;
camera.update(); camera.update();
this.tree = new BST<>();
initCharaters();
// this.tree.insert(new Hacker(,new BodySwap()));
// playSong(); // playSong();
@@ -66,6 +82,14 @@ public class MainGame extends ApplicationAdapter{
// connectToServer(); // connectToServer();
} }
private void initCharaters() {
Texture texture = new Texture(Gdx.files.internal("core/assets/characters.png"));
TextureRegion[][] characters = TextureRegion.split(texture,32,32);
this.testCharacter = new Hacker(characters[1][0],new BodySwap("test"));
this.tree.insert(testCharacter);
this.tree.insert(new Agent(characters[2][0],new Implant("test")));
}
private void playSong() { private void playSong() {
// play music // play music
@@ -144,5 +168,8 @@ public class MainGame extends ApplicationAdapter{
return map.getWidth(); return map.getWidth();
} }
public BST<Character> getTree() {
return tree;
}
} }

View File

@@ -0,0 +1,12 @@
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;
public class Agent extends Character {
public Agent(TextureRegion textureRegion, Ability... abilities) {
super("Agent", Faction.MEGACORPORATION, textureRegion, abilities);
}
}

View File

@@ -0,0 +1,12 @@
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;
public class Hacker extends Character {
public Hacker(TextureRegion textureRegion, Ability... abilities) {
super("Hacker", Faction.HACKER, textureRegion, abilities);
}
}

View File

@@ -1,4 +1,14 @@
package netwerkprog.game.client.game.characters.abilities; package netwerkprog.game.client.game.characters.abilities;
public class BodySwap { import netwerkprog.game.util.game.Ability;
public class BodySwap extends Ability {
public BodySwap(String name) {
super(name);
}
@Override
public String getCommand() {
return null;
}
} }

View File

@@ -1,4 +1,14 @@
package netwerkprog.game.client.game.characters.abilities; package netwerkprog.game.client.game.characters.abilities;
public class Implant { import netwerkprog.game.util.game.Ability;
public class Implant extends Ability {
public Implant(String name) {
super(name);
}
@Override
public String getCommand() {
return null;
}
} }

View File

@@ -128,6 +128,7 @@ public class GameInputProcessor implements InputProcessor {
GameTile gameTile = game.mapRenderer.getGameTiles()[row][col]; GameTile gameTile = game.mapRenderer.getGameTiles()[row][col];
if (gameTile.contains(touchPoint.x, touchPoint.y)) { if (gameTile.contains(touchPoint.x, touchPoint.y)) {
System.out.println(gameTile + " row: " + row + ", col: " + col); System.out.println(gameTile + " row: " + row + ", col: " + col);
gameTile.setCharacter(this.game.testCharacter);
//TODO make stuff happen with the tile //TODO make stuff happen with the tile
return true; return true;
} }

View File

@@ -25,7 +25,7 @@ public class GameTile extends Rectangle {
} }
public boolean containsCharacter() { public boolean containsCharacter() {
return character == null; return character != null;
} }
/** /**

View File

@@ -97,7 +97,7 @@ public class MapRenderer implements Renderable {
GameTile cur = gameTileRow[col]; GameTile cur = gameTileRow[col];
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(), x, y); batch.draw(cur.getCharacter().getTextureRegion(), cur.x, cur.y);
} }
} }
} }

View File

@@ -6,7 +6,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
public abstract class Character { public abstract class Character implements Comparable<Character> {
protected String name; protected String name;
protected Faction faction; protected Faction faction;
protected HashSet<Ability> abilities; protected HashSet<Ability> abilities;
@@ -39,9 +39,18 @@ public abstract class Character {
return textureRegion; return textureRegion;
} }
public void setTextureRegion(TextureRegion textureRegion) {
this.textureRegion = textureRegion;
}
public void render(float x, float y) { public void render(float x, float y) {
batch.begin(); batch.begin();
batch.draw(this.textureRegion, x, y); batch.draw(this.textureRegion, x, y);
batch.end(); batch.end();
} }
@Override
public int compareTo(Character o) {
return this.name.compareTo(o.name);
}
} }

View File

@@ -1,4 +1,6 @@
package netwerkprog.game.util.game; package netwerkprog.game.util.game;
public enum Faction { public enum Faction {
HACKER,
MEGACORPORATION
} }