From: fred-boy Date: Thu, 12 Apr 2018 05:10:44 +0000 (+0700) Subject: Minor enhancements X-Git-Tag: alpha0.1~14 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=503cd1720db3f53b7cbf7e3819968044de29a465;p=cavedroid.git Minor enhancements --- diff --git a/android/assets/char.png b/android/assets/char.png deleted file mode 100644 index f8f6dca..0000000 Binary files a/android/assets/char.png and /dev/null differ diff --git a/android/assets/font.fnt b/android/assets/font.fnt new file mode 100644 index 0000000..586fb37 --- /dev/null +++ b/android/assets/font.fnt @@ -0,0 +1,100 @@ +info face="Minecraft Regular" size=18 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=1,1,1,1 spacing=-2,-2 +common lineHeight=19 base=15 scaleW=512 scaleH=512 pages=1 packed=0 +page id=0 file="font.png" +chars count=95 +char id=10 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=0 page=0 chnl=0 +char id=32 x=0 y=0 width=0 height=0 xoffset=-1 yoffset=17 xadvance=7 page=0 chnl=0 +char id=33 x=472 y=0 width=4 height=15 xoffset=-1 yoffset=4 xadvance=4 page=0 chnl=0 +char id=34 x=349 y=17 width=9 height=8 xoffset=-1 yoffset=4 xadvance=9 page=0 chnl=0 +char id=35 x=114 y=17 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=36 x=92 y=17 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=37 x=103 y=17 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=38 x=125 y=17 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=39 x=358 y=17 width=6 height=8 xoffset=-1 yoffset=4 xadvance=6 page=0 chnl=0 +char id=40 x=491 y=0 width=10 height=15 xoffset=-1 yoffset=4 xadvance=9 page=0 chnl=0 +char id=41 x=501 y=0 width=9 height=15 xoffset=-1 yoffset=4 xadvance=9 page=0 chnl=0 +char id=42 x=379 y=17 width=9 height=7 xoffset=-1 yoffset=8 xadvance=9 page=0 chnl=0 +char id=43 x=327 y=17 width=11 height=11 xoffset=-1 yoffset=6 xadvance=11 page=0 chnl=0 +char id=44 x=364 y=17 width=4 height=7 xoffset=-1 yoffset=14 xadvance=4 page=0 chnl=0 +char id=45 x=405 y=17 width=11 height=4 xoffset=-1 yoffset=10 xadvance=11 page=0 chnl=0 +char id=46 x=388 y=17 width=4 height=6 xoffset=-1 yoffset=13 xadvance=4 page=0 chnl=0 +char id=47 x=57 y=17 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=48 x=461 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=49 x=362 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=50 x=373 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=51 x=384 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=52 x=395 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=53 x=406 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=54 x=417 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=55 x=428 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=56 x=439 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=57 x=450 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=58 x=180 y=17 width=4 height=13 xoffset=-1 yoffset=6 xadvance=4 page=0 chnl=0 +char id=59 x=487 y=0 width=4 height=15 xoffset=-1 yoffset=6 xadvance=4 page=0 chnl=0 +char id=60 x=35 y=17 width=9 height=15 xoffset=-1 yoffset=4 xadvance=9 page=0 chnl=0 +char id=61 x=338 y=17 width=11 height=9 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=62 x=44 y=17 width=9 height=15 xoffset=-1 yoffset=4 xadvance=9 page=0 chnl=0 +char id=63 x=476 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=64 x=68 y=17 width=13 height=15 xoffset=-1 yoffset=4 xadvance=13 page=0 chnl=0 +char id=65 x=11 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=66 x=22 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=67 x=33 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=68 x=44 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=69 x=55 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=70 x=66 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=71 x=77 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=72 x=88 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=73 x=99 y=0 width=7 height=15 xoffset=-1 yoffset=4 xadvance=7 page=0 chnl=0 +char id=74 x=106 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=75 x=117 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=76 x=128 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=77 x=139 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=78 x=150 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=79 x=161 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=80 x=172 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=81 x=183 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=82 x=194 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=83 x=205 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=84 x=216 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=85 x=227 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=86 x=238 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=87 x=249 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=88 x=260 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=89 x=271 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=90 x=282 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=91 x=0 y=17 width=8 height=15 xoffset=-1 yoffset=4 xadvance=7 page=0 chnl=0 +char id=92 x=81 y=17 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=93 x=8 y=17 width=8 height=15 xoffset=-1 yoffset=4 xadvance=8 page=0 chnl=0 +char id=94 x=368 y=17 width=11 height=7 xoffset=-1 yoffset=5 xadvance=11 page=0 chnl=0 +char id=95 x=405 y=17 width=11 height=4 xoffset=-1 yoffset=17 xadvance=11 page=0 chnl=0 +char id=97 x=184 y=17 width=11 height=11 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=98 x=293 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=99 x=195 y=17 width=11 height=11 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=100 x=304 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=101 x=206 y=17 width=11 height=11 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=102 x=315 y=0 width=9 height=15 xoffset=-1 yoffset=4 xadvance=9 page=0 chnl=0 +char id=103 x=136 y=17 width=11 height=13 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=104 x=324 y=0 width=11 height=15 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=105 x=335 y=0 width=4 height=15 xoffset=-1 yoffset=4 xadvance=4 page=0 chnl=0 +char id=106 x=0 y=0 width=11 height=17 xoffset=-1 yoffset=4 xadvance=11 page=0 chnl=0 +char id=107 x=339 y=0 width=9 height=15 xoffset=-1 yoffset=4 xadvance=9 page=0 chnl=0 +char id=108 x=348 y=0 width=6 height=15 xoffset=-1 yoffset=4 xadvance=6 page=0 chnl=0 +char id=109 x=217 y=17 width=11 height=11 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=110 x=228 y=17 width=11 height=11 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=111 x=239 y=17 width=11 height=11 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=112 x=147 y=17 width=11 height=13 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=113 x=158 y=17 width=11 height=13 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=114 x=250 y=17 width=11 height=11 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=115 x=261 y=17 width=11 height=11 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=116 x=354 y=0 width=8 height=15 xoffset=-1 yoffset=4 xadvance=8 page=0 chnl=0 +char id=117 x=272 y=17 width=11 height=11 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=118 x=283 y=17 width=11 height=11 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=119 x=294 y=17 width=11 height=11 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=120 x=305 y=17 width=11 height=11 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=121 x=169 y=17 width=11 height=13 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=122 x=316 y=17 width=11 height=11 xoffset=-1 yoffset=8 xadvance=11 page=0 chnl=0 +char id=123 x=16 y=17 width=10 height=15 xoffset=-1 yoffset=4 xadvance=9 page=0 chnl=0 +char id=124 x=53 y=17 width=4 height=15 xoffset=-1 yoffset=4 xadvance=4 page=0 chnl=0 +char id=125 x=26 y=17 width=9 height=15 xoffset=-1 yoffset=4 xadvance=9 page=0 chnl=0 +char id=126 x=392 y=17 width=13 height=6 xoffset=-1 yoffset=4 xadvance=13 page=0 chnl=0 +kernings count=0 diff --git a/android/assets/font.png b/android/assets/font.png new file mode 100644 index 0000000..e489797 Binary files /dev/null and b/android/assets/font.png differ diff --git a/core/src/ru/deadsoftware/cavecraft/Assets.java b/core/src/ru/deadsoftware/cavecraft/Assets.java index b24356f..3764a58 100644 --- a/core/src/ru/deadsoftware/cavecraft/Assets.java +++ b/core/src/ru/deadsoftware/cavecraft/Assets.java @@ -3,6 +3,7 @@ package ru.deadsoftware.cavecraft; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Animation; +import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureRegion; @@ -10,6 +11,8 @@ public class Assets { public static final int BLOCK_TEXTURES = 3; + public static BitmapFont minecraftFont; + public static Texture charTexture; public static Sprite[][] playerSkin = new Sprite[2][4]; @@ -29,6 +32,7 @@ public class Assets { public static TextureRegion touchSpace; public static void load() { + minecraftFont = new BitmapFont(Gdx.files.internal("font.fnt"), true); charTexture = new Texture(Gdx.files.internal("mobs/char.png")); //LOOK TO LEFT //head diff --git a/core/src/ru/deadsoftware/cavecraft/CaveGame.java b/core/src/ru/deadsoftware/cavecraft/CaveGame.java index 1856a33..50d9447 100644 --- a/core/src/ru/deadsoftware/cavecraft/CaveGame.java +++ b/core/src/ru/deadsoftware/cavecraft/CaveGame.java @@ -4,6 +4,8 @@ import com.badlogic.gdx.Game; public class CaveGame extends Game { + public static final String VERSION = "alpha 0.0"; + public static boolean TOUCH; public CaveGame() { diff --git a/core/src/ru/deadsoftware/cavecraft/GameScreen.java b/core/src/ru/deadsoftware/cavecraft/GameScreen.java index 3301805..f9f42ea 100644 --- a/core/src/ru/deadsoftware/cavecraft/GameScreen.java +++ b/core/src/ru/deadsoftware/cavecraft/GameScreen.java @@ -9,6 +9,8 @@ import ru.deadsoftware.cavecraft.game.GameProc; public class GameScreen implements Screen { + public static int FPS; + private GameProc gameProc; private GameInputHandler gameInput; @@ -35,6 +37,7 @@ public class GameScreen implements Screen { @Override public void render(float delta) { + FPS = (int)(1/delta); gameProc.update(delta); gameProc.renderer.render(); } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index f8843f2..3bd467d 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -3,6 +3,7 @@ package ru.deadsoftware.cavecraft.game; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.math.Vector3; import ru.deadsoftware.cavecraft.game.mobs.Mob; import ru.deadsoftware.cavecraft.game.objects.Player; @@ -19,6 +20,25 @@ public class GamePhysics { gravity = new Vector2(0,1); } + private boolean checkJump(Rectangle rect, int dir) { + int bl; + switch (dir) { + case 0: + bl = gameProc.world.getForeMap( + (int)((rect.x+(rect.width/2))/16) - 1, + (int)(rect.y/16)+1); + break; + case 1: + bl = gameProc.world.getForeMap( + (int)((rect.x+(rect.width/2))/16) + 1, + (int)(rect.y/16)+1); + break; + default: + bl=0; + } + return (bl!=0); + } + private boolean checkColl(Rectangle rect) { int[] bl = new int [6]; bl[0] = gameProc.world.getForeMap(((int)(rect.x)/16), ((int)rect.y/16)); @@ -49,7 +69,7 @@ public class GamePhysics { if (!pl.flyMode) pl.moveY.add(gravity); pl.position.add(pl.moveX); if (pl.position.x<0 || - pl.position.x+pl.width>gameProc.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;