forked from VulicSystems/EraOfDueling
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
371 additions
and
36 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
sprites.png | ||
size: 232, 232 | ||
format: RGBA8888 | ||
filter: Linear,Linear | ||
repeat: none | ||
swordsman | ||
rotate: false | ||
xy: 0, 0 | ||
size: 232, 232 | ||
orig: 232, 232 | ||
offset: 0, 0 | ||
index: -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
core/src/main/java/org/strategyGame/graphics/GraphicalPosition.java
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
core/src/main/java/org/strategyGame/graphics/GraphicsComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.strategyGame.graphics; | ||
|
||
import org.terasology.gestalt.entitysystem.component.Component; | ||
|
||
/** | ||
* The graphics information for an entity. For the position, 0,0 is the bottom-left corner. | ||
*/ | ||
public class GraphicsComponent implements Component<GraphicsComponent> { | ||
public int x, y; | ||
public String spriteName; | ||
public boolean isFlippedHorizontally, isFlippedVertically; | ||
|
||
@Override | ||
public void copy(GraphicsComponent other) { | ||
this.x = other.x; | ||
this.y = other.y; | ||
this.spriteName = other.spriteName; | ||
this.isFlippedHorizontally = other.isFlippedHorizontally; | ||
this.isFlippedVertically = other.isFlippedVertically; | ||
} | ||
} |
83 changes: 77 additions & 6 deletions
83
core/src/main/java/org/strategyGame/graphics/GraphicsManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,97 @@ | ||
package org.strategyGame.graphics; | ||
|
||
import com.badlogic.gdx.Gdx; | ||
import com.badlogic.gdx.graphics.Texture; | ||
import com.badlogic.gdx.graphics.g2d.Sprite; | ||
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | ||
import com.badlogic.gdx.graphics.g2d.TextureAtlas; | ||
import org.strategyGame.PlayerData; | ||
import org.strategyGame.resources.ResourceType; | ||
import org.strategyGame.ecsStructure.ECSManager; | ||
import org.terasology.gestalt.entitysystem.entity.EntityIterator; | ||
import org.terasology.gestalt.entitysystem.entity.EntityRef; | ||
|
||
import java.util.HashMap; | ||
|
||
/** | ||
* This handles the graphics for the game. Entities with a {@link GraphicsComponent} are automatically rendered, and | ||
* text can be displayed by calling {@code displayString()}. | ||
*/ | ||
public class GraphicsManager { | ||
|
||
private SpriteBatch batch; | ||
private TextDisplay textDisplay; | ||
|
||
private PlayerData playerData; | ||
private ECSManager ecsManager; | ||
|
||
public GraphicsManager(SpriteBatch batch, PlayerData playerData) { | ||
private TextureAtlas textureAtlas = new TextureAtlas("sprites.txt"); | ||
private HashMap<String, Sprite> sprites; | ||
|
||
public GraphicsManager(SpriteBatch batch, PlayerData playerData, ECSManager ecsManager) { | ||
this.batch = batch; | ||
batch.enableBlending(); | ||
textDisplay = new TextDisplay(batch); | ||
this.playerData = playerData; | ||
this.ecsManager = ecsManager; | ||
|
||
sprites = new HashMap<>(); | ||
} | ||
|
||
/** | ||
* Renders each entity with a {@link GraphicsComponent}. | ||
*/ | ||
public void render() { | ||
textDisplay.displayString(((int) playerData.getStorageAmount(ResourceType.WOOD)) + " wood", Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 2); | ||
batch.draw(new Texture("HexTile.png"), 100, 10); | ||
EntityIterator iterator = ecsManager.iterate(new GraphicsComponent()); | ||
while (iterator.next()) { | ||
renderEntity(iterator.getEntity()); | ||
} | ||
} | ||
|
||
/** | ||
* Renders a specific entity. | ||
*/ | ||
private void renderEntity(EntityRef entity) { | ||
GraphicsComponent graphicsComponent = entity.getComponent(GraphicsComponent.class).get(); | ||
Sprite sprite = getSprite(graphicsComponent.spriteName); | ||
if (sprite != null) { | ||
sprite.setPosition(graphicsComponent.x, graphicsComponent.y); | ||
sprite.setFlip(graphicsComponent.isFlippedHorizontally, graphicsComponent.isFlippedVertically); | ||
sprite.draw(batch); | ||
} | ||
} | ||
|
||
/** | ||
* Retrieves a sprite instance if one already exists, or creates one if not. | ||
*/ | ||
private Sprite getSprite(String spriteName) { | ||
if (!sprites.containsKey(spriteName)) { | ||
Sprite sprite = textureAtlas.createSprite(spriteName); | ||
if (sprite != null) { | ||
sprites.put(spriteName, sprite); | ||
} | ||
return sprite; | ||
} | ||
return sprites.get(spriteName); | ||
} | ||
|
||
/** | ||
* Displays a string at the specified horizontal and vertical location. | ||
*/ | ||
public void displayString(String string, float horizontalPosition, float verticalPosition) { | ||
textDisplay.displayString(string, horizontalPosition, verticalPosition); | ||
} | ||
|
||
/** | ||
* Displays a string at the specified horizontal and vertical location, multiplied in size by the scale. | ||
* | ||
* @param scale the size multiplier | ||
*/ | ||
public void displayString(String string, float horizontalPosition, float verticalPosition, float scale) { | ||
textDisplay.displayString(string, horizontalPosition, verticalPosition, scale); | ||
} | ||
|
||
/** | ||
* Cleans up assets when the game is closed. | ||
*/ | ||
public void dispose() { | ||
textureAtlas.dispose(); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.