debug mode added (ALT_LEFT)

master
GammelJAN 5 years ago
parent 0bd73badda
commit 4bef651d49

@ -0,0 +1,39 @@
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D sceneTex; // 0
uniform vec2 center; // Mouse position
uniform float time; // effect elapsed time
//uniform vec3 shockParams; // 10.0, 0.8, 0.1
varying vec2 v_texCoords;
void main()
{
// get pixel coordinates
vec2 l_texCoords = v_texCoords;
//vec2 center = vec2(0.5, 0.5);
vec3 shockParams = vec3(10.0, 0.8, 0.1);
float offset = (time- floor(time))/time;
float CurrentTime = (time)*(offset);
//get distance from center
float distance = distance(v_texCoords, center);
if ( (distance <= (CurrentTime + shockParams.z)) && (distance >= (CurrentTime - shockParams.z)) ) {
float diff = (distance - CurrentTime);
float powDiff = 0.0;
if(distance>0.05){
powDiff = 1.0 - pow(abs(diff*shockParams.x), shockParams.y);
}
float diffTime = diff * powDiff;
vec2 diffUV = normalize(v_texCoords-center);
//Perform the distortion and reduce the effect over time
l_texCoords = v_texCoords + ((diffUV * diffTime)/(CurrentTime * distance * 40.0));
}
gl_FragColor = texture2D(sceneTex, l_texCoords);
}

@ -0,0 +1,15 @@
attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;
uniform mat4 u_projTrans;
varying vec4 v_color;
varying vec2 v_texCoords;
void main() {
v_color = a_color;
v_texCoords = a_texCoord0;
gl_Position = u_projTrans * a_position;
}

@ -16,11 +16,14 @@ public class Main extends Game{
*/
// TEST
// -1: Debug
// 0: normal game world, 1: dialogue, 2: fight
// 7: Load MenuScreen 8: Load GameScreen 9: Load InventoryScreen
public static int gamestate = 0;
private int fallbackState = 0;
public static float CAMERA_WIDTH = 854;
public static float CAMERA_HEIGHT = 480;
MenuScreen menuScreen;
GameScreen gameScreen;
@ -93,6 +96,16 @@ public class Main extends Game{
renderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND);
*/
if(Gdx.input.isKeyJustPressed(Input.Keys.ALT_LEFT)){
if(gamestate == -1){
gamestate = fallbackState;
}
else{
fallbackState = gamestate;
gamestate = -1;
}
}
}
@Override

@ -14,6 +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.maps.MapObject;
import com.badlogic.gdx.maps.MapProperties;
import com.badlogic.gdx.maps.objects.RectangleMapObject;
@ -24,6 +25,7 @@ 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;
@ -97,6 +99,8 @@ public class MapContainer {
renderer.setView((OrthographicCamera)stage.getCamera());
stage.getCamera().update();
// adding MapObjects to the Stage
for(MapObject object : map.getLayers().get(5).getObjects().getByType(RectangleMapObject.class)){
Rectangle rect = ((RectangleMapObject) object).getRectangle();
@ -249,11 +253,13 @@ public class MapContainer {
getRenderer().render(getLayersBelowPlayer());
if(Main.gamestate == 0 || Main.gamestate == 1) {
/*
Actor[] old = getStage().getActors().toArray();
getStage().clear();
for(Actor a : sort(old)){
getStage().addActor(a);
}
*/
for(Actor a : getStage().getActors()) {
if(a instanceof Player) {
Rectangle rect = ((Player) a).getCollisionRect();
@ -263,7 +269,8 @@ public class MapContainer {
setCollidingDoor(d);
break;
}
}
}
break;
}
}
@ -271,7 +278,7 @@ public class MapContainer {
getStage().draw();
}
if(Main.gamestate == 2){
else if(Main.gamestate == 2){
if(getFs() == null) {
// CREATING MAP COLLISION OBJECTS
ArrayList<Rectangle> mapRectsTemp = new ArrayList<>();
@ -340,6 +347,12 @@ public class MapContainer {
getFs().draw();
}
}
else if(Main.gamestate == -1){
if(Gdx.input.isKeyPressed(Input.Keys.SPACE)){
getStage().act();
}
getStage().draw();
}
getRenderer().render(getLayersAbovePlayer());

@ -76,6 +76,10 @@ public class QuestWindow {
renderer.setProjectionMatrix(batch.getProjectionMatrix());
if(Main.gamestate == -1){
visible = false;
}
if(visible && Main.gamestate != 2 && Main.gamestate != 1){
if(visiblePerc < 1){
visiblePerc += animationSpeed;
@ -86,6 +90,10 @@ public class QuestWindow {
renderer.rect((float)(boxX + boxWidth-(boxWidth * visiblePerc)), (float)(boxY + boxHeight-(boxHeight * visiblePerc)), (float)(boxWidth * visiblePerc), (float)(boxHeight * visiblePerc));
renderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND);
renderer.begin(ShapeRenderer.ShapeType.Line);
renderer.setColor(Color.BLACK);
renderer.rect((float)(boxX + boxWidth-(boxWidth * visiblePerc)), (float)(boxY + boxHeight-(boxHeight * visiblePerc)), (float)(boxWidth * visiblePerc), (float)(boxHeight * visiblePerc));
renderer.end();
UIDrawer.drawCharBox(batch, font, boxX + boxWidth - 16 , boxY + boxHeight - 16, 32, "^");
}
else{
@ -95,7 +103,13 @@ public class QuestWindow {
renderer.setColor(0.1f, 0.1f, 0.1f, 0.5f);
renderer.rect(boxX, boxY, boxWidth, boxHeight);
renderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND);
renderer.begin(ShapeRenderer.ShapeType.Line);
renderer.setColor(Color.BLACK);
renderer.rect((float)(boxX + boxWidth-(boxWidth * visiblePerc)), (float)(boxY + boxHeight-(boxHeight * visiblePerc)), (float)(boxWidth * visiblePerc), (float)(boxHeight * visiblePerc));
renderer.end();
Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
batch.begin();
@ -130,7 +144,7 @@ public class QuestWindow {
Gdx.gl.glDisable(GL20.GL_BLEND);
}
if(Gdx.input.isKeyJustPressed(Input.Keys.UP)){
if(Gdx.input.isKeyJustPressed(Input.Keys.UP) && Main.gamestate != -1){
visible = false;
}
@ -145,13 +159,17 @@ public class QuestWindow {
renderer.rect((float)(boxX + boxWidth-(boxWidth * visiblePerc)), (float)(boxY + boxHeight-(boxHeight * visiblePerc)),(float)(boxWidth * visiblePerc), (float)(boxHeight * visiblePerc));
renderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND);
renderer.begin(ShapeRenderer.ShapeType.Line);
renderer.setColor(Color.BLACK);
renderer.rect((float)(boxX + boxWidth-(boxWidth * visiblePerc)), (float)(boxY + boxHeight-(boxHeight * visiblePerc)), (float)(boxWidth * visiblePerc), (float)(boxHeight * visiblePerc));
renderer.end();
UIDrawer.drawCharBox(batch, font, boxX + boxWidth - 16 , boxY + boxHeight - 16, 32, "V");
}
else{
UIDrawer.drawCharBox(batch, font, boxX + boxWidth - 16 , boxY + boxHeight - 16, 32, "V");
UIDrawer.drawIcon(batch, boxX + boxWidth - 16 , boxY + boxHeight - 16, 0);
}
if(Gdx.input.isKeyJustPressed(Input.Keys.DOWN)){
if(Gdx.input.isKeyJustPressed(Input.Keys.DOWN) && Main.gamestate != -1){
visible = true;
}
}

@ -64,11 +64,11 @@ public class Textbox extends Actor{
font = generator.generateFont(parameter);
generator.dispose();
font.setColor(Color.BLACK);
textHeight = getTextHeight(font,"A");
printChar = 0;
this.ans = ans;
setName("textbox");
font = new BitmapFont();
setWidth(Main.CAMERA_WIDTH - 40);
r = new Rectangle(20, 20, 814, 0);
@ -142,6 +142,8 @@ public class Textbox extends Actor{
@Override
public void draw(Batch camBatch, float parentAlpha) {
camBatch.end();
batch.setProjectionMatrix(m);
@ -151,6 +153,7 @@ public class Textbox extends Actor{
font.setColor(Color.CLEAR);
float height = font.draw(batch, toPrint.substring(0, (int)printChar), getX()+2, getY(), getWidth(), alignment, true).height;
float theight = height;
float textHeight = getTextHeight(font, "A");
if(state == 1){
for(String s : ans){
@ -177,9 +180,11 @@ public class Textbox extends Actor{
if(selectedAsw == i){
font.setColor(SelectedColor);
}
font.draw(batch, ans[i], getX()+20, (getY()+getHeight()-5) - (textHeight + i*(getTextHeight(font, "A")+5)), getWidth(), alignment, true);
else{
font.setColor(TextColor);
}
font.draw(batch, ans[i], getX()+20, (getY()+getHeight()-5) -theight- (i)*(textHeight+5), getWidth(), alignment, true);
font.setColor(TextColor);
}
}
batch.end();

@ -6,6 +6,8 @@
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.math.Matrix4;
import com.badlogic.gdx.math.Rectangle;
import com.trs.main.Main;
@ -61,10 +63,25 @@ public class GameScreen extends AbstractScreen{
loadNewMap(map.getCollidingDoor().destinationMap, map.getCollidingDoor().destinationDoor);
}
Player a = map.getPlayer();
map.getStage().getCamera().position.set((a.getX()+a.getWidth()/2), (a.getY()+a.getHeight()/2), 0);
//map.getStage().getCamera().update();
if(Main.gamestate == -1){
if(Gdx.input.isKeyPressed(Input.Keys.LEFT)){
map.getStage().getCamera().translate(-10, 0, 0);
}
if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)){
map.getStage().getCamera().translate(10, 0, 0);
}
if(Gdx.input.isKeyPressed(Input.Keys.UP)){
map.getStage().getCamera().translate(0, 10, 0);
}
if(Gdx.input.isKeyPressed(Input.Keys.DOWN)){
map.getStage().getCamera().translate(0, -10, 0);
}
}
else{
Player a = map.getPlayer();
map.getStage().getCamera().position.set((a.getX()+a.getWidth()/2), (a.getY()+a.getHeight()/2), 0);
//map.getStage().getCamera().update();
}
}
@Override

@ -53,7 +53,7 @@ public class AnimatedSprite {
}
public void draw(Batch batch) {
sprite.draw(batch);
sprite.draw(batch);
}
/**

@ -1,8 +1,10 @@
package com.trs.main.worldobjects;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Circle;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
@ -27,6 +29,8 @@ public class Hostile extends Actor {
private float speed = 2;
float movementX;
float movementY;
private ShapeRenderer shapeRenderer = new ShapeRenderer();
// 0: normal movement, 1: locked onto Player, 2: attacking
private int movementState;
@ -67,7 +71,7 @@ public class Hostile extends Actor {
POI = new Vector2(area.getX() + ((float) Math.random() * (float) area.getWidth()), area.getY() + ((float) Math.random() * (float) area.getHeight()));
}
Vector2 movement = new Vector2(speed,0);
movement.setAngleRad(StaticMath.calculateAngle(getX(), getY(), POI.x, POI.y));
movement.setAngleRad(StaticMath.calculateAngle(getX()+sprite.getSprite().getWidth()/2, getY()+sprite.getSprite().getHeight()/2, POI.x, POI.y));
if(movement.angleDeg() < 135 && movement.angleDeg() >= 45) {
facing = 0;
@ -82,7 +86,7 @@ public class Hostile extends Actor {
facing = 3;
}
if(StaticMath.calculateDistance(getX(), getY(), POI.x, POI.y) < 10f) {
if(StaticMath.calculateDistance(getX()+sprite.getSprite().getWidth()/2, getY()+sprite.getSprite().getHeight()/2, POI.x, POI.y) < 3f) {
movementX = 0;
movementY = 0;
}
@ -182,15 +186,43 @@ public class Hostile extends Actor {
@Override
public void draw(Batch batch, float deltatime) {
getSprite().draw(batch);
getSprite().draw(batch);
if(Main.gamestate == -1){
debug(batch);
}
super.draw(batch, deltatime);
}
private void debug(Batch batch){
batch.end();
shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
if(POI != null){
shapeRenderer.setColor(Color.RED);
shapeRenderer.circle(POI.x, POI.y, 5);
}
shapeRenderer.end();
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.setColor(Color.GREEN);
shapeRenderer.line(getX()+ sprite.getSprite().getWidth()/2, getY()+sprite.getSprite().getHeight()/2, POI.x, POI.y);
shapeRenderer.setColor(Color.YELLOW);
shapeRenderer.circle(getX()+ sprite.getSprite().getWidth()/2, getY()+sprite.getSprite().getHeight()/2, getAttentionCircle().radius);
shapeRenderer.setColor(Color.RED);
shapeRenderer.circle(getX()+ sprite.getSprite().getWidth()/2, getY()+sprite.getSprite().getHeight()/2, getAttackCircle().radius);
shapeRenderer.setColor(Color.WHITE);
shapeRenderer.rect(getX(), getY(), sprite.getSprite().getWidth(), sprite.getSprite().getHeight());
shapeRenderer.end();
batch.begin();
}
@Override
protected void positionChanged() {
getSprite().setSpritePosition((int)getX(), (int)getY());
setCollisionRect(new Rectangle(getX() + 16, getY(), 32, 16));
setAttackCircle(new Circle(getX() + 16, getY(), 100f));
setAttentionCircle(new Circle(getX() + 16, getY(), 300f));
setAttentionCircle(new Circle(getX() + 16, getY(), 300f));
super.positionChanged(); //To change body of generated methods, choose Tools | Templates.
}

@ -1,8 +1,10 @@
package com.trs.main.worldobjects;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
@ -22,6 +24,7 @@ public class InteractionObject extends Actor{
int id;
String dialoguePath;
private ShapeRenderer shapeRenderer = new ShapeRenderer();
public InteractionObject(Rectangle collisionRect, float xPos, float yPos,int mapId, int id, String texture){
setName("interactive");
@ -102,10 +105,30 @@ public class InteractionObject extends Actor{
@Override
public void draw(Batch batch, float parentAlpha) {
if(animatedSprite != null)animatedSprite.draw(batch);
if(animatedSprite != null){animatedSprite.draw(batch);}
if(Main.gamestate == -1){
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.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.end();
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.setColor(Color.WHITE);
shapeRenderer.rect(getX(), getY(), getWidth(), getHeight());
shapeRenderer.end();
batch.begin();
}
public boolean collidingWithMapCollisionObject(){
boolean value = false;
for(Actor a : getStage().getActors()){

@ -6,9 +6,11 @@
package com.trs.main.worldobjects;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
@ -53,6 +55,8 @@ public class MovingNpc extends Actor{
private AnimatedSprite questBubble;
private ShapeRenderer shapeRenderer = new ShapeRenderer();
public MovingNpc(Rectangle area, float xPos, float yPos, int id, int mapId, String texture){
super();
setName("npc");
@ -153,7 +157,7 @@ public class MovingNpc extends Actor{
POI = new Vector2(area.getX() + ((float) Math.random() * (float) area.getWidth()), area.getY() + ((float) Math.random() * (float) area.getHeight()));
}
Vector2 movement = new Vector2(speed,0);
movement.setAngleRad(StaticMath.calculateAngle(getX(), getY(), POI.x, POI.y));
movement.setAngleRad(StaticMath.calculateAngle(getX() + animatedSprite.getSprite().getWidth()/2, getY() + animatedSprite.getSprite().getHeight()/2, POI.x, POI.y));
if(movement.angleDeg() < 135 && movement.angleDeg() >= 45) {
facing = 0;
@ -168,7 +172,7 @@ public class MovingNpc extends Actor{
facing = 3;
}
if(StaticMath.calculateDistance(getX(), getY(), POI.x, POI.y) < 10f) {
if(StaticMath.calculateDistance(getX() + animatedSprite.getSprite().getWidth()/2, getY() + animatedSprite.getSprite().getHeight()/2, POI.x, POI.y) < 10f) {
movementX = 0;
movementY = 0;
}
@ -243,11 +247,34 @@ public class MovingNpc extends Actor{
}
}
if(Main.gamestate == -1){
debug(batch);
}
super.draw(batch, delta); //To change body of generated methods, choose Tools | Templates.
}
private void debug(Batch batch){
batch.end();
shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
if(POI != null){
shapeRenderer.setColor(Color.RED);
shapeRenderer.circle(POI.x, POI.y, 5);
}
shapeRenderer.end();
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
if(POI != null){
shapeRenderer.setColor(Color.GREEN);
shapeRenderer.line(getX()+ animatedSprite.getSprite().getWidth()/2, getY()+animatedSprite.getSprite().getHeight()/2, POI.x, POI.y);
}
shapeRenderer.setColor(Color.WHITE);
shapeRenderer.rect(getX(), getY(), animatedSprite.getSprite().getWidth(), animatedSprite.getSprite().getHeight());
shapeRenderer.end();
batch.begin();
}
public boolean collidingWithMapCollisionObject(){
for(Actor a : getStage().getActors()){
if(a instanceof MapCollisionObject){

@ -7,8 +7,10 @@ package com.trs.main.worldobjects;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
@ -45,6 +47,8 @@ public class Player extends Actor{
private Stats stats;
private ShapeRenderer shapeRenderer = new ShapeRenderer();
public Player(int xPos, int yPos){
setName("player");
t = new Texture(Gdx.files.internal("textureData/sprites/player.png"));
@ -198,8 +202,25 @@ public class Player extends Actor{
@Override
public void draw(Batch batch, float parentAlpha) {
getPlayerSprite().draw(batch);
if(Main.gamestate == -1){
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.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();
batch.begin();
}
@Override
public boolean remove() {

Loading…
Cancel
Save