DEADSOFTWARE

Fix drop picking
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / objects / drop / Drop.kt
index 9099864b39f8c12db0f2362d41a2eecd2739d393..edb3c81ff657a63fd41b865e4dbaea9a7dc01230 100644 (file)
@@ -10,9 +10,12 @@ class Drop @JvmOverloads constructor(
     x: Float,
     y: Float,
     _item: Item,
-    val amount: Int = 1,
+    _amount: Int = 1,
 ) : Rectangle(x, y, DROP_SIZE, DROP_SIZE) {
 
+    var amount: Int = _amount
+        private set
+
     val itemKey = _item.params.key
     val velocity = getInitialVelocity()
     var pickedUp = false
@@ -39,6 +42,15 @@ class Drop @JvmOverloads constructor(
         return Intersector.overlaps(magnetArea, rectangle)
     }
 
+    @JvmOverloads
+    fun subtract(count: Int = 1) {
+        if (count < 0) {
+            throw IllegalArgumentException("Can't subtract negative amount")
+        }
+
+        amount -= count
+    }
+
     private fun getMagnetArea(): Rectangle {
         return Rectangle(
             /* x = */ x - MAGNET_DISTANCE,