master^2
GammelJAN 5 years ago
parent 0113e0075d
commit 8d445b29dc

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 691 B

After

Width:  |  Height:  |  Size: 700 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 725 B

After

Width:  |  Height:  |  Size: 727 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 725 B

After

Width:  |  Height:  |  Size: 721 B

@ -19,11 +19,19 @@ public class Main extends Game{
// 0: normal game world, 1: dialogue, 2: fight
// 7: Load MenuScreen 8: Load GameScreen 9: Load InventoryScreen
public static int gamestate = 0;
public static boolean debugUI = false;
private int fallbackState = 0;
public static float CAMERA_WIDTH = 854;
public static float CAMERA_HEIGHT = 480;
public static float CAMERA_WIDTH = 960;
public static float CAMERA_HEIGHT = 540;
/**
* TODO:
* figure out, how(if) we can change CamWidth and Height while ingame (e.G. for debug mode)
*/
// DEBUG
public static boolean debugModeActive = false;
public static boolean drawAbove = true;
public static boolean drawBelow = true;
MenuScreen menuScreen;
GameScreen gameScreen;
@ -97,22 +105,46 @@ public class Main extends Game{
renderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND);
*/
if(Gdx.input.isKeyJustPressed(Input.Keys.F1)){
if(gamestate == -1){
debugUI = true;
gamestate = -2;
if(debugModeActive){
if(Gdx.input.isKeyJustPressed(Input.Keys.F8)){
if(drawAbove){
drawAbove = false;
}
else{
drawAbove = true;
}
}
else if(gamestate == -2){
debugUI = false;
gamestate = fallbackState;
if(Gdx.input.isKeyJustPressed(Input.Keys.F9)){
if(drawBelow){
drawBelow = false;
}
else{
drawBelow = true;
}
}
}
if(Gdx.input.isKeyJustPressed(Input.Keys.F1)){
if(!debugModeActive){
fallbackState = gamestate;
debugModeActive = true;
}
else{
debugUI = true;
gamestate = -1;
}
if(Gdx.input.isKeyJustPressed(Input.Keys.F2)){
if(!debugModeActive){
fallbackState = gamestate;
gamestate = -1;
debugModeActive = true;
}
gamestate = -2;
}
if(Gdx.input.isKeyJustPressed(Input.Keys.F3)){
if(debugModeActive){
gamestate = fallbackState;
debugModeActive = false;
fallbackState = 0;
}
}
}
@Override

@ -11,6 +11,7 @@ import com.trs.main.fightscreen.FightObject;
import com.trs.main.fightscreen.FightScreen;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.GL20;
import java.util.ArrayList;
import com.badlogic.gdx.graphics.OrthographicCamera;
@ -76,6 +77,7 @@ public class MapContainer {
private int[] layersBelowPlayer = {0, 1, 2};
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, ShapeRenderer uiRenderer) {
@ -200,6 +202,7 @@ public class MapContainer {
stage.addActor(p);
}
public void render(float f){
if(Gdx.input.isKeyJustPressed(Input.Keys.TAB)){
@ -249,7 +252,9 @@ public class MapContainer {
getRenderer().setView((OrthographicCamera)getStage().getCamera());
if(Main.drawBelow){
getRenderer().render(getLayersBelowPlayer());
}
if(Main.gamestate == 0 || Main.gamestate == 1) {
/*
@ -356,7 +361,9 @@ public class MapContainer {
getStage().draw();
}
getRenderer().render(getLayersAbovePlayer());
if(Main.drawAbove){
getRenderer().render(getLayersAbovePlayer());
}
for(Actor a : getStage().getActors()){
if(a instanceof Textbox){
@ -416,7 +423,25 @@ public class MapContainer {
return unsorted;
}
public void debugDoor(ShapeRenderer uiRenderer){
Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
uiRenderer.begin(ShapeRenderer.ShapeType.Filled);
uiRenderer.setColor(0f,136f/255f,0f,0.4f);
for(Door d : doors){
uiRenderer.rect(d.rect.x, d.rect.y, d.rect.width, d.rect.height);
}
uiRenderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND);
uiRenderer.setColor(0f,1f,0f,1f);
uiRenderer.begin(ShapeRenderer.ShapeType.Line);
for(Door d : doors){
uiRenderer.rect(d.rect.x, d.rect.y, d.rect.width, d.rect.height);
}
uiRenderer.end();
}
/**
* @return the stage
*/

@ -34,7 +34,6 @@ public class DebugUI {
Matrix4 uiMatrix = m.cpy();
uiMatrix.setToOrtho2D(0, 0, Main.CAMERA_WIDTH, Main.CAMERA_HEIGHT);
batch.setProjectionMatrix(uiMatrix);
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fontData/font.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 21;
@ -51,27 +50,66 @@ public class DebugUI {
float textHeight = getTextHeight(font, "A")+5;
ArrayList<String> strings = new ArrayList<>();
strings.add("DeltaTime: "+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(" ");
strings.add("DeltaTime: "+Gdx.graphics.getDeltaTime());
strings.add("FPS: "+(int)(Gdx.graphics.getFramesPerSecond()));
strings.add("Entities: "+entityAmount);
strings.add("CamX: "+camPos.x);
strings.add("CamY: "+camPos.y);
if(Main.gamestate == -1 || Main.gamestate == -2){
strings.add("DebugMode: "+Math.abs(Main.gamestate));
}
else{
strings.add("DebugMode: no debug state");
}
strings.add("Gamestate: "+Main.gamestate);
strings.add(" ");
strings.add("drawAbove: "+Main.drawAbove);
strings.add("drawBelow: "+Main.drawBelow);
if(Main.gamestate == -1){
strings.add("DebugMode: PlayerCam");
strings.add("Player input enabled");
strings.add(" ");
strings.add("DebugMode: PlayerCam");
strings.add("Player input: enabled");
strings.add("Doors: disabled");
if(Main.drawAbove || Main.drawBelow){
strings.add("TiledMap: enabled");
}
else{
strings.add("TiledMap: disabled");
}
strings.add(" ");
strings.add("CONTROLS:");
strings.add(" ");
strings.add("press [F1] for debugMode 1");
strings.add("press [F2] for debugMode 2");
strings.add("press [F3] to end debugMode");
strings.add("press [F8] to switch drawAbove");
strings.add("press [F9] to switch drawBelow");
strings.add(" ");
strings.add(" ");
}
else if(Main.gamestate == -2){
strings.add("DebugMode: FreeCam");
strings.add("Player input disabled");
strings.add("press [SPACE] for Actors to act");
strings.add("DebugMode: FreeCam");
strings.add("Player input: disabled");
strings.add("Doors: disabled");
if(Main.drawAbove || Main.drawBelow){
strings.add("TiledMap: enabled");
}
else{
strings.add("TiledMap: disabled");
}
strings.add(" ");
strings.add("CONTROLS:");
strings.add("hold [SPACE] for Actors to act");
strings.add("press [F1] for debugMode 1");
strings.add("press [F2] for debugMode 2");
strings.add("press [F3] to end debugMode");
strings.add("press [F8] to switch drawAbove");
strings.add("press [F9] to switch drawBelow");
strings.add("press [ARROW_KEYS] to move Camera");
strings.add("hold [ALT_GR] to slowly move Camera");
}
else{
strings.add("Gamestate "+Main.gamestate+" not supported");
}
strings.add("press [F1] to switch Gamestate");
float width = 0;
for(String s : strings){

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

@ -71,7 +71,7 @@ public class Textbox extends Actor{
setName("textbox");
setWidth(Main.CAMERA_WIDTH - 40);
r = new Rectangle(20, 20, 814, 0);
r = new Rectangle(20, 20, Main.CAMERA_WIDTH-40, 0);
setBounds(r.getX(), r.getY(), r.getWidth(), r.getHeight());
this.toPrint = toPrint;

@ -72,7 +72,7 @@ public class GameScreen extends AbstractScreen{
}
if(Main.gamestate == -2){
float camSpeed = 15;
float camSpeed = 10;
if(Gdx.input.isKeyPressed(Input.Keys.ALT_RIGHT)){
camSpeed = 1;
}
@ -97,10 +97,12 @@ public class GameScreen extends AbstractScreen{
//map.getStage().getCamera().update();
}
if(Main.debugUI){
if(Main.debugModeActive){
map.debugDoor(uiRenderer);
debugUI.draw(map.getStage().getActors().size, new Vector2(map.getStage().getCamera().position.x, map.getStage().getCamera().position.y));
}
}
@Override
public void resize(int width, int height) {

@ -21,6 +21,8 @@ public class Hostile extends Actor {
private AnimatedSprite sprite;
private Rectangle collisionRect;
private Rectangle area;
private float attackCircleRad = 80f;
private float attentionCircleRad = 200f;
private Circle attackCircle;
private Circle attentionCircle;
private boolean isMelee;
@ -48,8 +50,8 @@ public class Hostile extends Actor {
sprite = new AnimatedSprite(tx, 64, 64, true);
collisionRect = new Rectangle(xPos + 16, yPos, 32, 16);
attackCircle = new Circle(xPos + 16, yPos, 100f);
attentionCircle = new Circle(xPos + 16, yPos, 300f);
attackCircle = new Circle(xPos + 16, yPos, attackCircleRad);
attentionCircle = new Circle(xPos + 16, yPos, attentionCircleRad);
movementState = 0;
@ -135,50 +137,78 @@ public class Hostile extends Actor {
}
if(getMovementState() == 1 && Main.gamestate != 1) {
for(Actor a : getStage().getActors()) {
if(a instanceof Player) {
if(Intersector.overlaps(getAttackCircle(), ((Player) a).getCollisionRect())) {
setMovementState(2);
}
if(!Intersector.overlaps(attentionCircle, ((Player) a).getCollisionRect())) {
setMovementState(0);
}
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));
if(movement.angleDeg() < 135 && movement.angleDeg() >= 45) {
facing = 0;
}
else if(movement.angleDeg() >= 135 && movement.angleDeg() < 225) {
facing = 1;
}
else if(movement.angleDeg() >= 225 && movement.angleDeg() < 315) {
facing = 2;
}
else {
facing = 3;
}
if(StaticMath.calculateDistance(getX(), getY(), POI.x, POI.y) < 1f) {
movement.x = 0;
movement.y = 0;
}
setX(getX() + movement.x);
setY(getY() + movement.y);
int animationRow = 0;
if(movement.x != 0 || movement.y != 0) {
animationRow = 8;
}
getSprite().setRow(animationRow + facing);
}
}
}
Actor a = null;
for(Actor ac : getStage().getActors()) {
if(ac instanceof Player) {
if(Intersector.overlaps(getAttackCircle(), ((Player) ac).getCollisionRect())) {
setMovementState(2);
}
if(!Intersector.overlaps(attentionCircle, ((Player) ac).getCollisionRect())) {
setMovementState(0);
}
a = ac;
break;
}
}
if(a != null){
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));
if(movement.angleDeg() < 135 && movement.angleDeg() >= 45) {
facing = 0;
}
else if(movement.angleDeg() >= 135 && movement.angleDeg() < 225) {
facing = 1;
}
else if(movement.angleDeg() >= 225 && movement.angleDeg() < 315) {
facing = 2;
}
else {
facing = 3;
}
movementX = movement.x;
movementY = movement.y;
if(movementX == 0 && movementY == 0){
}
else if(movementX == 0 && movementY != 0){
setY(getY()+movementY);
if(collidingWithMapCollisionObject()){
setY(getY()-movementY);
}
}
else if(movementY == 0 && movementX != 0){
setX(getX()+movementX);
if(collidingWithMapCollisionObject()){
setX(getX()-movementX);
}
}
else if(movementX != 0 && movementY != 0){
setX(getX()+ (movementX));
if(collidingWithMapCollisionObject()){
setX(getX() - (movementX));
}
setY(getY() + (movementY));
if(collidingWithMapCollisionObject()){
setY(getY()- (movementY));
}
}
//setX(getX() + movement.x);
//setY(getY() + movement.y);
int animationRow = 0;
if(movement.x != 0 || movement.y != 0) {
animationRow = 8;
}
getSprite().setRow(animationRow + facing);
}
}
if(getMovementState() == 2) {
Main.gamestate = 2;
@ -189,7 +219,7 @@ public class Hostile extends Actor {
@Override
public void draw(Batch batch, float deltatime) {
getSprite().draw(batch);
if(Main.gamestate == -1 || Main.gamestate == -2){
if(Main.debugModeActive){
debug(batch);
}
super.draw(batch, deltatime);
@ -239,8 +269,8 @@ public class Hostile extends Actor {
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));
setAttackCircle(new Circle(getX() + 16, getY(), attackCircleRad));
setAttentionCircle(new Circle(getX() + 16, getY(), attentionCircleRad));
super.positionChanged(); //To change body of generated methods, choose Tools | Templates.
}
@ -252,7 +282,7 @@ public class Hostile extends Actor {
return true;
}
}
else if(a instanceof MovingNpc && a != this){
else if(a instanceof MovingNpc){
if(Intersector.overlaps(collisionRect, ((MovingNpc)a).collisionRect)){
return true;
}

@ -110,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 || Main.gamestate == -2){
if(Main.debugModeActive){
debug(batch);
}
super.draw(batch, parentAlpha); //To change body of generated methods, choose Tools | Templates.
@ -126,6 +126,7 @@ public class InteractionObject extends Actor{
shapeRenderer.end();
batch.begin();
}

@ -38,7 +38,7 @@ public class MapCollisionObject extends Actor{
@Override
public void draw(Batch batch, float parentAlpha) {
if(Main.gamestate == -1 || Main.gamestate == -2){
if(Main.debugModeActive){
debug(batch);
}
super.draw(batch, parentAlpha); //To change body of generated methods, choose Tools | Templates.

@ -265,7 +265,7 @@ public class MovingNpc extends Actor{
}
}
if(Main.gamestate == -1 || Main.gamestate == -2){
if(Main.debugModeActive){
debug(batch);
}
@ -286,6 +286,9 @@ public class MovingNpc extends Actor{
shapeRenderer.setColor(Color.ORANGE);
shapeRenderer.line(getCenterX(), getCenterY(), POI.x, POI.y);
}
shapeRenderer.setColor(Color.RED);
shapeRenderer.rect(collisionRect.x, collisionRect.y, collisionRect.width, collisionRect.height);
shapeRenderer.setColor(Color.WHITE);
shapeRenderer.rect(getX(), getY(), animatedSprite.getSprite().getWidth(), animatedSprite.getSprite().getHeight());

@ -203,7 +203,7 @@ public class Player extends Actor{
@Override
public void draw(Batch batch, float parentAlpha) {
getPlayerSprite().draw(batch);
if(Main.gamestate == -1 || Main.gamestate == -2){
if(Main.debugModeActive){
debug(batch);
}
super.draw(batch, parentAlpha); //To change body of generated methods, choose Tools | Templates.

@ -9,12 +9,10 @@ public class DesktopLauncher {
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.resizable = true;
config.width=1280;
config.height=720;
config.width=1600;
config.height=900;
config.fullscreen = false;
config.backgroundFPS = 100;
config.foregroundFPS = 100;
//config.width=1920;
//config.height=1080;

Loading…
Cancel
Save