Fix trigger zone loading offset + draw zones in debug renderer

This commit is contained in:
Mike Schwörer 2017-04-24 22:24:54 +02:00
parent 811143d192
commit c515ec9ffb
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
8 changed files with 668 additions and 584 deletions

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@ import com.badlogic.gdx.audio.Music;
import de.samdev.colorrunner.screens.menu.SplashScreen;
public class CRGame extends Game {
public final static boolean DEBUG = false;
public final static boolean DEBUG = true;
public static AssetManager manager;

View File

@ -87,29 +87,29 @@ public abstract class AbstractGameRenderer {
fontBatch.begin();
font.setColor(1, 0, 1, 1);
debugTextCount = 2;
debugTextCount = 0;
}
protected void beginHud(){
fontBatch2.begin();
font2.setColor(Color.RED);
//font2.setColor(0, 1, 1, 1);
hudTextCount = 0;
//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);
font.draw(fontBatch, s, coords.x, coords.y - debugTextCount++ * 20);
}
protected void renderHud(String s, int xCoord){
//Vector3 coords = cam.unproject(new Vector3(10, 10, 0));
if (hudTextCount == 0)
font2.setColor(Color.RED);
if (hudTextCount == 1)
font2.setColor(Color.GREEN);
//if (hudTextCount == 0)
// font2.setColor(Color.RED);
//if (hudTextCount == 1)
// font2.setColor(Color.GREEN);
hudTextCount++;
font2.draw(fontBatch2, s, xCoord, Gdx.graphics.getHeight() - 20);
//hudTextCount++;
//font2.draw(fontBatch2, s, xCoord, Gdx.graphics.getHeight() - 20);
}
protected void endDebug() {

View File

@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
@ -11,6 +12,8 @@ import de.samdev.colorrunner.CRGame;
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.entities.StaticEntity;
import de.samdev.colorrunner.game.world.entities.gameentities.floor.FloorTileEntity;
import de.samdev.colorrunner.game.world.map.provider.EndlessMapProvider;
import de.samdev.colorrunner.game.world.map.provider.StaticMapProvider;
@ -31,7 +34,7 @@ public class CRGameRenderer extends AbstractGameRenderer {
gameworld.camViewBoundaries = getCamViewRectangle();
renderMain();
renderHud();
//renderHud();
if (CRGame.DEBUG) renderDebugBoxes();
@ -52,7 +55,52 @@ public class CRGameRenderer extends AbstractGameRenderer {
shapeRenderer.line(me.bounds.getCenter(new Vector2()), me.bounds.getCenter(new Vector2()).add(0 , me.getVelocity().y / 15f));
}
}
shapeRenderer.end();
shapeRenderer.begin(ShapeType.Line);
Rectangle bounds = gameworld.camViewBoundaries;
float ftw = FloorTileEntity.FLOORTILE_WIDTH;
int minx = (int)((bounds.getX() + 0) / ftw) - 2;
int miny = (int)((bounds.getY() + 0) / ftw) - 2;
int maxx = (int)((bounds.getX() + bounds.getWidth()) / ftw) + 2;
int maxy = (int)((bounds.getY() + bounds.getHeight()) / ftw) + 2;
for (int x = minx; x < maxx; x++)
{
for (int y = miny; y < maxy; y++)
{
switch (gameworld.mapprovider.getTrigger(x, y))
{
case RUNBOTTOM:
shapeRenderer.setColor(1, 0, 0, 1f);
shapeRenderer.rect(x*ftw+0, y*ftw+0, ftw-0, ftw-0);
shapeRenderer.rect(x*ftw+4, y*ftw+4, ftw-8, ftw-8);
shapeRenderer.rect(x*ftw+8, y*ftw+8, ftw-16, ftw-16);
shapeRenderer.rect(x*ftw+12, y*ftw+12, ftw-24, ftw-24);
break;
case RUNTOP:
shapeRenderer.setColor(0, 1, 0, 1f);
shapeRenderer.rect(x*ftw+0, y*ftw+0, ftw-0, ftw-0);
shapeRenderer.rect(x*ftw+4, y*ftw+4, ftw-8, ftw-8);
shapeRenderer.rect(x*ftw+8, y*ftw+8, ftw-16, ftw-16);
shapeRenderer.rect(x*ftw+12, y*ftw+12, ftw-24, ftw-24);
break;
case FLY:
shapeRenderer.setColor(0, 0, 1, 1f);
shapeRenderer.rect(x*ftw+0, y*ftw+0, ftw-0, ftw-0);
shapeRenderer.rect(x*ftw+4, y*ftw+4, ftw-8, ftw-8);
shapeRenderer.rect(x*ftw+8, y*ftw+8, ftw-16, ftw-16);
shapeRenderer.rect(x*ftw+12, y*ftw+12, ftw-24, ftw-24);
break;
case NOTHING:
break;
}
}
}
shapeRenderer.end();
}
@ -81,15 +129,24 @@ public class CRGameRenderer extends AbstractGameRenderer {
private void renderDebugInfo() {
beginDebug();
renderDebug("FPS: " + (int)gameworld.fps.getFPS());
renderDebug("Entitys: " + gameworld.entities.size());
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 + "\"");
else if (gameworld.mapprovider instanceof StaticMapProvider)
renderDebug("Level Progress: " + ((StaticMapProvider)gameworld.mapprovider).mapPlayerPos + "/" + ((StaticMapProvider)gameworld.mapprovider).mapMaxWidth);
renderDebug("Player(tile): [" + (int)(gameworld.player.bounds.x / FloorTileEntity.FLOORTILE_WIDTH) + "|" + (int)(gameworld.player.bounds.y / FloorTileEntity.FLOORTILE_WIDTH) + "]");
renderDebug("Player(trigger): " + gameworld.mapprovider.getTrigger((int)(gameworld.player.bounds.x / FloorTileEntity.FLOORTILE_WIDTH), (int)(gameworld.player.bounds.y / FloorTileEntity.FLOORTILE_WIDTH)));
endDebug();
}

View File

@ -22,9 +22,9 @@ public class CRTiledMap {
public final static int GID_RIGHT = 24;
public final static int GID_DOWN = 33;
public final static int GID_LEFT = 22;
public final static int GID_INTER_UP = 18;
public final static int GID_INTER_DOWN = 19;
public final static int GID_INTER_RIGHT = 20;
public final static int GID_INTER_UP = 16;
public final static int GID_INTER_DOWN = 17;
public final static int GID_INTER_RIGHT = 18;
public int width;
public int height;
@ -59,7 +59,11 @@ public class CRTiledMap {
Array<Element> tiles = elemData.getChildrenByName("tile");
for (int i = 0; i < tiles.size; i++) {
result.map[i % width][i / width] = tiles.get(i).getInt("gid");
int gid = tiles.get(i).getInt("gid");
int tx = i % width;
int ty = height - i / width - 1;
result.map[tx][ty] = gid;
}
}
else if(elemLayer.getAttribute("name").equalsIgnoreCase("Interaktionen"))
@ -69,7 +73,11 @@ public class CRTiledMap {
Array<Element> tiles = elemData.getChildrenByName("tile");
for (int i = 0; i < tiles.size; i++) {
result.interaktionen[i % width][i / width] = tiles.get(i).getInt("gid");
int gid = tiles.get(i).getInt("gid");
int tx = i % width;
int ty = height - i / width - 1;
result.interaktionen[tx][ty] = gid;
}
}
else

View File

@ -1,5 +1,6 @@
package de.samdev.colorrunner.game.world.map.provider;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
@ -45,14 +46,21 @@ public class EndlessMapProvider extends MapProvider {
int end = sections.get(i).end;
if(start <= x && end > x){
if( sections.get(i).crTiledMap.interaktionen[x - start][y] == CRTiledMap.GID_INTER_UP)
if (y < 0) return TriggerType.NOTHING;
if (y >= sections.get(i).crTiledMap.getHeight()) return TriggerType.NOTHING;
if( sections.get(i).crTiledMap.interaktionen[x - start][y] == CRTiledMap.GID_INTER_UP)
return TriggerType.RUNTOP;
else if( sections.get(i).crTiledMap.interaktionen[x - start][y] == CRTiledMap.GID_INTER_DOWN)
else if( sections.get(i).crTiledMap.interaktionen[x - start][y] == CRTiledMap.GID_INTER_DOWN)
return TriggerType.RUNTOP;
else if( sections.get(i).crTiledMap.interaktionen[x - start][y] == CRTiledMap.GID_INTER_RIGHT)
else if( sections.get(i).crTiledMap.interaktionen[x - start][y] == CRTiledMap.GID_INTER_RIGHT)
return TriggerType.FLY;
else
return TriggerType.NOTHING;
else if(sections.get(i).crTiledMap.interaktionen[x][y] == 0)
return TriggerType.NOTHING;
else {
Gdx.app.error("MapProvider", "Unknown trigger: " + sections.get(i).crTiledMap.interaktionen[x][y]);
return TriggerType.NOTHING;
}
}
}
return TriggerType.NOTHING;
@ -80,7 +88,7 @@ public class EndlessMapProvider extends MapProvider {
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
float px = posX * FloorTileEntity.FLOORTILE_WIDTH + x * FloorTileEntity.FLOORTILE_WIDTH;
float py = (height - y) * FloorTileEntity.FLOORTILE_WIDTH;
float py = y * FloorTileEntity.FLOORTILE_WIDTH;
CRGameEntity e = CRTiledMap.CreateTile(world, map.getGID(x, y), px, py);
if (e != null) world.addEntity(e);

View File

@ -14,5 +14,5 @@ public abstract class MapProvider {
public abstract MapProvider createNew();
public abstract Enum<TriggerType> getTrigger(int x, int y);
public abstract TriggerType getTrigger(int x, int y);
}

View File

@ -1,5 +1,6 @@
package de.samdev.colorrunner.game.world.map.provider;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Rectangle;
import de.samdev.colorrunner.game.renderer.AbstractGameRenderer;
@ -30,14 +31,24 @@ public class StaticMapProvider extends MapProvider {
@Override
public TriggerType getTrigger(int x, int y) {
if(map.interaktionen[x][y] == CRTiledMap.GID_INTER_UP)
if (x < 0) return TriggerType.NOTHING;
if (y < 0) return TriggerType.NOTHING;
if (x >= map.getWidth()) return TriggerType.NOTHING;
if (y >= map.getHeight()) return TriggerType.NOTHING;
if(map.interaktionen[x][ y] == CRTiledMap.GID_INTER_UP)
return TriggerType.RUNTOP;
else if(map.interaktionen[x][y] == CRTiledMap.GID_INTER_DOWN)
return TriggerType.RUNBOTTOM;
else if(map.interaktionen[x][y] == CRTiledMap.GID_INTER_RIGHT)
return TriggerType.FLY;
else
else if(map.interaktionen[x][y] == 0)
return TriggerType.NOTHING;
else
{
Gdx.app.error("MapProvider", "Unknown trigger: " + map.interaktionen[x][y]);
return TriggerType.NOTHING;
}
}
@Override
@ -63,7 +74,7 @@ public class StaticMapProvider extends MapProvider {
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;
float py = y * FloorTileEntity.FLOORTILE_HEIGHT;
CRGameEntity e = CRTiledMap.CreateTile(world, map.getGID(x, y), px, py);
if (e != null) world.addEntity(e);