From: fred-boy Date: Fri, 6 Apr 2018 12:16:49 +0000 (+0700) Subject: Add different blocks X-Git-Tag: alpha0.1~24 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=f988ac987aae5e7dd99721ca4cf044d061153e89;p=cavedroid.git Add different blocks --- diff --git a/core/src/ru/deadsoftware/cavecraft/Assets.java b/core/src/ru/deadsoftware/cavecraft/Assets.java index 17395b3..fcbfe7a 100644 --- a/core/src/ru/deadsoftware/cavecraft/Assets.java +++ b/core/src/ru/deadsoftware/cavecraft/Assets.java @@ -7,15 +7,31 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; public class Assets { + public static final int BLOCK_TEXTURES = 3; + public static Texture charTexture; public static Sprite[] playerSprite = new Sprite[2]; + public static Sprite shade; + + public static Texture terrain; + public static TextureRegion[] blockTextures = new TextureRegion[BLOCK_TEXTURES]; + public static void load() { charTexture = new Texture(Gdx.files.internal("char.png")); playerSprite[0] = new Sprite(new TextureRegion(charTexture, 0,0,8,30)); playerSprite[0].flip(false,true); playerSprite[1] = new Sprite(new TextureRegion(charTexture, 8,0,8,30)); playerSprite[1].flip(false,true); + + shade = new Sprite(new Texture(Gdx.files.internal("shade.png"))); + + terrain = new Texture(Gdx.files.internal("terrain.png")); + for (int i=0; i BLOCKS = new ArrayMap(); + + public static void load() { + BLOCKS.put("none", null); + BLOCKS.put("stone", new Block(0,0,16,16,Assets.blockTextures[0])); + BLOCKS.put("dirt", new Block(0,0,16,16,Assets.blockTextures[1])); + BLOCKS.put("grass", new Block(0,0,16,16,Assets.blockTextures[2])); + } + +} diff --git a/core/src/ru/deadsoftware/cavecraft/GameScreen.java b/core/src/ru/deadsoftware/cavecraft/GameScreen.java index 9ad88f6..02d07e2 100644 --- a/core/src/ru/deadsoftware/cavecraft/GameScreen.java +++ b/core/src/ru/deadsoftware/cavecraft/GameScreen.java @@ -14,6 +14,7 @@ public class GameScreen implements Screen { public GameScreen() { Assets.load(); + BlocksLoader.load(); gameProc = new GameProc(); gameInput = new GameInputHandler(gameProc); Gdx.input.setInputProcessor(new InputHandler()); diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java b/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java index 26b4b6a..ff8fa2e 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java @@ -67,11 +67,11 @@ public class GameInputHandler { } public void touchDragged(int screenX, int screenY) { - gameProc.renderer.camera.position.x += (gameProc.touchDownX-screenX); + /*gameProc.renderer.camera.position.x += (gameProc.touchDownX-screenX); gameProc.renderer.camera.position.y += (gameProc.touchDownY-screenY); gameProc.touchDownX = screenX; gameProc.touchDownY = screenY; - gameProc.isTouchDown = false; + gameProc.isTouchDown = false;*/ } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index 631e9d1..bfde61c 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -34,20 +34,10 @@ public class GamePhysics { } private void movePlayer(Player pl) { - pl.position.add(pl.moveX); - if (pl.position.x<0 || - pl.position.x+pl.width>gameProc.world.getWidth()*16) - pl.position.sub(pl.moveX); - if (checkColl(pl.getRect())) { - int d = 0; - if (pl.moveX.x<0) d=1; else if (pl.moveX.x>0) d=-1; - pl.position.x = MathUtils.round(pl.position.x); - while (checkColl(pl.getRect())) pl.position.x+=d; - } pl.position.add(pl.moveY); if (checkColl(pl.getRect())) { pl.canJump = true; - float d = 0; + int d = -1; if (pl.moveY.y<0) d=1; else if (pl.moveY.y>0) d=-1; pl.position.y = MathUtils.round(pl.position.y); while (checkColl(pl.getRect())) pl.position.y+=d; @@ -56,6 +46,16 @@ public class GamePhysics { pl.canJump = false; } 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.sub(pl.moveX); + if (checkColl(pl.getRect())) { + int d = 0; + if (pl.moveX.x<0) d=1; else if (pl.moveX.x>0) d=-1; + 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; diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java index b93de89..09a433a 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java @@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector3; import ru.deadsoftware.cavecraft.Assets; +import ru.deadsoftware.cavecraft.BlocksLoader; import ru.deadsoftware.cavecraft.GameScreen; import ru.deadsoftware.cavecraft.game.objects.Player; @@ -63,44 +64,37 @@ public class GameRenderer { for (int y=minY; y0) { - setColor(128,128,128); - fillRect(x*16-camera.position.x, - y*16-camera.position.y,16,16); - setColor(0,0,0); - drawRect(x*16-camera.position.x, - y*16-camera.position.y,16,16); - } else { - if (gameProc.world.getBackMap(x,y)>0) { - setColor(64,64,64); - fillRect(x*16-camera.position.x, - y*16-camera.position.y,16,16); - setColor(0,0,0); - drawRect(x*16-camera.position.x, - y*16-camera.position.y,16,16); - } + spriteBatch.draw( + BlocksLoader.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture(), + x * 16 - camera.position.x,y * 16 - camera.position.y); + } else if (gameProc.world.getBackMap(x,y)>0) { + spriteBatch.draw( + BlocksLoader.BLOCKS.getValueAt(gameProc.world.getBackMap(x,y)).getTexture(), + x * 16 - camera.position.x,y * 16 - camera.position.y); + Assets.shade.setPosition(x * 16 - camera.position.x,y * 16 - camera.position.y); + Assets.shade.draw(spriteBatch); } - } } - shapeRenderer.setColor(Color.ORANGE); - drawRect(gameProc.cursorX*16-camera.position.x, - gameProc.cursorY*16-camera.position.y,16,16); } private void drawPlayer(Player pl) { - spriteBatch.begin(); Assets.playerSprite[pl.dir].setPosition(pl.position.x - camera.position.x, pl.position.y - camera.position.y); Assets.playerSprite[pl.dir].draw(spriteBatch); - spriteBatch.end(); } public void render() { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - shapeRenderer.begin(); + spriteBatch.begin(); drawWorld(); - shapeRenderer.end(); drawPlayer(gameProc.player); + spriteBatch.end(); + shapeRenderer.begin(ShapeRenderer.ShapeType.Line); + shapeRenderer.setColor(Color.ORANGE); + drawRect(gameProc.cursorX*16-camera.position.x, + gameProc.cursorY*16-camera.position.y,16,16); + shapeRenderer.end(); } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java index faf98ed..96aedf3 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java +++ b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java @@ -8,9 +8,17 @@ public class WorldGen { foreMap = new int[width][height]; backMap = new int[width][height]; for (int x=0; x