debug mode nice [F1]

master
GammelJAN 5 years ago
parent 66b588fdf7
commit 0113e0075d

@ -15,7 +15,7 @@ public class Main extends Game{
*/
// TEST
// -1: Debug
// -1: Debug centerCam, -2: Debug freeCam
// 0: normal game world, 1: dialogue, 2: fight
// 7: Load MenuScreen 8: Load GameScreen 9: Load InventoryScreen
public static int gamestate = 0;
@ -97,24 +97,22 @@ public class Main extends Game{
renderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND);
*/
if(Gdx.input.isKeyJustPressed(Input.Keys.ALT_LEFT)){
if(Gdx.input.isKeyJustPressed(Input.Keys.F1)){
if(gamestate == -1){
debugUI = true;
gamestate = -2;
}
else if(gamestate == -2){
debugUI = false;
gamestate = fallbackState;
}
else{
debugUI = true;
fallbackState = gamestate;
gamestate = -1;
}
}
if(Gdx.input.isKeyJustPressed(Input.Keys.F1)){
if(!debugUI){
debugUI = true;
}
else{
debugUI = false;
}
}
}
@Override

@ -14,7 +14,7 @@ import com.badlogic.gdx.Input;
import java.util.ArrayList;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.maps.MapObject;
import com.badlogic.gdx.maps.MapProperties;
import com.badlogic.gdx.maps.objects.RectangleMapObject;
@ -25,7 +25,6 @@ import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.trs.main.view.UI.Textbox;
@ -62,7 +61,7 @@ import com.trs.main.view.UI.Textbox;
*/
public class MapContainer {
private Stage stage;
private OrthographicCamera camera;
private TmxMapLoader maploader;
@ -79,7 +78,7 @@ public class MapContainer {
private int[] layersAbovePlayer = {3, 4};
// TODO: Value which shows from which door the player is coming?
public MapContainer(float CAMERA_WIDTH, float CAMERA_HEIGHT, Player p, String mapString, int inDoor, int mapId) {
public MapContainer(float CAMERA_WIDTH, float CAMERA_HEIGHT, Player p, String mapString, int inDoor, int mapId, ShapeRenderer uiRenderer) {
// CREATION OF STAGE
camera = new OrthographicCamera();
camera.setToOrtho(false, CAMERA_WIDTH, CAMERA_HEIGHT);
@ -104,7 +103,7 @@ public class MapContainer {
// adding MapObjects to the Stage
for(MapObject object : map.getLayers().get(5).getObjects().getByType(RectangleMapObject.class)){
Rectangle rect = ((RectangleMapObject) object).getRectangle();
stage.addActor(new MapCollisionObject((int)rect.getX(), (int)rect.getY(), (int)rect.getWidth(), (int)rect.getHeight()));
stage.addActor(new MapCollisionObject((int)rect.getX(), (int)rect.getY(), (int)rect.getWidth(), (int)rect.getHeight(), uiRenderer));
}
// adding the door links
@ -130,7 +129,7 @@ public class MapContainer {
int id = props.get("id", Integer.class);
String texture = props.get("texture", String.class);
stage.addActor(new MovingNpc(rect, rect.getX() + (float)(Math.random()*(rect.getWidth()-64)), rect.getY()+(float)(Math.random()*(rect.getHeight()-64)), id, mapId, texture));
stage.addActor(new MovingNpc(rect, rect.getX() + (float)(Math.random()*(rect.getWidth()-64)), rect.getY()+(float)(Math.random()*(rect.getHeight()-64)), id, mapId, texture, uiRenderer));
}
// adding the InteractionObjects
@ -142,16 +141,16 @@ public class MapContainer {
String texture = props.get("texture", String.class);
if(texture.equals("-")){
stage.addActor(new InteractionObject(rect, rect.getX(), rect.getY(), mapId, id));
stage.addActor(new InteractionObject(rect, rect.getX(), rect.getY(), mapId, id, uiRenderer));
}
else{
stage.addActor(new InteractionObject(rect, rect.getX(), rect.getY(), mapId, id, texture));
stage.addActor(new InteractionObject(rect, rect.getX(), rect.getY(), mapId, id, texture, uiRenderer));
}
stage.addActor(new MapCollisionObject((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height));
stage.addActor(new MapCollisionObject((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height, uiRenderer));
}
// adding the InteractionObjects
// adding the Hostiles
for(MapObject object : map.getLayers().get(9).getObjects().getByType(RectangleMapObject.class)){
Rectangle rect = ((RectangleMapObject) object).getRectangle();
MapProperties props = object.getProperties();
@ -168,7 +167,7 @@ public class MapContainer {
boolean isMelee = props.get("isMelee", Boolean.class);
Hostile h = new Hostile(rect, rect.getX() + (float)(Math.random()*(rect.getWidth()-64)), rect.getY()+(float)(Math.random()*(rect.getHeight()-64)), id, stats, texture, isMelee);
Hostile h = new Hostile(rect, rect.getX() + (float)(Math.random()*(rect.getWidth()-64)), rect.getY()+(float)(Math.random()*(rect.getHeight()-64)), id, stats, texture, isMelee, uiRenderer);
stage.addActor(h);
}
@ -277,7 +276,6 @@ public class MapContainer {
getStage().act(f);
getStage().draw();
}
else if(Main.gamestate == 2){
if(getFs() == null) {
// CREATING MAP COLLISION OBJECTS
@ -348,6 +346,10 @@ public class MapContainer {
}
}
else if(Main.gamestate == -1){
getStage().act();
getStage().draw();
}
else if(Main.gamestate == -2){
if(Gdx.input.isKeyPressed(Input.Keys.SPACE)){
getStage().act();
}

@ -52,10 +52,26 @@ public class DebugUI {
ArrayList<String> strings = new ArrayList<>();
strings.add("DeltaTime: "+Gdx.graphics.getDeltaTime());
strings.add("FPS: "+(int)(1/Gdx.graphics.getDeltaTime()));
strings.add("FPS: "+(int)(Gdx.graphics.getFramesPerSecond()));
strings.add("Entities: "+entityAmount);
strings.add("CamX: "+camPos.x);
strings.add("CamY: "+camPos.y);
strings.add("Gamestate: "+Main.gamestate);
strings.add(" ");
if(Main.gamestate == -1){
strings.add("DebugMode: PlayerCam");
strings.add("Player input enabled");
strings.add(" ");
}
else if(Main.gamestate == -2){
strings.add("DebugMode: FreeCam");
strings.add("Player input disabled");
strings.add("press [SPACE] for Actors to act");
}
else{
strings.add("Gamestate "+Main.gamestate+" not supported");
}
strings.add("press [F1] to switch Gamestate");
float width = 0;
for(String s : strings){
@ -71,7 +87,6 @@ public class DebugUI {
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.setColor(0.1f, 0.1f, 0.1f, 0.8f);
shapeRenderer.rect(5, Main.CAMERA_HEIGHT - (strings.size()+1)*textHeight-5, width+10,(strings.size()+1)*textHeight);
shapeRenderer.rect(5, Main.CAMERA_HEIGHT - (strings.size()+2)*textHeight-10, getTextWidth(font, "F1")+10, getTextHeight(font, "F1")*2f);
shapeRenderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND);
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
@ -81,8 +96,6 @@ public class DebugUI {
shapeRenderer.line(Main.CAMERA_WIDTH/2-3, Main.CAMERA_HEIGHT/2, Main.CAMERA_WIDTH/2+3, Main.CAMERA_HEIGHT/2);
shapeRenderer.setColor(Color.GREEN);
shapeRenderer.line(Main.CAMERA_WIDTH/2, Main.CAMERA_HEIGHT/2-3, Main.CAMERA_WIDTH/2, Main.CAMERA_HEIGHT/2+3);
shapeRenderer.setColor(Color.WHITE);
shapeRenderer.circle(Main.CAMERA_WIDTH/2, Main.CAMERA_HEIGHT/2, 6);
shapeRenderer.end();
@ -93,7 +106,6 @@ public class DebugUI {
for(int i = 1; i < strings.size()+1; i++){
font.draw(batch, strings.get(i-1), 10, Main.CAMERA_HEIGHT-textHeight*i);
}
font.draw(batch, "F1", 10, Main.CAMERA_HEIGHT-textHeight*(strings.size()+2));
batch.end();

@ -77,7 +77,7 @@ public class QuestWindow {
renderer.setProjectionMatrix(batch.getProjectionMatrix());
if(Main.gamestate == -1){
if(Main.debugUI){
visible = false;
}

@ -8,6 +8,7 @@ package com.trs.main.view.screens;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
@ -29,10 +30,12 @@ public class GameScreen extends AbstractScreen{
MapContainer map;
QuestWindow qw;
DebugUI debugUI;
public ShapeRenderer uiRenderer = new ShapeRenderer();
public GameScreen(Game game, float CAMERA_WIDTH, float CAMERA_HEIGHT) {
super(game, CAMERA_WIDTH, CAMERA_HEIGHT);
map = new MapContainer(CAMERA_WIDTH, CAMERA_HEIGHT, new Player(200, 200), "tiledmapData/maps/map1.tmx", 2, 1);
map = new MapContainer(CAMERA_WIDTH, CAMERA_HEIGHT, new Player(200, 200, uiRenderer), "tiledmapData/maps/map1.tmx", 2, 1, uiRenderer);
qw = new QuestWindow(map.getCamera().combined);
debugUI = new DebugUI(map.getCamera().combined);
Matrix4 uiMatrix = map.getCamera().combined.cpy();
@ -43,7 +46,7 @@ public class GameScreen extends AbstractScreen{
public void loadNewMap(int map, int doorId){
String filename = "tiledmapData/maps/map" + map + ".tmx";
this.map = new MapContainer(Main.CAMERA_WIDTH, Main.CAMERA_HEIGHT, this.map.getPlayer(), filename, doorId, map);
this.map = new MapContainer(Main.CAMERA_WIDTH, Main.CAMERA_HEIGHT, this.map.getPlayer(), filename, doorId, map, uiRenderer);
System.out.println("Doorid: " + doorId);
}
@ -68,7 +71,7 @@ public class GameScreen extends AbstractScreen{
loadNewMap(map.getCollidingDoor().destinationMap, map.getCollidingDoor().destinationDoor);
}
if(Main.gamestate == -1){
if(Main.gamestate == -2){
float camSpeed = 15;
if(Gdx.input.isKeyPressed(Input.Keys.ALT_RIGHT)){
camSpeed = 1;

@ -35,8 +35,10 @@ public class Hostile extends Actor {
// 0: normal movement, 1: locked onto Player, 2: attacking
private int movementState;
public Hostile(Rectangle movementRect, float xPos, float yPos, int id, Stats stats, String texture, boolean isMelee) {
public Hostile(Rectangle movementRect, float xPos, float yPos, int id, Stats stats, String texture, boolean isMelee, ShapeRenderer uiRenderer) {
shapeRenderer = uiRenderer;
this.id = id;
this.stats = stats;
this.isMelee = isMelee;
@ -143,7 +145,7 @@ public class Hostile extends Actor {
}
POI = new Vector2(a.getX(), a.getY());
POI = new Vector2(a.getX()+a.getWidth()/2, a.getY()+a.getHeight()/2);
Vector2 movement = new Vector2(speed,0);
movement.setAngleRad(StaticMath.calculateAngle(getX(), getY(), POI.x, POI.y));
@ -187,7 +189,7 @@ public class Hostile extends Actor {
@Override
public void draw(Batch batch, float deltatime) {
getSprite().draw(batch);
if(Main.gamestate == -1){
if(Main.gamestate == -1 || Main.gamestate == -2){
debug(batch);
}
super.draw(batch, deltatime);
@ -377,4 +379,5 @@ public class Hostile extends Actor {
}
}

@ -26,9 +26,10 @@ public class InteractionObject extends Actor{
String dialoguePath;
private ShapeRenderer shapeRenderer = new ShapeRenderer();
public InteractionObject(Rectangle collisionRect, float xPos, float yPos,int mapId, int id, String texture){
public InteractionObject(Rectangle collisionRect, float xPos, float yPos,int mapId, int id, String texture, ShapeRenderer uiRenderer){
setName("interactive");
this.id = id;
shapeRenderer = uiRenderer;
Texture t = new Texture(Gdx.files.internal("textureData/sprites/"+texture));
currentlyTalking = false;
@ -45,9 +46,10 @@ public class InteractionObject extends Actor{
setBounds(xPos, yPos, animatedSprite.getSprite().getWidth(), animatedSprite.getSprite().getHeight());
}
public InteractionObject(Rectangle collisionRect, float xPos, float yPos,int mapId, int id){
public InteractionObject(Rectangle collisionRect, float xPos, float yPos,int mapId, int id, ShapeRenderer uiRenderer){
setName("interactive");
this.id = id;
shapeRenderer = uiRenderer;
currentlyTalking = false;
@ -108,7 +110,7 @@ public class InteractionObject extends Actor{
@Override
public void draw(Batch batch, float parentAlpha) {
if(animatedSprite != null){animatedSprite.draw(batch);}
if(Main.gamestate == -1){
if(Main.gamestate == -1 || Main.gamestate == -2){
debug(batch);
}
super.draw(batch, parentAlpha); //To change body of generated methods, choose Tools | Templates.
@ -117,10 +119,6 @@ public class InteractionObject extends Actor{
private void debug(Batch batch){
batch.end();
shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.end();
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.setColor(Color.WHITE);

@ -5,9 +5,14 @@
*/
package com.trs.main.worldobjects;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.trs.main.Main;
/**
*
@ -16,11 +21,14 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
public class MapCollisionObject extends Actor{
private Rectangle r;
ShapeRenderer shapeRenderer;
public MapCollisionObject(int x, int y, int width, int height){
public MapCollisionObject(int x, int y, int width, int height, ShapeRenderer uiRenderer){
setName("mapobject");
r = new Rectangle(x, y, width, height);
setBounds(x, y, width, height);
shapeRenderer = uiRenderer;
}
@Override
@ -30,8 +38,31 @@ public class MapCollisionObject extends Actor{
@Override
public void draw(Batch batch, float parentAlpha) {
if(Main.gamestate == -1 || Main.gamestate == -2){
debug(batch);
}
super.draw(batch, parentAlpha); //To change body of generated methods, choose Tools | Templates.
}
private void debug(Batch batch){
batch.end();
shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
//ShapeRenderer shapeRenderer = new ShapeRenderer();
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.setColor(Color.RED);
shapeRenderer.rect(r.x, r.y, r.width, r.height);
shapeRenderer.end();
Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.setColor(1f,0f,0f,0.2f);
shapeRenderer.rect(r.x, r.y, r.width, r.height);
shapeRenderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND);
batch.begin();
}
/**
* @return the r

@ -55,10 +55,13 @@ public class MovingNpc extends Actor{
private AnimatedSprite questBubble;
private ShapeRenderer shapeRenderer = new ShapeRenderer();
private ShapeRenderer shapeRenderer;
public MovingNpc(Rectangle area, float xPos, float yPos, int id, int mapId, String texture){
public MovingNpc(Rectangle area, float xPos, float yPos, int id, int mapId, String texture, ShapeRenderer uiRenderer){
super();
shapeRenderer = uiRenderer;
setName("npc");
this.id = id;
this.mapId = mapId;
@ -262,7 +265,7 @@ public class MovingNpc extends Actor{
}
}
if(Main.gamestate == -1){
if(Main.gamestate == -1 || Main.gamestate == -2){
debug(batch);
}

@ -47,9 +47,10 @@ public class Player extends Actor{
private Stats stats;
private ShapeRenderer shapeRenderer = new ShapeRenderer();
private ShapeRenderer uiRenderer;
public Player(int xPos, int yPos){
public Player(int xPos, int yPos, ShapeRenderer uiRenderer){
this.uiRenderer = uiRenderer;
setName("player");
t = new Texture(Gdx.files.internal("textureData/sprites/player.png"));
playerSprite = new AnimatedSprite(getT(), 64, 64, true);
@ -92,7 +93,7 @@ public class Player extends Actor{
}
// PLAYER ACTING
if(Main.gamestate == 0) {
if(Main.gamestate == 0 || Main.gamestate == -1) {
if(Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)){
setSpeed(9);
}
@ -202,7 +203,7 @@ public class Player extends Actor{
@Override
public void draw(Batch batch, float parentAlpha) {
getPlayerSprite().draw(batch);
if(Main.gamestate == -1){
if(Main.gamestate == -1 || Main.gamestate == -2){
debug(batch);
}
super.draw(batch, parentAlpha); //To change body of generated methods, choose Tools | Templates.
@ -210,15 +211,13 @@ public class Player extends Actor{
private void debug(Batch batch){
batch.end();
shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.end();
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.setColor(Color.WHITE);
shapeRenderer.rect(getX(), getY(), playerSprite.getSprite().getWidth(), playerSprite.getSprite().getHeight());
shapeRenderer.end();
uiRenderer.setProjectionMatrix(batch.getProjectionMatrix());
uiRenderer.begin(ShapeRenderer.ShapeType.Line);
uiRenderer.setColor(Color.GRAY);
uiRenderer.rect(getX(), getY(), playerSprite.getSprite().getWidth(), playerSprite.getSprite().getHeight());
uiRenderer.setColor(Color.RED);
uiRenderer.rect(collisionRect.x, collisionRect.y, collisionRect.width, collisionRect.height);
uiRenderer.end();
batch.begin();
}

@ -1,5 +1,6 @@
package com.trs.main.desktop;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.trs.main.Main;
@ -12,7 +13,9 @@ public class DesktopLauncher {
config.width=1280;
config.height=720;
config.fullscreen = false;
config.backgroundFPS = 100;
config.foregroundFPS = 100;
//config.width=1920;
//config.height=1080;
//config.fullscreen = true;

Loading…
Cancel
Save