master
GammelJAN 5 years ago
parent 17bb657a9c
commit 6b642399e5

@ -0,0 +1,93 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.trs.main;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Rectangle;
/**
*
* @author janeh
*/
public class FightDialogue {
BitmapFont font;
Rectangle r;
ShapeRenderer renderer;
int selectedAsw = 0;
String[] ans = {"Melee", "Range", "Skip"};
public FightDialogue(float camX, float camY){
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fontData/font.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 21;
font = generator.generateFont(parameter);
generator.dispose();
font.setColor(Color.BLACK);
renderer = new ShapeRenderer();
r = new Rectangle(camX-Main.CAMERA_WIDTH/2f + Main.CAMERA_WIDTH*0.8f, camY-Main.CAMERA_HEIGHT/2 + Main.CAMERA_HEIGHT*0.2f, Main.CAMERA_WIDTH*0.18f, Main.CAMERA_HEIGHT*0.6f);
}
public void draw(Batch batch){
if(Gdx.input.isKeyJustPressed(Input.Keys.DOWN)){
if(selectedAsw < ans.length - 1) {
selectedAsw++;
}
}
if(Gdx.input.isKeyJustPressed(Input.Keys.UP)){
if(selectedAsw > 0) {
selectedAsw--;
}
}
if(Gdx.input.isKeyJustPressed(Input.Keys.ENTER)){
// DO THE STUFF NICENICECNICNEICNIENICENI
}
renderer.setProjectionMatrix(batch.getProjectionMatrix());
renderer.setColor(Color.BLUE);
renderer.begin(ShapeRenderer.ShapeType.Filled);
renderer.rect(r.x, r.y, r.width, r.height);
renderer.end();
renderer.setColor(Color.RED);
renderer.begin(ShapeRenderer.ShapeType.Line);
renderer.rect(r.x, r.y, r.width, r.height);
renderer.end();
batch.begin();
for(int i = 0; i < ans.length; i++){
if(i == selectedAsw){
font.setColor(Color.RED);
}
else font.setColor(Color.BLACK);
font.draw(batch, ans[i], r.x+5, r.y + r.height-i*1.2f*getTextHeight("A") - 5);
}
batch.end();
}
public float getTextWidth(String text){
GlyphLayout glyphLayout = new GlyphLayout();
glyphLayout.setText(font,text);
return glyphLayout.width;
}
public float getTextHeight(String text){
GlyphLayout glyphLayout = new GlyphLayout();
glyphLayout.setText(font,text);
return glyphLayout.height;
}
}

@ -1,11 +1,14 @@
package com.trs.main;
import com.badlogic.gdx.math.Vector2;
public abstract class FightObject {
protected AnimatedSprite sprite;
protected Stats stats;
protected int id;
protected float x;
protected float y;
protected Vector2 POI;
public FightObject(float x, float y, AnimatedSprite sprite, Stats stats, int id) {
this.sprite = sprite;

@ -1,6 +1,7 @@
package com.trs.main;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
@ -17,6 +18,8 @@ public class FightScreen {
ShapeRenderer renderer;
FightObject[] objects;
Rectangle[] collisionRects;
FightDialogue fightDialogue;
Vector2 gridPos;
@ -28,6 +31,7 @@ public class FightScreen {
this.objects = objects;
this.collisionRects = collisionRects;
this.renderer = new ShapeRenderer();
this.fightDialogue = new FightDialogue(camX, camY);
gridPos = new Vector2();
@ -54,7 +58,7 @@ public class FightScreen {
boolean finished = true;
for(FightObject object : objects){
Vector2 POI = new Vector2((int)(Math.ceil((double)(object.x)/32.0) * 32.0) - 16, (int)(Math.ceil((double)(object.y)/32.0) * 32.0));
float speed = 3;
float speed = 2.5f;
if(Math.abs(Vector2.dst(object.x, object.y, POI.x, POI.y)) < 3f && Math.abs(Vector2.dst(object.x, object.y, POI.x, POI.y)) != 0) {
speed = Math.abs(Vector2.dst(object.x, object.y, POI.x, POI.y));
@ -77,7 +81,7 @@ public class FightScreen {
facing = 3;
}
if(StaticMath.calculateDistance(object.x, object.y, POI.x, POI.y, movement.angleRad()) < 1f) {
if(StaticMath.calculateDistance(object.x, object.y, POI.x, POI.y, movement.angleRad()) == 0) {
movement.x = 0;
movement.y = 0;
}
@ -99,7 +103,34 @@ public class FightScreen {
state = 1;
}
}
else if(state == 1){
if(Gdx.input.isKeyJustPressed(Input.Keys.W)){
if(getPlayer().POI == null){
getPlayer().POI = new Vector2(getPlayer().x, getPlayer().y + 32);
System.out.println("W");
}
}
if(Gdx.input.isKeyJustPressed(Input.Keys.A)){
if(getPlayer().POI == null){
getPlayer().POI = new Vector2(getPlayer().x-32, getPlayer().y);
System.out.println("A");
}
}
if(Gdx.input.isKeyJustPressed(Input.Keys.S)){
if(getPlayer().POI == null){
getPlayer().POI = new Vector2(getPlayer().x, getPlayer().y - 32);
System.out.println("S");
}
}
if(Gdx.input.isKeyJustPressed(Input.Keys.D)){
if(getPlayer().POI == null){
getPlayer().POI = new Vector2(getPlayer().x + 32, getPlayer().y);
System.out.println("D");
}
}
}
gotoPOI();
for(FightObject object : objects) {
object.sprite.updateAnimation(deltatime);
}
@ -123,6 +154,7 @@ public class FightScreen {
}
renderer.end();
fightDialogue.draw(batch);
Gdx.gl.glDisable(GL20.GL_BLEND);
batch.begin();
@ -150,5 +182,62 @@ public class FightScreen {
}
}
}
public FightPlayer getPlayer(){
for(FightObject object : objects){
if(object instanceof FightPlayer){
return (FightPlayer) object;
}
}
System.out.println("großes Problem hahgaeu9ihgbidesrufhgred");
return null;
}
public void gotoPOI(){
for(FightObject object : objects){
if(object.POI != null){
//object.POI = new Vector2((int)(Math.ceil((double)(object.x)/32.0) * 32.0) - 16, (int)(Math.ceil((double)(object.y)/32.0) * 32.0));
float speed = 3f;
if(StaticMath.calculateDistance(object.x, object.y, object.POI.x, object.POI.y) < 3f && StaticMath.calculateDistance(object.x, object.y, object.POI.x, object.POI.y) != 0) {
speed = Math.abs(Vector2.dst(object.x, object.y, object.POI.x, object.POI.y));
}
Vector2 movement = new Vector2(speed,0);
movement.setAngleRad(StaticMath.calculateAngle(object.x, object.y, object.POI.x, object.POI.y));
int facing;
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((int)object.x == (int)object.POI.x && (int)object.y == (int)object.POI.y) {
movement.x = 0;
movement.y = 0;
}
object.setX(object.x + movement.x);
object.setY(object.y + movement.y);
int animationRow = 0;
if(movement.x != 0 || movement.y != 0) {
animationRow = 8;
}
else{
object.POI = null;
}
object.sprite.setRow(animationRow + facing);
}
}
}
}

@ -12,11 +12,11 @@ public class StaticMath {
double alpha;
if(deltaY == 0){
if(deltaX < 0){
alpha = Math.PI;
if(deltaX > 0){
alpha = 0;
}
else{
alpha = 0;
alpha = Math.PI;
}
}
else if(deltaX == 0 && deltaY >= 0){
@ -49,4 +49,12 @@ public class StaticMath {
double distance = Math.abs((deltaY / Math.sin(angle)));
return (float) distance;
}
public static float calculateDistance(float xPos1, float yPos1, float xPos2, float yPos2){
float deltaX = xPos2 - xPos1;
float deltaY = yPos2 - yPos1;
double distance = Math.abs((deltaY / Math.sin(calculateAngle(xPos1, yPos1, xPos2, yPos2))));
return (float) distance;
}
}

@ -6,17 +6,17 @@ import com.trs.main.Main;
public class DesktopLauncher {
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.resizable = true;
config.width=1280;
config.height=720;
config.fullscreen = false;
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.resizable = true;
config.width=1280;
config.height=720;
config.fullscreen = false;
//config.width=1920;
//config.height=1080;
//config.fullscreen = true;
new LwjglApplication(new Main(), config);
//config.height=1080;
//config.fullscreen = true;
new LwjglApplication(new Main(), config);
}
}

Loading…
Cancel
Save