FightScreen: Object position themselves in the beginning - bug

master
GammelJAN 5 years ago
parent 0d1e025819
commit 18186f4ff3

@ -2,7 +2,8 @@ package com.trs.main;
public class Enemy extends FightObject{
public Enemy(AnimatedSprite sprite, Stats stats, int id) {
super(sprite, stats, id);
}
public Enemy(float x, float y, AnimatedSprite sprite, Stats stats, int id) {
super(x, y, sprite, stats, id);
}
}

@ -4,12 +4,24 @@ public abstract class FightObject {
protected AnimatedSprite sprite;
protected Stats stats;
protected int id;
protected int x;
protected int y;
protected float x;
protected float y;
public FightObject(AnimatedSprite sprite, Stats stats, int id) {
public FightObject(float x, float y, AnimatedSprite sprite, Stats stats, int id) {
this.sprite = sprite;
this.stats = stats;
this.id = id;
this.x = x;
this.y = y;
}
void setX(float x) {
this.x = x;
this.sprite.setSpritePosition((int)this.x, (int)this.y);
}
void setY(float y) {
this.y = y;
this.sprite.setSpritePosition((int)this.x, (int)this.y);
}
}

@ -2,7 +2,8 @@ package com.trs.main;
public class FightPlayer extends FightObject{
public FightPlayer(AnimatedSprite sprite, Stats stats, int id) {
super(sprite, stats, id);
}
public FightPlayer(float x, float y, AnimatedSprite sprite, Stats stats, int id) {
super(x, y, sprite, stats, id);
}
}

@ -20,7 +20,7 @@ public class FightScreen {
Vector2 gridPos;
// 0: player turn, 1: enemy turn, 2: fight ends
// 0: positioning all Objects on the grid 1: player turn, 2: enemy turn, 3: fight ends
int state = 0;
public FightScreen(Batch batch, FightObject[] objects, Rectangle[] collisionRects, float camX, float camY) {
@ -34,9 +34,8 @@ public class FightScreen {
gridPos.x = (float)(Math.ceil((double)(camX-Main.CAMERA_WIDTH/2)/32.0) * 32.0) + 64;
gridPos.y = (float)(Math.ceil((double)(camY-Main.CAMERA_HEIGHT/2)/32.0) * 32.0) + 32;
// gridPos.x = camX-Main.CAMERA_WIDTH/2;
// gridPos.y = camY-Main.CAMERA_HEIGHT/2;
// SORTING OBJECTS BY INITIATIVE STAT
/*
for(int j = 0; j < objects.length-1; j++){
for(int i = objects.length-1; i >= 0; i--){
@ -46,11 +45,57 @@ public class FightScreen {
objects[i] = temp;
}
}
}*/
}
*/
}
public void act(float deltatime) {
if(state == 0){
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));
Vector2 movement = new Vector2(3,0);
movement.setAngleRad(StaticMath.calculateAngle(object.x, object.y, POI.x, 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(StaticMath.calculateDistance(object.x, object.y, POI.x, POI.y, movement.angleRad()) < 1f) {
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;
}
object.sprite.setRow(animationRow + facing);
if(movement.x != 0 || movement.y != 0){
finished = false;
}
}
if(finished){
state = 1;
}
}
for(FightObject object : objects) {
object.sprite.updateAnimation(deltatime);
}
}
public void draw() {
@ -74,11 +119,11 @@ public class FightScreen {
Gdx.gl.glDisable(GL20.GL_BLEND);
batch.begin();
/*
for(FightObject object : objects) {
object.sprite.draw(batch);
object.sprite.draw(batch);
}
*/
batch.end();
}

@ -158,19 +158,32 @@ public class MapContainer {
}
public void render(float f){
if(Gdx.input.isKeyJustPressed(Input.Keys.TAB)){
ArrayList<Rectangle> mapRectsTemp = new ArrayList<>();
for(Actor a : stage.getActors()){
if(a instanceof MapCollisionObject){
mapRectsTemp.add(((MapCollisionObject)a).r);
if(Main.gamestate == 0){
Main.gamestate = 2;
// CREATING MAP COLLISION OBJECTS
ArrayList<Rectangle> mapRectsTemp = new ArrayList<>();
for(Actor a : stage.getActors()){
if(a instanceof MapCollisionObject){
mapRectsTemp.add(((MapCollisionObject)a).r);
}
}
Rectangle[] rects = new Rectangle[mapRectsTemp.size()];
for(int i = 0; i< mapRectsTemp.size(); i++){
rects[i] = mapRectsTemp.get(i);
}
// CREATING FightObject Array
// Temporarily only Player
FightObject[] fightObjects = {new FightPlayer(getPlayer().getX(),getPlayer().getY(),getPlayer().playerSprite, getPlayer().stats, 0)};
fs = new FightScreen(stage.getBatch(), fightObjects, rects, getPlayer().getX()+32, getPlayer().getY()+32);
}
Rectangle[] rects = new Rectangle[mapRectsTemp.size()];
for(int i = 0; i< mapRectsTemp.size(); i++){
rects[i] = mapRectsTemp.get(i);
else if(Main.gamestate == 2){
Main.gamestate = 0;
fs = null;
}
fs = new FightScreen(stage.getBatch(), null, rects, getPlayer().getX()+32, getPlayer().getY()+32);
}
renderer.setView((OrthographicCamera)stage.getCamera());
@ -195,14 +208,18 @@ public class MapContainer {
}
}
}
if(fs != null){
fs.draw();
}
stage.act(f);
stage.draw();
}
if(Main.gamestate == 2){
fs.act(f);
fs.draw();
}
renderer.render(layersAbovePlayer);
for(Actor a : stage.getActors()){

@ -191,7 +191,7 @@ public class MovingNpc extends Actor{
int animationRow = 0;
if(movementX != 0 || movementY != 0) {
animationRow = 8;
animationRow = 8;
}
animatedSprite.setRow(animationRow + facing);

@ -25,7 +25,7 @@ public class Player extends Actor{
public static final float SQRT2 = 1.414f;
Texture t;
private AnimatedSprite playerSprite;
AnimatedSprite playerSprite;
float movementX = 0;
float movementY = 0;
float speed = 3f;
@ -39,6 +39,8 @@ public class Player extends Actor{
Group questGroup;
Stats stats;
public Player(int xPos, int yPos){
setName("player");
t = new Texture(Gdx.files.internal("textureData/sprites/player.png"));
@ -48,6 +50,8 @@ public class Player extends Actor{
setBounds(xPos, yPos, playerSprite.getSprite().getWidth(), playerSprite.getSprite().getHeight());
quests = new ArrayList<>();
stats = new Stats();
//TEST QUESTS
int[] n = {1, 1};
int[] m = {1, 0};

@ -12,8 +12,6 @@ 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.Matrix4;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
/**
*

Loading…
Cancel
Save