diff --git a/Main.gd b/Main.gd index a971be5..89035f6 100644 --- a/Main.gd +++ b/Main.gd @@ -18,4 +18,4 @@ func pause_game(): func _input(event): if event.is_action_pressed("ui_cancel"): - pause_game() \ No newline at end of file + pause_game() diff --git a/Menu.gd b/Menu.gd index 79a4d06..ef23984 100644 --- a/Menu.gd +++ b/Menu.gd @@ -111,4 +111,4 @@ func _update_options_values(): match Global.settings.input_mode: Global.InputMode.MOUSE: new_text = "Souris" Global.InputMode.KEYBOARD: new_text = "Clavier" - get_node("Options/InputMode/Value").set_text(new_text) \ No newline at end of file + get_node("Options/InputMode/Value").set_text(new_text) diff --git a/Player.gd b/Player.gd deleted file mode 100644 index 08660de..0000000 --- a/Player.gd +++ /dev/null @@ -1,27 +0,0 @@ -extends PathFollow2D - -signal lap_completed(laps) - -export (float) var speed = 0.125 - -var position_on_track := 0.0 -var target_on_track := 0.0 - -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 - elif target_on_track - position_on_track > 0.01: - # 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)) - position_on_track += speed * delta * speed_mod - set_unit_offset(min(position_on_track, target_on_track)) - else: - position_on_track = target_on_track - - -func _on_RaceTrack_player_moved(track_offset): - target_on_track = track_offset \ No newline at end of file diff --git a/RaceTrack.tscn b/RaceTrack.tscn index c9ae67b..97f00f8 100644 --- a/RaceTrack.tscn +++ b/RaceTrack.tscn @@ -30,7 +30,7 @@ [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://player_car.gd" type="Script" id=31] [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] @@ -50,6 +50,10 @@ width = 1920 0/tile_mode = 0 0/occluder_offset = Vector2( 0, 0 ) 0/navigation_offset = Vector2( 0, 0 ) +0/shape_offset = Vector2( 0, 0 ) +0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) +0/shape_one_way = false +0/shape_one_way_margin = 0.0 0/shapes = [ ] 0/z_index = 0 1/name = "dr" @@ -60,6 +64,10 @@ width = 1920 1/tile_mode = 0 1/occluder_offset = Vector2( 0, 0 ) 1/navigation_offset = Vector2( 0, 0 ) +1/shape_offset = Vector2( 0, 0 ) +1/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) +1/shape_one_way = false +1/shape_one_way_margin = 0.0 1/shapes = [ ] 1/z_index = 0 2/name = "lr" @@ -70,6 +78,10 @@ width = 1920 2/tile_mode = 0 2/occluder_offset = Vector2( 0, 0 ) 2/navigation_offset = Vector2( 0, 0 ) +2/shape_offset = Vector2( 0, 0 ) +2/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) +2/shape_one_way = false +2/shape_one_way_margin = 0.0 2/shapes = [ ] 2/z_index = 0 3/name = "start" @@ -80,6 +92,10 @@ width = 1920 3/tile_mode = 0 3/occluder_offset = Vector2( 0, 0 ) 3/navigation_offset = Vector2( 0, 0 ) +3/shape_offset = Vector2( 0, 0 ) +3/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) +3/shape_one_way = false +3/shape_one_way_margin = 0.0 3/shapes = [ ] 3/z_index = 0 4/name = "ud" @@ -90,6 +106,10 @@ width = 1920 4/tile_mode = 0 4/occluder_offset = Vector2( 0, 0 ) 4/navigation_offset = Vector2( 0, 0 ) +4/shape_offset = Vector2( 0, 0 ) +4/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) +4/shape_one_way = false +4/shape_one_way_margin = 0.0 4/shapes = [ ] 4/z_index = 0 5/name = "ul" @@ -100,6 +120,10 @@ width = 1920 5/tile_mode = 0 5/occluder_offset = Vector2( 0, 0 ) 5/navigation_offset = Vector2( 0, 0 ) +5/shape_offset = Vector2( 0, 0 ) +5/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) +5/shape_one_way = false +5/shape_one_way_margin = 0.0 5/shapes = [ ] 5/z_index = 0 6/name = "ur" @@ -110,6 +134,10 @@ width = 1920 6/tile_mode = 0 6/occluder_offset = Vector2( 0, 0 ) 6/navigation_offset = Vector2( 0, 0 ) +6/shape_offset = Vector2( 0, 0 ) +6/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) +6/shape_one_way = false +6/shape_one_way_margin = 0.0 6/shapes = [ ] 6/z_index = 0 @@ -157,11 +185,14 @@ animations = [ { [node name="RaceTrack" type="Node"] script = ExtResource( 1 ) -[node name="TextureRect" type="TextureRect" parent="."] +[node name="Background" type="TextureRect" parent="."] margin_right = 1920.0 margin_bottom = 1080.0 texture = SubResource( 2 ) expand = true +__meta__ = { +"_edit_use_anchors_": false +} [node name="TileMap" type="TileMap" parent="."] tile_set = SubResource( 3 ) diff --git a/player_car.gd b/player_car.gd index 990dcd6..c7fe588 100644 --- a/player_car.gd +++ b/player_car.gd @@ -1,17 +1,24 @@ -extends Node2D +extends PathFollow2D -export (String, "bus", "police", "car") var skin - - -enum { RIGHT, DOWN_RIGHT, DOWN, DOWN_LEFT, LEFT, UP_LEFT, UP, UP_RIGHT } - -# TODO: -# - Move track related logic inside TrackPlayer script ? -onready var track = get_node("/root/Track2/RaceTrack/TrackPlayer/") - - -func _ready(): - # Set player sprite - $CarSprite.set_animation(skin) +export (float) var speed = 0.250 + +var position_on_track := 0.0 +var target_on_track := 0.0 + +func _process(delta): + # Check if a lap was completed + if int(position_on_track) > Global.laps: + Global.laps += 1 + + # Move the player until target_on_track + elif target_on_track - position_on_track > 0.01: + # 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)) + position_on_track += speed * delta * speed_mod + set_unit_offset(min(position_on_track, target_on_track)) + else: + position_on_track = target_on_track +func _on_RaceTrack_player_moved(track_offset): + target_on_track = track_offset diff --git a/race_track.gd b/race_track.gd index 5368cd1..20ee069 100644 --- a/race_track.gd +++ b/race_track.gd @@ -6,7 +6,7 @@ signal player_moved(track_offset) signal wrong_way(coords) -# TODO: +# TODO : # - Keyboard controls !! var laps # This is duplicated here becayse of the track offset logic @@ -44,7 +44,7 @@ func _handle_mouse_input(event): if cell_idx != -1: # Check we are following the path if hover_cell == next_cell: - # Check if lap is completed. The is required + # Check if lap is completed. This is required # because the input can be way ahead player car sprite if next_cell == track[0]: laps += 1 @@ -69,4 +69,4 @@ func _reset_state(): track = TrackSelection.get_current_track() laps = 0 current_cell = track[0] - next_cell = track[1] \ No newline at end of file + next_cell = track[1] diff --git a/track_path.gd b/track_path.gd index 5699785..d76170e 100644 --- a/track_path.gd +++ b/track_path.gd @@ -87,4 +87,4 @@ func _direction_to(from_tile, to_tile): elif y_dir == -1: return UP else: - print_debug("Panic!! Path is not contiguous between", from_tile, " and ", to_tile) \ No newline at end of file + print_debug("Panic!! Path is not contiguous between", from_tile, " and ", to_tile) diff --git a/track_selection.gd b/track_selection.gd index 9a832df..eca3d32 100644 --- a/track_selection.gd +++ b/track_selection.gd @@ -97,4 +97,4 @@ func _find_track_files(): tracks.append(TRACKS_PATH + file) return tracks else: - print("An error occured while trying to load tracks. (Folder not found)") \ No newline at end of file + print("An error occured while trying to load tracks. (Folder not found)")