Changed GameCharacter to include sprites and draw method.

Added ScifiCritters testspirtes.
This commit is contained in:
MickWerf
2020-05-25 21:57:43 +02:00
parent cc37fc2858
commit 2e04560930
7 changed files with 19 additions and 45 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -1,12 +1,10 @@
package netwerkprog.game.client.game.characters;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import netwerkprog.game.util.game.Character;
import netwerkprog.game.util.game.GameCharacter;
import netwerkprog.game.util.game.Faction;
public class DevTest1 extends Character {
public class DevTest1 extends GameCharacter {
public DevTest1() {
super("DevTest1", Faction.HACKER, new Texture(Gdx.files.internal("core/assets/george.png")));
super("DevTest1", Faction.HACKER, "core/assets/ScifiCritters4.PNG");
}
}

View File

@@ -1,9 +1,9 @@
package netwerkprog.game.client.game.characters;
import netwerkprog.game.util.game.Character;
import netwerkprog.game.util.game.GameCharacter;
import netwerkprog.game.util.game.Faction;
public class DevTest2 extends Character {
public class DevTest2 extends GameCharacter {
public DevTest2() {
super("DevTest2", Faction.MEGACORPORATION, null);
}

View File

@@ -1,9 +1,9 @@
package netwerkprog.game.client.game.characters;
import netwerkprog.game.util.game.Character;
import netwerkprog.game.util.game.GameCharacter;
import netwerkprog.game.util.game.Faction;
public class DevTest3 extends Character {
public class DevTest3 extends GameCharacter {
public DevTest3() {
super("DevTest3", Faction.AI, null);
}

View File

@@ -1,30 +1,28 @@
package netwerkprog.game.util.game;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
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 extends Actor {
public abstract class GameCharacter extends Actor {
protected String name;
protected Faction faction;
protected HashSet<Ability> abilities;
protected TextureRegion[] sprites;
protected TextureRegion[][] sprites;
protected boolean override;
protected int x;
protected int y;
private final int maxSize = 1;
public Character(String name, Faction faction, Texture spriteSheet, Ability... abilities) {
public GameCharacter(String name, Faction faction, String 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);
this.sprites = TextureRegion.split(new Texture(spriteSheet),32,32);
super.setX(0);
super.setY(0);
}
public void addAbilities(Ability ability) {
@@ -39,17 +37,10 @@ public abstract class Character extends Actor {
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;
}
}
}
public void draw(SpriteBatch batch) {
batch.begin();
batch.draw(this.sprites[0][0],super.getX(),super.getY());
batch.end();
}
}

View File

@@ -1,15 +0,0 @@
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();
}
}