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 // TEST
// -1: Debug
// 0: normal game world, 1: dialogue, 2: fight // 0: normal game world, 1: dialogue, 2: fight
// 7: Load MenuScreen 8: Load GameScreen 9: Load InventoryScreen // 7: Load MenuScreen 8: Load GameScreen 9: Load InventoryScreen
public static int gamestate = 0; public static int gamestate = 0;
private int fallbackState = 0;
public static float CAMERA_WIDTH = 854; public static float CAMERA_WIDTH = 854;
public static float CAMERA_HEIGHT = 480; public static float CAMERA_HEIGHT = 480;
MenuScreen menuScreen; MenuScreen menuScreen;
GameScreen gameScreen; GameScreen gameScreen;
@ -93,6 +96,16 @@ public class Main extends Game{
renderer.end(); renderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND); 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 @Override

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

@ -76,6 +76,10 @@ public class QuestWindow {
renderer.setProjectionMatrix(batch.getProjectionMatrix()); renderer.setProjectionMatrix(batch.getProjectionMatrix());
if(Main.gamestate == -1){
visible = false;
}
if(visible && Main.gamestate != 2 && Main.gamestate != 1){ if(visible && Main.gamestate != 2 && Main.gamestate != 1){
if(visiblePerc < 1){ if(visiblePerc < 1){
visiblePerc += animationSpeed; 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.rect((float)(boxX + boxWidth-(boxWidth * visiblePerc)), (float)(boxY + boxHeight-(boxHeight * visiblePerc)), (float)(boxWidth * visiblePerc), (float)(boxHeight * visiblePerc));
renderer.end(); renderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND); 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, "^"); UIDrawer.drawCharBox(batch, font, boxX + boxWidth - 16 , boxY + boxHeight - 16, 32, "^");
} }
else{ else{
@ -95,7 +103,13 @@ public class QuestWindow {
renderer.setColor(0.1f, 0.1f, 0.1f, 0.5f); renderer.setColor(0.1f, 0.1f, 0.1f, 0.5f);
renderer.rect(boxX, boxY, boxWidth, boxHeight); renderer.rect(boxX, boxY, boxWidth, boxHeight);
renderer.end(); 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(); batch.begin();
@ -130,7 +144,7 @@ public class QuestWindow {
Gdx.gl.glDisable(GL20.GL_BLEND); 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; 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.rect((float)(boxX + boxWidth-(boxWidth * visiblePerc)), (float)(boxY + boxHeight-(boxHeight * visiblePerc)),(float)(boxWidth * visiblePerc), (float)(boxHeight * visiblePerc));
renderer.end(); renderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND); 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"); UIDrawer.drawCharBox(batch, font, boxX + boxWidth - 16 , boxY + boxHeight - 16, 32, "V");
} }
else{ else{
UIDrawer.drawCharBox(batch, font, boxX + boxWidth - 16 , boxY + boxHeight - 16, 32, "V"); UIDrawer.drawCharBox(batch, font, boxX + boxWidth - 16 , boxY + boxHeight - 16, 32, "V");
UIDrawer.drawIcon(batch, boxX + boxWidth - 16 , boxY + boxHeight - 16, 0); 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; visible = true;
} }
} }

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

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

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

@ -1,8 +1,10 @@
package com.trs.main.worldobjects; package com.trs.main.worldobjects;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch; 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.Circle;
import com.badlogic.gdx.math.Intersector; import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
@ -27,6 +29,8 @@ public class Hostile extends Actor {
private float speed = 2; private float speed = 2;
float movementX; float movementX;
float movementY; float movementY;
private ShapeRenderer shapeRenderer = new ShapeRenderer();
// 0: normal movement, 1: locked onto Player, 2: attacking // 0: normal movement, 1: locked onto Player, 2: attacking
private int movementState; 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())); 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); 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) { if(movement.angleDeg() < 135 && movement.angleDeg() >= 45) {
facing = 0; facing = 0;
@ -82,7 +86,7 @@ public class Hostile extends Actor {
facing = 3; 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; movementX = 0;
movementY = 0; movementY = 0;
} }
@ -182,15 +186,43 @@ public class Hostile extends Actor {
@Override @Override
public void draw(Batch batch, float deltatime) { 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 @Override
protected void positionChanged() { protected void positionChanged() {
getSprite().setSpritePosition((int)getX(), (int)getY()); getSprite().setSpritePosition((int)getX(), (int)getY());
setCollisionRect(new Rectangle(getX() + 16, getY(), 32, 16)); setCollisionRect(new Rectangle(getX() + 16, getY(), 32, 16));
setAttackCircle(new Circle(getX() + 16, getY(), 100f)); 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. super.positionChanged(); //To change body of generated methods, choose Tools | Templates.
} }

@ -1,8 +1,10 @@
package com.trs.main.worldobjects; package com.trs.main.worldobjects;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch; 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.Intersector;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
@ -22,6 +24,7 @@ public class InteractionObject extends Actor{
int id; int id;
String dialoguePath; 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){
setName("interactive"); setName("interactive");
@ -102,10 +105,30 @@ public class InteractionObject extends Actor{
@Override @Override
public void draw(Batch batch, float parentAlpha) { 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. 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(){ public boolean collidingWithMapCollisionObject(){
boolean value = false; boolean value = false;
for(Actor a : getStage().getActors()){ for(Actor a : getStage().getActors()){

@ -6,9 +6,11 @@
package com.trs.main.worldobjects; package com.trs.main.worldobjects;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite; 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.Intersector;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
@ -53,6 +55,8 @@ public class MovingNpc extends Actor{
private AnimatedSprite questBubble; private AnimatedSprite questBubble;
private ShapeRenderer shapeRenderer = new 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){
super(); super();
setName("npc"); 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())); 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); 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) { if(movement.angleDeg() < 135 && movement.angleDeg() >= 45) {
facing = 0; facing = 0;
@ -168,7 +172,7 @@ public class MovingNpc extends Actor{
facing = 3; 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; movementX = 0;
movementY = 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. 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(){ public boolean collidingWithMapCollisionObject(){
for(Actor a : getStage().getActors()){ for(Actor a : getStage().getActors()){
if(a instanceof MapCollisionObject){ if(a instanceof MapCollisionObject){

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

Loading…
Cancel
Save