|
@@ -5,9 +5,9 @@ var grid:TileMap
|
|
|
onready var tween = $Tween
|
|
|
|
|
|
# Misc
|
|
|
-var cell_size
|
|
|
-var cell_half_size
|
|
|
-var alive = false
|
|
|
+const cell_size = 64
|
|
|
+const cell_half_size = 32
|
|
|
+var running = false
|
|
|
|
|
|
# Enum
|
|
|
enum Direction {
|
|
@@ -28,33 +28,21 @@ var posiy
|
|
|
var dirx = 0
|
|
|
var diry = 0
|
|
|
|
|
|
-var dire
|
|
|
+var dire = 0
|
|
|
var dire_delta = 0
|
|
|
|
|
|
var target_pos
|
|
|
|
|
|
+const LEVEL_SPAWN_DURATION = 2
|
|
|
+
|
|
|
# Controls
|
|
|
export var turn_left_action:String
|
|
|
export var turn_right_action:String
|
|
|
|
|
|
func _ready():
|
|
|
- add_to_group("players")
|
|
|
- spring()
|
|
|
-
|
|
|
- assert(grid)
|
|
|
assert(turn_left_action)
|
|
|
assert(turn_right_action)
|
|
|
|
|
|
- cell_size = int (grid.get_cell_size().x)
|
|
|
- cell_half_size = cell_size / 2
|
|
|
-
|
|
|
- # Adjust spawn situation
|
|
|
- posix = int (position.x / 64)
|
|
|
- posiy = int (position.y / 64)
|
|
|
- dire = int((rotation_degrees + 45) / 90)
|
|
|
-
|
|
|
- apply_turn()
|
|
|
-
|
|
|
tween.connect_into(self)
|
|
|
|
|
|
func _unhandled_input(event):
|
|
@@ -66,24 +54,45 @@ func _unhandled_input(event):
|
|
|
prepare_turn(Side.RIGHT)
|
|
|
get_tree().set_input_as_handled()
|
|
|
|
|
|
-func _on_game_start():
|
|
|
- move()
|
|
|
+func spawn(newGrid, newPosition, newOrientation):
|
|
|
+ # Update arena
|
|
|
+ grid = newGrid
|
|
|
+
|
|
|
+ # Adjust spawn situation
|
|
|
+ dire_delta = 0
|
|
|
+ posix = int (newPosition.x / cell_size)
|
|
|
+ posiy = int (newPosition.y / cell_size)
|
|
|
+ dire = int((newOrientation + 45) / 90)
|
|
|
+ apply_turn()
|
|
|
+
|
|
|
+ # Animate spawning
|
|
|
+ tween.rotate_char(self, rotation_degrees, newOrientation, LEVEL_SPAWN_DURATION)
|
|
|
+ tween.move_char(self, newPosition, LEVEL_SPAWN_DURATION)
|
|
|
+ tween.start()
|
|
|
+
|
|
|
+func _on_round_start():
|
|
|
+ assert(grid)
|
|
|
+ spring()
|
|
|
|
|
|
func _on_tween_completed(_o, key):
|
|
|
if (key == ":position"):
|
|
|
move()
|
|
|
|
|
|
func _on_crash(body):
|
|
|
- die()
|
|
|
- generate_wall()
|
|
|
- # TODO : use enum for blocks
|
|
|
- grid.set_cell(posix, posiy, 2)
|
|
|
+ if running:
|
|
|
+ die()
|
|
|
+ generate_wall()
|
|
|
+ # TODO : use enum for blocks
|
|
|
+ grid.set_cell(posix, posiy, 2)
|
|
|
|
|
|
func generate_wall():
|
|
|
# TODO : use enum for blocks
|
|
|
grid.set_cell(posix - dirx, posiy - diry, 1)
|
|
|
|
|
|
func prepare_turn(left_or_right:int):
|
|
|
+ if !running:
|
|
|
+ return
|
|
|
+
|
|
|
var current_angle = (dire + dire_delta) * 90
|
|
|
|
|
|
dire_delta += left_or_right
|
|
@@ -125,7 +134,7 @@ func apply_turn():
|
|
|
push_error("dire out of range")
|
|
|
|
|
|
func move():
|
|
|
- if !alive:
|
|
|
+ if !running:
|
|
|
return
|
|
|
|
|
|
generate_wall()
|
|
@@ -151,13 +160,14 @@ func has_block_on(left_or_right:int):
|
|
|
return grid.get_cell(bposx, bposy) == 1
|
|
|
|
|
|
func die():
|
|
|
- if alive:
|
|
|
- remove_from_group("living")
|
|
|
- alive = false
|
|
|
+ if running:
|
|
|
+ remove_from_group("running")
|
|
|
+ running = false
|
|
|
|
|
|
func spring():
|
|
|
- alive = true
|
|
|
- add_to_group("living")
|
|
|
+ running = true
|
|
|
+ add_to_group("running")
|
|
|
+ move()
|
|
|
|
|
|
-func is_alive():
|
|
|
- return alive
|
|
|
+func is_running():
|
|
|
+ return running
|