diff --git a/Global.gd b/Global.gd index ff3644d..5393148 100644 --- a/Global.gd +++ b/Global.gd @@ -14,7 +14,7 @@ func set_laps(value): emit_signal("laps_changed", value) var settings = { - "input_mode": null, - "game_mode": null, - "player_skin": null, + "input_mode": InputMode.MOUSE, + "game_mode": GameMode.EASY, + "player_skin": PlayerSkin.CAR, } diff --git a/RaceTrack.tscn b/RaceTrack.tscn index b3545b9..c9ae67b 100644 --- a/RaceTrack.tscn +++ b/RaceTrack.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=39 format=2] +[gd_scene load_steps=40 format=2] [ext_resource path="res://race_track.gd" type="Script" id=1] [ext_resource path="res://assets/track_tiles/track.png" type="Texture" id=2] @@ -13,29 +13,26 @@ [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/bus/busiso_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_0003.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/car02/car02iso_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/car02/car02iso_0007.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/car02/car02iso_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/policeCar/policeiso_0003.png" type="Texture" id=22] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0004.png" type="Texture" id=23] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0001.png" type="Texture" id=24] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0002.png" type="Texture" id=25] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0007.png" type="Texture" id=26] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0000.png" type="Texture" id=27] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0005.png" type="Texture" id=28] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0006.png" type="Texture" id=29] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0003.png" type="Texture" id=14] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0004.png" type="Texture" id=15] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0001.png" type="Texture" id=16] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0002.png" type="Texture" id=17] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0007.png" type="Texture" id=18] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0000.png" type="Texture" id=19] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0005.png" type="Texture" id=20] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0006.png" type="Texture" id=21] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0003.png" type="Texture" id=22] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0004.png" type="Texture" id=23] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0001.png" type="Texture" id=24] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0002.png" type="Texture" id=25] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0007.png" type="Texture" id=26] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0000.png" type="Texture" id=27] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0005.png" type="Texture" id=28] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0006.png" type="Texture" id=29] [ext_resource path="res://car_sprite.gd" type="Script" id=30] [ext_resource path="res://Player.gd" type="Script" id=31] -[ext_resource path="res://wrong_way.tscn" type="PackedScene" id=32] - - - - +[ext_resource path="res://assets/France_road_sign_B1.svg" type="Texture" id=32] +[ext_resource path="res://wrong_way.gd" type="Script" id=33] [sub_resource type="Gradient" id=1] colors = PoolColorArray( 0.284025, 0.4375, 0.0803223, 1, 0.30305, 0.480469, 0.0675659, 1 ) @@ -130,12 +127,12 @@ animations = [ { }, { "frames": [ ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 21 ) ], "loop": true, -"name": "car", +"name": "police", "speed": 5.0 }, { "frames": [ ExtResource( 22 ), ExtResource( 23 ), ExtResource( 24 ), ExtResource( 25 ), ExtResource( 26 ), ExtResource( 27 ), ExtResource( 28 ), ExtResource( 29 ) ], "loop": true, -"name": "police", +"name": "car", "speed": 5.0 } ] @@ -146,15 +143,15 @@ animations = [ { "name": "bus", "speed": 5.0 }, { -"frames": [ ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 21 ) ], -"loop": true, -"name": "car", -"speed": 5.0 -}, { -"frames": [ ExtResource( 27 ), ExtResource( 24 ), ExtResource( 25 ), ExtResource( 22 ), ExtResource( 23 ), ExtResource( 28 ), ExtResource( 29 ), ExtResource( 26 ) ], +"frames": [ ExtResource( 19 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 14 ), ExtResource( 15 ), ExtResource( 20 ), ExtResource( 21 ), ExtResource( 18 ) ], "loop": true, "name": "police", "speed": 5.0 +}, { +"frames": [ ExtResource( 22 ), ExtResource( 23 ), ExtResource( 24 ), ExtResource( 25 ), ExtResource( 26 ), ExtResource( 27 ), ExtResource( 28 ), ExtResource( 29 ) ], +"loop": true, +"name": "car", +"speed": 5.0 } ] [node name="RaceTrack" type="Node"] @@ -182,13 +179,9 @@ position = Vector2( 606.951, 579.696 ) rotation = 0.112563 script = ExtResource( 5 ) -[node name="OpponentCar" type="Node2D" parent="TrackPath/Opponent"] -position = Vector2( 0, 22 ) -scale = Vector2( 0.25, 0.25 ) - -[node name="CarSprite" type="AnimatedSprite" parent="TrackPath/Opponent/OpponentCar"] -position = Vector2( -3.20422, 3.0376 ) -scale = Vector2( 0.8, 0.8 ) +[node name="CarSprite" type="AnimatedSprite" parent="TrackPath/Opponent"] +position = Vector2( -0.801025, 22.7594 ) +scale = Vector2( 0.2, 0.2 ) frames = SubResource( 5 ) animation = "car" script = ExtResource( 30 ) @@ -199,18 +192,24 @@ position = Vector2( 606.951, 579.696 ) rotation = 0.112563 script = ExtResource( 31 ) -[node name="PlayerCar" type="Node2D" parent="TrackPath/Player"] -position = Vector2( 1.89564, -22.3528 ) -scale = Vector2( 0.25, 0.25 ) - -[node name="CarSprite" type="AnimatedSprite" parent="TrackPath/Player/PlayerCar"] -position = Vector2( -3.20422, 3.0376 ) -scale = Vector2( 0.8, 0.8 ) +[node name="CarSprite" type="AnimatedSprite" parent="TrackPath/Player"] +position = Vector2( 1.09454, -21.5934 ) +scale = Vector2( 0.2, 0.2 ) frames = SubResource( 6 ) animation = "car" script = ExtResource( 30 ) -[node name="Wrong Way" parent="." instance=ExtResource( 32 )] +[node name="Wrong Way" type="TextureRect" parent="."] visible = false +margin_left = 445.793 +margin_top = 558.431 +margin_right = 930.792 +margin_bottom = 1043.43 +rect_scale = Vector2( 0.1, 0.1 ) +size_flags_horizontal = 0 +size_flags_vertical = 0 +texture = ExtResource( 32 ) +stretch_mode = 4 +script = ExtResource( 33 ) [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"] diff --git a/assets/France_road_sign_B1.svg b/assets/France_road_sign_B1.svg new file mode 100644 index 0000000..f561476 --- /dev/null +++ b/assets/France_road_sign_B1.svg @@ -0,0 +1,114 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/assets/France_road_sign_B1.svg.import b/assets/France_road_sign_B1.svg.import new file mode 100644 index 0000000..154cbe7 --- /dev/null +++ b/assets/France_road_sign_B1.svg.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/France_road_sign_B1.svg-69d4cf188193981c0635f7ce7bfdfc6d.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/France_road_sign_B1.svg" +dest_files=[ "res://.import/France_road_sign_B1.svg-69d4cf188193981c0635f7ce7bfdfc6d.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/race_track.gd b/race_track.gd index 993fde0..5368cd1 100644 --- a/race_track.gd +++ b/race_track.gd @@ -1,58 +1,72 @@ extends Node - +# This is where the racing logic is handled (player car input and movement, +# ensuring valid path, ...) +# We keep informations on player progress here. signal player_moved(track_offset) signal wrong_way(coords) + # TODO: -# - Find a mean to import tracks (arrays of cell coordinates). -# ( - Autopopulate the map according to track data ) -# - Build the track Curve2D from track and tiles data # - Keyboard controls !! -var laps +var laps # This is duplicated here becayse of the track offset logic var current_cell +var next_cell var track = null onready var map = $TileMap -func get_track_offset(coords): - 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(): TrackSelection.connect("track_changed", self, "_reset_state") _reset_state() + +func _input(event): + match Global.settings.input_mode: + Global.InputMode.MOUSE: + _handle_mouse_input(event) + Global.InputMode.KEYBOARD: + _handle_keyboard_input(event) + + +func _handle_keyboard_input(event): + if event is InputEventKey: + print_debug("Input Ignored: KEYBOARD MODE") + + +func _handle_mouse_input(event): + # Check if the mouse if following the tiles track + if event is InputEventMouseMotion: + var hover_cell = map.world_to_map(event.position) + if hover_cell != current_cell: # The mouse moved to a new cell + var cell_idx = track.find(hover_cell) + # Check the tile is on path + if cell_idx != -1: + # Check we are following the path + if hover_cell == next_cell: + # Check if lap is completed. The is required + # because the input can be way ahead player car sprite + if next_cell == track[0]: + laps += 1 + # We use the loop property of PathFollow2D to embed + # laps count inside the offset. + emit_signal("player_moved", laps + get_track_offset(hover_cell)) + emit_signal("wrong_way", Vector2(-1, -1)) + current_cell = next_cell + var next_idx = cell_idx + 1 if cell_idx < track.size() - 1 else 0 + next_cell = track[next_idx] + else: + emit_signal("wrong_way", map.map_to_world(hover_cell)) + + +func get_track_offset(coords): + # Returns the offset in Path2D of a track cell. + var offset = float(track.find(coords)) / float(len(track)) + return offset + + 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) - if hover_cell != current_cell: # The mouse moved to a new cell - # Check the tile is on path - if track.find(hover_cell) != -1: - # Check if a lap is finished - if hover_cell == track[0] and current_cell == track[-1]: - laps += 1 - # 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)) - emit_signal("wrong_way", Vector2(-1, -1)) - 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() - \ No newline at end of file + next_cell = track[1] \ No newline at end of file diff --git a/track_selection.gd b/track_selection.gd index beb18f2..9a832df 100644 --- a/track_selection.gd +++ b/track_selection.gd @@ -1,12 +1,13 @@ extends Node +# This is an autoload script handling things related to track data and state. signal track_changed() const TRACKS_PATH = "res://assets/tracks/" - var _tracks = [] var _selected : int + func _ready(): _load_tracks() _selected = 0 diff --git a/wrong_way.gd b/wrong_way.gd index f86db69..031eda7 100644 --- a/wrong_way.gd +++ b/wrong_way.gd @@ -1,4 +1,4 @@ -extends Label +extends TextureRect # Called when the node enters the scene tree for the first time. func _ready(): @@ -10,4 +10,4 @@ func _on_RaceTrack_wrong_way(coords): set_visible(false) else: set_visible(true) - set_position(coords) \ No newline at end of file + set_position(Vector2(coords.x + 32, coords.y + 32)) \ No newline at end of file