cleans code. adds sign for wrong way
This commit is contained in:
@@ -14,7 +14,7 @@ func set_laps(value):
|
|||||||
emit_signal("laps_changed", value)
|
emit_signal("laps_changed", value)
|
||||||
|
|
||||||
var settings = {
|
var settings = {
|
||||||
"input_mode": null,
|
"input_mode": InputMode.MOUSE,
|
||||||
"game_mode": null,
|
"game_mode": GameMode.EASY,
|
||||||
"player_skin": null,
|
"player_skin": PlayerSkin.CAR,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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://race_track.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]
|
||||||
@@ -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_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_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/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/policeCar/policeiso_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/policeCar/policeiso_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/policeCar/policeiso_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/policeCar/policeiso_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/policeCar/policeiso_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/policeCar/policeiso_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/policeCar/policeiso_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_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/car02/car02iso_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/car02/car02iso_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/car02/car02iso_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/car02/car02iso_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/car02/car02iso_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/car02/car02iso_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/car02/car02iso_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/car02/car02iso_0006.png" type="Texture" id=29]
|
||||||
[ext_resource path="res://car_sprite.gd" type="Script" id=30]
|
[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.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]
|
[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 )
|
||||||
@@ -130,12 +127,12 @@ animations = [ {
|
|||||||
}, {
|
}, {
|
||||||
"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": "police",
|
||||||
"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 ) ],
|
||||||
"loop": true,
|
"loop": true,
|
||||||
"name": "police",
|
"name": "car",
|
||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
} ]
|
} ]
|
||||||
|
|
||||||
@@ -146,15 +143,15 @@ animations = [ {
|
|||||||
"name": "bus",
|
"name": "bus",
|
||||||
"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( 19 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 14 ), ExtResource( 15 ), ExtResource( 20 ), ExtResource( 21 ), ExtResource( 18 ) ],
|
||||||
"loop": true,
|
|
||||||
"name": "car",
|
|
||||||
"speed": 5.0
|
|
||||||
}, {
|
|
||||||
"frames": [ ExtResource( 27 ), ExtResource( 24 ), ExtResource( 25 ), ExtResource( 22 ), ExtResource( 23 ), ExtResource( 28 ), ExtResource( 29 ), ExtResource( 26 ) ],
|
|
||||||
"loop": true,
|
"loop": true,
|
||||||
"name": "police",
|
"name": "police",
|
||||||
"speed": 5.0
|
"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"]
|
[node name="RaceTrack" type="Node"]
|
||||||
@@ -182,13 +179,9 @@ position = Vector2( 606.951, 579.696 )
|
|||||||
rotation = 0.112563
|
rotation = 0.112563
|
||||||
script = ExtResource( 5 )
|
script = ExtResource( 5 )
|
||||||
|
|
||||||
[node name="OpponentCar" type="Node2D" parent="TrackPath/Opponent"]
|
[node name="CarSprite" type="AnimatedSprite" parent="TrackPath/Opponent"]
|
||||||
position = Vector2( 0, 22 )
|
position = Vector2( -0.801025, 22.7594 )
|
||||||
scale = Vector2( 0.25, 0.25 )
|
scale = Vector2( 0.2, 0.2 )
|
||||||
|
|
||||||
[node name="CarSprite" type="AnimatedSprite" parent="TrackPath/Opponent/OpponentCar"]
|
|
||||||
position = Vector2( -3.20422, 3.0376 )
|
|
||||||
scale = Vector2( 0.8, 0.8 )
|
|
||||||
frames = SubResource( 5 )
|
frames = SubResource( 5 )
|
||||||
animation = "car"
|
animation = "car"
|
||||||
script = ExtResource( 30 )
|
script = ExtResource( 30 )
|
||||||
@@ -199,18 +192,24 @@ position = Vector2( 606.951, 579.696 )
|
|||||||
rotation = 0.112563
|
rotation = 0.112563
|
||||||
script = ExtResource( 31 )
|
script = ExtResource( 31 )
|
||||||
|
|
||||||
[node name="PlayerCar" type="Node2D" parent="TrackPath/Player"]
|
[node name="CarSprite" type="AnimatedSprite" parent="TrackPath/Player"]
|
||||||
position = Vector2( 1.89564, -22.3528 )
|
position = Vector2( 1.09454, -21.5934 )
|
||||||
scale = Vector2( 0.25, 0.25 )
|
scale = Vector2( 0.2, 0.2 )
|
||||||
|
|
||||||
[node name="CarSprite" type="AnimatedSprite" parent="TrackPath/Player/PlayerCar"]
|
|
||||||
position = Vector2( -3.20422, 3.0376 )
|
|
||||||
scale = Vector2( 0.8, 0.8 )
|
|
||||||
frames = SubResource( 6 )
|
frames = SubResource( 6 )
|
||||||
animation = "car"
|
animation = "car"
|
||||||
script = ExtResource( 30 )
|
script = ExtResource( 30 )
|
||||||
|
|
||||||
[node name="Wrong Way" parent="." instance=ExtResource( 32 )]
|
[node name="Wrong Way" type="TextureRect" parent="."]
|
||||||
visible = false
|
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="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"]
|
||||||
|
|||||||
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
|
||||||
@@ -1,58 +1,72 @@
|
|||||||
extends Node
|
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 player_moved(track_offset)
|
||||||
signal wrong_way(coords)
|
signal wrong_way(coords)
|
||||||
|
|
||||||
|
|
||||||
# TODO:
|
# 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 !!
|
# - Keyboard controls !!
|
||||||
|
|
||||||
var laps
|
var laps # This is duplicated here becayse of the track offset logic
|
||||||
var current_cell
|
var current_cell
|
||||||
|
var next_cell
|
||||||
var track = null
|
var track = null
|
||||||
onready var map = $TileMap
|
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():
|
func _ready():
|
||||||
TrackSelection.connect("track_changed", self, "_reset_state")
|
TrackSelection.connect("track_changed", self, "_reset_state")
|
||||||
_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():
|
func _reset_state():
|
||||||
track = TrackSelection.get_current_track()
|
track = TrackSelection.get_current_track()
|
||||||
laps = 0
|
laps = 0
|
||||||
current_cell = track[0]
|
current_cell = track[0]
|
||||||
|
next_cell = track[1]
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
extends Node
|
extends Node
|
||||||
|
# This is an autoload script handling things related to track data and state.
|
||||||
|
|
||||||
signal track_changed()
|
signal track_changed()
|
||||||
|
|
||||||
const TRACKS_PATH = "res://assets/tracks/"
|
const TRACKS_PATH = "res://assets/tracks/"
|
||||||
|
|
||||||
var _tracks = []
|
var _tracks = []
|
||||||
var _selected : int
|
var _selected : int
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
_load_tracks()
|
_load_tracks()
|
||||||
_selected = 0
|
_selected = 0
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
extends Label
|
extends TextureRect
|
||||||
|
|
||||||
# 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():
|
||||||
@@ -10,4 +10,4 @@ func _on_RaceTrack_wrong_way(coords):
|
|||||||
set_visible(false)
|
set_visible(false)
|
||||||
else:
|
else:
|
||||||
set_visible(true)
|
set_visible(true)
|
||||||
set_position(coords)
|
set_position(Vector2(coords.x + 32, coords.y + 32))
|
||||||
Reference in New Issue
Block a user