This commit is contained in:
Armin Benz 2017-04-14 01:19:16 +02:00
commit a3f874bd33
6 changed files with 114 additions and 52 deletions

View File

@ -1,21 +1,22 @@
package de.samdev.colorrunner;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.Gdx;
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());
public static CRGame Inst() {
return ((CRGame) Gdx.app.getApplicationListener());
}
}

View File

@ -11,6 +11,7 @@ import de.samdev.colorrunner.game.world.CRGameWorld;
import de.samdev.colorrunner.game.world.entities.CRGameEntity;
import de.samdev.colorrunner.game.world.entities.MovingEntity;
import de.samdev.colorrunner.game.world.map.provider.EndlessMapProvider;
import de.samdev.colorrunner.game.world.map.provider.StaticMapProvider;
public class CRGameRenderer extends AbstractGameRenderer {
private CRGameWorld gameworld;
@ -26,13 +27,13 @@ public class CRGameRenderer extends AbstractGameRenderer {
public void doRender() {
updateCameraOffset(gameworld.player.bounds.x + gameworld.player.bounds.width/2);
gameworld.camViewBoundaries = getCamViewRectangle();
if (CRGame.DEBUG) renderDebugInfo();
//renderHud();
renderMain();
if (CRGame.DEBUG) renderDebugBoxes();
if (CRGame.DEBUG) renderDebugInfo();
}
private void renderDebugBoxes() {
@ -83,7 +84,10 @@ public class CRGameRenderer extends AbstractGameRenderer {
renderDebug("ExecTime: " + (int)(avgExecTime*100) / 100.0+ " / " + (int)(10000/gameworld.fps.getFPS())/10.0 + "ms (" + (int)((avgExecTime/(1000/gameworld.fps.getFPS()))*1000) / 10.0 + "%)");
renderDebug("CameraOffset: (" + (int)cam.position.x + "|" + (int)cam.position.y + ")");
renderDebug("Player(x): " + (int)gameworld.player.bounds.x);
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 + "\"");
else if (gameworld.mapprovider instanceof StaticMapProvider)
renderDebug("Level Progress: " + ((StaticMapProvider)gameworld.mapprovider).mapPlayerPos + "/" + ((StaticMapProvider)gameworld.mapprovider).mapMaxWidth);
endDebug();
}

View File

@ -1,30 +1,21 @@
package de.samdev.colorrunner.game.world;
import java.util.ArrayList;
import java.util.List;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
<<<<<<< .merge_file_a12048
import de.samdev.colorrunner.CRGame;
import de.samdev.colorrunner.game.renderer.AbstractGameRenderer;
=======
import java.util.ArrayList;
import java.util.List;
>>>>>>> .merge_file_a07400
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.floor.DownStateFloorTileEntity;
import de.samdev.colorrunner.game.world.entities.gameentities.floor.FloorTileEntity;
import de.samdev.colorrunner.game.world.entities.gameentities.floor.LeftStateFloorTileEntity;
import de.samdev.colorrunner.game.world.entities.gameentities.floor.NoStateFloorTileEntity;
import de.samdev.colorrunner.game.world.entities.gameentities.floor.RightStateFloorTileEntity;
import de.samdev.colorrunner.game.world.entities.gameentities.floor.UpStateFloorTileEntity;
import de.samdev.colorrunner.game.world.map.CRMapStorage;
import de.samdev.colorrunner.game.world.map.CRTiledMap;
import de.samdev.colorrunner.game.world.map.MapSection;
import de.samdev.colorrunner.game.world.map.provider.EndlessMapProvider;
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 {
@ -36,14 +27,15 @@ public class CRGameWorld implements GameInputListener {
public MapProvider mapprovider;
public CRGameWorld() {
public CRGameWorld(MapProvider prov) {
mapprovider = prov;
reinitialize();
}
private void reinitialize() {
entities = new ArrayList<CRGameEntity>();
mapprovider = new EndlessMapProvider();
addEntity(player = new PlayerEntity(this, 40, 290));
mapprovider.init(this);

View File

@ -0,0 +1,62 @@
package de.samdev.colorrunner.game.world.map.provider;
import com.badlogic.gdx.math.Rectangle;
import de.samdev.colorrunner.game.renderer.AbstractGameRenderer;
import de.samdev.colorrunner.game.world.CRGameWorld;
import de.samdev.colorrunner.game.world.entities.CRGameEntity;
import de.samdev.colorrunner.game.world.entities.gameentities.floor.FloorTileEntity;
import de.samdev.colorrunner.game.world.map.CRTiledMap;
public class StaticMapProvider extends MapProvider {
private static final int CHUNK_SIZE = 16;
private CRTiledMap map;
private int mapRightBoundary = 0;
public int mapPlayerPos = 0;
public int mapMaxWidth = 0;
public StaticMapProvider(CRTiledMap m) {
map = m;
mapMaxWidth = map.getWidth();
}
@Override
public void init(CRGameWorld world) {
mapRightBoundary = appendMap(world);
}
private int appendMap(CRGameWorld world) {
int height = map.getHeight();
int width = map.getWidth();
int xstart = mapRightBoundary;
int xend = mapRightBoundary + CHUNK_SIZE;
if (xend > width) xend = width;
for (int x = xstart; x < xend; x++) {
for (int y = 0; y < height; y++) {
float px = x * FloorTileEntity.FLOORTILE_WIDTH;
float py = (height - y) * FloorTileEntity.FLOORTILE_WIDTH;
CRGameEntity e = CRTiledMap.CreateTile(world, map.getGID(x, y), px, py);
if (e != null) world.addEntity(e);
}
}
return xend;
}
@Override
public void update(CRGameWorld world, Rectangle player) {
mapPlayerPos = (int)(player.x / FloorTileEntity.FLOORTILE_WIDTH);
while (player.x + AbstractGameRenderer.MAX_GAME_WIDTH*2 > mapRightBoundary * FloorTileEntity.FLOORTILE_WIDTH && mapRightBoundary < mapMaxWidth) {
mapRightBoundary = appendMap(world);
}
}
}

View File

@ -5,13 +5,12 @@ 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;
import de.samdev.colorrunner.game.world.map.provider.MapProvider;
import de.samdev.colorrunner.input.CRGameInputProcessor;
public class GameScreen implements Screen {
@ -21,8 +20,8 @@ public class GameScreen implements Screen {
private AverageExecutionLogger execTime = new AverageExecutionLogger();
public GameScreen() {
world = new CRGameWorld(); // initialize world
public GameScreen(MapProvider prov) {
world = new CRGameWorld(prov); // initialize world
renderer = new CRGameRenderer(world, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // initialize renderer

View File

@ -1,6 +1,5 @@
package de.samdev.colorrunner.screens.menu;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
@ -15,6 +14,10 @@ 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.game.world.map.CRMapStorage;
import de.samdev.colorrunner.game.world.map.provider.EndlessMapProvider;
import de.samdev.colorrunner.game.world.map.provider.StaticMapProvider;
import de.samdev.colorrunner.screens.gameScreen.GameScreen;
public class MainMenu implements Screen {
@ -26,15 +29,14 @@ public class MainMenu implements Screen {
private Skin skin = new Skin(Gdx.files.internal("skins/menuSkin.json"),
new TextureAtlas(Gdx.files.internal("skins/menuSkin.pack")));
private TextButton buttonPlay = new TextButton("Play", skin),
buttonExit = new TextButton("Exit", skin),
buttonOption = new TextButton("Option", skin);
private TextButton buttonPlay1 = new TextButton("Play Level 1", skin);
private TextButton buttonPlay2 = new TextButton("Play Endless", skin);
private TextButton buttonExit = new TextButton("Exit", skin);
private TextButton buttonOption = new TextButton("Option", skin);
private Label title = new Label("Color Runner", skin);
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
@ -47,23 +49,29 @@ public class MainMenu implements Screen {
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
// NOP
}
@Override
public void show() {
buttonPlay.addListener(new ClickListener(){
buttonPlay1.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y){
((Game)Gdx.app.getApplicationListener()).setScreen(new GameScreen());
CRGame.Inst().setScreen(new GameScreen(new StaticMapProvider(CRMapStorage.lvl_01)));
}
});
buttonPlay2.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y){
CRGame.Inst().setScreen(new GameScreen(new EndlessMapProvider(System.currentTimeMillis())));
}
});
buttonOption.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y) {
((Game)Gdx.app.getApplicationListener()).setScreen(new OptionMenuScreen());
CRGame.Inst().setScreen(new OptionMenuScreen());
}
});
@ -71,12 +79,12 @@ public class MainMenu implements Screen {
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.app.exit();
// or System.exit(0);
}
});
table.add(title).padBottom(40).row();
table.add(buttonPlay).size((int)((double)Gdx.graphics.getWidth() / 2.0D),60).padBottom(20).row();
table.add(buttonPlay1).size((int)((double)Gdx.graphics.getWidth() / 2.0D),60).padBottom(20).row();
table.add(buttonPlay2).size((int)((double)Gdx.graphics.getWidth() / 2.0D),60).padBottom(20).row();
table.add(buttonOption).size((int)((double)Gdx.graphics.getWidth() / 2.0D),60).padBottom(20).row();
table.add(buttonExit).size((int)((double)Gdx.graphics.getWidth() / 2.0D),60).padBottom(20).row();
@ -84,25 +92,21 @@ public class MainMenu implements Screen {
stage.addActor(table);
Gdx.input.setInputProcessor(stage);
}
@Override
public void hide() {
dispose();
}
@Override
public void pause() {
// TODO Auto-generated method stub
// NOP
}
@Override
public void resume() {
// TODO Auto-generated method stub
// NOP
}
@Override