From 503cd1720db3f53b7cbf7e3819968044de29a465 Mon Sep 17 00:00:00 2001 From: fred-boy Date: Thu, 12 Apr 2018 12:10:44 +0700 Subject: [PATCH] Minor enhancements --- android/assets/char.png | Bin 616 -> 0 bytes android/assets/font.fnt | 100 ++++++++++++++++++ android/assets/font.png | Bin 0 -> 3097 bytes .../src/ru/deadsoftware/cavecraft/Assets.java | 4 + .../ru/deadsoftware/cavecraft/CaveGame.java | 2 + .../ru/deadsoftware/cavecraft/GameScreen.java | 3 + .../cavecraft/game/GamePhysics.java | 54 +++++----- .../deadsoftware/cavecraft/game/GameProc.java | 4 +- .../cavecraft/game/GameRenderer.java | 37 +++++-- .../deadsoftware/cavecraft/game/WorldGen.java | 18 +++- .../cavecraft/game/mobs/Human.java | 39 ++++--- .../deadsoftware/cavecraft/game/mobs/Mob.java | 2 +- .../cavecraft/game/objects/Player.java | 4 +- 13 files changed, 216 insertions(+), 51 deletions(-) delete mode 100644 android/assets/char.png create mode 100644 android/assets/font.fnt create mode 100644 android/assets/font.png diff --git a/android/assets/char.png b/android/assets/char.png deleted file mode 100644 index f8f6dca209d4d4200613a120171f8c88db5baba7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 616 zcmV-u0+;=XP)1gx5QV?{v%85?*!)Bm(15@NNGK#A0qODrDR}@y#T!tC zRJ;KNLiD@?QY0h_3X~#J1YJrjqF_gg&FsPc)zz#kbqVJhIgPmd4M1q?}Zmz4_IAU;lr1G^!7%J%sG74XE|9a zwk4)w0S1DwoGjt9KACfDZ?rJ$*RQ-*I94xRX7gSPr8Pf)cL)-&#-g<*NFXwXr+07j zY;%oTWH~uK<)oWpMS+bIqA0@qlqa`tuzBYi!8wjQoif1HMuX!{2k|M+d2E~@Dj)jN zot@GDx4S!f2~%`i67BZ6*lboG!k}hI*K?cZK+i9kjq(%T9(^v!?%@Hi#tPpYexhEB zi^`>7%bX6VK7MX zUk0;KWj?WkMPbK@dh=WH@V%PvwjWj-l#O#RKHx95&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-IPIe9Z=0b4DK%S|=iq@UR66iyu`Qm!}ClVd1t#5Js1rH#T(f zuwi_|$Ko@f8X2;p;^bkj8WD7$AO~Mr%sOIyd6W9K;O||Boxo{UVM@{sHcw1vCh6?LRnYWyi|!=jxEJCIzmY; zar4E_ZV2zu?t?&mN@lgsu;27eaKWO49UU9BE5Be+7qo1yecf1WT|0h9^6jS`fDR+k zjgiYoP}0C5*Udu`bX^{EP*V*Qs$^jiAX`NCOk2l780Z0bBFDG1cVb&laJW?y-?rlk zx8fesH~sWO{1)@$CBQ&mssR1F&_8tJ!R`9(=5(5Y7Tdwxwh$9(K+T~CLPHWCl zJzX9y%mmaed$#K#(6V-?RvyUTIxT18E5~S1(q};zB14R$@BF&n4fbDzc%iM>t(o@% zIJfEB0KCv0ApPpP7;>LP38o#(=3V!m`{7O|t^~l1})Dl4!4C07_ac zh4{fp+-NKD>)BTw7QWw1)VMlc(mF=8{pnmR#KugiGMLn?2r$mDU_*!ZKLSL`Fp^V3 z{F+he(nzc1KP5m%qYCaz%SPIf)%Ij!*OO0d4-t5!f14ZQ)usgameProc.world.getWidth()*16) + pl.position.x+pl.texWidth>=gameProc.world.getWidth()*16) pl.position.sub(pl.moveX); if (checkColl(pl.getRect())) { int d = 0; @@ -57,18 +77,11 @@ public class GamePhysics { pl.position.x = MathUtils.round(pl.position.x); while (checkColl(pl.getRect())) pl.position.x+=d; } - switch (pl.dir) { - case 0: - gameProc.renderer.camTargetPos.x = pl.position.x-gameProc.renderer.camera.viewportWidth+100; - break; - case 1: - gameProc.renderer.camTargetPos.x = pl.position.x-100; - break; + + if (checkJump(pl.getRect(), pl.dir) && !pl.flyMode && pl.canJump && !pl.moveX.equals(Vector2.Zero)) { + pl.moveY.add(0, -8); + pl.canJump = false; } - if (gameProc.renderer.camTargetPos.x < 0) gameProc.renderer.camTargetPos.x = 0; - if (gameProc.renderer.camTargetPos.x + gameProc.renderer.camera.viewportWidth > - gameProc.world.getWidth()*16) - gameProc.renderer.camTargetPos.x = gameProc.world.getWidth()*16-gameProc.renderer.camera.viewportWidth; } private void mobPhy(Mob mob) { @@ -104,18 +117,11 @@ public class GamePhysics { } playerPhy(gameProc.player); - if (gameProc.renderer.camera.position.x - gameProc.renderer.camTargetPos.x <= 8 && - gameProc.renderer.camera.position.x - gameProc.renderer.camTargetPos.x >= -8) { - gameProc.renderer.camera.position.x = gameProc.renderer.camTargetPos.x; - } - if (gameProc.renderer.camera.position.x > gameProc.renderer.camTargetPos.x) { - gameProc.renderer.camera.position.sub(16,0,0); - } - if (gameProc.renderer.camera.position.x < gameProc.renderer.camTargetPos.x) { - gameProc.renderer.camera.position.add(16,0,0); - } - gameProc.renderer.camera.position.y = gameProc.player.position.y+gameProc.player.height/2 - -gameProc.renderer.camera.viewportHeight/2; + gameProc.renderer.camera.position.set( + gameProc.player.position.x+gameProc.player.texWidth/2 - gameProc.renderer.camera.viewportWidth/2, + gameProc.player.position.y+gameProc.player.height/2-gameProc.renderer.camera.viewportHeight/2, + 0 + ); } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index 4c63912..fd6d0fe 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -32,9 +32,7 @@ public class GameProc { physics = new GamePhysics(this); player = new Player(); mobs = new Array(); - for (int i=0; i<6; i++) { - mobs.add(new Human(64*(i+1),0, this)); - } + } public void resetRenderer() { diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java index 59557a2..cc3bcde 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java @@ -19,10 +19,9 @@ public class GameRenderer { private GameProc gameProc; - public Vector3 camTargetPos; - public OrthographicCamera camera; + public OrthographicCamera camera, fontCam; ShapeRenderer shapeRenderer; - SpriteBatch spriteBatch; + SpriteBatch spriteBatch, fontBatch; public GameRenderer(GameProc gameProc) { Gdx.gl.glClearColor(0f,.6f,.6f,1f); @@ -30,14 +29,25 @@ public class GameRenderer { camera = new OrthographicCamera(); camera.setToOrtho(true, 360, 360*((float)GameScreen.getHeight()/GameScreen.getWidth())); - camera.position.x=0; - camera.position.y=0; - camTargetPos = camera.position.cpy(); + shapeRenderer = new ShapeRenderer(); shapeRenderer.setProjectionMatrix(camera.combined); shapeRenderer.setAutoShapeType(true); spriteBatch = new SpriteBatch(); spriteBatch.setProjectionMatrix(camera.combined); + + fontCam = new OrthographicCamera(); + fontCam.setToOrtho(true, GameScreen.getWidth(), GameScreen.getHeight()); + fontBatch = new SpriteBatch(); + fontBatch.setProjectionMatrix(fontCam.combined); + } + + private void setFontColor(int r, int g, int b) { + Assets.minecraftFont.setColor(r/255f, g/255f, b/255f, 1f); + } + + private void drawString(String str, float x, float y) { + Assets.minecraftFont.draw(fontBatch, str, x, y); } private void drawWorld() { @@ -72,7 +82,7 @@ public class GameRenderer { } private void drawPlayer(Player pl) { - if (!pl.moveX.equals(Vector2.Zero)) { + if (!pl.moveX.equals(Vector2.Zero) || Assets.playerSkin[0][2].getRotation()!=0) { Assets.playerSkin[0][2].rotate(Mob.ANIM_SPEED); Assets.playerSkin[1][2].rotate(-Mob.ANIM_SPEED); Assets.playerSkin[0][3].rotate(-Mob.ANIM_SPEED); @@ -156,6 +166,19 @@ public class GameRenderer { gameProc.cursorY * 16 - camera.position.y, 16, 16); shapeRenderer.end(); } + + fontBatch.begin(); + setFontColor(255,255,255); + drawString("CaveCraft "+CaveGame.VERSION, 0, 0); + drawString("FPS: "+GameScreen.FPS, 0, 20); + drawString("X: "+(int)(gameProc.player.position.x/16), 0, 40); + drawString("Y: "+(int)(gameProc.player.position.y/16), 0, 60); + drawString("Block: "+ + Items.BLOCKS.keys().toArray().get(gameProc.world.getForeMap( + (int)(gameProc.player.position.x/16), + (int)(gameProc.player.position.y/16+2))), + 0, 80); + fontBatch.end(); } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java index 9f6e693..5bc94ff 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java +++ b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java @@ -5,11 +5,17 @@ import com.badlogic.gdx.utils.TimeUtils; public class WorldGen { + private static RandomXS128 rand; + private static long seed; + private static int[][] foreMap, backMap; private static int[] hMap; + public static long getSeed() { + return seed; + } + static int[] genLandscape(int width, int mid, int min, int max) { - RandomXS128 rand = new RandomXS128(TimeUtils.millis()); int[] res = new int[width]; int t; res[0] = mid; @@ -23,15 +29,23 @@ public class WorldGen { } static void genWorld(int width, int height) { + genWorld(width, height, TimeUtils.millis()); + } + + static void genWorld(int width, int height, long s) { + int dirtH; + seed = s; + rand = new RandomXS128(seed); foreMap = new int[width][height]; backMap = new int[width][height]; hMap = genLandscape(width, height/2, height/4, height/4*3); for (int x=0; x=60 || Assets.playerSkin[0][2].getRotation()<=-60) + if (moveX.x!=0) { + animation+=Mob.ANIM_SPEED*anim_d; + if (animation<=-60 || animation>=60) anim_d=-anim_d; + } + tex[0][2].setRotation(animation); + tex[1][2].setRotation(-animation); + tex[0][3].setRotation(-animation); + tex[1][3].setRotation(animation); + spriteBatch.draw(tex[dir][0], x-2, y-2); + if (tex[0][2].getRotation()>=60 || tex[0][2].getRotation()<=-60) Mob.ANIM_SPEED = -Mob.ANIM_SPEED; - Assets.playerSkin[1][2].setPosition(x-6,y); - Assets.playerSkin[1][2].draw(spriteBatch); - Assets.playerSkin[1][3].setPosition(x-6, y+10); - Assets.playerSkin[1][3].draw(spriteBatch); - Assets.playerSkin[0][3].setPosition(x-6, y+10); - Assets.playerSkin[0][3].draw(spriteBatch); - spriteBatch.draw(Assets.playerSkin[dir][1], x-2, y + 8); - - Assets.playerSkin[0][2].setPosition(x-6, y); - Assets.playerSkin[0][2].draw(spriteBatch); + tex[1][2].setPosition(x-6,y); + tex[1][2].draw(spriteBatch); + tex[1][3].setPosition(x-6, y+10); + tex[1][3].draw(spriteBatch); + tex[0][3].setPosition(x-6, y+10); + tex[0][3].draw(spriteBatch); + spriteBatch.draw(tex[dir][1], x-2, y + 8); + + tex[0][2].setPosition(x-6, y); + tex[0][2].draw(spriteBatch); } public Rectangle getRect() { diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java index a4dca28..e0ff0e2 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java @@ -10,7 +10,7 @@ public abstract class Mob { public Vector2 position; public Vector2 moveX, moveY; - public int width, height, dir; + public int width, height, dir, animation, anim_d; public boolean canJump; public abstract void ai(); diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java index 56aa9c1..1dc516b 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java @@ -2,12 +2,13 @@ package ru.deadsoftware.cavecraft.game.objects; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; +import ru.deadsoftware.cavecraft.Assets; public class Player { public Vector2 position; public Vector2 moveX, moveY; - public int width, height, dir; + public int width, height, dir, texWidth; public boolean canJump; public int[] inventory; public boolean flyMode = false; @@ -18,6 +19,7 @@ public class Player { moveY = new Vector2(0, 0); width = 4; height = 30; + texWidth = 8; inventory = new int[9]; inventory[0] = 1; inventory[1] = 2; -- 2.29.2