summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7895e46)
raw | patch | inline | side by side (parent: 7895e46)
author | fred-boy <fred-boy@protonmail.com> | |
Fri, 6 Apr 2018 12:16:49 +0000 (19:16 +0700) | ||
committer | fred-boy <fred-boy@protonmail.com> | |
Fri, 6 Apr 2018 12:16:49 +0000 (19:16 +0700) |
diff --git a/core/src/ru/deadsoftware/cavecraft/Assets.java b/core/src/ru/deadsoftware/cavecraft/Assets.java
index 17395b387a392ebc120b298536e86da01f5ae084..fcbfe7a1a1ee8fd345216999555c06c710d0d53e 100644 (file)
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<BLOCK_TEXTURES; i++) {
+ blockTextures[i] = new TextureRegion(terrain,
+ (i%16)*16, (i/16)*16, 16,16);
+ blockTextures[i].flip(false,true);
+ }
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/BlocksLoader.java b/core/src/ru/deadsoftware/cavecraft/BlocksLoader.java
--- /dev/null
@@ -0,0 +1,17 @@
+package ru.deadsoftware.cavecraft;
+
+import com.badlogic.gdx.utils.ArrayMap;
+import ru.deadsoftware.cavecraft.game.objects.Block;
+
+public class BlocksLoader {
+
+ public static ArrayMap<String, Block> BLOCKS = new ArrayMap<String, Block>();
+
+ 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 9ad88f6eb4517c61f7c437ce202a6e5c49158d9c..02d07e212a615d3314ea4cfe283e6fc78e70106c 100644 (file)
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 26b4b6acdc9bfba26fd494d123ef7929c0ffcab2..ff8fa2e89438cec46984e53333740fcc9e72521b 100644 (file)
}
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 631e9d128c4c8b8a55ceab3cd033f8f55a5e16ac..bfde61c6a93f6d503e5d7771a68832d4838319a8 100644 (file)
}
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;
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 b93de89b8d756f9e42470882954f262fa0a03e2d..09a433a81e2f8d9d31702e0f910d66ac670c4e0e 100644 (file)
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;
for (int y=minY; y<maxY; y++) {
for (int x=minX; x<maxX; x++) {
if (gameProc.world.getForeMap(x,y)>0) {
- 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 faf98ed5e50e815b37863bd314f9922c6e83b8ef..96aedf3be559de55122d66030c3c0d6a0c4ee84d 100644 (file)
foreMap = new int[width][height];
backMap = new int[width][height];
for (int x=0; x<width; x++) {
- for (int y=height-16; y<height; y++) {
- foreMap[x][y]=1;
- backMap[x][y]=1;
+ for (int y=height-8; y<height; y++) {
+ if (y==height-8) {
+ foreMap[x][y] = 3;
+ backMap[x][y] = 3;
+ } else if (y<height-4) {
+ foreMap[x][y] = 2;
+ backMap[x][y] = 2;
+ } else {
+ foreMap[x][y] = 1;
+ backMap[x][y] = 1;
+ }
}
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java
--- /dev/null
@@ -0,0 +1,39 @@
+package ru.deadsoftware.cavecraft.game.objects;
+
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.math.Rectangle;
+
+public class Block {
+
+ private Rectangle rect;
+ private TextureRegion texture;
+
+ public Block(int x, int y, int w, int h, TextureRegion texture) {
+ rect = new Rectangle(x,y,w,h);
+ this.texture = texture;
+ }
+
+ public TextureRegion getTexture() {
+ return texture;
+ }
+
+ public Rectangle getRect() {
+ return rect;
+ }
+
+ public int getX() {
+ return (int)rect.x;
+ }
+
+ public int getY() {
+ return (int)rect.y;
+ }
+
+ public int getWidth() {
+ return (int)rect.width;
+ }
+
+ public int getHeight() {
+ return (int)rect.height;
+ }
+}