From c086c74ec6a3c115fa419a26e394c069355f2ba8 Mon Sep 17 00:00:00 2001 From: Armin Benz Date: Fri, 14 Apr 2017 01:11:39 +0200 Subject: [PATCH] zeugs von armin --- core/src/de/samdev/colorrunner/CRGame.java | 7 +++++-- .../game/renderer/AbstractGameRenderer.java | 15 +++++++++++++++ .../game/renderer/CRGameRenderer.java | 16 +++++++++++++--- .../colorrunner/game/world/CRGameWorld.java | 3 ++- .../screens/gameScreen/GameScreen.java | 5 ++++- .../colorrunner/screens/menu/MainMenu.java | 8 ++++++-- .../colorrunner/screens/menu/SplashScreen.java | 3 ++- 7 files changed, 47 insertions(+), 10 deletions(-) diff --git a/core/src/de/samdev/colorrunner/CRGame.java b/core/src/de/samdev/colorrunner/CRGame.java index 9b089d3..d688984 100644 --- a/core/src/de/samdev/colorrunner/CRGame.java +++ b/core/src/de/samdev/colorrunner/CRGame.java @@ -1,18 +1,21 @@ package de.samdev.colorrunner; import com.badlogic.gdx.Game; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; import de.samdev.colorrunner.screens.gameScreen.GameScreen; import de.samdev.colorrunner.screens.menu.SplashScreen; public class CRGame extends Game { public final static boolean DEBUG = true; - + + @Override public void create() { //if (DEBUG) // setScreen(new GameScreen()); //else - setScreen(new SplashScreen()); + + setScreen(new SplashScreen()); } } diff --git a/core/src/de/samdev/colorrunner/game/renderer/AbstractGameRenderer.java b/core/src/de/samdev/colorrunner/game/renderer/AbstractGameRenderer.java index b5b2241..b7485f0 100644 --- a/core/src/de/samdev/colorrunner/game/renderer/AbstractGameRenderer.java +++ b/core/src/de/samdev/colorrunner/game/renderer/AbstractGameRenderer.java @@ -17,6 +17,7 @@ public abstract class AbstractGameRenderer { private final static float FREE_ROAM_WIDTH = 1f/2f; private int debugTextCount; + private int hudTextCount; protected OrthographicCamera cam; protected ShapeRenderer shapeRenderer; @@ -85,15 +86,29 @@ public abstract class AbstractGameRenderer { debugTextCount = 0; } + protected void beginHud(){ + fontBatch.begin(); + font.setColor(1, 0, 1, 1); + + hudTextCount = 0; + } protected void renderDebug(String s) { Vector3 coords = cam.unproject(new Vector3(10, 10, 0)); font.draw(fontBatch, s, coords.x, coords.y - debugTextCount++ * 20); } + protected void renderHud(String s){ + Vector3 coords = cam.unproject(new Vector3(10, 10, 0)); + font.draw(fontBatch, s, coords.x + hudTextCount++ * 20, coords.y); + } protected void endDebug() { fontBatch.end(); } + + protected void endHud(){ + fontBatch.end(); + } public abstract void doRender(); } diff --git a/core/src/de/samdev/colorrunner/game/renderer/CRGameRenderer.java b/core/src/de/samdev/colorrunner/game/renderer/CRGameRenderer.java index 38da0ca..f590553 100644 --- a/core/src/de/samdev/colorrunner/game/renderer/CRGameRenderer.java +++ b/core/src/de/samdev/colorrunner/game/renderer/CRGameRenderer.java @@ -28,8 +28,9 @@ public class CRGameRenderer extends AbstractGameRenderer { gameworld.camViewBoundaries = getCamViewRectangle(); if (CRGame.DEBUG) renderDebugInfo(); - + //renderHud(); renderMain(); + if (CRGame.DEBUG) renderDebugBoxes(); } @@ -65,12 +66,13 @@ public class CRGameRenderer extends AbstractGameRenderer { e.visualRotation, true); } - + + spriteBatch.enableBlending(); Vector3 cw_coords = cam.unproject(new Vector3(Gdx.graphics.getWidth(), 0, 0)); spriteBatch.draw(CRAssets.TEX_COLORWHEEL, cw_coords.x - 70, cw_coords.y - 70, 64, 64); spriteBatch.disableBlending(); - + spriteBatch.end(); } @@ -84,4 +86,12 @@ public class CRGameRenderer extends AbstractGameRenderer { if (gameworld.mapprovider instanceof EndlessMapProvider)renderDebug("Procedural Piece: \"" + ((EndlessMapProvider)gameworld.mapprovider).getCurrentSection(gameworld.player.bounds).piece_name + "\""); endDebug(); } + + private void renderHud(){ + beginHud(); + renderHud("Test"); + renderHud("TEst2"); + if (gameworld.mapprovider instanceof EndlessMapProvider)renderDebug("Procedural Piece: \"" + ((EndlessMapProvider)gameworld.mapprovider).getCurrentSection(gameworld.player.bounds).piece_name + "\""); + endHud(); + } } diff --git a/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java b/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java index ddb801c..c433374 100644 --- a/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java +++ b/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java @@ -8,6 +8,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; +import de.samdev.colorrunner.CRGame; import de.samdev.colorrunner.game.renderer.AbstractGameRenderer; import de.samdev.colorrunner.game.world.entities.CRGameEntity; import de.samdev.colorrunner.game.world.entities.gameentities.PlayerEntity; @@ -62,7 +63,7 @@ public class CRGameWorld implements GameInputListener { if(player.getPosition().y < - 10) { - ((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu()); + ((Game) Gdx.app.getApplicationListener()).setScreen(new GameScreen()); } mapprovider.update(this, player.bounds); diff --git a/core/src/de/samdev/colorrunner/screens/gameScreen/GameScreen.java b/core/src/de/samdev/colorrunner/screens/gameScreen/GameScreen.java index 1998899..4be426c 100644 --- a/core/src/de/samdev/colorrunner/screens/gameScreen/GameScreen.java +++ b/core/src/de/samdev/colorrunner/screens/gameScreen/GameScreen.java @@ -3,10 +3,12 @@ package de.samdev.colorrunner.screens.gameScreen; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.InputMultiplexer; import com.badlogic.gdx.Screen; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.input.GestureDetector; import com.badlogic.gdx.maps.tiled.TiledMap; import com.badlogic.gdx.maps.tiled.TmxMapLoader; +import de.samdev.colorrunner.CRGame; import de.samdev.colorrunner.game.renderer.CRGameRenderer; import de.samdev.colorrunner.game.world.AverageExecutionLogger; import de.samdev.colorrunner.game.world.CRGameWorld; @@ -22,7 +24,8 @@ public class GameScreen implements Screen { public GameScreen() { world = new CRGameWorld(); // initialize world renderer = new CRGameRenderer(world, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // initialize renderer - + + input = new CRGameInputProcessor(world); } diff --git a/core/src/de/samdev/colorrunner/screens/menu/MainMenu.java b/core/src/de/samdev/colorrunner/screens/menu/MainMenu.java index 66b02fa..0dd8587 100644 --- a/core/src/de/samdev/colorrunner/screens/menu/MainMenu.java +++ b/core/src/de/samdev/colorrunner/screens/menu/MainMenu.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; @@ -13,13 +14,15 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; +import de.samdev.colorrunner.CRGame; import de.samdev.colorrunner.screens.gameScreen.GameScreen; public class MainMenu implements Screen { private Stage stage = new Stage(); private Table table = new Table(); - + private CRGame game; + private Skin skin = new Skin(Gdx.files.internal("skins/menuSkin.json"), new TextureAtlas(Gdx.files.internal("skins/menuSkin.pack"))); @@ -30,7 +33,8 @@ public class MainMenu implements Screen { private Label title = new Label("Color Runner", skin); - + + @Override public void render(float delta) { Gdx.gl.glClearColor(0, 0, 0, 1); diff --git a/core/src/de/samdev/colorrunner/screens/menu/SplashScreen.java b/core/src/de/samdev/colorrunner/screens/menu/SplashScreen.java index 87305fd..28ccbf9 100644 --- a/core/src/de/samdev/colorrunner/screens/menu/SplashScreen.java +++ b/core/src/de/samdev/colorrunner/screens/menu/SplashScreen.java @@ -9,10 +9,11 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.MathUtils; +import de.samdev.colorrunner.CRGame; public class SplashScreen implements Screen { - + private float loadTime = 0; private int random = MathUtils.random(5);