Added destruction wall and player destruction
This commit is contained in:
@@ -7,6 +7,7 @@ const CORRUPTION_DAMAGE = 10.0
|
||||
|
||||
@export var initial_corruption_x := 0.0
|
||||
@export var corruption_speed := 0.0
|
||||
@export var desctruction_offset := 100.0
|
||||
|
||||
|
||||
var _corruption_x: float
|
||||
@@ -18,9 +19,14 @@ var _corruption_x: float
|
||||
@onready var health_bar : HealthBar = $%HealthBar
|
||||
|
||||
@onready var corruption_timer : Timer = $CorruptionTimer
|
||||
@onready var destruction_timer : Timer = $DestructionTimer
|
||||
@onready var death_fall_timer : Timer = $DeathFallTimer
|
||||
|
||||
@onready var level_material : ShaderMaterial = $%LevelColorRect.material
|
||||
@onready var code_material : ShaderMaterial = $%CodeSprite.material
|
||||
|
||||
@onready var camera : Camera2D = player.camera
|
||||
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -37,24 +43,30 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
var screen_to_world := player.camera.get_canvas_transform().affine_inverse()
|
||||
var screen_to_world := camera.get_canvas_transform().affine_inverse()
|
||||
level_material.set_shader_parameter("screen_to_world", screen_to_world)
|
||||
level_material.set_shader_parameter("corruption_x", _corruption_x)
|
||||
code_material.set_shader_parameter("screen_to_world", screen_to_world)
|
||||
code_material.set_shader_parameter("destruction_x", _corruption_x - desctruction_offset)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
_corruption_x += corruption_speed * delta
|
||||
|
||||
if player.position.x < _corruption_x:
|
||||
if not player: return
|
||||
|
||||
if player.position.x < _corruption_x - desctruction_offset:
|
||||
_destroy_player()
|
||||
elif player.position.x < _corruption_x:
|
||||
if corruption_timer.is_stopped():
|
||||
corruption_timer.start()
|
||||
else:
|
||||
corruption_timer.stop()
|
||||
|
||||
if player.position.y > 0.0:
|
||||
if death_fall_timer.is_stopped():
|
||||
death_fall_timer.start()
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_fall, player.global_position)
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_fall, player.global_position)
|
||||
death_fall_timer.start()
|
||||
_delete_player()
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
@@ -65,6 +77,17 @@ func _input(event: InputEvent) -> void:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
|
||||
|
||||
func _destroy_player() -> void:
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_destruction, player.global_position)
|
||||
_delete_player()
|
||||
|
||||
|
||||
func _delete_player() -> void:
|
||||
player.camera.reparent(self)
|
||||
destruction_timer.start()
|
||||
player.queue_free()
|
||||
|
||||
|
||||
func _show_game_over() -> void:
|
||||
get_tree().paused = true
|
||||
game_over_menu.show()
|
||||
@@ -72,6 +95,9 @@ func _show_game_over() -> void:
|
||||
|
||||
|
||||
func _on_corruption_timer_timeout() -> void:
|
||||
if not player:
|
||||
corruption_timer.stop()
|
||||
return
|
||||
player.deal_damage(CORRUPTION_DAMAGE)
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_corruption, player.global_position)
|
||||
|
||||
@@ -83,3 +109,7 @@ func _on_player_dead() -> void:
|
||||
|
||||
func _on_death_fall_timer_timeout() -> void:
|
||||
_show_game_over()
|
||||
|
||||
|
||||
func _on_destruction_timer_timeout() -> void:
|
||||
_show_game_over()
|
||||
|
||||
Reference in New Issue
Block a user