From 9f899928ab57fc6c2c6151023190ef8d7c3eac03 Mon Sep 17 00:00:00 2001 From: fredboy Date: Fri, 19 Apr 2024 19:20:00 +0700 Subject: [PATCH] Handle mob hits --- .../ru/deadsoftware/cavedroid/game/GameInput.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java index 291311a..a0c5f66 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java @@ -3,6 +3,7 @@ package ru.deadsoftware.cavedroid.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.math.Intersector; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.utils.TimeUtils; import com.google.common.collect.Range; @@ -215,6 +216,16 @@ public class GameInput { } } + private void hitMobs() { + final Player player = mMobsController.getPlayer(); + mMobsController.forEach((mob) -> { + if (Intersector.overlaps(mob, player)) { + mob.damage(5); + mob.jump(); + } + }); + } + private void pressLMB() { if (mMainConfig.checkGameUiWindow(GameUiWindow.NONE)) { mPlayer.startHitting(); @@ -244,6 +255,7 @@ public class GameInput { mTouchedDown = false; } } else { + hitMobs(); mTouchedDown = false; } } -- 2.29.2