diff --git a/core/assets/sprites/staticplayer.png b/core/assets/sprites/staticplayer.png new file mode 100644 index 0000000..6e60cea Binary files /dev/null and b/core/assets/sprites/staticplayer.png differ diff --git a/core/src/com/saltosion/gladiator/GladiatorBrawler.java b/core/src/com/saltosion/gladiator/GladiatorBrawler.java index 828d618..5ca5169 100644 --- a/core/src/com/saltosion/gladiator/GladiatorBrawler.java +++ b/core/src/com/saltosion/gladiator/GladiatorBrawler.java @@ -1,27 +1,41 @@ package com.saltosion.gladiator; +import com.badlogic.ashley.core.Engine; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.saltosion.gladiator.util.GlobalStrings; +import com.saltosion.gladiator.util.SpriteLoader; public class GladiatorBrawler extends ApplicationAdapter { - SpriteBatch batch; - Texture img; + + private Batch batch; + private Sprite staticplayer; + private OrthographicCamera camera; + private Engine engine; @Override public void create () { + engine = new Engine(); + + camera = new OrthographicCamera(); + camera.setToOrtho(false, 384, 216); batch = new SpriteBatch(); - img = new Texture("badlogic.jpg"); + staticplayer = SpriteLoader.loadSprite(GlobalStrings.STATICPLAYER); } @Override public void render () { - Gdx.gl.glClearColor(1, 0, 0, 1); + Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + batch.setProjectionMatrix(camera.combined); batch.begin(); - batch.draw(img, 0, 0); + batch.draw(staticplayer, 0, 0); batch.end(); } } diff --git a/core/src/com/saltosion/gladiator/util/GlobalStrings.java b/core/src/com/saltosion/gladiator/util/GlobalStrings.java new file mode 100644 index 0000000..74e45e6 --- /dev/null +++ b/core/src/com/saltosion/gladiator/util/GlobalStrings.java @@ -0,0 +1,9 @@ +package com.saltosion.gladiator.util; + +public class GlobalStrings { + + public static final String STATICPLAYER = "STATICPLAYER"; + + public static final String GAME_NAME = "Gladiator Brawl"; + +} diff --git a/core/src/com/saltosion/gladiator/util/SpriteLoader.java b/core/src/com/saltosion/gladiator/util/SpriteLoader.java new file mode 100644 index 0000000..5eea753 --- /dev/null +++ b/core/src/com/saltosion/gladiator/util/SpriteLoader.java @@ -0,0 +1,61 @@ +package com.saltosion.gladiator.util; + +import java.util.ArrayList; +import java.util.HashMap; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.Sprite; +import com.badlogic.gdx.graphics.g2d.TextureRegion; + +public class SpriteLoader { + + public static HashMap textures = new HashMap(); + + static { + loadTexture(GlobalStrings.STATICPLAYER, "sprites/staticplayer.png"); + } + + /** + * Returns a sprite, which is a piece from texture. + * @param texKey + * @param x + * @param y + * @param width + * @param height + * @return + */ + public static Sprite loadSprite(String texKey, int x, int y, int width, int height) { + TextureRegion tr = new TextureRegion(textures.get(texKey), x, y, width, height); + return new Sprite(tr); + } + + /** + * Returns a sprite, which is originally a texture. + * @param texKey + * @return + */ + public static Sprite loadSprite(String texKey) { + return new Sprite(textures.get(texKey)); + } + + /** + * Load texture from path. + * @param filePath + */ + public static Texture loadTexture(String key, String filePath) { + Texture t = new Texture(Gdx.files.internal(filePath)); + textures.put(key, t); + return t; + } + + /** + * Disposes all the textures loaded so far. + */ + public static void dispose () { + for (Texture tex : textures.values()) { + tex.dispose(); + } + } + +} diff --git a/desktop/src/com/saltosion/gladiator/desktop/DesktopLauncher.java b/desktop/src/com/saltosion/gladiator/desktop/DesktopLauncher.java index be850b0..fec2a25 100644 --- a/desktop/src/com/saltosion/gladiator/desktop/DesktopLauncher.java +++ b/desktop/src/com/saltosion/gladiator/desktop/DesktopLauncher.java @@ -3,10 +3,14 @@ package com.saltosion.gladiator.desktop; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; import com.saltosion.gladiator.GladiatorBrawler; +import com.saltosion.gladiator.util.GlobalStrings; public class DesktopLauncher { public static void main (String[] arg) { LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); + config.title = GlobalStrings.GAME_NAME; + config.width = 720; + config.height = 480; new LwjglApplication(new GladiatorBrawler(), config); } }