Expanded Character to include sprites and positions.
Added George sprites for testing. TestCode for George
This commit is contained in:
BIN
core/assets/george.png
Normal file
BIN
core/assets/george.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
@@ -1,4 +1,12 @@
|
||||
package netwerkprog.game.client.game.characters;
|
||||
|
||||
public class DevTest1 {
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import netwerkprog.game.util.game.Character;
|
||||
import netwerkprog.game.util.game.Faction;
|
||||
|
||||
public class DevTest1 extends Character {
|
||||
public DevTest1() {
|
||||
super("DevTest1", Faction.HACKER, new Texture(Gdx.files.internal("core/assets/george.png")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
package netwerkprog.game.client.game.characters;
|
||||
|
||||
public class DevTest2 {
|
||||
import netwerkprog.game.util.game.Character;
|
||||
import netwerkprog.game.util.game.Faction;
|
||||
|
||||
public class DevTest2 extends Character {
|
||||
public DevTest2() {
|
||||
super("DevTest2", Faction.MEGACORPORATION, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package netwerkprog.game.client.game.characters;
|
||||
|
||||
import netwerkprog.game.util.game.Character;
|
||||
import netwerkprog.game.util.game.Faction;
|
||||
|
||||
public class DevTest3 extends Character {
|
||||
public DevTest3() {
|
||||
super("DevTest3", Faction.AI, null);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,30 @@
|
||||
package netwerkprog.game.util.game;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
public abstract class Character {
|
||||
public abstract class Character extends Actor {
|
||||
protected String name;
|
||||
protected Faction faction;
|
||||
protected HashSet<Ability> abilities;
|
||||
protected TextureRegion[] sprites;
|
||||
protected boolean override;
|
||||
protected int x;
|
||||
protected int y;
|
||||
private final int maxSize = 1;
|
||||
|
||||
public Character(String name, Faction faction, Ability... abilities) {
|
||||
|
||||
public Character(String name, Faction faction, Texture spriteSheet, Ability... abilities) {
|
||||
this.name = name;
|
||||
this.faction = faction;
|
||||
this.sprites = new TextureRegion[this.maxSize];
|
||||
this.abilities = new HashSet<>(Arrays.asList(abilities));
|
||||
this.override = false;
|
||||
loadSprites(spriteSheet);
|
||||
}
|
||||
|
||||
public void addAbilities(Ability ability) {
|
||||
@@ -27,4 +38,18 @@ public abstract class Character {
|
||||
public void changeControl() {
|
||||
this.override = !this.override;
|
||||
}
|
||||
|
||||
private void loadSprites(Texture spriteSheet) {
|
||||
int counter = 0;
|
||||
TextureRegion[][] temp = TextureRegion.split(spriteSheet,32,32);
|
||||
for (TextureRegion[] array : temp) {
|
||||
for (TextureRegion sprite : array) {
|
||||
this.sprites[counter] = sprite;
|
||||
counter++;
|
||||
if (counter >= this.maxSize) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
package netwerkprog.game.util.game;
|
||||
|
||||
public enum Faction {
|
||||
MEGACORPORATION("MegaCorp"),
|
||||
HACKER("Hacker"),
|
||||
AI("AI");
|
||||
|
||||
String name;
|
||||
|
||||
Faction(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
15
core/src/test/java/CharacterLoadingTest.java
Normal file
15
core/src/test/java/CharacterLoadingTest.java
Normal file
@@ -0,0 +1,15 @@
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import netwerkprog.game.client.game.characters.DevTest1;
|
||||
import netwerkprog.game.util.game.Character;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CharacterLoadingTest {
|
||||
|
||||
@Test
|
||||
public void george() {
|
||||
String path = "core/assets/george.png";
|
||||
Texture texture = new Texture(Gdx.files.internal(path));
|
||||
Character george = new DevTest1();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user