add auto generation of turns
This commit is contained in:
parent
0323cfb638
commit
4a39252688
@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=12 format=3 uid="uid://c0xv7v6ako25a"]
|
[gd_scene load_steps=11 format=3 uid="uid://c0xv7v6ako25a"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Tiles/tile_turn.gd" id="1_f1mql"]
|
[ext_resource type="Script" path="res://Tiles/tile_turn.gd" id="1_f1mql"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dh2nm1sphyfqx" path="res://Tiles/TilePath.tscn" id="2_yvi2s"]
|
[ext_resource type="PackedScene" uid="uid://dh2nm1sphyfqx" path="res://Tiles/TilePath.tscn" id="2_yvi2s"]
|
||||||
@ -29,13 +29,6 @@ _data = {
|
|||||||
}
|
}
|
||||||
point_count = 2
|
point_count = 2
|
||||||
|
|
||||||
[sub_resource type="Curve3D" id="Curve3D_f5rtl"]
|
|
||||||
_data = {
|
|
||||||
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, -5, 0, 0, 0, 0, 0, 0, 5, 0, -5),
|
|
||||||
"tilts": PackedFloat32Array(0, 0, 0)
|
|
||||||
}
|
|
||||||
point_count = 3
|
|
||||||
|
|
||||||
[sub_resource type="Curve3D" id="Curve3D_a3s3y"]
|
[sub_resource type="Curve3D" id="Curve3D_a3s3y"]
|
||||||
_data = {
|
_data = {
|
||||||
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, -5, 0, 0, 0, 0, 0, 0, -5, 0, -5),
|
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, -5, 0, 0, 0, 0, 0, 0, -5, 0, -5),
|
||||||
@ -67,9 +60,6 @@ curve = SubResource("Curve3D_r80si")
|
|||||||
[node name="PathForward" parent="." instance=ExtResource("2_yvi2s")]
|
[node name="PathForward" parent="." instance=ExtResource("2_yvi2s")]
|
||||||
curve = SubResource("Curve3D_gpbgb")
|
curve = SubResource("Curve3D_gpbgb")
|
||||||
|
|
||||||
[node name="PathRight" parent="." instance=ExtResource("2_yvi2s")]
|
|
||||||
curve = SubResource("Curve3D_f5rtl")
|
|
||||||
|
|
||||||
[node name="PathLeft" parent="." instance=ExtResource("2_yvi2s")]
|
[node name="PathLeft" parent="." instance=ExtResource("2_yvi2s")]
|
||||||
curve = SubResource("Curve3D_a3s3y")
|
curve = SubResource("Curve3D_a3s3y")
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=12 format=3 uid="uid://b88nuwe42bhc1"]
|
[gd_scene load_steps=11 format=3 uid="uid://b88nuwe42bhc1"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Tiles/tile_turn.gd" id="1_wj6en"]
|
[ext_resource type="Script" path="res://Tiles/tile_turn.gd" id="1_wj6en"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dkcjoccsgbggg" path="res://obstacles/Obstacle.tscn" id="2_tnkvo"]
|
[ext_resource type="PackedScene" uid="uid://dkcjoccsgbggg" path="res://obstacles/Obstacle.tscn" id="2_tnkvo"]
|
||||||
@ -36,13 +36,6 @@ _data = {
|
|||||||
}
|
}
|
||||||
point_count = 3
|
point_count = 3
|
||||||
|
|
||||||
[sub_resource type="Curve3D" id="Curve3D_jhtrd"]
|
|
||||||
_data = {
|
|
||||||
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, -5, 0, 0, 0, 0, 0, 0, -5, 0, -5),
|
|
||||||
"tilts": PackedFloat32Array(0, 0, 0)
|
|
||||||
}
|
|
||||||
point_count = 3
|
|
||||||
|
|
||||||
[sub_resource type="BoxShape3D" id="BoxShape3D_uvh3q"]
|
[sub_resource type="BoxShape3D" id="BoxShape3D_uvh3q"]
|
||||||
size = Vector3(9.80943, 5.486, 17.6183)
|
size = Vector3(9.80943, 5.486, 17.6183)
|
||||||
|
|
||||||
@ -70,11 +63,8 @@ curve = SubResource("Curve3D_gpbgb")
|
|||||||
[node name="PathRight" parent="." instance=ExtResource("3_e2l5m")]
|
[node name="PathRight" parent="." instance=ExtResource("3_e2l5m")]
|
||||||
curve = SubResource("Curve3D_f5rtl")
|
curve = SubResource("Curve3D_f5rtl")
|
||||||
|
|
||||||
[node name="PathLeft" parent="." instance=ExtResource("3_e2l5m")]
|
|
||||||
curve = SubResource("Curve3D_jhtrd")
|
|
||||||
|
|
||||||
[node name="SpawnPoint" type="Marker3D" parent="."]
|
[node name="SpawnPoint" type="Marker3D" parent="."]
|
||||||
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 5, 0, 0)
|
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 5, 0, -5)
|
||||||
|
|
||||||
[node name="Area3D" type="Area3D" parent="."]
|
[node name="Area3D" type="Area3D" parent="."]
|
||||||
|
|
||||||
|
@ -38,8 +38,11 @@ func load_path() -> void:
|
|||||||
|
|
||||||
func turn(direction: String) -> void:
|
func turn(direction: String) -> void:
|
||||||
if on_main_path:
|
if on_main_path:
|
||||||
|
var next_path: TilePath = get_path_by_direction(direction)
|
||||||
|
if next_path == null:
|
||||||
|
return
|
||||||
current_direction = direction
|
current_direction = direction
|
||||||
paths[path_index+1] = get_path_by_direction(current_direction)
|
paths[path_index+1] = next_path
|
||||||
|
|
||||||
|
|
||||||
func get_path_by_direction(direction: String) -> TilePath:
|
func get_path_by_direction(direction: String) -> TilePath:
|
||||||
|
@ -3,7 +3,7 @@ class_name Character
|
|||||||
|
|
||||||
signal turn(direction: String)
|
signal turn(direction: String)
|
||||||
|
|
||||||
@export var speed: float = 10.0
|
@export var speed: float = 20.0
|
||||||
@export var tile: Tile
|
@export var tile: Tile
|
||||||
|
|
||||||
var total_distance: float = 0.0
|
var total_distance: float = 0.0
|
||||||
|
@ -7,6 +7,9 @@ var tile_index: int = 0
|
|||||||
var run_started: bool = false
|
var run_started: bool = false
|
||||||
var tile_parent: Node
|
var tile_parent: Node
|
||||||
var character: Character
|
var character: Character
|
||||||
|
var min_turn: int = 3
|
||||||
|
var max_turn: int = 10
|
||||||
|
var turn_counter: int = randi_range(min_turn, max_turn)
|
||||||
|
|
||||||
var current_tile: Tile:
|
var current_tile: Tile:
|
||||||
get = get_current_tile
|
get = get_current_tile
|
||||||
@ -35,9 +38,7 @@ func start_run(tile_parent: Node) -> void:
|
|||||||
character = Utils.get_first_node_of_type(get_tree().root, Character) as Character
|
character = Utils.get_first_node_of_type(get_tree().root, Character) as Character
|
||||||
get_current_tiles()
|
get_current_tiles()
|
||||||
if tiles.size() == 0:
|
if tiles.size() == 0:
|
||||||
var tile: Tile = generate_tile()
|
add_first_tile()
|
||||||
tiles.append(tile)
|
|
||||||
tile_parent.add_child(tile)
|
|
||||||
character.tile = current_tile
|
character.tile = current_tile
|
||||||
run_started = true
|
run_started = true
|
||||||
|
|
||||||
@ -48,17 +49,31 @@ func get_current_tiles() -> void:
|
|||||||
tile.left_screen.connect(tile_left_screen, CONNECT_ONE_SHOT)
|
tile.left_screen.connect(tile_left_screen, CONNECT_ONE_SHOT)
|
||||||
|
|
||||||
|
|
||||||
func generate_tile() -> Tile:
|
func generate_tile(tiles: Array[PackedScene]) -> Tile:
|
||||||
var index = randi_range(0, tile_set.strait_tiles.size()-1)
|
var index = randi_range(0, tiles.size()-1)
|
||||||
var tile_scene: PackedScene = tile_set.strait_tiles[index]
|
var tile_scene: PackedScene = tiles[index]
|
||||||
var tile: Tile = tile_scene.instantiate() as Tile
|
var tile: Tile = tile_scene.instantiate() as Tile
|
||||||
tile.left_screen.connect(tile_left_screen, CONNECT_ONE_SHOT)
|
tile.left_screen.connect(tile_left_screen, CONNECT_ONE_SHOT)
|
||||||
return tile
|
return tile
|
||||||
|
|
||||||
|
|
||||||
|
func add_first_tile() -> void:
|
||||||
|
var tile: Tile = generate_tile(tile_set.strait_tiles)
|
||||||
|
tiles.append(tile)
|
||||||
|
tile_parent.add_child(tile)
|
||||||
|
tile.global_position = Vector3.ZERO
|
||||||
|
tile.global_rotation = Vector3.ZERO
|
||||||
|
|
||||||
|
|
||||||
func add_tile() -> void:
|
func add_tile() -> void:
|
||||||
var last_tile: Tile = tiles[tiles.size()-1]
|
var last_tile: Tile = tiles[tiles.size()-1]
|
||||||
var tile: Tile = generate_tile()
|
var tile: Tile
|
||||||
|
if turn_counter <= 0:
|
||||||
|
tile = generate_tile(tile_set.turn_tiles)
|
||||||
|
turn_counter = randi_range(min_turn, max_turn)
|
||||||
|
else:
|
||||||
|
tile = generate_tile(tile_set.strait_tiles)
|
||||||
|
turn_counter -= 1
|
||||||
tiles.append(tile)
|
tiles.append(tile)
|
||||||
tile_parent.add_child(tile)
|
tile_parent.add_child(tile)
|
||||||
tile.global_position = last_tile.spawn_point.global_position
|
tile.global_position = last_tile.spawn_point.global_position
|
||||||
|
Loading…
Reference in New Issue
Block a user