summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: be2690f)
raw | patch | inline | side by side (parent: be2690f)
author | fred-boy <fred-boy@protonmail.com> | |
Sun, 30 Sep 2018 16:16:38 +0000 (23:16 +0700) | ||
committer | fred-boy <fred-boy@protonmail.com> | |
Sun, 30 Sep 2018 16:16:38 +0000 (23:16 +0700) |
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameItems.java b/core/src/ru/deadsoftware/cavecraft/game/GameItems.java
index 6a39f0584613c169209904777d032ef6a8ce0552..52c2e75a2af1cd52fa7bee88d710f3e0e6abac76 100644 (file)
//5
blocks.put("planks", new Block(4, 180, 5));
//6
- blocks.put("sapling", new Block(5, 0, 6, false, false, true));
+ blocks.put("sapling", new Block(5, 0, 6, false, false, true, true));
//7
blocks.put("bedrock", new Block(6, -1, 7));
//8
//25
blocks.put("cobweb", new Block(24, 1200, 0, false, false, true));
//26
- blocks.put("tallgrass", new Block(25, 0, 0, false, false, true));
+ blocks.put("tallgrass", new Block(25, 0, 0, false, false, true, true));
//27
- blocks.put("deadbush", new Block(26, 0, 0, false, false, true));
+ blocks.put("deadbush", new Block(26, 0, 0, false, false, true, true));
//28
blocks.put("brick_block", new Block(27, 600, 22));
//29
- blocks.put("dandelion", new Block(28, 0, 23, false, false, true));
+ blocks.put("dandelion", new Block(28, 0, 23, false, false, true, true));
//30
- blocks.put("rose", new Block(29, 0, 24, false, false, true));
+ blocks.put("rose", new Block(29, 0, 24, false, false, true, true));
//31
- blocks.put("brown_mushroom", new Block(30, 0, 25, false, false, true));
+ blocks.put("brown_mushroom", new Block(30, 0, 25, false, false, true, true));
//32
- blocks.put("red_mushroom", new Block(31, 0, 26, false, false, true));
+ blocks.put("red_mushroom", new Block(31, 0, 26, false, false, true, true));
//33
blocks.put("wool_while", new Block(32, 75, 27, true, false, false));
//34
//58
blocks.put("stone_brick_slab", new Block(0, 8, 16, 8, 56, 450, 51, true, false, true));
//59
- blocks.put("cactus", new Block(1, 0, 14, 16, 57, 39, 52, true, false, true));
+ blocks.put("cactus", new Block(1, 0, 14, 16, 57, 39, 52, true, false, true, true));
//60
blocks.put("water_16", new Block(7, -1, 0, false, false, true));
//61
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
index d314b82cda6929bd1581d373294e52e08bfdcca3..dc0c93d65c6df3ec56f4a95296653a44c3af8d96 100644 (file)
}
private void dropPhy(Drop drop) {
- if (drop.move.y < 9) drop.move.y += gravity.y / 4;
+ if (drop.closeToPlayer(gp) > 0) {
+ drop.moveToPlayer(gp);
+ } else {
+ if (drop.move.y < 9) drop.move.y += gravity.y / 4;
+ }
drop.pos.add(drop.move);
+ if (drop.pos.x + 8 > gp.world.getWidth() * 16) drop.pos.x -= gp.world.getWidth() * 16;
+ else if (drop.pos.x < 0) drop.pos.x += gp.world.getWidth() * 16;
drop.pos.y = MathUtils.round(drop.pos.y);
while (checkColl(drop.getRect())) {
drop.pos.y--;
for (Iterator<Drop> it = gp.drops.iterator(); it.hasNext(); ) {
Drop drop = it.next();
dropPhy(drop);
- if (Intersector.overlaps(drop.getRect(), gp.player.getRect()))
- drop.pickUpDrop(gp.player);
+ if (Intersector.overlaps(drop.getRect(), gp.player.getRect())) drop.pickUpDrop(gp.player);
if (drop.pickedUp) it.remove();
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java
index 08f44251f6ed20bdca7fa9d38cbcab54c799a647..14b7015c4d0ba5eb4878cbc937be35044e4685b7 100644 (file)
}
}
- if (world.getForeMap(x, y) == 59) {
+ if (world.getForeMap(x, y) > 0 && GameItems.getBlock(world.getForeMap(x, y)).rb) {
if (world.getForeMap(x, y + 1) == 0 || !GameItems.getBlock(world.getForeMap(x, y + 1)).coll) {
- world.setForeMap(x, y, 0);
+ world.destroyForeMap(x, y, this);
updateBlock(x, y - 1);
}
}
checkCursorBounds();
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) {
+ 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) {
blockDmg++;
- if (blockDmg >= GameItems.getBlock(world.getForeMap(curX, curY)).getHp()) {
- if (GameItems.getBlock(world.getForeMap(curX, curY)).getDrop() > 0)
- drops.add(new Drop(curX * 16 + 4, curY * 16 + 4, GameItems.getBlock(world.getForeMap(curX, curY)).getDrop()));
- world.placeToForeground(curX, curY, 0);
- blockDmg = 0;
+ if (world.getForeMap(curX, curY) > 0) {
+ if (blockDmg >= GameItems.getBlock(world.getForeMap(curX, curY)).getHp()) {
+ world.destroyForeMap(curX, curY, this);
+ blockDmg = 0;
+ }
+ } else if (world.getBackMap(curX, curY) > 0) {
+ if (blockDmg >= GameItems.getBlock(world.getBackMap(curX, curY)).getHp()) {
+ world.destroyBackMap(curX, curY, this);
+ blockDmg = 0;
+ }
}
}
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
index 96f8c786d9a0cb21ce98ef72659545a4f3c96063..162c77b885eb4747dd893530f71fceb8b41e059b 100644 (file)
return y * 16 - getCamY();
}
- private void drawWreck() {
+ private void drawWreck(int bl) {
if (gp.blockDmg > 0) {
spriter.draw(Assets.wreck[
10 * gp.blockDmg /
- GameItems.getBlock(gp.world.getForeMap(gp.curX, gp.curY)).getHp()],
+ GameItems.getBlock(bl).getHp()],
gp.curX * 16 - getCamX(),
gp.curY * 16 - getCamY());
}
spriter.draw(
Assets.blockTex[GameItems.getBlock(gp.world.getBackMap(x, y)).getTex()],
drawX(x), drawY(y));
- if (gp.world.getForeMap(x, y) == 0) drawWreck();
+ if (gp.world.getForeMap(x, y) == 0 && x == gp.curX && y == gp.curY)
+ drawWreck(gp.world.getBackMap(gp.curX, gp.curY));
Assets.shade.setPosition(drawX(x), drawY(y));
Assets.shade.draw(spriter);
}
spriter.draw(
Assets.blockTex[GameItems.getBlock(gp.world.getForeMap(x, y)).getTex()],
drawX(x), drawY(y));
- drawWreck();
+ if (x == gp.curX && y == gp.curY)
+ drawWreck(gp.world.getForeMap(gp.curX, gp.curY));
}
}
}
spriter.draw(
Assets.blockTex[GameItems.getBlock(gp.world.getForeMap(x, y)).getTex()],
drawX(x), drawY(y));
- drawWreck();
+ if (x == gp.curX && y == gp.curY)
+ drawWreck(gp.world.getForeMap(gp.curX, gp.curY));
}
}
}
private void drawDrop(Drop drop) {
switch (GameItems.getItem(drop.getId()).getType()) {
case 0:
- Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(drop.pos.x - getCamX() - gp.world.getWidth() * 16, drop.pos.y - getCamY());
+ Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(
+ drop.pos.x - getCamX() - gp.world.getWidth() * 16,
+ drop.pos.y - getCamY());
Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].draw(spriter);
- Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(drop.pos.x - getCamX(), drop.pos.y - getCamY());
+ Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(
+ drop.pos.x - getCamX(),
+ drop.pos.y - getCamY());
Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].draw(spriter);
- Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(drop.pos.x - getCamX() + gp.world.getWidth() * 16, drop.pos.y - getCamY());
+ Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].setPosition(
+ drop.pos.x - getCamX() + gp.world.getWidth() * 16,
+ drop.pos.y - getCamY());
Assets.blockTex[GameItems.getItem(drop.getId()).getTex()].draw(spriter);
}
}
spriter.draw(Assets.plSprite[pl.dir][1],
pl.pos.x - getCamX() - 2, pl.pos.y - getCamY() + 8);
//item in hand
- if (pl.inv[gp.slot] > 0)
+ if (pl.inv[gp.slot] > 0) {
+ float handRotation = MathUtils.degRad * Assets.plSprite[0][2].getRotation();
switch (GameItems.getItem(pl.inv[gp.slot]).getType()) {
case 0:
Assets.blockTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].setPosition(
- pl.pos.x - getCamX() - 8 * MathUtils.sin(MathUtils.degRad * Assets.plSprite[0][2].getRotation()),
- pl.pos.y - getCamY() + 6 + 8 * MathUtils.cos(MathUtils.degRad * Assets.plSprite[0][2].getRotation()));
+ pl.pos.x - getCamX() - 8 * MathUtils.sin(handRotation),
+ pl.pos.y - getCamY() + 6 + 8 * MathUtils.cos(handRotation));
Assets.blockTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].draw(spriter);
break;
default:
Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].setRotation(
-45 + pl.dir * 90 + Assets.plSprite[0][2].getRotation());
Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].setPosition(
- pl.pos.x - getCamX() - 10 + (12 * pl.dir) - 8 * MathUtils.sin(MathUtils.degRad * Assets.plSprite[0][2].getRotation()),
- pl.pos.y - getCamY() + 2 + 8 * MathUtils.cos(MathUtils.degRad * Assets.plSprite[0][2].getRotation()));
+ pl.pos.x - getCamX() - 10 + (12 * pl.dir) - 8 * MathUtils.sin(handRotation),
+ pl.pos.y - getCamY() + 2 + 8 * MathUtils.cos(handRotation));
Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].draw(spriter);
Assets.itemTex[GameItems.getItem(pl.inv[gp.slot]).getTex()].flip((pl.dir == 0), false);
break;
}
+ }
//front hand
Assets.plSprite[0][2].setPosition(
pl.pos.x - getCamX() - 6,
spriter.draw(Assets.guiCur,
gp.curX * 16 - getCamX(),
gp.curY * 16 - getCamY());
- spriter.draw(Assets.invBar, getWidth() / 2 - Assets.invBar.getRegionWidth() / 2, 0);
+ spriter.draw(Assets.invBar, getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2, 0);
for (int i = 0; i < 9; i++) {
if (gp.player.inv[i] > 0) {
switch (GameItems.getItem(gp.player.inv[i]).getType()) {
case 0:
spriter.draw(Assets.blockTex[GameItems.getItem(gp.player.inv[i]).getTex()],
- getWidth() / 2 - Assets.invBar.getRegionWidth() / 2 + 3 + i * 20,
+ getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 + 3 + i * 20,
3);
break;
case 1:
spriter.draw(Assets.itemTex[GameItems.getItem(gp.player.inv[i]).getTex()],
- getWidth() / 2 - Assets.invBar.getRegionWidth() / 2 + 3 + i * 20,
+ getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 + 3 + i * 20,
3);
break;
}
}
}
spriter.draw(Assets.invBarCur,
- getWidth() / 2 - Assets.invBar.getRegionWidth() / 2 - 1 + 20 * gp.slot,
+ getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 - 1 + 20 * gp.slot,
-1);
}
drawString("Drops: " + gp.drops.size(), 0, 40);
drawString("Block: " + GameItems.getBlockKey(gp.world.getForeMap(gp.curX, gp.curY)), 0, 50);
}
-
spriter.end();
}
diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java
index 073c3d56a384df2df41f097a78fbbf195ad6c8bf..d84faa32f8b7ae495d0003b1557b3f6c5a363f06 100644 (file)
package ru.deadsoftware.cavecraft.game;
import com.badlogic.gdx.math.Vector2;
+import ru.deadsoftware.cavecraft.game.objects.Drop;
public class GameWorld {
}
}
+ public void destroyForeMap(int x, int y, GameProc gp) {
+ if (GameItems.getBlock(getForeMap(x, y)).getDrop() > 0)
+ gp.drops.add(new Drop(transformX(x) * 16 + 4, y * 16 + 4, GameItems.getBlock(getForeMap(x, y)).getDrop()));
+ placeToForeground(x, y, 0);
+ }
+
+ public void destroyBackMap(int x, int y, GameProc gp) {
+ if (GameItems.getBlock(getBackMap(x, y)).getDrop() > 0)
+ gp.drops.add(new Drop(transformX(x) * 16 + 4, y * 16 + 4, GameItems.getBlock(getBackMap(x, y)).getDrop()));
+ placeToBackground(x, y, 0);
+ }
+
public Vector2 getSpawnPoint() {
int x = 0, y = 0;
while (true) {
diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Block.java
index 839e383bfd48f63045ceaf21b29767eb65312aa1..8d27235a4fc941f87309855bf6c85e6e09538ed9 100644 (file)
private int tex;
private int hp, drop;
- public boolean coll, bg, tp;
+ public boolean coll, bg, tp, rb;
public Block(int tex, int hp, int drop) {
- this(0, 0, 16, 16, tex, hp, drop, true, false, false);
+ this(0, 0, 16, 16, tex, hp, drop, true, false, false, false);
}
public Block(int tex, int hp, int drop, boolean coll, boolean bg, boolean tp) {
- this(0, 0, 16, 16, tex, hp, drop, coll, bg, tp);
+ this(0, 0, 16, 16, tex, hp, drop, coll, bg, tp, false);
+ }
+
+ public Block(int tex, int hp, int drop, boolean coll, boolean bg, boolean tp, boolean rb) {
+ this(0, 0, 16, 16, tex, hp, drop, coll, bg, tp, rb);
}
public Block(int x, int y, int w, int h, int tex, int hp, int drop, boolean coll, boolean bg, boolean tp) {
+ this(x, y, w, h, tex, hp, drop, coll, bg, tp, false);
+ }
+
+ public Block(int x, int y, int w, int h, int tex, int hp, int drop, boolean coll, boolean bg, boolean tp, boolean rb) {
this.x = x;
this.y = y;
this.w = w;
this.coll = coll;
this.bg = bg;
this.tp = tp;
+ this.rb = rb;
}
public int getTex() {
diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java
index fa60f6b60d67f9eec9385988f66da77537c7eed2..478a05b5efec729cf036ebad2cffbea2771a20e0 100644 (file)
package ru.deadsoftware.cavecraft.game.objects;
+import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
+import ru.deadsoftware.cavecraft.game.GameProc;
import java.io.Serializable;
move = new Vector2(0, -1);
}
+ public int closeToPlayer(GameProc gp) {
+ boolean c1 = Intersector.overlaps(new Rectangle(gp.player.pos.x - 16, gp.player.pos.y - 16, gp.player.texWidth + 32, gp.player.height + 32), getRect());
+ boolean c2 = Intersector.overlaps(new Rectangle((gp.player.pos.x + gp.world.getWidth() * 16) - 16, gp.player.pos.y - 16, gp.player.texWidth + 32, gp.player.height + 32), getRect());
+ boolean c3 = Intersector.overlaps(new Rectangle((gp.player.pos.x - gp.world.getWidth() * 16) - 16, gp.player.pos.y - 16, gp.player.texWidth + 32, gp.player.height + 32), getRect());
+ if (c1) return 1;
+ if (c2) return 2;
+ if (c3) return 3;
+ return 0;
+ }
+
+ 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);
+ switch (ctp) {
+ case 2:
+ px += gp.world.getWidth() * 16;
+ break;
+ case 3:
+ px -= gp.world.getWidth() * 16;
+ break;
+ }
+ float dx = 0, dy = 0;
+ if (px < pos.x + 4) dx = -.5f;
+ else if (px > pos.x + 4) dx = .5f;
+ if (py < 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;
+ }
+ }
+
public void pickUpDrop(Player pl) {
for (int i = 0; i < pl.inv.length; i++) {
if (pl.inv[i] == 0 || pl.inv[i] == id) {