summaryrefslogtreecommitdiff
path: root/Scenes/MonsterRandCardinal.gd
diff options
context:
space:
mode:
authorHenrique Alves <henriquelalves@gmail.com>2022-07-16 00:46:23 -0300
committerHenrique Alves <henriquelalves@gmail.com>2022-07-16 00:46:23 -0300
commitc679cf2d5d20c50dbf1c9e6fd7ac302af0c9d859 (patch)
tree4032c8003188c5ef3cfd4c7d634b574926564555 /Scenes/MonsterRandCardinal.gd
parentef33112d4c103b8d7ff7fb7a5773bf31075eb131 (diff)
downloadgamejam-gmtk-2022-c679cf2d5d20c50dbf1c9e6fd7ac302af0c9d859.tar.gz
gamejam-gmtk-2022-c679cf2d5d20c50dbf1c9e6fd7ac302af0c9d859.tar.bz2
gamejam-gmtk-2022-c679cf2d5d20c50dbf1c9e6fd7ac302af0c9d859.zip
Add monster logic
Diffstat (limited to 'Scenes/MonsterRandCardinal.gd')
-rw-r--r--Scenes/MonsterRandCardinal.gd30
1 files changed, 30 insertions, 0 deletions
diff --git a/Scenes/MonsterRandCardinal.gd b/Scenes/MonsterRandCardinal.gd
new file mode 100644
index 0000000..46a1d62
--- /dev/null
+++ b/Scenes/MonsterRandCardinal.gd
@@ -0,0 +1,30 @@
+extends Monster
+
+onready var cardinal = Vector2.UP
+onready var moved = false
+
+func _ready():
+ if randf() < 0.5:
+ cardinal = Vector2.RIGHT
+
+func try_moving(player_pos : Vector2, monster_pos : Vector2) -> MonsterAction:
+ var next_movement = cardinal
+ if moved:
+ next_movement *= -1
+ moved = !moved
+
+ var next_pos = monster_pos + next_movement
+
+ var action = MonsterAction.new()
+
+ if next_pos == player_pos:
+ action.type = MonsterActionType.ATTACK
+ else:
+ action.type = MonsterActionType.MOVE
+ action.dir = next_movement
+
+ return action
+
+
+func cor_attack(args : Array):
+ yield(.cor_attack(args), "completed")