add auto generation of turns

This commit is contained in:
Matthew Welch 2024-10-12 16:16:43 -07:00
parent 0323cfb638
commit 4a39252688
5 changed files with 30 additions and 32 deletions

View File

@ -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="PackedScene" uid="uid://dh2nm1sphyfqx" path="res://Tiles/TilePath.tscn" id="2_yvi2s"]
@ -29,13 +29,6 @@ _data = {
}
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"]
_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),
@ -67,9 +60,6 @@ curve = SubResource("Curve3D_r80si")
[node name="PathForward" parent="." instance=ExtResource("2_yvi2s")]
curve = SubResource("Curve3D_gpbgb")
[node name="PathRight" parent="." instance=ExtResource("2_yvi2s")]
curve = SubResource("Curve3D_f5rtl")
[node name="PathLeft" parent="." instance=ExtResource("2_yvi2s")]
curve = SubResource("Curve3D_a3s3y")

View File

@ -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="PackedScene" uid="uid://dkcjoccsgbggg" path="res://obstacles/Obstacle.tscn" id="2_tnkvo"]
@ -36,13 +36,6 @@ _data = {
}
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"]
size = Vector3(9.80943, 5.486, 17.6183)
@ -70,11 +63,8 @@ curve = SubResource("Curve3D_gpbgb")
[node name="PathRight" parent="." instance=ExtResource("3_e2l5m")]
curve = SubResource("Curve3D_f5rtl")
[node name="PathLeft" parent="." instance=ExtResource("3_e2l5m")]
curve = SubResource("Curve3D_jhtrd")
[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="."]

View File

@ -38,8 +38,11 @@ func load_path() -> void:
func turn(direction: String) -> void:
if on_main_path:
var next_path: TilePath = get_path_by_direction(direction)
if next_path == null:
return
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:

View File

@ -3,7 +3,7 @@ class_name Character
signal turn(direction: String)
@export var speed: float = 10.0
@export var speed: float = 20.0
@export var tile: Tile
var total_distance: float = 0.0

View File

@ -7,6 +7,9 @@ var tile_index: int = 0
var run_started: bool = false
var tile_parent: Node
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:
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
get_current_tiles()
if tiles.size() == 0:
var tile: Tile = generate_tile()
tiles.append(tile)
tile_parent.add_child(tile)
add_first_tile()
character.tile = current_tile
run_started = true
@ -48,17 +49,31 @@ func get_current_tiles() -> void:
tile.left_screen.connect(tile_left_screen, CONNECT_ONE_SHOT)
func generate_tile() -> Tile:
var index = randi_range(0, tile_set.strait_tiles.size()-1)
var tile_scene: PackedScene = tile_set.strait_tiles[index]
func generate_tile(tiles: Array[PackedScene]) -> Tile:
var index = randi_range(0, tiles.size()-1)
var tile_scene: PackedScene = tiles[index]
var tile: Tile = tile_scene.instantiate() as Tile
tile.left_screen.connect(tile_left_screen, CONNECT_ONE_SHOT)
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:
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)
tile_parent.add_child(tile)
tile.global_position = last_tile.spawn_point.global_position