adds track parser from txt files

This commit is contained in:
2020-11-03 00:47:59 +01:00
parent d5ad9b8e1c
commit 4f2a4768c8
31 changed files with 649 additions and 103 deletions

View File

@@ -10,19 +10,22 @@ signal wrong_way(coords)
# - Build the track Curve2D from track and tiles data
# - Keyboard controls !!
const TRACK_TILES = Global.TRACKS[0]
var laps
var current_cell
onready var track = TrackSelection.get_current_track()
onready var map = $TileMap
var laps = 0
var current_cell = TRACK_TILES[0]
func get_track_offset(coords):
var offset = float(TRACK_TILES.find(coords)) / float(len(TRACK_TILES))
var offset = float(track.find(coords)) / float(len(track))
return offset
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
_reset_progress()
func _reset_progress():
laps = 0
current_cell = track[0]
func _input(event):
# Check if the mouse if following the tiles track
@@ -30,13 +33,13 @@ func _input(event):
var hover_cell = map.world_to_map(event.position)
if hover_cell != current_cell: # The mouse moved to a new cell
# Check the tile is on path
if TRACK_TILES.find(hover_cell) != -1:
if track.find(hover_cell) != -1:
# Check if a lap is finished
if hover_cell == TRACK_TILES[0] and current_cell == TRACK_TILES[-1]:
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_TILES[TRACK_TILES.find(hover_cell) - 1] == current_cell:
if track[track.find(hover_cell) - 1] == current_cell:
emit_signal("player_moved", laps + get_track_offset(hover_cell))
emit_signal("wrong_way", Vector2(-1, -1))
current_cell = hover_cell