implementet the Music and change something at the hud

This commit is contained in:
Armin Benz 2017-04-14 12:32:25 +02:00
parent dba41061a4
commit 99714c24ce
8 changed files with 60 additions and 11 deletions

Binary file not shown.

Binary file not shown.

View File

@ -2,18 +2,27 @@ package de.samdev.colorrunner;
import com.badlogic.gdx.Game; import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Music;
import de.samdev.colorrunner.screens.menu.SplashScreen; import de.samdev.colorrunner.screens.menu.SplashScreen;
public class CRGame extends Game { public class CRGame extends Game {
public final static boolean DEBUG = true; public final static boolean DEBUG = true;
public static AssetManager manager;
@Override @Override
public void create() { public void create() {
//if (DEBUG) //if (DEBUG)
// setScreen(new GameScreen()); // setScreen(new GameScreen());
//else //else
setScreen(new SplashScreen());
manager = new AssetManager();
manager.load("sound/mainsound.mp3", Music.class);
manager.load("sound/menusound.mp3", Music.class);
manager.finishLoading();
setScreen(new SplashScreen());
} }
public static CRGame Inst() { public static CRGame Inst() {

View File

@ -1,6 +1,7 @@
package de.samdev.colorrunner.game.renderer; package de.samdev.colorrunner.game.renderer;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
@ -23,8 +24,10 @@ public abstract class AbstractGameRenderer {
protected ShapeRenderer shapeRenderer; protected ShapeRenderer shapeRenderer;
protected BitmapFont font = new BitmapFont(); protected BitmapFont font = new BitmapFont();
protected BitmapFont font2 = new BitmapFont();
protected SpriteBatch spriteBatch = new SpriteBatch(); protected SpriteBatch spriteBatch = new SpriteBatch();
protected SpriteBatch fontBatch = new SpriteBatch(); protected SpriteBatch fontBatch = new SpriteBatch();
protected SpriteBatch fontBatch2 = new SpriteBatch();
public AbstractGameRenderer(float width, float height) { public AbstractGameRenderer(float width, float height) {
cam = new OrthographicCamera(); cam = new OrthographicCamera();
@ -84,11 +87,12 @@ public abstract class AbstractGameRenderer {
fontBatch.begin(); fontBatch.begin();
font.setColor(1, 0, 1, 1); font.setColor(1, 0, 1, 1);
debugTextCount = 0; debugTextCount = 2;
} }
protected void beginHud(){ protected void beginHud(){
fontBatch.begin(); fontBatch2.begin();
font.setColor(0, 1, 1, 1); font2.setColor(Color.RED);
//font2.setColor(0, 1, 1, 1);
hudTextCount = 0; hudTextCount = 0;
} }
@ -97,9 +101,15 @@ public abstract class AbstractGameRenderer {
Vector3 coords = cam.unproject(new Vector3(10, 10, 0)); Vector3 coords = cam.unproject(new Vector3(10, 10, 0));
font.draw(fontBatch, s, coords.x, coords.y - debugTextCount++ * 20); font.draw(fontBatch, s, coords.x, coords.y - debugTextCount++ * 20);
} }
protected void renderHud(String s){ protected void renderHud(String s, int xCoord){
Vector3 coords = cam.unproject(new Vector3(10, 10, 0)); Vector3 coords = cam.unproject(new Vector3(10, 10, 0));
font.draw(fontBatch, s, coords.x+ 75 + hudTextCount++ * 40, coords.y); if (hudTextCount == 0)
font2.setColor(Color.RED);
if (hudTextCount == 1)
font2.setColor(Color.GREEN);
hudTextCount++;
font2.draw(fontBatch2, s, xCoord, Gdx.graphics.getHeight() - 20);
} }
protected void endDebug() { protected void endDebug() {
@ -107,7 +117,7 @@ public abstract class AbstractGameRenderer {
} }
protected void endHud(){ protected void endHud(){
fontBatch.end(); fontBatch2.end();
} }
public abstract void doRender(); public abstract void doRender();

View File

@ -93,8 +93,8 @@ public class CRGameRenderer extends AbstractGameRenderer {
private void renderHud(){ private void renderHud(){
beginHud(); beginHud();
renderHud("Test"); renderHud("Points:", 10);
renderHud("TEst2"); renderHud("Time:", (Gdx.graphics.getWidth() / 2) - 10);
if (gameworld.mapprovider instanceof EndlessMapProvider)renderDebug("Procedural Piece: \"" + ((EndlessMapProvider)gameworld.mapprovider).getCurrentSection(gameworld.player.bounds).piece_name + "\""); if (gameworld.mapprovider instanceof EndlessMapProvider)renderDebug("Procedural Piece: \"" + ((EndlessMapProvider)gameworld.mapprovider).getCurrentSection(gameworld.player.bounds).piece_name + "\"");
endHud(); endHud();
} }

View File

@ -2,15 +2,18 @@ package de.samdev.colorrunner.game.world;
import com.badlogic.gdx.Game; import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.samdev.colorrunner.CRGame;
import de.samdev.colorrunner.game.world.entities.CRGameEntity; import de.samdev.colorrunner.game.world.entities.CRGameEntity;
import de.samdev.colorrunner.game.world.entities.gameentities.PlayerEntity; import de.samdev.colorrunner.game.world.entities.gameentities.PlayerEntity;
import de.samdev.colorrunner.game.world.map.provider.MapProvider; import de.samdev.colorrunner.game.world.map.provider.MapProvider;
import de.samdev.colorrunner.input.GameInputListener; import de.samdev.colorrunner.input.GameInputListener;
import de.samdev.colorrunner.screens.gameScreen.GameScreen;
import de.samdev.colorrunner.screens.menu.MainMenu; import de.samdev.colorrunner.screens.menu.MainMenu;
public class CRGameWorld implements GameInputListener { public class CRGameWorld implements GameInputListener {
@ -21,10 +24,17 @@ public class CRGameWorld implements GameInputListener {
public Rectangle camViewBoundaries = new Rectangle(); public Rectangle camViewBoundaries = new Rectangle();
public MapProvider mapprovider; public MapProvider mapprovider;
private Music music;
public CRGameWorld(MapProvider prov) { public CRGameWorld(MapProvider prov) {
mapprovider = prov; mapprovider = prov;
music = CRGame.manager.get("sound/mainsound.mp3", Music.class);
music.setLooping(true);
music.play();
reinitialize(); reinitialize();
} }
@ -51,6 +61,7 @@ public class CRGameWorld implements GameInputListener {
if(player.getPosition().y < - 10) if(player.getPosition().y < - 10)
{ {
((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu()); ((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu());
music.stop();
} }
mapprovider.update(this, player.bounds); mapprovider.update(this, player.bounds);

View File

@ -3,6 +3,8 @@ package de.samdev.colorrunner.screens.gameScreen;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer; import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.Screen; import com.badlogic.gdx.Screen;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.input.GestureDetector; import com.badlogic.gdx.input.GestureDetector;
@ -12,6 +14,7 @@ import de.samdev.colorrunner.game.world.AverageExecutionLogger;
import de.samdev.colorrunner.game.world.CRGameWorld; import de.samdev.colorrunner.game.world.CRGameWorld;
import de.samdev.colorrunner.game.world.map.provider.MapProvider; import de.samdev.colorrunner.game.world.map.provider.MapProvider;
import de.samdev.colorrunner.input.CRGameInputProcessor; import de.samdev.colorrunner.input.CRGameInputProcessor;
import de.samdev.colorrunner.screens.menu.SplashScreen;
public class GameScreen implements Screen { public class GameScreen implements Screen {
private CRGameWorld world; private CRGameWorld world;
@ -20,11 +23,17 @@ public class GameScreen implements Screen {
private AverageExecutionLogger execTime = new AverageExecutionLogger(); private AverageExecutionLogger execTime = new AverageExecutionLogger();
public GameScreen(MapProvider prov) { public GameScreen(MapProvider prov) {
world = new CRGameWorld(prov); // initialize world world = new CRGameWorld(prov); // initialize world
renderer = new CRGameRenderer(world, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // initialize renderer renderer = new CRGameRenderer(world, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // initialize renderer
input = new CRGameInputProcessor(world); input = new CRGameInputProcessor(world);
} }

View File

@ -2,6 +2,7 @@ package de.samdev.colorrunner.screens.menu;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen; import com.badlogic.gdx.Screen;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
@ -39,9 +40,16 @@ public class MainMenu implements Screen {
private TextButton buttonExit = new TextButton("Exit", skin); private TextButton buttonExit = new TextButton("Exit", skin);
private TextButton buttonOption = new TextButton("Option", skin); private TextButton buttonOption = new TextButton("Option", skin);
private Label title = new Label("Color Runner", skin); private Label title = new Label("Color Runner", skin);
private Music music;
public MainMenu() {
music = CRGame.manager.get("sound/menusound.mp3", Music.class);
music.setLooping(true);
music.play();
}
@Override @Override
public void render(float delta) { public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClearColor(0, 0, 0, 1);
@ -73,6 +81,7 @@ public class MainMenu implements Screen {
@Override @Override
public void clicked(InputEvent event, float x, float y){ public void clicked(InputEvent event, float x, float y){
CRGame.Inst().setScreen(new GameScreen(new StaticMapProvider(CRMapStorage.lvl_01))); CRGame.Inst().setScreen(new GameScreen(new StaticMapProvider(CRMapStorage.lvl_01)));
music.stop();
} }
}); });
@ -80,6 +89,7 @@ public class MainMenu implements Screen {
@Override @Override
public void clicked(InputEvent event, float x, float y){ public void clicked(InputEvent event, float x, float y){
CRGame.Inst().setScreen(new GameScreen(new EndlessMapProvider(System.currentTimeMillis()))); CRGame.Inst().setScreen(new GameScreen(new EndlessMapProvider(System.currentTimeMillis())));
music.stop();
} }
}); });