summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 46c9d58)
raw | patch | inline | side by side (parent: 46c9d58)
author | fredboy <fredboy@protonmail.com> | |
Fri, 19 Apr 2024 12:12:27 +0000 (19:12 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Fri, 19 Apr 2024 12:12:27 +0000 (19:12 +0700) |
diff --git a/android/assets/health.png b/android/assets/health.png
new file mode 100644 (file)
index 0000000..93314e6
Binary files /dev/null and b/android/assets/health.png differ
index 0000000..93314e6
Binary files /dev/null and b/android/assets/health.png differ
index e1f3e48adc14ebf25d3578a590cfc545826017c8..9254986879a7c3fed8678fee60fdd9214f800f9d 100644 (file)
},
"shade": {},
"gamelogo": {},
- "background": {}
+ "background": {},
+ "health":{
+ "heart_whole": {
+ "w": 9
+ },
+ "heart_half": {
+ "x": 9,
+ "w": 9
+ }
+ }
}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java
index 70afcbfe5d3f1be77cdd772d61584b142022f7bd..4127b6dba4ee9fbb6af1b90d3c47390591467d9f 100644 (file)
if (d == -1) {
mob.setCanJump(true);
mob.setFlyMode(false);
+
+ int dmg = ((int)Math.max(0f, (((mob.getVelocity().y * mob.getVelocity().y) / (2 * gravity.y)) - 48f) / 16f));
+ if (dmg > 0) {
+ mob.damage(dmg);
+ }
}
mob.y = MathUtils.round(mob.getY());
mob.getVelocity().y = 0;
-
-
- //todo fall damage
- // h = (v^2) / 2g
- // dmg = max(0, (h - 48) / 32) - half of blocks fallen starting from 3 blocks height
- // int dmg = ((int)Math.max(0f, (((mob.getVelocity().y * mob.getVelocity().y) / (2 * gravity.y)) - 48f) / 16f));
- // if (dmg > 0) System.out.println("Damage: " + dmg);
-
} else {
mob.y += 1;
mob.setCanJump(checkColl(mob));
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java
index c18ee5393ce9482fa245a2e246585b268c2cb054..b555f6bde14fc927d6e4de3d965de81bdf5a9887 100644 (file)
}
+ private void drawHealth(float x, float y) {
+ Player player = mMobsController.getPlayer();
+
+ if (player.gameMode == 1) {
+ return;
+ }
+
+ TextureRegion wholeHeart = textureRegions.get("heart_whole");
+ TextureRegion halfHeart = textureRegions.get("heart_half");
+
+ int wholeHearts = player.getHealth() / 2;
+
+ for (int i = 0; i < wholeHearts; i++) {
+ spriter.draw(wholeHeart, x + i * wholeHeart.getRegionWidth(), y);
+ }
+
+ if (player.getHealth() % 2 == 1) {
+ spriter.draw(halfHeart, x + wholeHearts * wholeHeart.getRegionWidth(), y);
+ }
+ }
+
private void drawGUI() {
TextureRegion cursor = textureRegions.get("cursor");
TextureRegion hotbar = textureRegions.get("hotbar");
mGameInput.getControlMode() == ControlMode.CURSOR || mMainConfig.isTouch()) {
spriter.draw(cursor, mGameInput.getCurX() * 16 - getCamX(), mGameInput.getCurY() * 16 - getCamY());
}
- spriter.draw(hotbar, getWidth() / 2 - (float) hotbar.getRegionWidth() / 2, 0);
+
+ float hotbarX = getWidth() / 2 - (float) hotbar.getRegionWidth() / 2;
+ spriter.draw(hotbar, hotbarX, 0);
+ drawHealth(hotbarX, hotbar.getRegionHeight());
+
for (int i = 0; i < 9; i++) {
if (mMobsController.getPlayer().inventory[i] > 0) {
if (GameItems.getItem(mMobsController.getPlayer().inventory[i]).isBlock()) {
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java
index ede6ba2888490622cc11be47239e4d571d379444..81fdb93b5dbd0e2c8e918167969f19a517f6e17d 100644 (file)
* @param y Y in pixels
*/
public FallingGravel(float x, float y) {
- super(x, y, 16, 16, Direction.LEFT, Type.GRAVEL);
+ super(x, y, 16, 16, Direction.LEFT, Type.GRAVEL, Integer.MAX_VALUE);
mVelocity = new Vector2(0, 1);
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java
index c59c3fc94d4de16a1bf94eb2c03d4295ace04bae..7186b3a1ff13ee0af1375eb65fd6b2aba9cc202d 100644 (file)
* @param y Y in pixels
*/
public FallingSand(float x, float y) {
- super(x, y, 16, 16, Direction.LEFT, Type.SAND);
+ super(x, y, 16, 16, Direction.LEFT, Type.SAND, Integer.MAX_VALUE);
mVelocity = new Vector2(0, 1);
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java
index f19d247c4d9df9a972eb4d423cedbd3ea8c35ac1..592f78da7afc56dae4fbbab3c6670938d2e29673 100644 (file)
package ru.deadsoftware.cavedroid.game.mobs;
+import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
private boolean mCanJump;
private boolean mFlyMode;
+ private final int mMaxHealth;
+ private int mHealth;
+
/**
* @param x in pixels
* @param y in pixels
* @param height in pixels
* @param mDirection Direction in which mob is looking
*/
- protected Mob(float x, float y, float width, float height, Direction mDirection, Type type) {
+ protected Mob(float x, float y, float width, float height, Direction mDirection, Type type, int maxHealth) {
super(x, y, width, height);
mVelocity = new Vector2(0, 0);
mCanJump = false;
mDead = false;
this.mDirection = mDirection;
this.mType = type;
+ this.mMaxHealth = maxHealth;
+ this.mHealth = mMaxHealth;
}
protected static Direction randomDir() {
return mAnim > 0 && mAnimDelta > 0 || mAnim < 0 && mAnimDelta < 0;
}
+ private void checkHealth() {
+ mHealth = MathUtils.clamp(mHealth, 0, mMaxHealth);
+
+ if (mHealth <= 0) {
+ kill();
+ }
+ }
+
protected final void updateAnimation(float delta) {
if (mVelocity.x != 0f || Math.abs(mAnim) > mAnimDelta * delta) {
mAnim += mAnimDelta * delta;
}
}
+ public final int getHealth() {
+ return mHealth;
+ }
+
+ public void damage(int damage) {
+ if (damage < 0) {
+ Gdx.app.error(this.getClass().getSimpleName(), "Damage cant be negative!");
+ return;
+ }
+
+ if (mHealth <= Integer.MIN_VALUE + damage) {
+ mHealth = Integer.MIN_VALUE + damage;
+ }
+
+ mHealth -= damage;
+ checkHealth();
+ }
+
+ public void heal(int heal) {
+ if (heal < 0) {
+ Gdx.app.error(this.getClass().getSimpleName(), "Heal cant be negative!");
+ return;
+ }
+
+ if (mHealth >= Integer.MAX_VALUE - heal) {
+ mHealth = Integer.MAX_VALUE - heal;
+ }
+
+ mHealth += heal;
+ checkHealth();
+ }
+
public abstract void draw(SpriteBatch spriteBatch, float x, float y, float delta);
public abstract void ai(GameWorld gameWorld, float delta);
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.kt b/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.kt
index a9295464e43cd7c0b03d5c9a9f2a54077f022815..4f9d5fcef6caa2d48dd59cb8cdb291696a8c55f8 100644 (file)
import ru.deadsoftware.cavedroid.misc.utils.mobs.MobSprites.Pig.getLegsRelativeY
import ru.deadsoftware.cavedroid.misc.utils.mobs.MobSprites.Pig.getRightLegRelativeX
-class Pig(x: Float, y: Float) : Mob(x, y, WIDTH, HEIGHT, randomDir(), Type.MOB) {
+class Pig(x: Float, y: Float) : Mob(x, y, WIDTH, HEIGHT, randomDir(), Type.MOB, MAX_HEALTH) {
override fun getSpeed(): Float {
return SPEED
private const val HEIGHT = 18f
private const val SPEED = 69.072f
private const val JUMP_VELOCITY = -133.332f
+ private const val MAX_HEALTH = 10;
}
}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
index 8fce1169be150a7a5e568adf1925ef6cb014afd2..ebdd9c0dbed6281204809267f6ed0997f270925b 100644 (file)
private static final float SPEED = 69.072f;
private static final float JUMP_VELOCITY = -133.332f;
+ private static final int MAX_HEALTH = 20;
private boolean hitting = false;
private float hitAnim = 0f;
public float headRotation = 0f;
public Player() {
- super(0, 0, 4, 30, randomDir(), Type.MOB);
+ super(0, 0, 4, 30, randomDir(), Type.MOB, MAX_HEALTH);
this.gameMode = 1;
inventory = new int[9];
swim = false;
this.y = pos.y;
mVelocity.setZero();
mDead = false;
+ heal(MAX_HEALTH);
}
public void pickUpDrop(Drop drop) {
public void changeDir() {
}
+ @Override
+ public void damage(int damage) {
+ if (gameMode == 1) {
+ return;
+ }
+ super.damage(damage);
+ }
+
+ @Override
+ public void heal(int heal) {
+ if (gameMode == 1) {
+ return;
+ }
+ super.heal(heal);
+ }
+
private void drawItem(SpriteBatch spriteBatch, float x, float y, float anim) {
final int itemId = inventory[slot];
final Item item = GameItems.getItem(itemId);
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/Assets.java b/core/src/ru/deadsoftware/cavedroid/misc/Assets.java
index c58f7032bbb213931a93567280b0113a1ba5c34d..05bd47f0559b162702919b950bc20ca20d35e159 100644 (file)
package ru.deadsoftware.cavedroid.misc;
-import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;