merge Character tile into master #7
@@ -1,28 +1,27 @@
|
|||||||
package netwerkprog.game.util.game;
|
package netwerkprog.game.util.game;
|
||||||
|
|
||||||
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 com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class GameCharacter extends Actor {
|
public abstract class GameCharacter implements Comparable<GameCharacter> {
|
||||||
protected String name;
|
protected String name;
|
||||||
protected Faction faction;
|
protected Faction faction;
|
||||||
protected HashSet<Ability> abilities;
|
protected HashSet<Ability> abilities;
|
||||||
protected TextureRegion[][] sprites;
|
|
||||||
protected boolean override;
|
protected boolean override;
|
||||||
|
protected TextureRegion textureRegion;
|
||||||
|
protected SpriteBatch batch;
|
||||||
|
|
||||||
public GameCharacter(String name, Faction faction, String spriteSheet, Ability... abilities) {
|
public GameCharacter(String name, Faction faction, TextureRegion textureRegion, Ability... abilities) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.faction = faction;
|
this.faction = faction;
|
||||||
this.abilities = new HashSet<>(Arrays.asList(abilities));
|
this.abilities = new HashSet<>(Arrays.asList(abilities));
|
||||||
this.override = false;
|
this.override = false;
|
||||||
this.sprites = TextureRegion.split(new Texture(spriteSheet),32,32);
|
this.textureRegion = textureRegion;
|
||||||
super.setX(0);
|
batch = new SpriteBatch();
|
||||||
super.setY(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAbilities(Ability ability) {
|
public void addAbilities(Ability ability) {
|
||||||
@@ -37,10 +36,47 @@ public abstract class GameCharacter extends Actor {
|
|||||||
this.override = !this.override;
|
this.override = !this.override;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(SpriteBatch batch) {
|
public TextureRegion getTextureRegion() {
|
||||||
|
return textureRegion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTextureRegion(TextureRegion textureRegion) {
|
||||||
|
this.textureRegion = textureRegion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(float x, float y) {
|
||||||
batch.begin();
|
batch.begin();
|
||||||
batch.draw(this.sprites[0][0],super.getX(),super.getY());
|
batch.draw(this.textureRegion, x, y);
|
||||||
batch.end();
|
batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null) return false;
|
||||||
|
if (!(o instanceof GameCharacter)) return false;
|
||||||
|
GameCharacter character = (GameCharacter) 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(GameCharacter o) {
|
||||||
|
return this.name.compareTo(o.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "GameCharacter{" +
|
||||||
|
"name='" + name + '\'' +
|
||||||
|
", faction=" + faction +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user