cleans up some unused code
This commit is contained in:
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
|
|
||||||
@@ -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_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://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_car.gd" type="Script" id=31]
|
||||||
[ext_resource path="res://assets/France_road_sign_B1.svg" type="Texture" 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]
|
[ext_resource path="res://wrong_way.gd" type="Script" id=33]
|
||||||
|
|
||||||
@@ -50,6 +50,10 @@ width = 1920
|
|||||||
0/tile_mode = 0
|
0/tile_mode = 0
|
||||||
0/occluder_offset = Vector2( 0, 0 )
|
0/occluder_offset = Vector2( 0, 0 )
|
||||||
0/navigation_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/shapes = [ ]
|
||||||
0/z_index = 0
|
0/z_index = 0
|
||||||
1/name = "dr"
|
1/name = "dr"
|
||||||
@@ -60,6 +64,10 @@ width = 1920
|
|||||||
1/tile_mode = 0
|
1/tile_mode = 0
|
||||||
1/occluder_offset = Vector2( 0, 0 )
|
1/occluder_offset = Vector2( 0, 0 )
|
||||||
1/navigation_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/shapes = [ ]
|
||||||
1/z_index = 0
|
1/z_index = 0
|
||||||
2/name = "lr"
|
2/name = "lr"
|
||||||
@@ -70,6 +78,10 @@ width = 1920
|
|||||||
2/tile_mode = 0
|
2/tile_mode = 0
|
||||||
2/occluder_offset = Vector2( 0, 0 )
|
2/occluder_offset = Vector2( 0, 0 )
|
||||||
2/navigation_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/shapes = [ ]
|
||||||
2/z_index = 0
|
2/z_index = 0
|
||||||
3/name = "start"
|
3/name = "start"
|
||||||
@@ -80,6 +92,10 @@ width = 1920
|
|||||||
3/tile_mode = 0
|
3/tile_mode = 0
|
||||||
3/occluder_offset = Vector2( 0, 0 )
|
3/occluder_offset = Vector2( 0, 0 )
|
||||||
3/navigation_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/shapes = [ ]
|
||||||
3/z_index = 0
|
3/z_index = 0
|
||||||
4/name = "ud"
|
4/name = "ud"
|
||||||
@@ -90,6 +106,10 @@ width = 1920
|
|||||||
4/tile_mode = 0
|
4/tile_mode = 0
|
||||||
4/occluder_offset = Vector2( 0, 0 )
|
4/occluder_offset = Vector2( 0, 0 )
|
||||||
4/navigation_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/shapes = [ ]
|
||||||
4/z_index = 0
|
4/z_index = 0
|
||||||
5/name = "ul"
|
5/name = "ul"
|
||||||
@@ -100,6 +120,10 @@ width = 1920
|
|||||||
5/tile_mode = 0
|
5/tile_mode = 0
|
||||||
5/occluder_offset = Vector2( 0, 0 )
|
5/occluder_offset = Vector2( 0, 0 )
|
||||||
5/navigation_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/shapes = [ ]
|
||||||
5/z_index = 0
|
5/z_index = 0
|
||||||
6/name = "ur"
|
6/name = "ur"
|
||||||
@@ -110,6 +134,10 @@ width = 1920
|
|||||||
6/tile_mode = 0
|
6/tile_mode = 0
|
||||||
6/occluder_offset = Vector2( 0, 0 )
|
6/occluder_offset = Vector2( 0, 0 )
|
||||||
6/navigation_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/shapes = [ ]
|
||||||
6/z_index = 0
|
6/z_index = 0
|
||||||
|
|
||||||
@@ -157,11 +185,14 @@ animations = [ {
|
|||||||
[node name="RaceTrack" type="Node"]
|
[node name="RaceTrack" type="Node"]
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="TextureRect" type="TextureRect" parent="."]
|
[node name="Background" type="TextureRect" parent="."]
|
||||||
margin_right = 1920.0
|
margin_right = 1920.0
|
||||||
margin_bottom = 1080.0
|
margin_bottom = 1080.0
|
||||||
texture = SubResource( 2 )
|
texture = SubResource( 2 )
|
||||||
expand = true
|
expand = true
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
[node name="TileMap" type="TileMap" parent="."]
|
[node name="TileMap" type="TileMap" parent="."]
|
||||||
tile_set = SubResource( 3 )
|
tile_set = SubResource( 3 )
|
||||||
|
|||||||
@@ -1,17 +1,24 @@
|
|||||||
extends Node2D
|
extends PathFollow2D
|
||||||
|
|
||||||
export (String, "bus", "police", "car") var skin
|
export (float) var speed = 0.250
|
||||||
|
|
||||||
|
var position_on_track := 0.0
|
||||||
enum { RIGHT, DOWN_RIGHT, DOWN, DOWN_LEFT, LEFT, UP_LEFT, UP, UP_RIGHT }
|
var target_on_track := 0.0
|
||||||
|
|
||||||
# TODO:
|
func _process(delta):
|
||||||
# - Move track related logic inside TrackPlayer script ?
|
# Check if a lap was completed
|
||||||
onready var track = get_node("/root/Track2/RaceTrack/TrackPlayer/")
|
if int(position_on_track) > Global.laps:
|
||||||
|
Global.laps += 1
|
||||||
|
|
||||||
func _ready():
|
# Move the player until target_on_track
|
||||||
# Set player sprite
|
elif target_on_track - position_on_track > 0.01:
|
||||||
$CarSprite.set_animation(skin)
|
# 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
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ signal player_moved(track_offset)
|
|||||||
signal wrong_way(coords)
|
signal wrong_way(coords)
|
||||||
|
|
||||||
|
|
||||||
# TODO:
|
# TODO :
|
||||||
# - Keyboard controls !!
|
# - Keyboard controls !!
|
||||||
|
|
||||||
var laps # This is duplicated here becayse of the track offset logic
|
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:
|
if cell_idx != -1:
|
||||||
# Check we are following the path
|
# Check we are following the path
|
||||||
if hover_cell == next_cell:
|
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
|
# because the input can be way ahead player car sprite
|
||||||
if next_cell == track[0]:
|
if next_cell == track[0]:
|
||||||
laps += 1
|
laps += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user