Compare commits
5 Commits
1b29065bf8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 39451c5553 | |||
|
|
9726fb8fcf | ||
| 4565755868 | |||
| d439d67813 | |||
| a8280df733 |
@@ -1,12 +1,12 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Countdown.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Oswald-Bold.otf" type="DynamicFontData" id=2]
|
||||
[ext_resource path="res://assets/Oswald-Bold.otf" type="DynamicFontData" id=2]
|
||||
|
||||
[sub_resource type="DynamicFont" id=1]
|
||||
size = 255
|
||||
outline_size = 20
|
||||
outline_color = Color( 0.145098, 0.145098, 0.145098, 1 )
|
||||
outline_size = 8
|
||||
outline_color = Color( 0.129412, 0.129412, 0.129412, 1 )
|
||||
use_filter = true
|
||||
font_data = ExtResource( 2 )
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
34
Gui.tscn
34
Gui.tscn
@@ -1,16 +1,6 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://Oswald-Bold.otf" type="DynamicFontData" id=1]
|
||||
|
||||
[sub_resource type="DynamicFont" id=1]
|
||||
size = 19
|
||||
font_data = ExtResource( 1 )
|
||||
|
||||
[sub_resource type="DynamicFont" id=2]
|
||||
size = 34
|
||||
outline_size = 2
|
||||
outline_color = Color( 0.25098, 0.25098, 0.25098, 1 )
|
||||
font_data = ExtResource( 1 )
|
||||
[ext_resource path="res://font.tres" type="DynamicFont" id=1]
|
||||
|
||||
[node name="GUI" type="MarginContainer"]
|
||||
margin_left = 10.5631
|
||||
@@ -19,20 +9,18 @@ margin_right = 159.563
|
||||
margin_bottom = 59.2427
|
||||
|
||||
[node name="Laps" type="HBoxContainer" parent="."]
|
||||
margin_right = 148.0
|
||||
margin_bottom = 50.0
|
||||
margin_right = 155.0
|
||||
margin_bottom = 66.0
|
||||
|
||||
[node name="Text" type="Label" parent="Laps"]
|
||||
margin_top = 11.0
|
||||
margin_right = 50.0
|
||||
margin_bottom = 38.0
|
||||
custom_fonts/font = SubResource( 1 )
|
||||
margin_right = 125.0
|
||||
margin_bottom = 66.0
|
||||
custom_fonts/font = ExtResource( 1 )
|
||||
text = "Laps : "
|
||||
|
||||
[node name="Value" type="Label" parent="Laps"]
|
||||
margin_left = 54.0
|
||||
margin_top = 1.0
|
||||
margin_right = 72.0
|
||||
margin_bottom = 49.0
|
||||
custom_fonts/font = SubResource( 2 )
|
||||
margin_left = 129.0
|
||||
margin_right = 155.0
|
||||
margin_bottom = 66.0
|
||||
custom_fonts/font = ExtResource( 1 )
|
||||
text = "0"
|
||||
|
||||
@@ -21,6 +21,5 @@ visible = false
|
||||
delay = 3
|
||||
|
||||
[node name="GUI" parent="." instance=ExtResource( 5 )]
|
||||
visible = false
|
||||
script = ExtResource( 6 )
|
||||
[connection signal="game_started" from="Menu" to="." method="start_game"]
|
||||
|
||||
40
Menu.gd
40
Menu.gd
@@ -11,10 +11,10 @@ enum Actions {
|
||||
PREV_TRACK,
|
||||
# PREV_SKIN,
|
||||
# NEXT_SKIN,
|
||||
# PREV_INPUT_MODE,
|
||||
# NEXT_INPUT_MODE,
|
||||
# PREV_GAME_MODE,
|
||||
# NEXT_GAME_MODE,
|
||||
PREV_INPUT_MODE,
|
||||
NEXT_INPUT_MODE,
|
||||
PREV_GAME_MODE,
|
||||
NEXT_GAME_MODE,
|
||||
QUIT,
|
||||
}
|
||||
var actions = {} # Registered actions
|
||||
@@ -29,6 +29,11 @@ func _ready():
|
||||
_connect_action("Options/Return", Actions.EXIT_OPTIONS)
|
||||
_connect_action("Options/TrackSelection/LeftArrow", Actions.PREV_TRACK)
|
||||
_connect_action("Options/TrackSelection/RightArrow", Actions.NEXT_TRACK)
|
||||
_connect_action("Options/GameMode/LeftArrow", Actions.PREV_GAME_MODE)
|
||||
_connect_action("Options/GameMode/RightArrow", Actions.NEXT_GAME_MODE)
|
||||
_connect_action("Options/InputMode/LeftArrow", Actions.PREV_INPUT_MODE)
|
||||
_connect_action("Options/InputMode/RightArrow", Actions.NEXT_INPUT_MODE)
|
||||
_update_options_values()
|
||||
|
||||
TrackSelection.connect("track_changed", self, "_on_track_changed")
|
||||
_on_track_changed()
|
||||
@@ -53,6 +58,20 @@ func _input(event):
|
||||
TrackSelection.set_previous_track()
|
||||
Actions.NEXT_TRACK:
|
||||
TrackSelection.set_next_track()
|
||||
Actions.NEXT_GAME_MODE,Actions.PREV_GAME_MODE:
|
||||
if Global.settings.game_mode == Global.GameMode.TRAIN:
|
||||
Global.settings.game_mode = Global.GameMode.EASY
|
||||
else:
|
||||
Global.settings.game_mode = Global.GameMode.TRAIN
|
||||
_update_options_values()
|
||||
|
||||
Actions.NEXT_INPUT_MODE,Actions.PREV_INPUT_MODE:
|
||||
if Global.settings.input_mode == Global.InputMode.MOUSE:
|
||||
Global.settings.input_mode = Global.InputMode.KEYBOARD
|
||||
else:
|
||||
Global.settings.input_mode = Global.InputMode.MOUSE
|
||||
_update_options_values()
|
||||
|
||||
|
||||
|
||||
func _on_track_changed():
|
||||
@@ -80,3 +99,16 @@ func _set_active(is_active, node):
|
||||
# Updates the focus effect for node
|
||||
var color = Color.orange if is_active else Color.white
|
||||
node.set("custom_colors/font_color", color)
|
||||
|
||||
|
||||
func _update_options_values():
|
||||
var new_text
|
||||
match Global.settings.game_mode:
|
||||
Global.GameMode.EASY: new_text = "Facile"
|
||||
Global.GameMode.TRAIN: new_text = "Entraînement"
|
||||
get_node("Options/GameMode/Value").set_text(new_text)
|
||||
|
||||
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)
|
||||
|
||||
@@ -38,6 +38,7 @@ margin_bottom = 421.063
|
||||
rect_scale = Vector2( 2, 2 )
|
||||
|
||||
[node name="TrackSelection" type="HBoxContainer" parent="Options"]
|
||||
editor/display_folded = true
|
||||
margin_right = 960.0
|
||||
margin_bottom = 66.0
|
||||
custom_constants/separation = 20
|
||||
@@ -83,6 +84,7 @@ custom_constants/shadow_offset_y = 3
|
||||
text = ">"
|
||||
|
||||
[node name="GameMode" type="HBoxContainer" parent="Options"]
|
||||
editor/display_folded = true
|
||||
margin_top = 70.0
|
||||
margin_right = 960.0
|
||||
margin_bottom = 136.0
|
||||
@@ -129,6 +131,7 @@ custom_constants/shadow_offset_y = 3
|
||||
text = ">"
|
||||
|
||||
[node name="InputMode" type="HBoxContainer" parent="Options"]
|
||||
editor/display_folded = true
|
||||
margin_top = 140.0
|
||||
margin_right = 960.0
|
||||
margin_bottom = 206.0
|
||||
|
||||
27
Player.gd
27
Player.gd
@@ -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
|
||||
117
RaceTrack.tscn
117
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://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]
|
||||
|
||||
[sub_resource type="Gradient" id=1]
|
||||
colors = PoolColorArray( 0.284025, 0.4375, 0.0803223, 1, 0.30305, 0.480469, 0.0675659, 1 )
|
||||
@@ -53,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"
|
||||
@@ -63,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"
|
||||
@@ -73,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"
|
||||
@@ -83,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"
|
||||
@@ -93,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"
|
||||
@@ -103,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"
|
||||
@@ -113,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
|
||||
|
||||
@@ -128,12 +153,12 @@ animations = [ {
|
||||
"name": "bus",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [ ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 21 ) ],
|
||||
"frames": [ ExtResource( 22 ), ExtResource( 23 ), ExtResource( 24 ), ExtResource( 25 ), ExtResource( 26 ), ExtResource( 27 ), ExtResource( 28 ), ExtResource( 29 ) ],
|
||||
"loop": true,
|
||||
"name": "car",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [ ExtResource( 22 ), ExtResource( 23 ), ExtResource( 24 ), ExtResource( 25 ), ExtResource( 26 ), ExtResource( 27 ), ExtResource( 28 ), ExtResource( 29 ) ],
|
||||
"frames": [ ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 21 ) ],
|
||||
"loop": true,
|
||||
"name": "police",
|
||||
"speed": 5.0
|
||||
@@ -146,12 +171,12 @@ animations = [ {
|
||||
"name": "bus",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [ ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 21 ) ],
|
||||
"frames": [ ExtResource( 22 ), ExtResource( 23 ), ExtResource( 24 ), ExtResource( 25 ), ExtResource( 26 ), ExtResource( 27 ), ExtResource( 28 ), ExtResource( 29 ) ],
|
||||
"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( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 21 ) ],
|
||||
"loop": true,
|
||||
"name": "police",
|
||||
"speed": 5.0
|
||||
@@ -160,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 )
|
||||
@@ -182,13 +210,10 @@ 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"]
|
||||
visible = false
|
||||
position = Vector2( -0.801025, 22.7594 )
|
||||
scale = Vector2( 0.2, 0.2 )
|
||||
frames = SubResource( 5 )
|
||||
animation = "car"
|
||||
script = ExtResource( 30 )
|
||||
@@ -199,18 +224,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"]
|
||||
|
||||
55
TileMap.gd
55
TileMap.gd
@@ -5,11 +5,11 @@ enum { LEFT, RIGHT, UP, DOWN }
|
||||
enum { DOWN_LEFT, DOWN_RIGHT, LEFT_RIGHT, START, UP_DOWN, UP_LEFT, UP_RIGHT }
|
||||
|
||||
func _ready():
|
||||
TrackSelection.connect("track_changed", self, "_reload_track")
|
||||
_reload_track()
|
||||
TrackSelection.connect("track_changed", self, "reload_track")
|
||||
reload_track()
|
||||
|
||||
func _reload_track():
|
||||
_clear_tiles()
|
||||
func reload_track():
|
||||
clear_tiles()
|
||||
var track = TrackSelection.get_current_track()
|
||||
for idx in range(track.size()):
|
||||
var cell = track[idx]
|
||||
@@ -19,37 +19,28 @@ func _reload_track():
|
||||
else:
|
||||
var prev = track[idx - 1]
|
||||
var next = track[wrapi(idx + 1, 0, track.size())]
|
||||
tile = _find_tile(cell.direction_to(prev), cell.direction_to(next))
|
||||
tile = find_tile(cell.direction_to(prev), cell.direction_to(next))
|
||||
set_cell(cell.x, cell.y, tile)
|
||||
|
||||
func _find_tile(prev, next):
|
||||
func find_tile(prev, next):
|
||||
""" Find the right tile given prev and next directions """
|
||||
prev = _as_dir(prev)
|
||||
next = _as_dir(next)
|
||||
# Could be smarter
|
||||
if prev == LEFT:
|
||||
match next:
|
||||
DOWN: return DOWN_LEFT
|
||||
UP: return UP_LEFT
|
||||
RIGHT: return LEFT_RIGHT
|
||||
elif prev == RIGHT:
|
||||
match next:
|
||||
DOWN: return DOWN_RIGHT
|
||||
UP: return UP_RIGHT
|
||||
LEFT: return LEFT_RIGHT
|
||||
elif prev == UP:
|
||||
match next:
|
||||
DOWN: return UP_DOWN
|
||||
LEFT: return UP_LEFT
|
||||
RIGHT: return UP_RIGHT
|
||||
elif prev == DOWN:
|
||||
match next:
|
||||
UP: return UP_DOWN
|
||||
LEFT: return DOWN_LEFT
|
||||
RIGHT: return DOWN_RIGHT
|
||||
prev = as_direction(prev)
|
||||
next = as_direction(next)
|
||||
match [prev, next]:
|
||||
[LEFT, DOWN]: return DOWN_LEFT
|
||||
[LEFT, UP]: return UP_LEFT
|
||||
[LEFT, RIGHT]: return LEFT_RIGHT
|
||||
[RIGHT, DOWN]: return DOWN_RIGHT
|
||||
[RIGHT, UP]: return UP_RIGHT
|
||||
[RIGHT, LEFT]: return LEFT_RIGHT
|
||||
[UP, DOWN]: return UP_DOWN
|
||||
[UP, LEFT]: return UP_LEFT
|
||||
[UP, RIGHT]: return UP_RIGHT
|
||||
[DOWN, UP]: return UP_DOWN
|
||||
[DOWN, LEFT]: return DOWN_LEFT
|
||||
[DOWN, RIGHT]: return DOWN_RIGHT
|
||||
|
||||
|
||||
func _as_dir(vector):
|
||||
func as_direction(vector):
|
||||
""" Returns the vector direction as a LEFT, RIGHT, UP or DOWN variant """
|
||||
if abs(vector.x) + abs(vector.y) != 1:
|
||||
return -1 # This is not a valid variant
|
||||
@@ -67,6 +58,6 @@ func _as_dir(vector):
|
||||
#func _process(delta):
|
||||
# pass
|
||||
|
||||
func _clear_tiles():
|
||||
func clear_tiles():
|
||||
for cell in get_used_cells():
|
||||
self.set_cell(cell.x, cell.y, -1)
|
||||
114
assets/France_road_sign_B1.svg
Normal file
114
assets/France_road_sign_B1.svg
Normal file
@@ -0,0 +1,114 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
id="svg2985"
|
||||
version="1.1"
|
||||
inkscape:version="0.48.4 r9939"
|
||||
width="485.33627"
|
||||
height="485.33627"
|
||||
sodipodi:docname="600px-France_road_sign_B1j.svg[1].png">
|
||||
<metadata
|
||||
id="metadata2991">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<defs
|
||||
id="defs2989" />
|
||||
<sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1272"
|
||||
inkscape:window-height="745"
|
||||
id="namedview2987"
|
||||
showgrid="false"
|
||||
inkscape:snap-global="true"
|
||||
inkscape:snap-grids="true"
|
||||
inkscape:snap-bbox="true"
|
||||
inkscape:bbox-paths="true"
|
||||
inkscape:bbox-nodes="true"
|
||||
inkscape:snap-bbox-edge-midpoints="true"
|
||||
inkscape:snap-bbox-midpoints="true"
|
||||
inkscape:object-paths="true"
|
||||
inkscape:snap-intersection-paths="true"
|
||||
inkscape:object-nodes="true"
|
||||
inkscape:snap-smooth-nodes="true"
|
||||
inkscape:snap-midpoints="true"
|
||||
inkscape:snap-object-midpoints="true"
|
||||
inkscape:snap-center="false"
|
||||
fit-margin-top="0"
|
||||
fit-margin-left="0"
|
||||
fit-margin-right="0"
|
||||
fit-margin-bottom="0"
|
||||
inkscape:zoom="0.59970176"
|
||||
inkscape:cx="390.56499"
|
||||
inkscape:cy="244.34365"
|
||||
inkscape:window-x="86"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1">
|
||||
<inkscape:grid
|
||||
type="xygrid"
|
||||
id="grid2995"
|
||||
empspacing="5"
|
||||
visible="true"
|
||||
enabled="true"
|
||||
snapvisiblegridlinesonly="true"
|
||||
originx="-57.33186px"
|
||||
originy="-57.33186px" />
|
||||
</sodipodi:namedview>
|
||||
<g
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
inkscape:label="1"
|
||||
style="display:inline"
|
||||
transform="translate(-57.33186,-57.33186)">
|
||||
<path
|
||||
sodipodi:type="arc"
|
||||
style="color:#000000;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2.5;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
|
||||
id="path2997"
|
||||
sodipodi:cx="300"
|
||||
sodipodi:cy="300"
|
||||
sodipodi:rx="240"
|
||||
sodipodi:ry="240"
|
||||
d="M 540,300 C 540,432.54834 432.54834,540 300,540 167.45166,540 60,432.54834 60,300 60,167.45166 167.45166,60 300,60 432.54834,60 540,167.45166 540,300 z"
|
||||
transform="matrix(1.0058783,0,0,1.0058783,-1.76349,-1.76349)" />
|
||||
<path
|
||||
sodipodi:type="arc"
|
||||
style="color:#000000;fill:#ff0000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.5;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
|
||||
id="path4005"
|
||||
sodipodi:cx="304.75"
|
||||
sodipodi:cy="214.75"
|
||||
sodipodi:rx="44.75"
|
||||
sodipodi:ry="44.75"
|
||||
d="m 349.5,214.75 c 0,24.71474 -20.03526,44.75 -44.75,44.75 -24.71474,0 -44.75,-20.03526 -44.75,-44.75 0,-24.71474 20.03526,-44.75 44.75,-44.75 24.71474,0 44.75,20.03526 44.75,44.75 z"
|
||||
transform="matrix(5.1364411,0,0,5.1364411,-1265.3304,-803.05073)" />
|
||||
<rect
|
||||
style="color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.5;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
|
||||
id="rect4001"
|
||||
width="345"
|
||||
height="80.599998"
|
||||
x="127.5"
|
||||
y="259.70001" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
34
assets/France_road_sign_B1.svg.import
Normal file
34
assets/France_road_sign_B1.svg.import
Normal file
@@ -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
|
||||
8
assets/tracks/Circuit_de_bernede.txt
Normal file
8
assets/tracks/Circuit_de_bernede.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
...............
|
||||
.xxsxxxxxxxx...
|
||||
.x.........xxx.
|
||||
.x...xxxxx...x.
|
||||
.x...x...x...x.
|
||||
.xxxxx...xxxxx.
|
||||
...............
|
||||
...............
|
||||
8
assets/tracks/track2.txt
Normal file
8
assets/tracks/track2.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
...............
|
||||
.xxxsxxxxxxxxx.
|
||||
.x...........x.
|
||||
.x...........x.
|
||||
.xxxxxxxx....x.
|
||||
........x....x.
|
||||
........xxxxxx.
|
||||
...............
|
||||
@@ -4,9 +4,8 @@ name="Linux/X11"
|
||||
platform="Linux/X11"
|
||||
runnable=true
|
||||
custom_features=""
|
||||
export_filter="scenes"
|
||||
export_files=PoolStringArray( "res://Track1.tscn" )
|
||||
include_filter=""
|
||||
export_filter="all_resources"
|
||||
include_filter="*.txt"
|
||||
exclude_filter=""
|
||||
export_path="/mnt/Data/Projets/godot/CarRacer/release.x86_64"
|
||||
patch_list=PoolStringArray( )
|
||||
|
||||
@@ -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
|
||||
|
||||
119
race_track.gd
119
race_track.gd
@@ -1,58 +1,101 @@
|
||||
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 step_next():
|
||||
""" Step this module state to the next cell """
|
||||
current_cell = next_cell
|
||||
var current_idx = track.find(current_cell)
|
||||
var next_idx = current_idx + 1 if current_idx < track.size() - 1 else 0
|
||||
next_cell = track[next_idx]
|
||||
emit_signal("player_moved", laps + get_track_offset(current_cell))
|
||||
emit_signal("wrong_way", Vector2(-1, -1)) # Cancel any wrong way sign
|
||||
|
||||
func _handle_keyboard_input(event):
|
||||
if event is InputEventKey:
|
||||
var direction_to_next = current_cell.direction_to(next_cell)
|
||||
if event.is_action_pressed("ui_up"):
|
||||
print_debug("Up key")
|
||||
if direction_to_next == Vector2(0, -1):
|
||||
step_next()
|
||||
else:
|
||||
emit_signal("wrong_way", map.map_to_world(Vector2(current_cell.x, current_cell.y - 1)))
|
||||
elif event.is_action_pressed("ui_right"):
|
||||
print_debug("Right key")
|
||||
if direction_to_next == Vector2(1, 0):
|
||||
step_next()
|
||||
else:
|
||||
emit_signal("wrong_way", map.map_to_world(Vector2(current_cell.x + 1, current_cell.y)))
|
||||
elif event.is_action_pressed("ui_left"):
|
||||
print_debug("Left key")
|
||||
if direction_to_next == Vector2(-1, 0):
|
||||
step_next()
|
||||
else:
|
||||
emit_signal("wrong_way", map.map_to_world(Vector2(current_cell.x - 1, current_cell.y)))
|
||||
elif event.is_action_pressed("ui_down"):
|
||||
print_debug("Key down")
|
||||
if direction_to_next == Vector2(0, 1):
|
||||
step_next()
|
||||
else:
|
||||
emit_signal("wrong_way", map.map_to_world(Vector2(current_cell.x, current_cell.y + 1)))
|
||||
|
||||
|
||||
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. This 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.
|
||||
step_next()
|
||||
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()
|
||||
|
||||
next_cell = track[1]
|
||||
|
||||
@@ -54,7 +54,7 @@ func _build_track(tiles):
|
||||
# pass
|
||||
|
||||
func _point_at(_curve, pos, dir):
|
||||
# Use only control_in since it gives smoother turns
|
||||
# Using only control_in gives smoother turns
|
||||
var half_size = tile_size / 2
|
||||
var control_in
|
||||
match dir:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
set_position(Vector2(coords.x + 32, coords.y + 32))
|
||||
Reference in New Issue
Block a user