Skip to content

Commit

Permalink
Reapply 2074287
Browse files Browse the repository at this point in the history
  • Loading branch information
Molytho committed Apr 15, 2024
1 parent edb24d4 commit ad03dae
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions src/scripts/world.gd
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
extends Node2D

const ROOMS_PER_DIFFICULTY := 1

const door = preload("res://scenes/door.tscn")

const main_room = preload("res://scenes/rooms/room_main.tscn")
const rooms = [
preload("res://scenes/rooms/room1.tscn"),
preload("res://scenes/rooms/room2.tscn"),
preload("res://scenes/rooms/room3.tscn"),
preload("res://scenes/rooms/room-illuminati.tscn"),
preload("res://scenes/rooms/room-wheel.tscn"),
preload("res://scenes/rooms/room_4.tscn"),
preload("res://scenes/rooms/room-tunnel.tscn"),
]
const room_type := preload("res://scripts/room.gd")
const rooms := {
room_type.difficulty.EASY: [preload("res://scenes/rooms/room3.tscn")],
room_type.difficulty.MEDIUM: [preload("res://scenes/rooms/room2.tscn")],
room_type.difficulty.HARD: [
preload("res://scenes/rooms/room1.tscn"),
preload("res://scenes/rooms/room-illuminati.tscn"),
preload("res://scenes/rooms/room-wheel.tscn"),
preload("res://scenes/rooms/room_4.tscn"),
preload("res://scenes/rooms/room-tunnel.tscn"),
]
}

var room_idx: int = -1
var room_scene: PackedScene
var room: Node2D

const Spell = SpellBook.Spells
Expand All @@ -30,19 +35,30 @@ const spell_order = [
]
var next_spell_idx := 0

var next_difficulty := room_type.difficulty.EASY
var count_until_next_difficulty := ROOMS_PER_DIFFICULTY

func _update_difficulty():
count_until_next_difficulty -= 1
if count_until_next_difficulty == 0 and next_difficulty != room_type.difficulty.HARD:
next_difficulty += 1
count_until_next_difficulty = ROOMS_PER_DIFFICULTY

## Spawn a new room.
func new_room():
var available_rooms = rooms.duplicate()
var available_rooms = rooms[next_difficulty].duplicate()
# avoid picking the same room again
if room_idx >= 0:
available_rooms.remove_at(room_idx)
available_rooms.erase(room_scene)
assert(available_rooms.size() > 0)
_update_difficulty()
load_room(available_rooms.pick_random())

func load_room(scene: PackedScene):
if room:
room.queue_free()
await room.tree_exited
room = scene.instantiate()
room_scene = scene
room = room_scene.instantiate()
add_child(room)
check_room_cleared()
$Player.position = room.find_child("PlayerMarker").position
Expand Down

0 comments on commit ad03dae

Please sign in to comment.