putting together in Main scene
This commit is contained in:
15
CarSprite.gd
15
CarSprite.gd
@@ -2,25 +2,25 @@ extends AnimatedSprite
|
|||||||
|
|
||||||
enum { RIGHT, DOWN_RIGHT, DOWN, DOWN_LEFT, LEFT, UP_LEFT, UP, UP_RIGHT }
|
enum { RIGHT, DOWN_RIGHT, DOWN, DOWN_LEFT, LEFT, UP_LEFT, UP, UP_RIGHT }
|
||||||
|
|
||||||
var sprite := UP
|
|
||||||
export (int) var threshold = 5 # Range to snap around axis direction, in degrees.
|
export (int) var threshold = 5 # Range to snap around axis direction, in degrees.
|
||||||
|
export (String, "bus", "police", "car") var skin = "car"
|
||||||
|
var sprite := UP
|
||||||
|
|
||||||
var time = 0.0
|
|
||||||
# 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():
|
||||||
pass # Replace with function body.
|
set_animation(skin)
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
"""
|
"""
|
||||||
The sprite has its own representation of rotation, so we need to tweak things.
|
The sprite has its own representation of rotation, so we need to tweak things.
|
||||||
The sprite inherits orientation from its parent (track) that must be canceled.
|
The sprite inherits orientation from its parent (TrackFollow) that must be canceled.
|
||||||
"""
|
"""
|
||||||
var global = get_global_rotation_degrees()
|
var global = get_global_rotation_degrees()
|
||||||
var local = get_rotation_degrees()
|
var local = get_rotation_degrees()
|
||||||
var total = wrapf(global - local, -180.0, 180.0)
|
var total = wrapf(global - local, -180.0, 180.0)
|
||||||
var r = snap_rotation(total)
|
var r = snap_rotation(total)
|
||||||
if _update_sprite(r):
|
if _update_sprite(r):
|
||||||
print_debug("frame changed")
|
#print_debug("frame changed")
|
||||||
set_frame(sprite)
|
set_frame(sprite)
|
||||||
# We can just cancel out the "part of" the rotation
|
# We can just cancel out the "part of" the rotation
|
||||||
# embedded in the sprites, leaving out a small
|
# embedded in the sprites, leaving out a small
|
||||||
@@ -29,11 +29,6 @@ func _process(delta):
|
|||||||
# ...Or we just cancel out everything
|
# ...Or we just cancel out everything
|
||||||
set_rotation_degrees(-total)
|
set_rotation_degrees(-total)
|
||||||
|
|
||||||
get_node("/root/Track2/HBoxContainer/Rotation").set_text("%.1f°" % r)
|
|
||||||
time += delta
|
|
||||||
if time >= 0.1:
|
|
||||||
print_debug("%.1f" % get_rotation_degrees(), "° | global: ", "%.1f" % get_global_rotation_degrees(), "°")
|
|
||||||
|
|
||||||
|
|
||||||
func snap_rotation(r):
|
func snap_rotation(r):
|
||||||
"""
|
"""
|
||||||
|
|||||||
32
Countdown.gd
Normal file
32
Countdown.gd
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
extends Node2D
|
||||||
|
|
||||||
|
signal race_started
|
||||||
|
|
||||||
|
export (int) var delay = 3
|
||||||
|
var timer
|
||||||
|
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
# Set up a timer
|
||||||
|
timer = Timer.new()
|
||||||
|
add_child(timer)
|
||||||
|
timer.wait_time = 1.0
|
||||||
|
timer.connect("timeout", self, "_timeout")
|
||||||
|
timer.start()
|
||||||
|
|
||||||
|
$Number.set_text("%d" % delay)
|
||||||
|
|
||||||
|
|
||||||
|
func _timeout():
|
||||||
|
#print("Timeout !")
|
||||||
|
delay -= 1
|
||||||
|
if delay < 0:
|
||||||
|
timer.stop()
|
||||||
|
set_visible(false)
|
||||||
|
elif delay == 0:
|
||||||
|
# Go !
|
||||||
|
$Number.set_text("GO")
|
||||||
|
emit_signal("race_started")
|
||||||
|
else:
|
||||||
|
$Number.set_text("%d" % delay)
|
||||||
|
|
||||||
23
Countdown.tscn
Normal file
23
Countdown.tscn
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
[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]
|
||||||
|
|
||||||
|
[sub_resource type="DynamicFont" id=1]
|
||||||
|
size = 255
|
||||||
|
outline_size = 20
|
||||||
|
outline_color = Color( 0.145098, 0.145098, 0.145098, 1 )
|
||||||
|
use_filter = true
|
||||||
|
font_data = ExtResource( 2 )
|
||||||
|
|
||||||
|
[node name="Countdown" type="Node2D"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
delay = 5
|
||||||
|
|
||||||
|
[node name="Number" type="Label" parent="."]
|
||||||
|
margin_right = 1920.0
|
||||||
|
margin_bottom = 1080.0
|
||||||
|
custom_fonts/font = SubResource( 1 )
|
||||||
|
text = "3"
|
||||||
|
align = 1
|
||||||
|
valign = 1
|
||||||
10
Global.gd
Normal file
10
Global.gd
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
const TRACKS = [
|
||||||
|
[ Vector2(7,1), Vector2(8,1), Vector2(9,1), Vector2(9,2), Vector2(9,3),
|
||||||
|
Vector2(8,3), Vector2(7,3), Vector2(7,4), Vector2(7,5), Vector2(7,6),
|
||||||
|
Vector2(6,6), Vector2(6,5), Vector2(6,4), Vector2(6,3), Vector2(5,3),
|
||||||
|
Vector2(4,3), Vector2(4,2), Vector2(4,1), Vector2(5,1), Vector2(6,1), ],
|
||||||
|
]
|
||||||
|
|
||||||
|
var selected_track
|
||||||
18
Main.gd
Normal file
18
Main.gd
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
# Declare member variables here. Examples:
|
||||||
|
# var a = 2
|
||||||
|
# var b = "text"
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
Global.selected_track = 0
|
||||||
|
|
||||||
|
|
||||||
|
func start_game():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
func change_track():
|
||||||
|
""" Change the race track """
|
||||||
|
pass
|
||||||
23
Main.tscn
Normal file
23
Main.tscn
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
[gd_scene load_steps=7 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Main.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://Menu.tscn" type="PackedScene" id=2]
|
||||||
|
[ext_resource path="res://RaceTrack.tscn" type="PackedScene" id=3]
|
||||||
|
[ext_resource path="res://PlayerCar.tscn" type="PackedScene" id=4]
|
||||||
|
[ext_resource path="res://Gui.tscn" type="PackedScene" id=5]
|
||||||
|
[ext_resource path="res://Countdown.tscn" type="PackedScene" id=6]
|
||||||
|
|
||||||
|
[node name="Main" type="Node"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
|
[node name="Menu" parent="." instance=ExtResource( 2 )]
|
||||||
|
|
||||||
|
[node name="RaceTrack" parent="." instance=ExtResource( 3 )]
|
||||||
|
|
||||||
|
[node name="PlayerCar" parent="RaceTrack" instance=ExtResource( 4 )]
|
||||||
|
|
||||||
|
[node name="GUI" parent="." instance=ExtResource( 5 )]
|
||||||
|
visible = false
|
||||||
|
|
||||||
|
[node name="Countdown" parent="." instance=ExtResource( 6 )]
|
||||||
|
visible = false
|
||||||
16
Menu.gd
Normal file
16
Menu.gd
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
extends CanvasLayer
|
||||||
|
|
||||||
|
signal track_changed(track_idx)
|
||||||
|
signal skin_changed(skin)
|
||||||
|
|
||||||
|
# Declare member variables here. Examples:
|
||||||
|
# var a = 2
|
||||||
|
# var b = "text"
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
#func _process(delta):
|
||||||
|
# pass
|
||||||
67
Menu.tscn
Normal file
67
Menu.tscn
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
[gd_scene load_steps=5 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Menu.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://Oswald-Bold.otf" type="DynamicFontData" id=2]
|
||||||
|
[ext_resource path="res://font.tres" type="DynamicFont" id=3]
|
||||||
|
|
||||||
|
[sub_resource type="DynamicFont" id=1]
|
||||||
|
resource_name = "BaseFont"
|
||||||
|
size = 60
|
||||||
|
use_filter = true
|
||||||
|
font_data = ExtResource( 2 )
|
||||||
|
|
||||||
|
[node name="Menu" type="CanvasLayer"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
|
[node name="Title" type="Label" parent="."]
|
||||||
|
margin_left = 701.404
|
||||||
|
margin_top = 169.251
|
||||||
|
margin_right = 944.404
|
||||||
|
margin_bottom = 252.251
|
||||||
|
rect_scale = Vector2( 2, 2 )
|
||||||
|
custom_fonts/font = SubResource( 1 )
|
||||||
|
custom_colors/font_color = Color( 0.219608, 0.137255, 0.709804, 1 )
|
||||||
|
custom_colors/font_color_shadow = Color( 0.423529, 0.2, 0.0352941, 1 )
|
||||||
|
custom_constants/shadow_offset_x = 2
|
||||||
|
custom_constants/shadow_offset_y = 3
|
||||||
|
custom_constants/shadow_as_outline = 0
|
||||||
|
text = "Car Racer"
|
||||||
|
|
||||||
|
[node name="ButtonBox" type="VBoxContainer" parent="."]
|
||||||
|
margin_left = 800.375
|
||||||
|
margin_top = 448.991
|
||||||
|
margin_right = 949.375
|
||||||
|
margin_bottom = 654.991
|
||||||
|
rect_scale = Vector2( 2, 2 )
|
||||||
|
|
||||||
|
[node name="Jouer" type="Label" parent="ButtonBox"]
|
||||||
|
margin_right = 149.0
|
||||||
|
margin_bottom = 66.0
|
||||||
|
custom_fonts/font = ExtResource( 3 )
|
||||||
|
custom_colors/font_color_shadow = Color( 0.454902, 0.219608, 0.0901961, 1 )
|
||||||
|
custom_constants/shadow_offset_x = 2
|
||||||
|
custom_constants/shadow_offset_y = 3
|
||||||
|
text = "Jouer"
|
||||||
|
align = 1
|
||||||
|
|
||||||
|
[node name="Options" type="Label" parent="ButtonBox"]
|
||||||
|
margin_top = 70.0
|
||||||
|
margin_right = 149.0
|
||||||
|
margin_bottom = 136.0
|
||||||
|
custom_fonts/font = ExtResource( 3 )
|
||||||
|
custom_colors/font_color_shadow = Color( 0.454902, 0.219608, 0.0901961, 1 )
|
||||||
|
custom_constants/shadow_offset_x = 2
|
||||||
|
custom_constants/shadow_offset_y = 3
|
||||||
|
text = "Options"
|
||||||
|
align = 1
|
||||||
|
|
||||||
|
[node name="Quitter" type="Label" parent="ButtonBox"]
|
||||||
|
margin_top = 140.0
|
||||||
|
margin_right = 149.0
|
||||||
|
margin_bottom = 206.0
|
||||||
|
custom_fonts/font = ExtResource( 3 )
|
||||||
|
custom_colors/font_color_shadow = Color( 0.454902, 0.219608, 0.0901961, 1 )
|
||||||
|
custom_constants/shadow_offset_x = 2
|
||||||
|
custom_constants/shadow_offset_y = 3
|
||||||
|
text = "Quitter"
|
||||||
|
align = 1
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
extends Node2D
|
extends PathFollow2D
|
||||||
|
|
||||||
onready var track = get_node("/root/Track2/RaceTrack/TrackOpponent/")
|
|
||||||
export (float) var speed = 0.125
|
export (float) var speed = 0.125
|
||||||
|
|
||||||
|
|
||||||
# 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():
|
||||||
$CarSprite.set_animation("police")
|
pass
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
var position = track.get_unit_offset()
|
var position = get_unit_offset()
|
||||||
position += speed * delta
|
position += speed * delta
|
||||||
track.set_unit_offset(position)
|
set_unit_offset(position)
|
||||||
|
|
||||||
|
|||||||
120
RaceTrack.gd
120
RaceTrack.gd
@@ -1,86 +1,44 @@
|
|||||||
extends Path2D
|
extends Node
|
||||||
|
|
||||||
enum { UP, RIGHT, DOWN, LEFT }
|
signal player_moved(track_offset)
|
||||||
const TRACK_TILES = [
|
signal lap_completed(laps)
|
||||||
Vector2(7,1), Vector2(8,1), Vector2(9,1), Vector2(9,2), Vector2(9,3),
|
signal wrong_way(coords)
|
||||||
Vector2(8,3), Vector2(7,3), Vector2(7,4), Vector2(7,5), Vector2(7,6),
|
|
||||||
Vector2(6,6), Vector2(6,5), Vector2(6,4), Vector2(6,3), Vector2(5,3),
|
# TODO:
|
||||||
Vector2(4,3), Vector2(4,2), Vector2(4,1), Vector2(5,1), Vector2(6,1),
|
# - 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 !!
|
||||||
|
|
||||||
|
const TRACK_TILES = Global.TRACKS[0]
|
||||||
|
|
||||||
|
onready var map = $TileMap
|
||||||
|
var laps = 0
|
||||||
|
var current_cell = TRACK_TILES[0]
|
||||||
|
|
||||||
|
func get_track_offset(coords):
|
||||||
|
var offset = float(TRACK_TILES.find(coords)) / float(len(TRACK_TILES))
|
||||||
|
return offset
|
||||||
|
|
||||||
var tile_size : int = 128
|
|
||||||
var half_size : int = tile_size / 2
|
|
||||||
onready var map = get_node("/root/Track2/TileMap")
|
|
||||||
# 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():
|
||||||
_build_track(TRACK_TILES)
|
pass # Replace with function body.
|
||||||
|
|
||||||
func _draw():
|
func _input(event):
|
||||||
draw_polyline(curve.get_baked_points(), Color.red, 4.0)
|
# Check if the mouse if following the tiles track
|
||||||
for idx in range(0,curve.get_point_count()):
|
if event is InputEventMouseMotion:
|
||||||
draw_circle(curve.get_point_in(idx), 2.0, Color.green)
|
var hover_cell = map.world_to_map(event.position)
|
||||||
draw_circle(curve.get_point_out(idx), 2.0, Color.blue)
|
if hover_cell != current_cell: # The mouse moved to a new cell
|
||||||
|
# Check the tile is on path
|
||||||
func _build_track(tiles):
|
if TRACK_TILES.find(hover_cell) != -1:
|
||||||
""" Build the track curve given a tile path """
|
# Check if a lap is finished
|
||||||
var _curve = get_curve()
|
if hover_cell == TRACK_TILES[0] and current_cell == TRACK_TILES[-1]:
|
||||||
_curve.clear_points()
|
laps += 1
|
||||||
# Set start point
|
emit_signal("lap_completed", laps)
|
||||||
var start_point = map.map_to_world(tiles[0])
|
# Check we are following the path
|
||||||
start_point.y += half_size
|
if TRACK_TILES[TRACK_TILES.find(hover_cell) - 1] == current_cell:
|
||||||
start_point.x += half_size
|
emit_signal("player_moved", laps + get_track_offset(hover_cell))
|
||||||
_point_at(_curve, start_point, RIGHT)
|
emit_signal("wrong_way", Vector2(-1, -1))
|
||||||
for idx in range(0, tiles.size()):
|
current_cell = hover_cell
|
||||||
var next_idx = idx + 1 if idx < tiles.size() - 1 else 0
|
else:
|
||||||
var dir = _direction_to(tiles[idx], tiles[next_idx])
|
emit_signal("wrong_way", map.map_to_world(hover_cell))
|
||||||
# Find position of next point
|
|
||||||
var pos = map.map_to_world(tiles[idx])
|
|
||||||
match dir:
|
|
||||||
# We start from upper left corner
|
|
||||||
UP: pos = Vector2(pos.x + half_size, pos.y)
|
|
||||||
RIGHT: pos = Vector2(pos.x + tile_size, pos.y + half_size)
|
|
||||||
DOWN: pos = Vector2(pos.x + half_size, pos.y + tile_size)
|
|
||||||
LEFT: pos = Vector2(pos.x, pos.y + half_size)
|
|
||||||
_point_at(_curve, pos, dir)
|
|
||||||
_point_at(_curve, start_point, RIGHT)
|
|
||||||
set_curve(_curve)
|
|
||||||
print_debug("Built track !", _curve)
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
#func _process(delta):
|
|
||||||
# pass
|
|
||||||
|
|
||||||
func _point_at(_curve, pos, dir):
|
|
||||||
# Use only control_in since it gives smoother turns
|
|
||||||
var half_size = tile_size / 2
|
|
||||||
var control_in
|
|
||||||
match dir:
|
|
||||||
DOWN:
|
|
||||||
control_in = Vector2(0, - half_size)
|
|
||||||
#control_out = Vector2(0, half_size)
|
|
||||||
UP:
|
|
||||||
control_in = Vector2(0, half_size)
|
|
||||||
#control_out = Vector2(0, -half_size)
|
|
||||||
RIGHT:
|
|
||||||
control_in = Vector2( - half_size, 0)
|
|
||||||
#control_out = Vector2(half_size, 0)
|
|
||||||
LEFT:
|
|
||||||
control_in = Vector2(half_size, 0)
|
|
||||||
#control_out = Vector2(-half_size, 0)
|
|
||||||
#print_debug("Add point: ", pos, ", in=", control_in), " out=", control_out, " | ", dir)
|
|
||||||
_curve.add_point(pos, control_in) #, control_out)
|
|
||||||
|
|
||||||
|
|
||||||
func _direction_to(from_tile, to_tile):
|
|
||||||
var x_dir = to_tile.x - from_tile.x
|
|
||||||
var y_dir = to_tile.y - from_tile.y
|
|
||||||
if abs(x_dir + y_dir) == 1:
|
|
||||||
if x_dir == 1:
|
|
||||||
return RIGHT
|
|
||||||
elif x_dir == -1:
|
|
||||||
return LEFT
|
|
||||||
elif y_dir == 1:
|
|
||||||
return DOWN
|
|
||||||
elif y_dir == -1:
|
|
||||||
return UP
|
|
||||||
else:
|
|
||||||
print_debug("Panic!! Path is not contiguous between", from_tile, " and ", to_tile)
|
|
||||||
|
|||||||
119
RaceTrack.tscn
119
RaceTrack.tscn
@@ -1,72 +1,99 @@
|
|||||||
[gd_scene load_steps=30 format=2]
|
[gd_scene load_steps=34 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://RaceTrack.gd" type="Script" id=1]
|
[ext_resource path="res://RaceTrack.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://OpponentCar.gd" type="Script" id=2]
|
[ext_resource path="res://TrackPath.gd" type="Script" id=2]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0007.png" type="Texture" id=3]
|
[ext_resource path="res://OpponentCar.gd" type="Script" id=3]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0004.png" type="Texture" id=4]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0007.png" type="Texture" id=4]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0001.png" type="Texture" id=5]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0004.png" type="Texture" id=5]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0002.png" type="Texture" id=6]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0001.png" type="Texture" id=6]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0003.png" type="Texture" id=7]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0002.png" type="Texture" id=7]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0000.png" type="Texture" id=8]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0003.png" type="Texture" id=8]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0005.png" type="Texture" id=9]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0000.png" type="Texture" id=9]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0006.png" type="Texture" id=10]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0005.png" type="Texture" id=10]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0003.png" type="Texture" id=11]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0006.png" type="Texture" id=11]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0004.png" type="Texture" id=12]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0003.png" type="Texture" id=12]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0001.png" type="Texture" id=13]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0004.png" type="Texture" id=13]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0002.png" type="Texture" id=14]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0001.png" type="Texture" id=14]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0007.png" type="Texture" id=15]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0002.png" type="Texture" id=15]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0000.png" type="Texture" id=16]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0007.png" type="Texture" id=16]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0005.png" type="Texture" id=17]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0000.png" type="Texture" id=17]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0006.png" type="Texture" id=18]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0005.png" type="Texture" id=18]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0003.png" type="Texture" id=19]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0006.png" type="Texture" id=19]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0004.png" type="Texture" id=20]
|
[ext_resource path="res://track1/policeCar/policeiso_0003.png" type="Texture" id=20]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0001.png" type="Texture" id=21]
|
[ext_resource path="res://track1/policeCar/policeiso_0004.png" type="Texture" id=21]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0002.png" type="Texture" id=22]
|
[ext_resource path="res://track1/policeCar/policeiso_0001.png" type="Texture" id=22]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0007.png" type="Texture" id=23]
|
[ext_resource path="res://track1/policeCar/policeiso_0002.png" type="Texture" id=23]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0000.png" type="Texture" id=24]
|
[ext_resource path="res://track1/policeCar/policeiso_0007.png" type="Texture" id=24]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0005.png" type="Texture" id=25]
|
[ext_resource path="res://track1/policeCar/policeiso_0000.png" type="Texture" id=25]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0006.png" type="Texture" id=26]
|
[ext_resource path="res://track1/policeCar/policeiso_0005.png" type="Texture" id=26]
|
||||||
[ext_resource path="res://CarSprite.gd" type="Script" id=27]
|
[ext_resource path="res://track1/policeCar/policeiso_0006.png" type="Texture" id=27]
|
||||||
|
[ext_resource path="res://CarSprite.gd" type="Script" id=28]
|
||||||
|
[ext_resource path="res://wrong_way.tscn" type="PackedScene" id=29]
|
||||||
|
|
||||||
[sub_resource type="Curve2D" id=6]
|
[sub_resource type="Gradient" id=3]
|
||||||
|
colors = PoolColorArray( 0.284025, 0.4375, 0.0803223, 1, 0.30305, 0.480469, 0.0675659, 1 )
|
||||||
|
|
||||||
|
[sub_resource type="GradientTexture" id=4]
|
||||||
|
gradient = SubResource( 3 )
|
||||||
|
width = 1920
|
||||||
|
|
||||||
|
[sub_resource type="Curve2D" id=1]
|
||||||
_data = {
|
_data = {
|
||||||
"points": PoolVector2Array( )
|
"points": PoolVector2Array( 0, 0, 0, 0, -17.3556, 327.792, 0, 0, 0, 0, 1930.1, 452.427 )
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="SpriteFrames" id=2]
|
[sub_resource type="SpriteFrames" id=2]
|
||||||
animations = [ {
|
animations = [ {
|
||||||
"frames": [ ExtResource( 3 ), ExtResource( 4 ), ExtResource( 5 ), ExtResource( 6 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 9 ), ExtResource( 10 ) ],
|
"frames": [ ExtResource( 4 ), ExtResource( 5 ), ExtResource( 6 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 9 ), ExtResource( 10 ), ExtResource( 11 ) ],
|
||||||
"loop": true,
|
"loop": true,
|
||||||
"name": "bus",
|
"name": "bus",
|
||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
}, {
|
}, {
|
||||||
"frames": [ ExtResource( 11 ), ExtResource( 12 ), ExtResource( 13 ), ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ) ],
|
"frames": [ ExtResource( 12 ), ExtResource( 13 ), ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ), ExtResource( 19 ) ],
|
||||||
"loop": true,
|
|
||||||
"name": "police",
|
|
||||||
"speed": 5.0
|
|
||||||
}, {
|
|
||||||
"frames": [ ExtResource( 19 ), ExtResource( 20 ), ExtResource( 21 ), ExtResource( 22 ), ExtResource( 23 ), ExtResource( 24 ), ExtResource( 25 ), ExtResource( 26 ) ],
|
|
||||||
"loop": true,
|
"loop": true,
|
||||||
"name": "car",
|
"name": "car",
|
||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [ ExtResource( 20 ), ExtResource( 21 ), ExtResource( 22 ), ExtResource( 23 ), ExtResource( 24 ), ExtResource( 25 ), ExtResource( 26 ), ExtResource( 27 ) ],
|
||||||
|
"loop": true,
|
||||||
|
"name": "police",
|
||||||
|
"speed": 5.0
|
||||||
} ]
|
} ]
|
||||||
|
|
||||||
[node name="RaceTrack" type="Path2D"]
|
[node name="RaceTrack" type="Node"]
|
||||||
curve = SubResource( 6 )
|
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="TrackOpponent" type="PathFollow2D" parent="."]
|
[node name="TextureRect" type="TextureRect" parent="."]
|
||||||
position = Vector2( 928.559, 184.278 )
|
margin_right = 1920.0
|
||||||
rotation = -0.013337
|
margin_bottom = 1080.0
|
||||||
|
texture = SubResource( 4 )
|
||||||
|
expand = true
|
||||||
|
|
||||||
[node name="OpponentCar" type="Node2D" parent="TrackOpponent"]
|
[node name="TileMap" type="TileMap" parent="."]
|
||||||
position = Vector2( 0, 22 )
|
cell_size = Vector2( 128, 128 )
|
||||||
scale = Vector2( 0.25, 0.25 )
|
format = 1
|
||||||
|
|
||||||
|
[node name="TrackPath" type="Path2D" parent="."]
|
||||||
|
curve = SubResource( 1 )
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="CarSprite" type="AnimatedSprite" parent="TrackOpponent/OpponentCar"]
|
[node name="Opponent" type="PathFollow2D" parent="TrackPath"]
|
||||||
|
position = Vector2( -17.3556, 327.792 )
|
||||||
|
rotation = 0.0639077
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
|
[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 )
|
position = Vector2( -3.20422, 3.0376 )
|
||||||
scale = Vector2( 0.8, 0.8 )
|
scale = Vector2( 0.8, 0.8 )
|
||||||
frames = SubResource( 2 )
|
frames = SubResource( 2 )
|
||||||
animation = "car"
|
animation = "car"
|
||||||
script = ExtResource( 27 )
|
script = ExtResource( 28 )
|
||||||
|
skin = "bus"
|
||||||
|
|
||||||
|
[node name="Wrong Way" parent="." instance=ExtResource( 29 )]
|
||||||
|
visible = false
|
||||||
|
[connection signal="wrong_way" from="." to="Wrong Way" method="_on_RaceTrack_wrong_way"]
|
||||||
|
|||||||
57
Track2.tscn
57
Track2.tscn
@@ -1,6 +1,6 @@
|
|||||||
[gd_scene load_steps=13 format=2]
|
[gd_scene load_steps=12 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://TileMap2.gd" type="Script" id=1]
|
[ext_resource path="res://TileMap.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://RaceTrack.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://RaceTrack.tscn" type="PackedScene" id=2]
|
||||||
[ext_resource path="res://PlayerCar.tscn" type="PackedScene" id=3]
|
[ext_resource path="res://PlayerCar.tscn" type="PackedScene" id=3]
|
||||||
[ext_resource path="res://track2/track.png" type="Texture" id=4]
|
[ext_resource path="res://track2/track.png" type="Texture" id=4]
|
||||||
@@ -9,18 +9,13 @@
|
|||||||
[ext_resource path="res://Oswald-Bold.otf" type="DynamicFontData" id=7]
|
[ext_resource path="res://Oswald-Bold.otf" type="DynamicFontData" id=7]
|
||||||
[ext_resource path="res://Wrong Way.gd" type="Script" id=8]
|
[ext_resource path="res://Wrong Way.gd" type="Script" id=8]
|
||||||
|
|
||||||
[sub_resource type="Curve2D" id=1]
|
[sub_resource type="Gradient" id=1]
|
||||||
_data = {
|
|
||||||
"points": PoolVector2Array( 0, 0, 0, 0, 480.755, 160.968, -44.1176, -1.2605, 44.1176, 1.2605, 684, 160.042, 0, 0, 0, 0, 759.607, 207.133, 0, -74.5098, 0, 74.5098, 769.296, 303.494, 0.926585, -49.109, -0.926585, 49.109, 768.41, 373.455, 31.9672, -0.926585, -31.9672, 0.926585, 708.312, 430.479, 0, 0, 0, 0, 572.437, 428.124, 6.46179, -42.6478, -6.46179, 42.6478, 517.286, 470.208, 0, 0, 0, 0, 513.409, 733.849, 76.2492, 0, -76.2492, 0, 447.99, 810.7, 0, 0, 0, 0, 382.881, 731.264, 0, 52.9867, 0, -52.9867, 384.173, 475.378, 0, 0, 0, 0, 329.971, 426.614, 13.9668, 1.39668, -13.9668, -1.39668, 184.018, 428.709, 1.39668, 43.297, -1.39668, -43.297, 121.023, 363.376, 0.814508, 29.1703, -0.814508, -29.1703, 118.928, 292.145, -63.5488, 1.39668, 63.5488, -1.39668, 182.477, 159.461, 0, 0, 0, 0, 304.658, 160.902, 0, 0, 0, 0, 480.755, 161.631 )
|
|
||||||
}
|
|
||||||
|
|
||||||
[sub_resource type="Gradient" id=3]
|
|
||||||
colors = PoolColorArray( 0.242729, 0.410156, 0.128174, 1, 0.088892, 0.507812, 0.0753784, 1 )
|
colors = PoolColorArray( 0.242729, 0.410156, 0.128174, 1, 0.088892, 0.507812, 0.0753784, 1 )
|
||||||
|
|
||||||
[sub_resource type="GradientTexture" id=4]
|
[sub_resource type="GradientTexture" id=2]
|
||||||
gradient = SubResource( 3 )
|
gradient = SubResource( 1 )
|
||||||
|
|
||||||
[sub_resource type="DynamicFont" id=5]
|
[sub_resource type="DynamicFont" id=3]
|
||||||
size = 13
|
size = 13
|
||||||
outline_size = 2
|
outline_size = 2
|
||||||
outline_color = Color( 0.254902, 0.121569, 0.121569, 1 )
|
outline_color = Color( 0.254902, 0.121569, 0.121569, 1 )
|
||||||
@@ -38,55 +33,31 @@ script = ExtResource( 1 )
|
|||||||
[node name="RaceTrack" parent="." instance=ExtResource( 2 )]
|
[node name="RaceTrack" parent="." instance=ExtResource( 2 )]
|
||||||
|
|
||||||
[node name="TrackPlayer" type="PathFollow2D" parent="RaceTrack"]
|
[node name="TrackPlayer" type="PathFollow2D" parent="RaceTrack"]
|
||||||
position = Vector2( 928.559, 184.278 )
|
position = Vector2( -17.3556, 327.792 )
|
||||||
rotation = -0.013337
|
rotation = 0.0639077
|
||||||
|
|
||||||
[node name="PlayerCar" parent="RaceTrack/TrackPlayer" instance=ExtResource( 3 )]
|
[node name="PlayerCar" parent="RaceTrack/TrackPlayer" instance=ExtResource( 3 )]
|
||||||
position = Vector2( 0, -22.892 )
|
position = Vector2( 0, -22.892 )
|
||||||
scale = Vector2( 0.25, 0.25 )
|
scale = Vector2( 0.25, 0.25 )
|
||||||
skin = "car"
|
skin = "car"
|
||||||
|
|
||||||
[node name="Track" type="Path2D" parent="."]
|
[node name="TrackImage" type="CanvasLayer" parent="."]
|
||||||
position = Vector2( 447.804, 23.3101 )
|
|
||||||
z_index = 2
|
|
||||||
curve = SubResource( 1 )
|
|
||||||
|
|
||||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
|
||||||
layer = -1
|
layer = -1
|
||||||
|
|
||||||
[node name="TextureRect" type="TextureRect" parent="CanvasLayer"]
|
[node name="TextureRect" type="TextureRect" parent="TrackImage"]
|
||||||
margin_right = 1923.0
|
margin_right = 1923.0
|
||||||
margin_bottom = 1084.0
|
margin_bottom = 1084.0
|
||||||
texture = ExtResource( 4 )
|
texture = ExtResource( 4 )
|
||||||
|
|
||||||
[node name="CanvasLayer" type="CanvasLayer" parent="CanvasLayer"]
|
[node name="CanvasLayer" type="CanvasLayer" parent="TrackImage"]
|
||||||
layer = -1
|
layer = -1
|
||||||
|
|
||||||
[node name="TextureRect2" type="TextureRect" parent="CanvasLayer/CanvasLayer"]
|
[node name="TextureRect2" type="TextureRect" parent="TrackImage/CanvasLayer"]
|
||||||
margin_right = 1923.0
|
margin_right = 1923.0
|
||||||
margin_bottom = 1080.0
|
margin_bottom = 1080.0
|
||||||
texture = SubResource( 4 )
|
texture = SubResource( 2 )
|
||||||
expand = true
|
expand = true
|
||||||
|
|
||||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
|
||||||
margin_left = 11.2102
|
|
||||||
margin_top = 57.7727
|
|
||||||
margin_right = 159.21
|
|
||||||
margin_bottom = 107.773
|
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="HBoxContainer"]
|
|
||||||
margin_top = 18.0
|
|
||||||
margin_right = 53.0
|
|
||||||
margin_bottom = 32.0
|
|
||||||
text = "Rotation"
|
|
||||||
|
|
||||||
[node name="Rotation" type="Label" parent="HBoxContainer"]
|
|
||||||
margin_left = 57.0
|
|
||||||
margin_top = 18.0
|
|
||||||
margin_right = 71.0
|
|
||||||
margin_bottom = 32.0
|
|
||||||
text = "0°"
|
|
||||||
|
|
||||||
[node name="GUI" parent="." instance=ExtResource( 5 )]
|
[node name="GUI" parent="." instance=ExtResource( 5 )]
|
||||||
editor/display_folded = false
|
editor/display_folded = false
|
||||||
script = ExtResource( 6 )
|
script = ExtResource( 6 )
|
||||||
@@ -98,7 +69,7 @@ margin_right = 920.258
|
|||||||
margin_bottom = 431.587
|
margin_bottom = 431.587
|
||||||
rect_rotation = -5.0
|
rect_rotation = -5.0
|
||||||
rect_clip_content = true
|
rect_clip_content = true
|
||||||
custom_fonts/font = SubResource( 5 )
|
custom_fonts/font = SubResource( 3 )
|
||||||
custom_colors/font_color = Color( 0.780392, 0.129412, 0.129412, 1 )
|
custom_colors/font_color = Color( 0.780392, 0.129412, 0.129412, 1 )
|
||||||
text = "WRONG WAY !!"
|
text = "WRONG WAY !!"
|
||||||
align = 1
|
align = 1
|
||||||
|
|||||||
14
TrackOpponent.gd
Normal file
14
TrackOpponent.gd
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
extends PathFollow2D
|
||||||
|
|
||||||
|
export (float) var speed = 0.125
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _process(delta):
|
||||||
|
var position = get_unit_offset()
|
||||||
|
position += speed * delta
|
||||||
|
set_unit_offset(position)
|
||||||
|
|
||||||
83
TrackPath.gd
Normal file
83
TrackPath.gd
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
extends Path2D
|
||||||
|
|
||||||
|
enum { UP, RIGHT, DOWN, LEFT }
|
||||||
|
const TRACK_TILES = Global.TRACKS[0]
|
||||||
|
|
||||||
|
var tile_size : int = 128
|
||||||
|
var half_size : int = tile_size / 2
|
||||||
|
onready var map = get_node("../TileMap/")
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
_build_track(TRACK_TILES)
|
||||||
|
|
||||||
|
"""
|
||||||
|
func _draw():
|
||||||
|
draw_polyline(curve.get_baked_points(), Color.chartreuse, 4.0)
|
||||||
|
for idx in range(0,curve.get_point_count()):
|
||||||
|
draw_circle(curve.get_point_in(idx), 2.0, Color.green)
|
||||||
|
draw_circle(curve.get_point_out(idx), 2.0, Color.blue)
|
||||||
|
"""
|
||||||
|
|
||||||
|
func _build_track(tiles):
|
||||||
|
""" Build the track curve given a tile path """
|
||||||
|
var _curve = get_curve()
|
||||||
|
_curve.clear_points()
|
||||||
|
# Set start point
|
||||||
|
var start_point = map.map_to_world(tiles[0])
|
||||||
|
start_point.y += half_size
|
||||||
|
start_point.x += half_size
|
||||||
|
_point_at(_curve, start_point, RIGHT)
|
||||||
|
for idx in range(0, tiles.size()):
|
||||||
|
var next_idx = idx + 1 if idx < tiles.size() - 1 else 0
|
||||||
|
var dir = _direction_to(tiles[idx], tiles[next_idx])
|
||||||
|
# Find position of next point
|
||||||
|
var pos = map.map_to_world(tiles[idx])
|
||||||
|
match dir:
|
||||||
|
# We start from upper left corner
|
||||||
|
UP: pos = Vector2(pos.x + half_size, pos.y)
|
||||||
|
RIGHT: pos = Vector2(pos.x + tile_size, pos.y + half_size)
|
||||||
|
DOWN: pos = Vector2(pos.x + half_size, pos.y + tile_size)
|
||||||
|
LEFT: pos = Vector2(pos.x, pos.y + half_size)
|
||||||
|
_point_at(_curve, pos, dir)
|
||||||
|
_point_at(_curve, start_point, RIGHT)
|
||||||
|
set_curve(_curve)
|
||||||
|
print_debug("Built track !", _curve)
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
#func _process(delta):
|
||||||
|
# pass
|
||||||
|
|
||||||
|
func _point_at(_curve, pos, dir):
|
||||||
|
# Use only control_in since it gives smoother turns
|
||||||
|
var half_size = tile_size / 2
|
||||||
|
var control_in
|
||||||
|
match dir:
|
||||||
|
DOWN:
|
||||||
|
control_in = Vector2(0, - half_size)
|
||||||
|
#control_out = Vector2(0, half_size)
|
||||||
|
UP:
|
||||||
|
control_in = Vector2(0, half_size)
|
||||||
|
#control_out = Vector2(0, -half_size)
|
||||||
|
RIGHT:
|
||||||
|
control_in = Vector2( - half_size, 0)
|
||||||
|
#control_out = Vector2(half_size, 0)
|
||||||
|
LEFT:
|
||||||
|
control_in = Vector2(half_size, 0)
|
||||||
|
#control_out = Vector2(-half_size, 0)
|
||||||
|
#print_debug("Add point: ", pos, ", in=", control_in), " out=", control_out, " | ", dir)
|
||||||
|
_curve.add_point(pos, control_in) #, control_out)
|
||||||
|
|
||||||
|
|
||||||
|
func _direction_to(from_tile, to_tile):
|
||||||
|
var x_dir = to_tile.x - from_tile.x
|
||||||
|
var y_dir = to_tile.y - from_tile.y
|
||||||
|
if abs(x_dir + y_dir) == 1:
|
||||||
|
if x_dir == 1:
|
||||||
|
return RIGHT
|
||||||
|
elif x_dir == -1:
|
||||||
|
return LEFT
|
||||||
|
elif y_dir == 1:
|
||||||
|
return DOWN
|
||||||
|
elif y_dir == -1:
|
||||||
|
return UP
|
||||||
|
else:
|
||||||
|
print_debug("Panic!! Path is not contiguous between", from_tile, " and ", to_tile)
|
||||||
@@ -4,7 +4,8 @@ extends Label
|
|||||||
func _ready():
|
func _ready():
|
||||||
set_visible(false)
|
set_visible(false)
|
||||||
|
|
||||||
func _on_TileMap_wrong_way(coords):
|
|
||||||
|
func _on_RaceTrack_wrong_way(coords):
|
||||||
if coords == Vector2(-1,-1):
|
if coords == Vector2(-1,-1):
|
||||||
set_visible(false)
|
set_visible(false)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user