adds track parser from txt files
@@ -12,8 +12,8 @@ func _ready():
|
|||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
"""
|
"""
|
||||||
The sprite has its own representation of rotation, so we need to tweak things.
|
The sprite contains a representation of rotation in its own, so we need to tweak things.
|
||||||
The sprite inherits orientation from its parent (TrackFollow) that must be canceled.
|
In particular, 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()
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
extends Node
|
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
|
var race_started = false
|
||||||
|
var laps = 0
|
||||||
1
Gui.tscn
@@ -13,7 +13,6 @@ outline_color = Color( 0.25098, 0.25098, 0.25098, 1 )
|
|||||||
font_data = ExtResource( 1 )
|
font_data = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="GUI" type="MarginContainer"]
|
[node name="GUI" type="MarginContainer"]
|
||||||
editor/display_folded = true
|
|
||||||
margin_left = 10.5631
|
margin_left = 10.5631
|
||||||
margin_top = 9.24268
|
margin_top = 9.24268
|
||||||
margin_right = 159.563
|
margin_right = 159.563
|
||||||
|
|||||||
2
Main.gd
@@ -6,7 +6,7 @@ extends Node
|
|||||||
|
|
||||||
# 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():
|
||||||
Global.selected_track = 0
|
pass
|
||||||
|
|
||||||
|
|
||||||
func start_game():
|
func start_game():
|
||||||
|
|||||||
25
Player.gd
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
extends PathFollow2D
|
||||||
|
|
||||||
|
export (float) var speed = 0.125
|
||||||
|
|
||||||
|
var position_on_track := 0.0
|
||||||
|
var target_on_track := 0.0
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
# Move the player until target_on_track
|
||||||
|
if 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(position_on_track)
|
||||||
|
else:
|
||||||
|
position_on_track = target_on_track
|
||||||
|
|
||||||
|
|
||||||
|
func _on_RaceTrack_player_moved(track_offset):
|
||||||
|
target_on_track = track_offset
|
||||||
18
PlayerCar.gd
@@ -1,31 +1,17 @@
|
|||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
export (String, "bus", "police", "car") var skin
|
export (String, "bus", "police", "car") var skin
|
||||||
export (float) var speed = 0.125
|
|
||||||
|
|
||||||
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 }
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
# - Move track related logic inside TrackPlayer script ?
|
# - Move track related logic inside TrackPlayer script ?
|
||||||
onready var track = get_node("/root/Track2/RaceTrack/TrackPlayer/")
|
onready var track = get_node("/root/Track2/RaceTrack/TrackPlayer/")
|
||||||
var position_on_track := 0.0
|
|
||||||
var target_on_track := 0.0
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
# Set player sprite
|
# Set player sprite
|
||||||
$CarSprite.set_animation(skin)
|
$CarSprite.set_animation(skin)
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
|
||||||
# Move the player until target_on_track
|
|
||||||
if 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
|
|
||||||
track.set_unit_offset(position_on_track)
|
|
||||||
else:
|
|
||||||
position_on_track = target_on_track
|
|
||||||
|
|
||||||
|
|
||||||
func _on_TileMap_player_moved(track_offset):
|
|
||||||
target_on_track = track_offset
|
|
||||||
|
|||||||
@@ -9,22 +9,22 @@
|
|||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0000.png" type="Texture" id=7]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0000.png" type="Texture" id=7]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0005.png" type="Texture" id=8]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0005.png" type="Texture" id=8]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0006.png" type="Texture" id=9]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0006.png" type="Texture" id=9]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0003.png" type="Texture" id=10]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0003.png" type="Texture" id=10]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0004.png" type="Texture" id=11]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0004.png" type="Texture" id=11]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0001.png" type="Texture" id=12]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0001.png" type="Texture" id=12]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0002.png" type="Texture" id=13]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0002.png" type="Texture" id=13]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0007.png" type="Texture" id=14]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0007.png" type="Texture" id=14]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0000.png" type="Texture" id=15]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0000.png" type="Texture" id=15]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0005.png" type="Texture" id=16]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0005.png" type="Texture" id=16]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0006.png" type="Texture" id=17]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0006.png" type="Texture" id=17]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0003.png" type="Texture" id=18]
|
[ext_resource path="res://track1/policeCar/policeiso_0003.png" type="Texture" id=18]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0004.png" type="Texture" id=19]
|
[ext_resource path="res://track1/policeCar/policeiso_0004.png" type="Texture" id=19]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0001.png" type="Texture" id=20]
|
[ext_resource path="res://track1/policeCar/policeiso_0001.png" type="Texture" id=20]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0002.png" type="Texture" id=21]
|
[ext_resource path="res://track1/policeCar/policeiso_0002.png" type="Texture" id=21]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0007.png" type="Texture" id=22]
|
[ext_resource path="res://track1/policeCar/policeiso_0007.png" type="Texture" id=22]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0000.png" type="Texture" id=23]
|
[ext_resource path="res://track1/policeCar/policeiso_0000.png" type="Texture" id=23]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0005.png" type="Texture" id=24]
|
[ext_resource path="res://track1/policeCar/policeiso_0005.png" type="Texture" id=24]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0006.png" type="Texture" id=25]
|
[ext_resource path="res://track1/policeCar/policeiso_0006.png" type="Texture" id=25]
|
||||||
[ext_resource path="res://CarSprite.gd" type="Script" id=26]
|
[ext_resource path="res://CarSprite.gd" type="Script" id=26]
|
||||||
|
|
||||||
[sub_resource type="SpriteFrames" id=1]
|
[sub_resource type="SpriteFrames" id=1]
|
||||||
@@ -36,12 +36,12 @@ animations = [ {
|
|||||||
}, {
|
}, {
|
||||||
"frames": [ ExtResource( 10 ), ExtResource( 11 ), ExtResource( 12 ), ExtResource( 13 ), ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ) ],
|
"frames": [ ExtResource( 10 ), ExtResource( 11 ), ExtResource( 12 ), ExtResource( 13 ), ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ) ],
|
||||||
"loop": true,
|
"loop": true,
|
||||||
"name": "police",
|
"name": "car",
|
||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
}, {
|
}, {
|
||||||
"frames": [ ExtResource( 18 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 21 ), ExtResource( 22 ), ExtResource( 23 ), ExtResource( 24 ), ExtResource( 25 ) ],
|
"frames": [ ExtResource( 18 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 21 ), ExtResource( 22 ), ExtResource( 23 ), ExtResource( 24 ), ExtResource( 25 ) ],
|
||||||
"loop": true,
|
"loop": true,
|
||||||
"name": "car",
|
"name": "police",
|
||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
} ]
|
} ]
|
||||||
|
|
||||||
|
|||||||
21
RaceTrack.gd
@@ -10,19 +10,22 @@ signal wrong_way(coords)
|
|||||||
# - Build the track Curve2D from track and tiles data
|
# - Build the track Curve2D from track and tiles data
|
||||||
# - Keyboard controls !!
|
# - Keyboard controls !!
|
||||||
|
|
||||||
const TRACK_TILES = Global.TRACKS[0]
|
var laps
|
||||||
|
var current_cell
|
||||||
|
onready var track = TrackSelection.get_current_track()
|
||||||
onready var map = $TileMap
|
onready var map = $TileMap
|
||||||
var laps = 0
|
|
||||||
var current_cell = TRACK_TILES[0]
|
|
||||||
|
|
||||||
func get_track_offset(coords):
|
func get_track_offset(coords):
|
||||||
var offset = float(TRACK_TILES.find(coords)) / float(len(TRACK_TILES))
|
var offset = float(track.find(coords)) / float(len(track))
|
||||||
return offset
|
return offset
|
||||||
|
|
||||||
# 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.
|
_reset_progress()
|
||||||
|
|
||||||
|
func _reset_progress():
|
||||||
|
laps = 0
|
||||||
|
current_cell = track[0]
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
# Check if the mouse if following the tiles track
|
# Check if the mouse if following the tiles track
|
||||||
@@ -30,13 +33,13 @@ func _input(event):
|
|||||||
var hover_cell = map.world_to_map(event.position)
|
var hover_cell = map.world_to_map(event.position)
|
||||||
if hover_cell != current_cell: # The mouse moved to a new cell
|
if hover_cell != current_cell: # The mouse moved to a new cell
|
||||||
# Check the tile is on path
|
# Check the tile is on path
|
||||||
if TRACK_TILES.find(hover_cell) != -1:
|
if track.find(hover_cell) != -1:
|
||||||
# Check if a lap is finished
|
# Check if a lap is finished
|
||||||
if hover_cell == TRACK_TILES[0] and current_cell == TRACK_TILES[-1]:
|
if hover_cell == track[0] and current_cell == track[-1]:
|
||||||
laps += 1
|
laps += 1
|
||||||
emit_signal("lap_completed", laps)
|
emit_signal("lap_completed", laps)
|
||||||
# Check we are following the path
|
# Check we are following the path
|
||||||
if TRACK_TILES[TRACK_TILES.find(hover_cell) - 1] == current_cell:
|
if track[track.find(hover_cell) - 1] == current_cell:
|
||||||
emit_signal("player_moved", laps + get_track_offset(hover_cell))
|
emit_signal("player_moved", laps + get_track_offset(hover_cell))
|
||||||
emit_signal("wrong_way", Vector2(-1, -1))
|
emit_signal("wrong_way", Vector2(-1, -1))
|
||||||
current_cell = hover_cell
|
current_cell = hover_cell
|
||||||
|
|||||||
180
RaceTrack.tscn
@@ -1,60 +1,136 @@
|
|||||||
[gd_scene load_steps=34 format=2]
|
[gd_scene load_steps=39 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://TrackPath.gd" type="Script" id=2]
|
[ext_resource path="res://assets/track_tiles/track.png" type="Texture" id=2]
|
||||||
[ext_resource path="res://OpponentCar.gd" type="Script" id=3]
|
[ext_resource path="res://TileMap.gd" type="Script" id=3]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0007.png" type="Texture" id=4]
|
[ext_resource path="res://TrackPath.gd" type="Script" id=4]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0004.png" type="Texture" id=5]
|
[ext_resource path="res://OpponentCar.gd" type="Script" id=5]
|
||||||
[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_0007.png" type="Texture" id=6]
|
||||||
[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_0004.png" type="Texture" id=7]
|
||||||
[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_0001.png" type="Texture" id=8]
|
||||||
[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_0002.png" type="Texture" id=9]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0005.png" type="Texture" id=10]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0003.png" type="Texture" id=10]
|
||||||
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0006.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/car02/car02iso_0003.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/car02/car02iso_0004.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_0001.png" type="Texture" id=14]
|
[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_0002.png" type="Texture" id=15]
|
[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_0007.png" type="Texture" id=16]
|
[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_0000.png" type="Texture" id=17]
|
[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_0005.png" type="Texture" id=18]
|
[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_0006.png" type="Texture" id=19]
|
[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0000.png" type="Texture" id=19]
|
||||||
[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_0005.png" type="Texture" id=20]
|
||||||
[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_0006.png" type="Texture" id=21]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0001.png" type="Texture" id=22]
|
[ext_resource path="res://track1/policeCar/policeiso_0003.png" type="Texture" id=22]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0002.png" type="Texture" id=23]
|
[ext_resource path="res://track1/policeCar/policeiso_0004.png" type="Texture" id=23]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0007.png" type="Texture" id=24]
|
[ext_resource path="res://track1/policeCar/policeiso_0001.png" type="Texture" id=24]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0000.png" type="Texture" id=25]
|
[ext_resource path="res://track1/policeCar/policeiso_0002.png" type="Texture" id=25]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0005.png" type="Texture" id=26]
|
[ext_resource path="res://track1/policeCar/policeiso_0007.png" type="Texture" id=26]
|
||||||
[ext_resource path="res://track1/policeCar/policeiso_0006.png" type="Texture" id=27]
|
[ext_resource path="res://track1/policeCar/policeiso_0000.png" type="Texture" id=27]
|
||||||
[ext_resource path="res://CarSprite.gd" type="Script" id=28]
|
[ext_resource path="res://track1/policeCar/policeiso_0005.png" type="Texture" id=28]
|
||||||
[ext_resource path="res://wrong_way.tscn" type="PackedScene" id=29]
|
[ext_resource path="res://track1/policeCar/policeiso_0006.png" type="Texture" id=29]
|
||||||
|
[ext_resource path="res://CarSprite.gd" type="Script" id=30]
|
||||||
|
[ext_resource path="res://Player.gd" type="Script" id=31]
|
||||||
|
[ext_resource path="res://PlayerCar.tscn" type="PackedScene" id=32]
|
||||||
|
[ext_resource path="res://wrong_way.tscn" type="PackedScene" id=33]
|
||||||
|
|
||||||
[sub_resource type="Gradient" id=3]
|
[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 )
|
||||||
|
|
||||||
[sub_resource type="GradientTexture" id=4]
|
[sub_resource type="GradientTexture" id=2]
|
||||||
gradient = SubResource( 3 )
|
gradient = SubResource( 1 )
|
||||||
width = 1920
|
width = 1920
|
||||||
|
|
||||||
[sub_resource type="Curve2D" id=1]
|
[sub_resource type="TileSet" id=3]
|
||||||
|
0/name = "dl"
|
||||||
|
0/texture = ExtResource( 2 )
|
||||||
|
0/tex_offset = Vector2( 0, 0 )
|
||||||
|
0/modulate = Color( 1, 1, 1, 1 )
|
||||||
|
0/region = Rect2( 0, 0, 128, 128 )
|
||||||
|
0/tile_mode = 0
|
||||||
|
0/occluder_offset = Vector2( 0, 0 )
|
||||||
|
0/navigation_offset = Vector2( 0, 0 )
|
||||||
|
0/shapes = [ ]
|
||||||
|
0/z_index = 0
|
||||||
|
1/name = "dr"
|
||||||
|
1/texture = ExtResource( 2 )
|
||||||
|
1/tex_offset = Vector2( 0, 0 )
|
||||||
|
1/modulate = Color( 1, 1, 1, 1 )
|
||||||
|
1/region = Rect2( 128, 0, 128, 128 )
|
||||||
|
1/tile_mode = 0
|
||||||
|
1/occluder_offset = Vector2( 0, 0 )
|
||||||
|
1/navigation_offset = Vector2( 0, 0 )
|
||||||
|
1/shapes = [ ]
|
||||||
|
1/z_index = 0
|
||||||
|
2/name = "lr"
|
||||||
|
2/texture = ExtResource( 2 )
|
||||||
|
2/tex_offset = Vector2( 0, 0 )
|
||||||
|
2/modulate = Color( 1, 1, 1, 1 )
|
||||||
|
2/region = Rect2( 256, 0, 128, 128 )
|
||||||
|
2/tile_mode = 0
|
||||||
|
2/occluder_offset = Vector2( 0, 0 )
|
||||||
|
2/navigation_offset = Vector2( 0, 0 )
|
||||||
|
2/shapes = [ ]
|
||||||
|
2/z_index = 0
|
||||||
|
3/name = "start"
|
||||||
|
3/texture = ExtResource( 2 )
|
||||||
|
3/tex_offset = Vector2( 0, 0 )
|
||||||
|
3/modulate = Color( 1, 1, 1, 1 )
|
||||||
|
3/region = Rect2( 384, 0, 128, 128 )
|
||||||
|
3/tile_mode = 0
|
||||||
|
3/occluder_offset = Vector2( 0, 0 )
|
||||||
|
3/navigation_offset = Vector2( 0, 0 )
|
||||||
|
3/shapes = [ ]
|
||||||
|
3/z_index = 0
|
||||||
|
4/name = "ud"
|
||||||
|
4/texture = ExtResource( 2 )
|
||||||
|
4/tex_offset = Vector2( 0, 0 )
|
||||||
|
4/modulate = Color( 1, 1, 1, 1 )
|
||||||
|
4/region = Rect2( 0, 128, 128, 128 )
|
||||||
|
4/tile_mode = 0
|
||||||
|
4/occluder_offset = Vector2( 0, 0 )
|
||||||
|
4/navigation_offset = Vector2( 0, 0 )
|
||||||
|
4/shapes = [ ]
|
||||||
|
4/z_index = 0
|
||||||
|
5/name = "ul"
|
||||||
|
5/texture = ExtResource( 2 )
|
||||||
|
5/tex_offset = Vector2( 0, 0 )
|
||||||
|
5/modulate = Color( 1, 1, 1, 1 )
|
||||||
|
5/region = Rect2( 128, 128, 128, 128 )
|
||||||
|
5/tile_mode = 0
|
||||||
|
5/occluder_offset = Vector2( 0, 0 )
|
||||||
|
5/navigation_offset = Vector2( 0, 0 )
|
||||||
|
5/shapes = [ ]
|
||||||
|
5/z_index = 0
|
||||||
|
6/name = "ur"
|
||||||
|
6/texture = ExtResource( 2 )
|
||||||
|
6/tex_offset = Vector2( 0, 0 )
|
||||||
|
6/modulate = Color( 1, 1, 1, 1 )
|
||||||
|
6/region = Rect2( 256, 128, 128, 128 )
|
||||||
|
6/tile_mode = 0
|
||||||
|
6/occluder_offset = Vector2( 0, 0 )
|
||||||
|
6/navigation_offset = Vector2( 0, 0 )
|
||||||
|
6/shapes = [ ]
|
||||||
|
6/z_index = 0
|
||||||
|
|
||||||
|
[sub_resource type="Curve2D" id=4]
|
||||||
_data = {
|
_data = {
|
||||||
"points": PoolVector2Array( 0, 0, 0, 0, -17.3556, 327.792, 0, 0, 0, 0, 1930.1, 452.427 )
|
"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=5]
|
||||||
animations = [ {
|
animations = [ {
|
||||||
"frames": [ ExtResource( 4 ), ExtResource( 5 ), ExtResource( 6 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 9 ), ExtResource( 10 ), ExtResource( 11 ) ],
|
"frames": [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 9 ), ExtResource( 10 ), ExtResource( 11 ), ExtResource( 12 ), ExtResource( 13 ) ],
|
||||||
"loop": true,
|
"loop": true,
|
||||||
"name": "bus",
|
"name": "bus",
|
||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
}, {
|
}, {
|
||||||
"frames": [ ExtResource( 12 ), ExtResource( 13 ), ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ), ExtResource( 19 ) ],
|
"frames": [ ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 21 ) ],
|
||||||
"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 ) ],
|
"frames": [ ExtResource( 22 ), ExtResource( 23 ), ExtResource( 24 ), ExtResource( 25 ), ExtResource( 26 ), ExtResource( 27 ), ExtResource( 28 ), ExtResource( 29 ) ],
|
||||||
"loop": true,
|
"loop": true,
|
||||||
"name": "police",
|
"name": "police",
|
||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
@@ -66,21 +142,24 @@ script = ExtResource( 1 )
|
|||||||
[node name="TextureRect" type="TextureRect" parent="."]
|
[node name="TextureRect" type="TextureRect" parent="."]
|
||||||
margin_right = 1920.0
|
margin_right = 1920.0
|
||||||
margin_bottom = 1080.0
|
margin_bottom = 1080.0
|
||||||
texture = SubResource( 4 )
|
texture = SubResource( 2 )
|
||||||
expand = true
|
expand = true
|
||||||
|
|
||||||
[node name="TileMap" type="TileMap" parent="."]
|
[node name="TileMap" type="TileMap" parent="."]
|
||||||
|
tile_set = SubResource( 3 )
|
||||||
cell_size = Vector2( 128, 128 )
|
cell_size = Vector2( 128, 128 )
|
||||||
format = 1
|
format = 1
|
||||||
|
tile_data = PoolIntArray( 131079, 3, 0, 131080, 2, 0, 131081, 0, 0, 196616, 1, 0, 196617, 5, 0, 262152, 4, 0, 327688, 4, 0, 327690, 4, 0, 393224, 6, 0, 393225, 2, 0, 393226, 5, 0 )
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
[node name="TrackPath" type="Path2D" parent="."]
|
[node name="TrackPath" type="Path2D" parent="."]
|
||||||
curve = SubResource( 1 )
|
curve = SubResource( 4 )
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 4 )
|
||||||
|
|
||||||
[node name="Opponent" type="PathFollow2D" parent="TrackPath"]
|
[node name="Opponent" type="PathFollow2D" parent="TrackPath"]
|
||||||
position = Vector2( -17.3556, 327.792 )
|
position = Vector2( -17.3556, 327.792 )
|
||||||
rotation = 0.0639077
|
rotation = 0.0639077
|
||||||
script = ExtResource( 3 )
|
script = ExtResource( 5 )
|
||||||
|
|
||||||
[node name="OpponentCar" type="Node2D" parent="TrackPath/Opponent"]
|
[node name="OpponentCar" type="Node2D" parent="TrackPath/Opponent"]
|
||||||
position = Vector2( 0, 22 )
|
position = Vector2( 0, 22 )
|
||||||
@@ -89,11 +168,22 @@ scale = Vector2( 0.25, 0.25 )
|
|||||||
[node name="CarSprite" type="AnimatedSprite" parent="TrackPath/Opponent/OpponentCar"]
|
[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( 5 )
|
||||||
animation = "car"
|
animation = "car"
|
||||||
script = ExtResource( 28 )
|
script = ExtResource( 30 )
|
||||||
skin = "bus"
|
skin = "police"
|
||||||
|
|
||||||
[node name="Wrong Way" parent="." instance=ExtResource( 29 )]
|
[node name="Player" type="PathFollow2D" parent="TrackPath"]
|
||||||
|
position = Vector2( -17.3556, 327.792 )
|
||||||
|
rotation = 0.0639077
|
||||||
|
script = ExtResource( 31 )
|
||||||
|
|
||||||
|
[node name="PlayerCar" parent="TrackPath/Player" instance=ExtResource( 32 )]
|
||||||
|
position = Vector2( 1.89564, -22.3528 )
|
||||||
|
scale = Vector2( 0.25, 0.25 )
|
||||||
|
script = null
|
||||||
|
|
||||||
|
[node name="Wrong Way" parent="." instance=ExtResource( 33 )]
|
||||||
visible = false
|
visible = false
|
||||||
|
[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"]
|
||||||
|
|||||||
69
TileMap.gd
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
extends TileMap
|
||||||
|
|
||||||
|
enum { LEFT, RIGHT, UP, DOWN }
|
||||||
|
# Enum for tiles from tile_set
|
||||||
|
enum { DOWN_LEFT, DOWN_RIGHT, LEFT_RIGHT, START, UP_DOWN, UP_LEFT, UP_RIGHT }
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
_clear_tiles()
|
||||||
|
var track = TrackSelection.get_current_track()
|
||||||
|
for idx in range(track.size()):
|
||||||
|
var cell = track[idx]
|
||||||
|
var tile
|
||||||
|
if idx == 0:
|
||||||
|
tile = START
|
||||||
|
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))
|
||||||
|
set_cell(cell.x, cell.y, tile)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
func _as_dir(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
|
||||||
|
if vector.x == -1:
|
||||||
|
return LEFT
|
||||||
|
elif vector.x == 1:
|
||||||
|
return RIGHT
|
||||||
|
elif vector.y == -1:
|
||||||
|
return UP
|
||||||
|
elif vector.y == 1:
|
||||||
|
return DOWN
|
||||||
|
return -1 # Impossible case
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
#func _process(delta):
|
||||||
|
# pass
|
||||||
|
|
||||||
|
func _clear_tiles():
|
||||||
|
for cell in get_used_cells():
|
||||||
|
self.set_cell(cell.x, cell.y, -1)
|
||||||
@@ -1,22 +1,23 @@
|
|||||||
extends Path2D
|
extends Path2D
|
||||||
|
|
||||||
enum { UP, RIGHT, DOWN, LEFT }
|
enum { UP, RIGHT, DOWN, LEFT }
|
||||||
const TRACK_TILES = Global.TRACKS[0]
|
|
||||||
|
|
||||||
var tile_size : int = 128
|
var tile_size : int = 128
|
||||||
var half_size : int = tile_size / 2
|
var half_size : int = tile_size / 2
|
||||||
onready var map = get_node("../TileMap/")
|
onready var map = get_node("../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)
|
var track = TrackSelection.get_current_track()
|
||||||
|
_build_track(track)
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
func _draw():
|
func _draw():
|
||||||
draw_polyline(curve.get_baked_points(), Color.chartreuse, 4.0)
|
draw_polyline(curve.get_baked_points(), Color.chartreuse, 4.0)
|
||||||
for idx in range(0,curve.get_point_count()):
|
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_in(idx), 2.0, Color.green)
|
||||||
draw_circle(curve.get_point_out(idx), 2.0, Color.blue)
|
draw_circle(curve.get_point_out(idx), 2.0, Color.blue)
|
||||||
"""
|
|
||||||
|
|
||||||
func _build_track(tiles):
|
func _build_track(tiles):
|
||||||
""" Build the track curve given a tile path """
|
""" Build the track curve given a tile path """
|
||||||
|
|||||||
BIN
assets/track_tiles/dl.png
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
34
assets/track_tiles/dl.png.import
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/dl.png-b61487678edbb5d041ecd44844cc359b.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/track_tiles/dl.png"
|
||||||
|
dest_files=[ "res://.import/dl.png-b61487678edbb5d041ecd44844cc359b.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
|
||||||
BIN
assets/track_tiles/dr.png
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
34
assets/track_tiles/dr.png.import
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/dr.png-94ada50cc17b446a2958bdfc16ac64ca.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/track_tiles/dr.png"
|
||||||
|
dest_files=[ "res://.import/dr.png-94ada50cc17b446a2958bdfc16ac64ca.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
|
||||||
BIN
assets/track_tiles/lr.png
Normal file
|
After Width: | Height: | Size: 474 B |
34
assets/track_tiles/lr.png.import
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/lr.png-dae9afde66fc513ed9fbec9a413fcd2e.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/track_tiles/lr.png"
|
||||||
|
dest_files=[ "res://.import/lr.png-dae9afde66fc513ed9fbec9a413fcd2e.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
|
||||||
BIN
assets/track_tiles/start.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
34
assets/track_tiles/start.png.import
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/start.png-422062d2659d16a0a9668325f28ede9d.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/track_tiles/start.png"
|
||||||
|
dest_files=[ "res://.import/start.png-422062d2659d16a0a9668325f28ede9d.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
|
||||||
BIN
assets/track_tiles/track.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
34
assets/track_tiles/track.png.import
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/track.png-07e8d2fd85e34f44aac7c4b2e2ba0f7e.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/track_tiles/track.png"
|
||||||
|
dest_files=[ "res://.import/track.png-07e8d2fd85e34f44aac7c4b2e2ba0f7e.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
|
||||||
BIN
assets/track_tiles/ud.png
Normal file
|
After Width: | Height: | Size: 548 B |
34
assets/track_tiles/ud.png.import
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/ud.png-8d239d32473fb1f173314607d502fead.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/track_tiles/ud.png"
|
||||||
|
dest_files=[ "res://.import/ud.png-8d239d32473fb1f173314607d502fead.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
|
||||||
BIN
assets/track_tiles/ul.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
34
assets/track_tiles/ul.png.import
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/ul.png-7024cf834cdbb918ff81490da18cb8c6.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/track_tiles/ul.png"
|
||||||
|
dest_files=[ "res://.import/ul.png-7024cf834cdbb918ff81490da18cb8c6.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
|
||||||
BIN
assets/track_tiles/ur.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
34
assets/track_tiles/ur.png.import
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/ur.png-8d1a716720fdad1dcbdaaab4c29c0007.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/track_tiles/ur.png"
|
||||||
|
dest_files=[ "res://.import/ur.png-8d1a716720fdad1dcbdaaab4c29c0007.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/demo.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
...............
|
||||||
|
.xxxsxxx.......
|
||||||
|
.x.....x.......
|
||||||
|
.x.....x.......
|
||||||
|
.xxxxxxx.......
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
...............
|
||||||
8
assets/tracks/track1.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
...............
|
||||||
|
....xxxsxxxxx..
|
||||||
|
....xxxxxxxxx..
|
||||||
|
....xx..xx.....
|
||||||
|
....xx..xxxxx..
|
||||||
|
........xxxxx..
|
||||||
|
...............
|
||||||
|
...............
|
||||||
@@ -23,6 +23,7 @@ config/icon="res://icon.png"
|
|||||||
[autoload]
|
[autoload]
|
||||||
|
|
||||||
Global="*res://Global.gd"
|
Global="*res://Global.gd"
|
||||||
|
TrackSelection="*res://track_selection.gd"
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
|
|
||||||
|
|||||||
89
track_selection.gd
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
const TRACKS_PATH = "res://assets/tracks/"
|
||||||
|
|
||||||
|
var _tracks = [
|
||||||
|
[ Vector2(2, 1), Vector2(3, 1), Vector2(4, 1),
|
||||||
|
Vector2(4, 2), Vector2(3, 2), Vector2(2, 2), Vector2(1, 2), Vector2(1, 1),
|
||||||
|
|
||||||
|
],
|
||||||
|
[ 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 : int = 1
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
_load_tracks()
|
||||||
|
|
||||||
|
func set_next_track():
|
||||||
|
_selected = wrapi(_selected + 1, 0, _tracks.size())
|
||||||
|
|
||||||
|
func set_previous_track():
|
||||||
|
_selected = wrapi(_selected - 1, 0, _tracks.size())
|
||||||
|
|
||||||
|
func get_current_track():
|
||||||
|
return _tracks[_selected]
|
||||||
|
|
||||||
|
func _load_tracks():
|
||||||
|
var loaded = []
|
||||||
|
for path in _find_track_files():
|
||||||
|
var file = File.new()
|
||||||
|
file.open(path, File.READ)
|
||||||
|
var track = _load_from_txt(file.get_as_text())
|
||||||
|
if track.size() > 1:
|
||||||
|
loaded.append(track)
|
||||||
|
else:
|
||||||
|
print("Error in track file : ", path)
|
||||||
|
|
||||||
|
if loaded:
|
||||||
|
print("Successfully loaded ", loaded.size(), " tracks.")
|
||||||
|
_tracks = loaded
|
||||||
|
|
||||||
|
|
||||||
|
func _load_from_txt(content):
|
||||||
|
var used_cells = []
|
||||||
|
var start
|
||||||
|
# Load the content
|
||||||
|
var lines = content.split("\n")
|
||||||
|
for y in range(0, lines.size()):
|
||||||
|
for x in range(0, lines[y].length()):
|
||||||
|
if lines[y][x] == "s":
|
||||||
|
start = Vector2(x,y)
|
||||||
|
elif lines[y][x] == "x":
|
||||||
|
used_cells.append(Vector2(x,y))
|
||||||
|
# Build an oriented path from start cell going right first
|
||||||
|
var path = [start]
|
||||||
|
while used_cells.size() > 0:
|
||||||
|
var next = __find_adjacent(path[-1], used_cells)
|
||||||
|
if next == -1:
|
||||||
|
print("Error while loading path. (Path is invalid)")
|
||||||
|
else:
|
||||||
|
path.append(used_cells[next])
|
||||||
|
used_cells.remove(next)
|
||||||
|
#print_debug("Loading map from txt. Starting at : ", start, " | Path : \n", path)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
func __find_adjacent(coords, cells):
|
||||||
|
for dir in [Vector2(1,0), Vector2(0,1), Vector2(-1,0), Vector2(0,-1)]:
|
||||||
|
var idx = cells.find(coords + dir)
|
||||||
|
if idx != -1:
|
||||||
|
return idx
|
||||||
|
return -1
|
||||||
|
|
||||||
|
func _find_track_files():
|
||||||
|
var tracks = []
|
||||||
|
var dir = Directory.new()
|
||||||
|
if dir.open(TRACKS_PATH) == OK:
|
||||||
|
dir.list_dir_begin(true, true)
|
||||||
|
while true:
|
||||||
|
var file = dir.get_next()
|
||||||
|
if file == "":
|
||||||
|
break
|
||||||
|
if file.ends_with(".txt"):
|
||||||
|
tracks.append(TRACKS_PATH + file)
|
||||||
|
return tracks
|
||||||
|
else:
|
||||||
|
print("An error occured while trying to load tracks. (Folder not found)")
|
||||||