From: fred-boy Date: Mon, 1 Oct 2018 08:28:41 +0000 (+0700) Subject: Fix bugs X-Git-Tag: alpha0.4~75 X-Git-Url: http://deadsoftware.ru/gitweb?p=cavedroid.git;a=commitdiff_plain;h=d7f5950fc751cec8fa64005dd1886cac4081ee99 Fix bugs --- diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index dc0c93d..b5c5eab 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -71,6 +71,9 @@ public class GamePhysics { if (drop.closeToPlayer(gp) > 0) { drop.moveToPlayer(gp); } else { + if (drop.move.x >= .5f) drop.move.x -= .5f; + else if (drop.move.x <= -.5f) drop.move.x += .5f; + else drop.move.x = 0; if (drop.move.y < 9) drop.move.y += gravity.y / 4; } drop.pos.add(drop.move); @@ -128,7 +131,7 @@ public class GamePhysics { if (pl.pos.x + pl.texWidth / 2 > gp.world.getWidth() * 16) pl.pos.x -= gp.world.getWidth() * 16; if (pl.pos.y > gp.world.getHeight() * 16) { - pl.pos = gp.world.getSpawnPoint().cpy(); + pl.respawn(gp.world); } if (CaveGame.TOUCH && checkJump(pl.getRect(), pl.dir) && !pl.flyMode && pl.canJump && pl.move.x != 0) { pl.move.add(0, -8); diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index da02862..5b497a4 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -47,7 +47,7 @@ public class GameProc implements Serializable { public GameProc(int gameMode) { world = new GameWorld(); world.generate(1024, 256); - player = new Player(world.getSpawnPoint(), gameMode); + player = new Player(world, gameMode); drops = new ArrayList(); mobs = new ArrayList(); for (int i = 0; i < 16; i++) { @@ -410,7 +410,9 @@ public class GameProc implements Serializable { if (isTouchDown && touchDownBtn == Input.Buttons.LEFT) { if ((world.getForeMap(curX, curY) > 0 && GameItems.getBlock(world.getForeMap(curX, curY)).getHp() >= 0) || - world.getBackMap(curX, curY) > 0 && GameItems.getBlock(world.getBackMap(curX, curY)).getHp() >= 0) { + (world.getForeMap(curX, curY) == 0 && + world.getBackMap(curX, curY) > 0 && + GameItems.getBlock(world.getBackMap(curX, curY)).getHp() >= 0)) { if (player.gameMode == 0) { blockDmg++; if (world.getForeMap(curX, curY) > 0) { @@ -425,8 +427,8 @@ public class GameProc implements Serializable { } } } else { - if (world.getForeMap(curX, curY) > 0) world.setForeMap(curX, curY, 0); - else if (world.getBackMap(curX, curY) > 0) world.setBackMap(curX, curY, 0); + if (world.getForeMap(curX, curY) > 0) world.placeToForeground(curX, curY, 0); + else if (world.getBackMap(curX, curY) > 0) world.placeToBackground(curX, curY, 0); isTouchDown = false; } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java index d84faa3..a58a73b 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java @@ -1,6 +1,5 @@ package ru.deadsoftware.cavecraft.game; -import com.badlogic.gdx.math.Vector2; import ru.deadsoftware.cavecraft.game.objects.Drop; public class GameWorld { @@ -124,17 +123,6 @@ public class GameWorld { placeToBackground(x, y, 0); } - public Vector2 getSpawnPoint() { - int x = 0, y = 0; - while (true) { - y++; - if (getForeMap(x, y) > 0 && GameItems.getBlock(getForeMap(x, y)).coll) break; - } - x = x * 16 + 4; - y = y * 16 - 32; - return new Vector2(x, y); - } - public void generate(int w, int h) { WIDTH = w; HEIGHT = h; diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java index 478a05b..271be8c 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java @@ -31,8 +31,8 @@ public class Drop implements Serializable { public void moveToPlayer(GameProc gp) { int ctp = closeToPlayer(gp); if (ctp > 0) { - float px = gp.player.pos.x + (gp.player.texWidth / 2); - float py = gp.player.pos.y + (gp.player.height / 2); + float px = gp.player.pos.x; + float py = gp.player.pos.y; switch (ctp) { case 2: px += gp.world.getWidth() * 16; @@ -42,15 +42,15 @@ public class Drop implements Serializable { break; } float dx = 0, dy = 0; - if (px < pos.x + 4) dx = -.5f; + if (px + gp.player.texWidth < pos.x + 4) dx = -.5f; else if (px > pos.x + 4) dx = .5f; - if (py < pos.y + 4) dy = -.5f; + if (py + gp.player.height < pos.y + 4) dy = -.5f; else if (py > pos.y + 4) dy = .5f; move.add(dx, dy); -// if (move.x > 2) move.x = 2; -// if (move.x < -2) move.x = -2; -// if (move.y > 2) move.y = 2; -// if (move.y < -2) move.y = -2; + if (move.x > 2) move.x = 1; + if (move.x < -2) move.x = -1; + if (move.y > 2) move.y = 1; + if (move.y < -2) move.y = -1; } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java index 4c7d962..11838d1 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java @@ -2,6 +2,8 @@ package ru.deadsoftware.cavecraft.game.objects; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; +import ru.deadsoftware.cavecraft.game.GameItems; +import ru.deadsoftware.cavecraft.game.GameWorld; import java.io.Serializable; @@ -11,20 +13,42 @@ public class Player implements Serializable { public Vector2 pos; public Vector2 move; - public int width, height, dir, texWidth; + public int width, height, dir, texWidth, hp; public boolean canJump; public int[] inv; public boolean flyMode = false; public int gameMode; - public Player(Vector2 spawnPoint, int gameMode) { + public Player(GameWorld world, int gameMode) { this.gameMode = gameMode; - pos = spawnPoint.cpy(); + pos = getSpawnPoint(world).cpy(); move = new Vector2(0, 0); width = 4; height = 30; texWidth = 8; inv = new int[9]; + hp = 20; + } + + public void respawn(GameWorld world) { + pos.set(getSpawnPoint(world)); + move.setZero(); + hp = 20; + } + + private Vector2 getSpawnPoint(GameWorld world) { + int x = 0, y; + for (y = 0; y < world.getHeight(); y++) { + if (y == world.getHeight() - 1) { + y = 60; + world.setForeMap(x, y, 1); + break; + } + if (world.getForeMap(x, y) > 0 && GameItems.getBlock(world.getForeMap(x, y)).coll) break; + } + x = x * 16 + texWidth / 2; + y = y * 16 - height; + return new Vector2(x, y); } public Rectangle getRect() {