adds basic menu functionnality

This commit is contained in:
2020-11-03 23:04:17 +01:00
parent 4f2a4768c8
commit 3e10a98beb
13 changed files with 175 additions and 95 deletions

View File

@@ -1,7 +1,6 @@
extends Node
signal player_moved(track_offset)
signal lap_completed(laps)
signal wrong_way(coords)
# TODO:
@@ -12,7 +11,7 @@ signal wrong_way(coords)
var laps
var current_cell
onready var track = TrackSelection.get_current_track()
var track = null
onready var map = $TileMap
func get_track_offset(coords):
@@ -21,13 +20,17 @@ func get_track_offset(coords):
# Called when the node enters the scene tree for the first time.
func _ready():
_reset_progress()
_reset_state()
func _reset_progress():
func _reset_state():
track = TrackSelection.get_current_track()
laps = 0
current_cell = track[0]
func _input(event):
if not Global.race_started:
return -1
# Check if the mouse if following the tiles track
if event is InputEventMouseMotion:
var hover_cell = map.world_to_map(event.position)
@@ -37,7 +40,6 @@ func _input(event):
# Check if a lap is finished
if hover_cell == track[0] and current_cell == track[-1]:
laps += 1
emit_signal("lap_completed", laps)
# Check we are following the path
if track[track.find(hover_cell) - 1] == current_cell:
emit_signal("player_moved", laps + get_track_offset(hover_cell))
@@ -45,3 +47,11 @@ func _input(event):
current_cell = hover_cell
else:
emit_signal("wrong_way", map.map_to_world(hover_cell))
func _on_Menu_track_changed():
print("Options clicked")
TrackSelection.set_next_track()
_reset_state()
$TileMap._reset()
$TrackPath._reset()