summaryrefslogtreecommitdiff
path: root/Scenes/MonsterSquare.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Scenes/MonsterSquare.gd')
-rw-r--r--Scenes/MonsterSquare.gd12
1 files changed, 5 insertions, 7 deletions
diff --git a/Scenes/MonsterSquare.gd b/Scenes/MonsterSquare.gd
index 89ae2e3..443d3ec 100644
--- a/Scenes/MonsterSquare.gd
+++ b/Scenes/MonsterSquare.gd
@@ -1,22 +1,20 @@
extends Monster
-onready var cardinal = Vector2.UP
-
const directions = [Vector2(1,0), Vector2(0,1), Vector2(-1,0), Vector2(0,-1)]
+
var dir_i = 0
+var dir = 1
func _ready():
._ready()
- dir_i = 0
+ dir_i = randi() % 4
if randf() < 0.5:
- cardinal = Vector2.RIGHT
+ dir = -1
func try_moving(player_pos : Vector2, monster_pos : Vector2) -> MonsterAction:
var action = MonsterAction.new()
- var next_tile = monster_pos
var next_movement = directions[dir_i]
-
var next_pos = monster_pos + next_movement
if next_pos == player_pos:
@@ -24,7 +22,7 @@ func try_moving(player_pos : Vector2, monster_pos : Vector2) -> MonsterAction:
else:
action.type = MonsterActionType.MOVE
action.dir = next_movement
- dir_i = (dir_i + 1) % 4
+ dir_i = (dir_i + dir) % 4
return action