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

@@ -4,6 +4,7 @@ signal race_started
export (int) var delay = 3 export (int) var delay = 3
var timer var timer
var time_left = delay
func _ready(): func _ready():
@@ -12,21 +13,26 @@ func _ready():
add_child(timer) add_child(timer)
timer.wait_time = 1.0 timer.wait_time = 1.0
timer.connect("timeout", self, "_timeout") timer.connect("timeout", self, "_timeout")
func start():
set_visible(true)
time_left = delay
$Number.set_text("%d" % time_left)
timer.start() timer.start()
return self
$Number.set_text("%d" % delay)
func _timeout(): func _timeout():
#print("Timeout !") #print("Timeout !")
delay -= 1 time_left -= 1
if delay < 0: if time_left < 0:
timer.stop() timer.stop()
set_visible(false) set_visible(false)
elif delay == 0: elif time_left == 0:
# Go ! # Go !
$Number.set_text("GO") $Number.set_text("GO")
emit_signal("race_started") emit_signal("race_started")
else: else:
$Number.set_text("%d" % delay) $Number.set_text("%d" % time_left)

2
Gui.gd
View File

@@ -6,5 +6,5 @@ onready var lap_counter = get_node("Laps/Value")
func _ready(): func _ready():
pass # Replace with function body. pass # Replace with function body.
func _on_TileMap_lap_completed(laps): func _on_lap_completed(laps):
lap_counter.set_text("%d" % laps) lap_counter.set_text("%d" % laps)

23
Main.gd
View File

@@ -1,18 +1,15 @@
extends Node extends Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass
func start_game(): func start_game():
pass print("Game starting")
$Menu.set_visible(false)
yield($Countdown.start(), "race_started")
Global.race_started = true
func pause_game():
$Menu.set_visible(true)
Global.race_started = false
func change_track(): func _input(event):
""" Change the race track """ if event.is_action_pressed("ui_cancel"):
pass pause_game()

View File

@@ -1,23 +1,19 @@
[gd_scene load_steps=7 format=2] [gd_scene load_steps=5 format=2]
[ext_resource path="res://Main.gd" type="Script" id=1] [ext_resource path="res://Main.gd" type="Script" id=1]
[ext_resource path="res://Menu.tscn" type="PackedScene" id=2] [ext_resource path="res://RaceTrack.tscn" type="PackedScene" id=2]
[ext_resource path="res://RaceTrack.tscn" type="PackedScene" id=3] [ext_resource path="res://Menu.tscn" type="PackedScene" id=3]
[ext_resource path="res://PlayerCar.tscn" type="PackedScene" id=4] [ext_resource path="res://Countdown.tscn" type="PackedScene" id=4]
[ext_resource path="res://Gui.tscn" type="PackedScene" id=5]
[ext_resource path="res://Countdown.tscn" type="PackedScene" id=6]
[node name="Main" type="Node"] [node name="Main" type="Node"]
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="Menu" parent="." instance=ExtResource( 2 )] [node name="RaceTrack" parent="." instance=ExtResource( 2 )]
[node name="RaceTrack" parent="." instance=ExtResource( 3 )] [node name="Menu" parent="." instance=ExtResource( 3 )]
[node name="PlayerCar" parent="RaceTrack" instance=ExtResource( 4 )] [node name="Countdown" parent="." instance=ExtResource( 4 )]
[node name="GUI" parent="." instance=ExtResource( 5 )]
visible = false
[node name="Countdown" parent="." instance=ExtResource( 6 )]
visible = false visible = false
delay = 3
[connection signal="game_started" from="Menu" to="." method="start_game"]
[connection signal="track_changed" from="Menu" to="RaceTrack" method="_on_Menu_track_changed"]

52
Menu.gd
View File

@@ -1,12 +1,15 @@
extends CanvasLayer extends Control
signal track_changed(track_idx) signal game_started()
signal track_changed()
signal skin_changed(skin) signal skin_changed(skin)
# Declare member variables here. Examples: enum Actions { PLAY, CHANGE_TRACK, QUIT }
# var a = 2 var _focus = null setget _set_focus
# var b = "text"
func _set_focus(value):
_focus = value
print("New focus: ", value)
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
pass # Replace with function body. pass # Replace with function body.
@@ -14,3 +17,42 @@ func _ready():
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta): #func _process(delta):
# pass # pass
func _input(event):
if event is InputEventMouseButton:
if _focus != null:
if event.button_index == BUTTON_LEFT and event.pressed:
match _focus:
Actions.PLAY:
emit_signal("game_started")
Actions.CHANGE_TRACK:
emit_signal("track_changed")
Actions.QUIT:
get_tree().quit()
_focus = null
func _on_Jouer_mouse_exited():
get_node("Main/Jouer").set("custom_colors/font_color", Color.white)
_focus = null
func _on_Jouer_mouse_entered():
get_node("Main/Jouer").set("custom_colors/font_color", Color.orange)
_set_focus(Actions.PLAY)
func _on_Options_mouse_exited():
get_node("Main/Options").set("custom_colors/font_color", Color.white)
_focus = null
func _on_Options_mouse_entered():
get_node("Main/Options").set("custom_colors/font_color", Color.orange)
_set_focus(Actions.CHANGE_TRACK)
func _on_Quitter_mouse_entered():
get_node("Main/Quitter").set("custom_colors/font_color", Color.orange)
_set_focus(Actions.QUIT)
func _on_Quitter_mouse_exited():
get_node("Main/Quitter").set("custom_colors/font_color", Color.white)
_focus = null

View File

@@ -10,7 +10,10 @@ size = 60
use_filter = true use_filter = true
font_data = ExtResource( 2 ) font_data = ExtResource( 2 )
[node name="Menu" type="CanvasLayer"] [node name="Menu" type="Control"]
margin_right = 1920.0
margin_bottom = 1080.0
mouse_filter = 1
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="Title" type="Label" parent="."] [node name="Title" type="Label" parent="."]
@@ -39,23 +42,29 @@ margin_top = -76.9716
margin_right = 9.42896 margin_right = 9.42896
margin_bottom = 129.028 margin_bottom = 129.028
rect_scale = Vector2( 2, 2 ) rect_scale = Vector2( 2, 2 )
mouse_default_cursor_shape = 9
[node name="Jouer" type="Label" parent="Main"] [node name="Jouer" type="Label" parent="Main"]
margin_right = 149.0 margin_right = 149.0
margin_bottom = 66.0 margin_bottom = 66.0
mouse_filter = 0
custom_fonts/font = ExtResource( 3 ) custom_fonts/font = ExtResource( 3 )
custom_colors/font_color_shadow = Color( 0.454902, 0.219608, 0.0901961, 1 ) custom_colors/font_color = Color( 1, 1, 1, 1 )
custom_colors/font_color_shadow = Color( 0.823529, 0.517647, 0.0823529, 1 )
custom_constants/shadow_offset_x = 2 custom_constants/shadow_offset_x = 2
custom_constants/shadow_offset_y = 3 custom_constants/shadow_offset_y = 3
text = "Jouer" text = "Jouer"
align = 1 align = 1
valign = 1
[node name="Options" type="Label" parent="Main"] [node name="Options" type="Label" parent="Main"]
margin_top = 70.0 margin_top = 70.0
margin_right = 149.0 margin_right = 149.0
margin_bottom = 136.0 margin_bottom = 136.0
mouse_filter = 0
custom_fonts/font = ExtResource( 3 ) custom_fonts/font = ExtResource( 3 )
custom_colors/font_color_shadow = Color( 0.454902, 0.219608, 0.0901961, 1 ) custom_colors/font_color = Color( 1, 1, 1, 1 )
custom_colors/font_color_shadow = Color( 0.823529, 0.517647, 0.0823529, 1 )
custom_constants/shadow_offset_x = 2 custom_constants/shadow_offset_x = 2
custom_constants/shadow_offset_y = 3 custom_constants/shadow_offset_y = 3
text = "Options" text = "Options"
@@ -65,8 +74,10 @@ align = 1
margin_top = 140.0 margin_top = 140.0
margin_right = 149.0 margin_right = 149.0
margin_bottom = 206.0 margin_bottom = 206.0
mouse_filter = 0
custom_fonts/font = ExtResource( 3 ) custom_fonts/font = ExtResource( 3 )
custom_colors/font_color_shadow = Color( 0.454902, 0.219608, 0.0901961, 1 ) custom_colors/font_color = Color( 1, 1, 1, 1 )
custom_colors/font_color_shadow = Color( 0.823529, 0.517647, 0.0823529, 1 )
custom_constants/shadow_offset_x = 2 custom_constants/shadow_offset_x = 2
custom_constants/shadow_offset_y = 3 custom_constants/shadow_offset_y = 3
text = "Quitter" text = "Quitter"
@@ -81,3 +92,9 @@ margin_left = -20.0
margin_top = -20.0 margin_top = -20.0
margin_right = 20.0 margin_right = 20.0
margin_bottom = 20.0 margin_bottom = 20.0
[connection signal="mouse_entered" from="Main/Jouer" to="." method="_on_Jouer_mouse_entered"]
[connection signal="mouse_exited" from="Main/Jouer" to="." method="_on_Jouer_mouse_exited"]
[connection signal="mouse_entered" from="Main/Options" to="." method="_on_Options_mouse_entered"]
[connection signal="mouse_exited" from="Main/Options" to="." method="_on_Options_mouse_exited"]
[connection signal="mouse_entered" from="Main/Quitter" to="." method="_on_Quitter_mouse_entered"]
[connection signal="mouse_exited" from="Main/Quitter" to="." method="_on_Quitter_mouse_exited"]

View File

@@ -8,6 +8,9 @@ func _ready():
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
if not Global.race_started:
return -1
var position = get_unit_offset() var position = get_unit_offset()
position += speed * delta position += speed * delta
set_unit_offset(position) set_unit_offset(position)

View File

@@ -1,22 +1,24 @@
extends PathFollow2D extends PathFollow2D
signal lap_completed(laps)
export (float) var speed = 0.125 export (float) var speed = 0.125
var position_on_track := 0.0 var position_on_track := 0.0
var target_on_track := 0.0 var target_on_track := 0.0
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func _process(delta): func _process(delta):
# Check if a lap was completed
if int(position_on_track) > Global.laps:
Global.laps += 1
emit_signal("lap_completed", Global.laps)
# Move the player until target_on_track # Move the player until target_on_track
if target_on_track - position_on_track > 0.01: elif target_on_track - position_on_track > 0.01:
# Speed up car as the target_on_track goes further # Speed up car as the target_on_track goes further
var speed_mod = int(clamp((target_on_track - position_on_track) / speed, 1.0, 4.0)) var speed_mod = int(clamp((target_on_track - position_on_track) / speed, 1.0, 4.0))
position_on_track += speed * delta * speed_mod position_on_track += speed * delta * speed_mod
set_unit_offset(position_on_track) set_unit_offset(min(position_on_track, target_on_track))
else: else:
position_on_track = target_on_track position_on_track = target_on_track

View File

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

View File

@@ -1,26 +1,26 @@
[gd_scene load_steps=39 format=2] [gd_scene load_steps=41 format=2]
[ext_resource path="res://RaceTrack.gd" type="Script" id=1] [ext_resource path="res://RaceTrack.gd" type="Script" id=1]
[ext_resource path="res://assets/track_tiles/track.png" type="Texture" id=2] [ext_resource path="res://assets/track_tiles/track.png" type="Texture" id=2]
[ext_resource path="res://TileMap.gd" type="Script" id=3] [ext_resource path="res://TileMap.gd" type="Script" id=3]
[ext_resource path="res://TrackPath.gd" type="Script" id=4] [ext_resource path="res://TrackPath.gd" type="Script" id=4]
[ext_resource path="res://OpponentCar.gd" type="Script" id=5] [ext_resource path="res://OpponentCar.gd" type="Script" id=5]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0007.png" type="Texture" id=6] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0003.png" type="Texture" id=6]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0004.png" type="Texture" id=7] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0004.png" type="Texture" id=7]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0001.png" type="Texture" id=8] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0001.png" type="Texture" id=8]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0002.png" type="Texture" id=9] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0002.png" type="Texture" id=9]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0003.png" type="Texture" id=10] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0007.png" type="Texture" id=10]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0000.png" type="Texture" id=11] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0000.png" type="Texture" id=11]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0005.png" type="Texture" id=12] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0005.png" type="Texture" id=12]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0006.png" type="Texture" id=13] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0006.png" type="Texture" id=13]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0003.png" type="Texture" id=14] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0007.png" type="Texture" id=14]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0004.png" type="Texture" id=15] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0004.png" type="Texture" id=15]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0001.png" type="Texture" id=16] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0001.png" type="Texture" id=16]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0002.png" type="Texture" id=17] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0002.png" type="Texture" id=17]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0007.png" type="Texture" id=18] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0003.png" type="Texture" id=18]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0000.png" type="Texture" id=19] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0000.png" type="Texture" id=19]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0005.png" type="Texture" id=20] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0005.png" type="Texture" id=20]
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0006.png" type="Texture" id=21] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0006.png" type="Texture" id=21]
[ext_resource path="res://track1/policeCar/policeiso_0003.png" type="Texture" id=22] [ext_resource path="res://track1/policeCar/policeiso_0003.png" type="Texture" id=22]
[ext_resource path="res://track1/policeCar/policeiso_0004.png" type="Texture" id=23] [ext_resource path="res://track1/policeCar/policeiso_0004.png" type="Texture" id=23]
[ext_resource path="res://track1/policeCar/policeiso_0001.png" type="Texture" id=24] [ext_resource path="res://track1/policeCar/policeiso_0001.png" type="Texture" id=24]
@@ -33,6 +33,8 @@
[ext_resource path="res://Player.gd" type="Script" id=31] [ext_resource path="res://Player.gd" type="Script" id=31]
[ext_resource path="res://PlayerCar.tscn" type="PackedScene" id=32] [ext_resource path="res://PlayerCar.tscn" type="PackedScene" id=32]
[ext_resource path="res://wrong_way.tscn" type="PackedScene" id=33] [ext_resource path="res://wrong_way.tscn" type="PackedScene" id=33]
[ext_resource path="res://Gui.tscn" type="PackedScene" id=34]
[ext_resource path="res://Gui.gd" type="Script" id=35]
[sub_resource type="Gradient" id=1] [sub_resource type="Gradient" id=1]
colors = PoolColorArray( 0.284025, 0.4375, 0.0803223, 1, 0.30305, 0.480469, 0.0675659, 1 ) colors = PoolColorArray( 0.284025, 0.4375, 0.0803223, 1, 0.30305, 0.480469, 0.0675659, 1 )
@@ -115,19 +117,19 @@ width = 1920
[sub_resource type="Curve2D" id=4] [sub_resource type="Curve2D" id=4]
_data = { _data = {
"points": PoolVector2Array( 0, 0, 0, 0, -17.3556, 327.792, 0, 0, 0, 0, 1930.1, 452.427 ) "points": PoolVector2Array( 0, 0, 0, 0, 606.951, 579.696, 0, 0, 0, 0, 755.584, 596.499 )
} }
[sub_resource type="SpriteFrames" id=5] [sub_resource type="SpriteFrames" id=5]
animations = [ { animations = [ {
"frames": [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 9 ), ExtResource( 10 ), ExtResource( 11 ), ExtResource( 12 ), ExtResource( 13 ) ], "frames": [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 9 ), ExtResource( 10 ), ExtResource( 11 ), ExtResource( 12 ), ExtResource( 13 ) ],
"loop": true, "loop": true,
"name": "bus", "name": "car",
"speed": 5.0 "speed": 5.0
}, { }, {
"frames": [ ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 21 ) ], "frames": [ ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 21 ) ],
"loop": true, "loop": true,
"name": "car", "name": "bus",
"speed": 5.0 "speed": 5.0
}, { }, {
"frames": [ ExtResource( 22 ), ExtResource( 23 ), ExtResource( 24 ), ExtResource( 25 ), ExtResource( 26 ), ExtResource( 27 ), ExtResource( 28 ), ExtResource( 29 ) ], "frames": [ ExtResource( 22 ), ExtResource( 23 ), ExtResource( 24 ), ExtResource( 25 ), ExtResource( 26 ), ExtResource( 27 ), ExtResource( 28 ), ExtResource( 29 ) ],
@@ -149,7 +151,7 @@ expand = true
tile_set = SubResource( 3 ) tile_set = SubResource( 3 )
cell_size = Vector2( 128, 128 ) cell_size = Vector2( 128, 128 )
format = 1 format = 1
tile_data = PoolIntArray( 131079, 3, 0, 131080, 2, 0, 131081, 0, 0, 196616, 1, 0, 196617, 5, 0, 262152, 4, 0, 327688, 4, 0, 327690, 4, 0, 393224, 6, 0, 393225, 2, 0, 393226, 5, 0 ) tile_data = PoolIntArray( 262147, 1, 0, 262148, 3, 0, 262149, 2, 0, 262150, 2, 0, 262151, 0, 0, 327683, 4, 0, 327687, 4, 0, 393219, 6, 0, 393220, 2, 0, 393221, 2, 0, 393222, 2, 0, 393223, 5, 0 )
script = ExtResource( 3 ) script = ExtResource( 3 )
[node name="TrackPath" type="Path2D" parent="."] [node name="TrackPath" type="Path2D" parent="."]
@@ -157,8 +159,8 @@ curve = SubResource( 4 )
script = ExtResource( 4 ) script = ExtResource( 4 )
[node name="Opponent" type="PathFollow2D" parent="TrackPath"] [node name="Opponent" type="PathFollow2D" parent="TrackPath"]
position = Vector2( -17.3556, 327.792 ) position = Vector2( 606.951, 579.696 )
rotation = 0.0639077 rotation = 0.112561
script = ExtResource( 5 ) script = ExtResource( 5 )
[node name="OpponentCar" type="Node2D" parent="TrackPath/Opponent"] [node name="OpponentCar" type="Node2D" parent="TrackPath/Opponent"]
@@ -174,8 +176,8 @@ script = ExtResource( 30 )
skin = "police" skin = "police"
[node name="Player" type="PathFollow2D" parent="TrackPath"] [node name="Player" type="PathFollow2D" parent="TrackPath"]
position = Vector2( -17.3556, 327.792 ) position = Vector2( 606.951, 579.696 )
rotation = 0.0639077 rotation = 0.112561
script = ExtResource( 31 ) script = ExtResource( 31 )
[node name="PlayerCar" parent="TrackPath/Player" instance=ExtResource( 32 )] [node name="PlayerCar" parent="TrackPath/Player" instance=ExtResource( 32 )]
@@ -185,5 +187,9 @@ script = null
[node name="Wrong Way" parent="." instance=ExtResource( 33 )] [node name="Wrong Way" parent="." instance=ExtResource( 33 )]
visible = false visible = false
[node name="GUI" parent="." instance=ExtResource( 34 )]
script = ExtResource( 35 )
[connection signal="player_moved" from="." to="TrackPath/Player" method="_on_RaceTrack_player_moved"] [connection signal="player_moved" from="." to="TrackPath/Player" method="_on_RaceTrack_player_moved"]
[connection signal="wrong_way" from="." to="Wrong Way" method="_on_RaceTrack_wrong_way"] [connection signal="wrong_way" from="." to="Wrong Way" method="_on_RaceTrack_wrong_way"]
[connection signal="lap_completed" from="TrackPath/Player" to="GUI" method="_on_lap_completed"]

View File

@@ -5,7 +5,10 @@ enum { LEFT, RIGHT, UP, DOWN }
enum { DOWN_LEFT, DOWN_RIGHT, LEFT_RIGHT, START, UP_DOWN, UP_LEFT, UP_RIGHT } enum { DOWN_LEFT, DOWN_RIGHT, LEFT_RIGHT, START, UP_DOWN, UP_LEFT, UP_RIGHT }
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _reset():
_reload_track()
func _reload_track():
_clear_tiles() _clear_tiles()
var track = TrackSelection.get_current_track() var track = TrackSelection.get_current_track()
for idx in range(track.size()): for idx in range(track.size()):

View File

@@ -7,17 +7,19 @@ var half_size : int = tile_size / 2
onready var map = get_node("../TileMap/") onready var map = get_node("../TileMap/")
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _reset():
var track = TrackSelection.get_current_track() var track = TrackSelection.get_current_track()
_build_track(track) _build_track(track)
$Opponent.set_offset(0.0)
$Player.set_offset(0.0)
"""
func _draw(): func _draw():
draw_polyline(curve.get_baked_points(), Color.chartreuse, 4.0) draw_polyline(curve.get_baked_points(), Color.chartreuse, 4.0)
for idx in range(0,curve.get_point_count()): for idx in range(0,curve.get_point_count()):
draw_circle(curve.get_point_in(idx), 2.0, Color.green) draw_circle(curve.get_point_in(idx), 2.0, Color.green)
draw_circle(curve.get_point_out(idx), 2.0, Color.blue) draw_circle(curve.get_point_out(idx), 2.0, Color.blue)
"""
func _build_track(tiles): func _build_track(tiles):
""" Build the track curve given a tile path """ """ Build the track curve given a tile path """

View File

@@ -2,16 +2,7 @@ extends Node
const TRACKS_PATH = "res://assets/tracks/" const TRACKS_PATH = "res://assets/tracks/"
var _tracks = [ var _tracks = []
[ Vector2(2, 1), Vector2(3, 1), Vector2(4, 1),
Vector2(4, 2), Vector2(3, 2), Vector2(2, 2), Vector2(1, 2), Vector2(1, 1),
],
[ Vector2(7,1), Vector2(8,1), Vector2(9,1), Vector2(9,2), Vector2(9,3),
Vector2(8,3), Vector2(7,3), Vector2(7,4), Vector2(7,5), Vector2(7,6),
Vector2(6,6), Vector2(6,5), Vector2(6,4), Vector2(6,3), Vector2(5,3),
Vector2(4,3), Vector2(4,2), Vector2(4,1), Vector2(5,1), Vector2(6,1), ],
]
var _selected : int = 1 var _selected : int = 1
func _ready(): func _ready():
@@ -19,13 +10,17 @@ func _ready():
func set_next_track(): func set_next_track():
_selected = wrapi(_selected + 1, 0, _tracks.size()) _selected = wrapi(_selected + 1, 0, _tracks.size())
print("set_next_track : ", _selected)
func set_previous_track(): func set_previous_track():
_selected = wrapi(_selected - 1, 0, _tracks.size()) _selected = wrapi(_selected - 1, 0, _tracks.size())
func get_current_track(): func get_current_track():
return _tracks[_selected] return _tracks[_selected]
func _load_tracks(): func _load_tracks():
var loaded = [] var loaded = []
for path in _find_track_files(): for path in _find_track_files():
@@ -73,6 +68,7 @@ func __find_adjacent(coords, cells):
return idx return idx
return -1 return -1
func _find_track_files(): func _find_track_files():
var tracks = [] var tracks = []
var dir = Directory.new() var dir = Directory.new()