summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e31e819)
raw | patch | inline | side by side (parent: e31e819)
author | fred-boy <fred-boy@protonmail.com> | |
Mon, 1 Oct 2018 08:28:41 +0000 (15:28 +0700) | ||
committer | fred-boy <fred-boy@protonmail.com> | |
Mon, 1 Oct 2018 08:28:41 +0000 (15:28 +0700) |
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
index dc0c93d65c6df3ec56f4a95296653a44c3af8d96..b5c5eab20a717acb6a00c1b7e1263b6026961078 100644 (file)
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);
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 da028621decbfd3cd09fde9ec7549744993944f6..5b497a4ae17b846d794dabf8869940dd48f886d6 100644 (file)
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<Drop>();
mobs = new ArrayList<Mob>();
for (int i = 0; i < 16; i++) {
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) {
}
}
} 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 d84faa32f8b7ae495d0003b1557b3f6c5a363f06..a58a73bb1991fb4a485f806ff61c5df26d118de7 100644 (file)
package ru.deadsoftware.cavecraft.game;
-import com.badlogic.gdx.math.Vector2;
import ru.deadsoftware.cavecraft.game.objects.Drop;
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 478a05b5efec729cf036ebad2cffbea2771a20e0..271be8c88389cc863eb8c897fc9c2696cc97660b 100644 (file)
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;
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 4c7d962ca37c86d2dae698016bd45b83aa350bdc..11838d16195e8a3bf5e4c7faad17126704afc85a 100644 (file)
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;
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() {