Level loading and camera bounds system
- Added MainGame scene - Converted player into reusable scene - Added CameraBounds support - Added Demon Woods level - Fixed SceneManager references
This commit is contained in:
1 parent
07b5ce7c8d
commit
7c7e607a6e
15 files changed
+350
-155
No files matched your search
@@ -3,7 +3,7 @@ extends Node2D
|
||||
var totalCoinsAvailable
|
||||
|
||||
var timer = Timer.new()
|
||||
var timeAvailable
|
||||
var timeAvailable := 0
|
||||
var level="res://Scenes/game.tscn"
|
||||
var levelTwo = "res://Scenes/level2.tscn"
|
||||
var startingCoins = 0
|
||||
@@ -33,6 +33,7 @@ func _ready() -> void:
|
||||
enemy = load("res://Scripts/rscs/slimeStats.tres")
|
||||
|
||||
playerHealth = player.starting_health
|
||||
timeAvailable = timers[currentLevel]
|
||||
|
||||
add_child(timer)
|
||||
timer.wait_time = 1
|
||||
|
||||
+26
-17
@@ -9,6 +9,7 @@ const JUMP_VELOCITY = -400.0
|
||||
@onready var right_spawn: Node2D = $RightSpawn
|
||||
@onready var left_spawn: Node2D = $LeftSpawn
|
||||
@onready var player_graphic: AnimatedSprite2D = $PlayerGraphic
|
||||
@onready var camera: Camera2D = $Camera2D
|
||||
|
||||
|
||||
enum FaceDirection{LEFT, RIGHT}
|
||||
@@ -37,18 +38,18 @@ func _physics_process(delta: float) -> void:
|
||||
handle_input()
|
||||
#calculate the movement
|
||||
|
||||
# --- STAIRS OPT-IN LOGIC ---
|
||||
# --- STAIRS OPT-IN LOGIC ---
|
||||
if can_mount_stairs and not is_on_stairs:
|
||||
print("Player: inside stairs trigger, waiting for up/down")
|
||||
|
||||
if Input.is_action_just_pressed("ui_up"):
|
||||
print("Player: ui_up pressed")
|
||||
if Input.is_action_just_pressed("ui_down"):
|
||||
print("Player: ui_down pressed")
|
||||
|
||||
if Input.is_action_just_pressed("ui_up") or Input.is_action_just_pressed("ui_down"):
|
||||
print("Player: START stairs mode requested")
|
||||
_start_stairs_mode()
|
||||
|
||||
if Input.is_action_just_pressed("ui_up"):
|
||||
print("Player: ui_up pressed")
|
||||
|
||||
if Input.is_action_just_pressed("ui_down"):
|
||||
print("Player: ui_down pressed")
|
||||
|
||||
if Input.is_action_just_pressed("ui_up") or Input.is_action_just_pressed("ui_down"):
|
||||
print("Player: START stairs mode requested")
|
||||
_start_stairs_mode()
|
||||
# ---------------------------
|
||||
|
||||
handle_movement(delta)
|
||||
@@ -97,11 +98,7 @@ func update_animation():
|
||||
player_graphic.play("hurt")
|
||||
State.DEATH:
|
||||
player_graphic.play("death")
|
||||
func handle_movement(delta):
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
|
||||
func handle_movement(_delta):
|
||||
if direction:
|
||||
velocity.x = direction * SPEED
|
||||
if direction <0:
|
||||
@@ -135,8 +132,8 @@ func handle_input():
|
||||
%SceneManager.makeBullet(left_spawn.global_transform, -700)
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
direction = Input.get_axis("ui_left", "ui_right")
|
||||
|
||||
func handle_collisions():
|
||||
for i in get_slide_collision_count():
|
||||
var c = get_slide_collision(i)
|
||||
@@ -169,6 +166,18 @@ func _ready() -> void:
|
||||
# Allow climbing up steeper slopes (default is ~45°)
|
||||
floor_max_angle = deg_to_rad(60) # you can increase or decrease as needed
|
||||
|
||||
func set_camera_limits(left: int, top: int, right: int, bottom: int) -> void:
|
||||
camera.limit_left = left
|
||||
camera.limit_top = top
|
||||
camera.limit_right = right
|
||||
camera.limit_bottom = bottom
|
||||
|
||||
print("Camera limits set:")
|
||||
print("Left: ", left)
|
||||
print("Top: ", top)
|
||||
print("Right: ", right)
|
||||
print("Bottom: ", bottom)
|
||||
|
||||
func _set_stair_collision(enabled: bool) -> void:
|
||||
print("[Player] set stair collision to:", enabled)
|
||||
set_collision_mask_value(STAIRS_LAYER, enabled)
|
||||
|
||||
@@ -1,16 +1,30 @@
|
||||
extends Node2D
|
||||
|
||||
var bullet = preload("res://Scenes/bullet.tscn")
|
||||
var bulletArray =[]
|
||||
var bulletArray = []
|
||||
var totalAllowedBullets = 7
|
||||
@onready var triggers: Node2D = $"../Triggers"
|
||||
@onready var coins: Node2D = $"../Coins"
|
||||
@onready var enemies: Node2D = $"../Enemies"
|
||||
@onready var player: Player = $"../Player"
|
||||
@onready var ui: Control = $"../CanvasLayer/UI"
|
||||
|
||||
var current_level_container: Node2D
|
||||
var current_level: Node2D
|
||||
var triggers: Node2D
|
||||
var coins: Node2D
|
||||
var enemies: Node2D
|
||||
var player: Player
|
||||
var ui: Control
|
||||
|
||||
func _ready() -> void:
|
||||
current_level_container = $"../CurrentLevel"
|
||||
current_level = current_level_container.get_child(0)
|
||||
|
||||
triggers = current_level.get_node("Triggers")
|
||||
coins = current_level.get_node("Coins")
|
||||
enemies = current_level.get_node_or_null("Enemies")
|
||||
|
||||
player = get_parent().get_node("Player")
|
||||
ui = current_level.get_node_or_null("CanvasLayer/UI")
|
||||
|
||||
apply_camera_limits()
|
||||
|
||||
Gamecontroller.reset()
|
||||
|
||||
for obj in triggers.get_children():
|
||||
@@ -35,6 +49,23 @@ func _ready() -> void:
|
||||
Gamecontroller.playerDiesSignal.connect(player.playerDies)
|
||||
player.deathAnimationCompleteSignal.connect(Gamecontroller.playerDead)
|
||||
|
||||
func apply_camera_limits() -> void:
|
||||
var bounds = current_level.get_node_or_null("CameraBounds")
|
||||
|
||||
if bounds == null:
|
||||
print("No CameraBounds found in level")
|
||||
return
|
||||
|
||||
var top_left = bounds.get_node("TopLeft")
|
||||
var bottom_right = bounds.get_node("BottomRight")
|
||||
|
||||
player.set_camera_limits(
|
||||
int(top_left.global_position.x),
|
||||
int(top_left.global_position.y),
|
||||
int(bottom_right.global_position.x),
|
||||
int(bottom_right.global_position.y)
|
||||
)
|
||||
|
||||
#call this any time the coins change
|
||||
func updateCoins() -> void:
|
||||
var coinCount = 0
|
||||
|
||||
Reference in new issue
Block a user