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.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Music;
import de.samdev.colorrunner.screens.menu.SplashScreen;
public class CRGame extends Game {
public final static boolean DEBUG = true;
public static AssetManager manager;
@Override
public void create() {
//if (DEBUG)
// setScreen(new GameScreen());
//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() {

View File

@ -1,6 +1,7 @@
package de.samdev.colorrunner.game.renderer;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
@ -23,8 +24,10 @@ public abstract class AbstractGameRenderer {
protected ShapeRenderer shapeRenderer;
protected BitmapFont font = new BitmapFont();
protected BitmapFont font2 = new BitmapFont();
protected SpriteBatch spriteBatch = new SpriteBatch();
protected SpriteBatch fontBatch = new SpriteBatch();
protected SpriteBatch fontBatch2 = new SpriteBatch();
public AbstractGameRenderer(float width, float height) {
cam = new OrthographicCamera();
@ -84,11 +87,12 @@ public abstract class AbstractGameRenderer {
fontBatch.begin();
font.setColor(1, 0, 1, 1);
debugTextCount = 0;
debugTextCount = 2;
}
protected void beginHud(){
fontBatch.begin();
font.setColor(0, 1, 1, 1);
fontBatch2.begin();
font2.setColor(Color.RED);
//font2.setColor(0, 1, 1, 1);
hudTextCount = 0;
}
@ -97,9 +101,15 @@ public abstract class AbstractGameRenderer {
Vector3 coords = cam.unproject(new Vector3(10, 10, 0));
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));
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() {
@ -107,7 +117,7 @@ public abstract class AbstractGameRenderer {
}
protected void endHud(){
fontBatch.end();
fontBatch2.end();
}
public abstract void doRender();

View File

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

View File

@ -2,15 +2,18 @@ package de.samdev.colorrunner.game.world;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.math.Rectangle;
import java.util.ArrayList;
import java.util.List;
import de.samdev.colorrunner.CRGame;
import de.samdev.colorrunner.game.world.entities.CRGameEntity;
import de.samdev.colorrunner.game.world.entities.gameentities.PlayerEntity;
import de.samdev.colorrunner.game.world.map.provider.MapProvider;
import de.samdev.colorrunner.input.GameInputListener;
import de.samdev.colorrunner.screens.gameScreen.GameScreen;
import de.samdev.colorrunner.screens.menu.MainMenu;
public class CRGameWorld implements GameInputListener {
@ -21,10 +24,17 @@ public class CRGameWorld implements GameInputListener {
public Rectangle camViewBoundaries = new Rectangle();
public MapProvider mapprovider;
private Music music;
public CRGameWorld(MapProvider prov) {
mapprovider = prov;
music = CRGame.manager.get("sound/mainsound.mp3", Music.class);
music.setLooping(true);
music.play();
reinitialize();
}
@ -51,6 +61,7 @@ public class CRGameWorld implements GameInputListener {
if(player.getPosition().y < - 10)
{
((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu());
music.stop();
}
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.InputMultiplexer;
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.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.map.provider.MapProvider;
import de.samdev.colorrunner.input.CRGameInputProcessor;
import de.samdev.colorrunner.screens.menu.SplashScreen;
public class GameScreen implements Screen {
private CRGameWorld world;
@ -20,11 +23,17 @@ public class GameScreen implements Screen {
private AverageExecutionLogger execTime = new AverageExecutionLogger();
public GameScreen(MapProvider prov) {
world = new CRGameWorld(prov); // initialize world
renderer = new CRGameRenderer(world, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // initialize renderer
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.Screen;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
@ -39,9 +40,16 @@ public class MainMenu implements Screen {
private TextButton buttonExit = new TextButton("Exit", skin);
private TextButton buttonOption = new TextButton("Option", 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
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
@ -73,6 +81,7 @@ public class MainMenu implements Screen {
@Override
public void clicked(InputEvent event, float x, float y){
CRGame.Inst().setScreen(new GameScreen(new StaticMapProvider(CRMapStorage.lvl_01)));
music.stop();
}
});
@ -80,6 +89,7 @@ public class MainMenu implements Screen {
@Override
public void clicked(InputEvent event, float x, float y){
CRGame.Inst().setScreen(new GameScreen(new EndlessMapProvider(System.currentTimeMillis())));
music.stop();
}
});