diff --git a/core/src/com/trs/main/Enemy.java b/core/src/com/trs/main/Enemy.java new file mode 100644 index 0000000..ad4c02c --- /dev/null +++ b/core/src/com/trs/main/Enemy.java @@ -0,0 +1,8 @@ +package com.trs.main; + +public class Enemy extends FightObject{ + + public Enemy(AnimatedSprite sprite, Stats stats, int id) { + super(sprite, stats, id); + } +} diff --git a/core/src/com/trs/main/FightObject.java b/core/src/com/trs/main/FightObject.java new file mode 100644 index 0000000..241b0a3 --- /dev/null +++ b/core/src/com/trs/main/FightObject.java @@ -0,0 +1,15 @@ +package com.trs.main; + +public abstract class FightObject { + protected AnimatedSprite sprite; + protected Stats stats; + protected int id; + protected int x; + protected int y; + + public FightObject(AnimatedSprite sprite, Stats stats, int id) { + this.sprite = sprite; + this.stats = stats; + this.id = id; + } +} diff --git a/core/src/com/trs/main/FightPlayer.java b/core/src/com/trs/main/FightPlayer.java new file mode 100644 index 0000000..83c5b03 --- /dev/null +++ b/core/src/com/trs/main/FightPlayer.java @@ -0,0 +1,8 @@ +package com.trs.main; + +public class FightPlayer extends FightObject{ + + public FightPlayer(AnimatedSprite sprite, Stats stats, int id) { + super(sprite, stats, id); + } +} diff --git a/core/src/com/trs/main/FightScreen.java b/core/src/com/trs/main/FightScreen.java new file mode 100644 index 0000000..fa5b683 --- /dev/null +++ b/core/src/com/trs/main/FightScreen.java @@ -0,0 +1,94 @@ +package com.trs.main; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.GL20; +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.math.Vector2; + +public class FightScreen { + + final int gridWidth = 20; + final int gridHeight = 12; + + Batch batch; + ShapeRenderer renderer; + FightObject[] objects; + Rectangle[] collisionRects; + + Vector2 gridPos; + + // 0: player turn, 1: enemy turn, 2: fight ends + int state = 0; + + public FightScreen(Batch batch, FightObject[] objects, Rectangle[] collisionRects, float camX, float camY) { + this.batch = batch; + this.objects = objects; + this.collisionRects = collisionRects; + this.renderer = new ShapeRenderer(); + + gridPos = new Vector2(); + + 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; + + /* + for(int j = 0; j < objects.length-1; j++){ + for(int i = objects.length-1; i >= 0; i--){ + if(i > 0 && objects[i].stats.getInit() > objects[i-1].stats.getInit()){ + FightObject temp = objects[i-1]; + objects[i-1] = objects[i]; + objects[i] = temp; + } + } + }*/ + } + + public void act(float deltatime) { + + } + + public void draw() { + + renderer.setProjectionMatrix(batch.getProjectionMatrix()); + renderer.setColor(0.6f, 0.6f, 0.6f, 1f); + Gdx.gl.glEnable(GL20.GL_BLEND); + Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); + renderer.begin(ShapeRenderer.ShapeType.Line); + + for(int i = 0; i < gridWidth; i++){ + for(int j = 0; j < gridHeight; j++){ + Rectangle r = new Rectangle(gridPos.x+i*32, gridPos.y+j*32, 32, 32); + if(!collidingMapObject(r)){ + renderer.rect(r.x, r.y, r.width, r.height); + } + } + } + + renderer.end(); + Gdx.gl.glDisable(GL20.GL_BLEND); + + batch.begin(); + /* + for(FightObject object : objects) { + object.sprite.draw(batch); + } + */ + batch.end(); + } + + public boolean collidingMapObject(Rectangle r){ + for(Rectangle rect : collisionRects){ + if(Intersector.overlaps(r, rect)){ + return true; + } + } + return false; + } + +} diff --git a/core/src/com/trs/main/MapContainer.java b/core/src/com/trs/main/MapContainer.java index b93464d..71a20c4 100644 --- a/core/src/com/trs/main/MapContainer.java +++ b/core/src/com/trs/main/MapContainer.java @@ -1,6 +1,7 @@ package com.trs.main; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; import java.util.ArrayList; import com.badlogic.gdx.graphics.OrthographicCamera; @@ -49,6 +50,8 @@ public class MapContainer { Door[] doors; public Door collidingDoor; + FightScreen fs; + TransitionScreen t; final int[] layersBelowPlayer = {0, 1, 2}; @@ -67,6 +70,7 @@ public class MapContainer { t = new TransitionScreen(0.01f); + //CREATION OF TILEDMAP maploader = new TmxMapLoader(); map = maploader.load(mapString); @@ -154,29 +158,50 @@ public class MapContainer { } public void render(float f){ + + if(Gdx.input.isKeyJustPressed(Input.Keys.TAB)){ + ArrayList 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); + } + fs = new FightScreen(stage.getBatch(), null, rects, getPlayer().getX()+32, getPlayer().getY()+32); + } + renderer.setView((OrthographicCamera)stage.getCamera()); renderer.render(layersBelowPlayer); - Actor[] old = stage.getActors().toArray(); - stage.clear(); - for(Actor a : sort(old)){ - stage.addActor(a); - } - for(Actor a : stage.getActors()) { - if(a instanceof Player) { - Rectangle rect = ((Player) a).collisionRect; - - for(Door d : doors) { - if(Intersector.overlaps(rect, d.rect)) { - collidingDoor = d; - break; - } - } + if(Main.gamestate == 0) { + Actor[] old = stage.getActors().toArray(); + stage.clear(); + for(Actor a : sort(old)){ + stage.addActor(a); } + for(Actor a : stage.getActors()) { + if(a instanceof Player) { + Rectangle rect = ((Player) a).collisionRect; + + for(Door d : doors) { + if(Intersector.overlaps(rect, d.rect)) { + collidingDoor = d; + break; + } + } + } + } + if(fs != null){ + fs.draw(); + } + + stage.act(f); + stage.draw(); } - stage.act(f); - stage.draw(); renderer.render(layersAbovePlayer); diff --git a/core/src/com/trs/main/Stats.java b/core/src/com/trs/main/Stats.java new file mode 100644 index 0000000..1b116c2 --- /dev/null +++ b/core/src/com/trs/main/Stats.java @@ -0,0 +1,54 @@ +package com.trs.main; + +public class Stats { + private int level; + private int hp; + private int def; + private int atk; + private int init; + + public Stats() { + + } + + public int getLevel() { + return level; + } + + public void setLevel(int level) { + this.level = level; + } + + public int getHp() { + return hp; + } + + public void setHp(int hp) { + this.hp = hp; + } + + public int getDef() { + return def; + } + + public void setDef(int def) { + this.def = def; + } + + public int getAtk() { + return atk; + } + + public void setAtk(int atk) { + this.atk = atk; + } + + public int getInit() { + return init; + } + + public void setInit(int init) { + this.init = init; + } + +} diff --git a/desktop/src/com/trs/main/desktop/DesktopLauncher.java b/desktop/src/com/trs/main/desktop/DesktopLauncher.java index 1c77c14..160e76b 100644 --- a/desktop/src/com/trs/main/desktop/DesktopLauncher.java +++ b/desktop/src/com/trs/main/desktop/DesktopLauncher.java @@ -13,7 +13,7 @@ public class DesktopLauncher { config.height=720; config.fullscreen = false; - //config.width=1920; + //config.width=1920; //config.height=1080; //config.fullscreen = true; new LwjglApplication(new Main(), config);