Added player health and health bar
This commit is contained in:
@@ -2,6 +2,9 @@ class_name AbstractLevel
|
||||
extends Node2D
|
||||
|
||||
|
||||
const CORRUPTION_DAMAGE = 10.0
|
||||
|
||||
|
||||
@export var initial_corruption_x := 0.0
|
||||
@export var corruption_speed := 0.0
|
||||
|
||||
@@ -11,6 +14,9 @@ var _corruption_x: float
|
||||
|
||||
@onready var player : Player = $Player
|
||||
@onready var pause_menu : PauseMenu = $%PauseMenu
|
||||
@onready var health_bar : HealthBar = $%HealthBar
|
||||
|
||||
@onready var corruption_timer : Timer = $CorruptionTimer
|
||||
|
||||
@onready var level_material : ShaderMaterial = $%LevelColorRect.material
|
||||
|
||||
@@ -18,21 +24,35 @@ var _corruption_x: float
|
||||
func _ready() -> void:
|
||||
_corruption_x = initial_corruption_x
|
||||
pause_menu.hide()
|
||||
health_bar.initialize(player.MAX_HEALTH, player.MAX_HEALTH)
|
||||
player.health_changed.connect(health_bar.set_current_value)
|
||||
|
||||
#TODO Add gameplay music
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
_corruption_x += corruption_speed * delta
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
var screen_to_world := player.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)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
_corruption_x += corruption_speed * delta
|
||||
|
||||
if player.position.x < _corruption_x:
|
||||
if corruption_timer.is_stopped():
|
||||
corruption_timer.start()
|
||||
else:
|
||||
corruption_timer.stop()
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("pause"):
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
get_tree().paused = true
|
||||
pause_menu.show()
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
|
||||
|
||||
func _on_corruption_timer_timeout() -> void:
|
||||
player.deal_damage(CORRUPTION_DAMAGE)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
[ext_resource type="PackedScene" uid="uid://0e3xvmn36j5b" path="res://game/menu/pause_menu.tscn" id="3_fnnmn"]
|
||||
[ext_resource type="Shader" uid="uid://brudtlwas6x66" path="res://game/shaders/glitch.gdshader" id="4_6b8cu"]
|
||||
[ext_resource type="Texture2D" uid="uid://b8rm1kxgci4l1" path="res://images/level/beams.png" id="4_pi5fd"]
|
||||
[ext_resource type="PackedScene" uid="uid://b1x0tmnf7hx7h" path="res://game/hud/health_bar.tscn" id="6_x8k35"]
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_6b8cu"]
|
||||
resource_name = "Beams"
|
||||
@@ -1195,3 +1196,11 @@ offset_bottom = 360.0
|
||||
[node name="PauseMenu" parent="CanvasLayer" unique_id=1815975678 instance=ExtResource("3_fnnmn")]
|
||||
unique_name_in_owner = true
|
||||
process_mode = 2
|
||||
|
||||
[node name="HealthBar" parent="CanvasLayer" unique_id=256637218 instance=ExtResource("6_x8k35")]
|
||||
unique_name_in_owner = true
|
||||
position = Vector2(51, 19)
|
||||
|
||||
[node name="CorruptionTimer" type="Timer" parent="." unique_id=783383429]
|
||||
|
||||
[connection signal="timeout" from="CorruptionTimer" to="." method="_on_corruption_timer_timeout"]
|
||||
|
||||
Reference in New Issue
Block a user