add energy mechanic to sg2083

This commit is contained in:
Haze Weathers 2024-02-27 22:12:30 -05:00
parent fd10cfca8c
commit e0e56d3ffa
5 changed files with 53 additions and 5 deletions

View file

@ -2,12 +2,14 @@ extends "res://maps/map.gd"
onready var sg_health: HSlider = $"%SGHealth" onready var sg_health: HSlider = $"%SGHealth"
onready var sg_energy: HSlider = $"%SGEnergy"
onready var fami_health: HSlider = $"%FamiHealth" onready var fami_health: HSlider = $"%FamiHealth"
onready var sg2083: KinematicBody2D = $"2083" onready var sg2083: KinematicBody2D = $"2083"
onready var famira: Node2D = $Famira onready var famira: Node2D = $Famira
func _ready() -> void: func _ready() -> void:
sg_energy.max_value = sg2083.max_energy
sg2083.state = sg2083.State.INACTIVE sg2083.state = sg2083.State.INACTIVE
famira.animation_player.play("grow", -1.0, 0.0) famira.animation_player.play("grow", -1.0, 0.0)
@ -27,3 +29,7 @@ func _on_cutscene_finished() -> void:
famira.animation_player.play("grow") famira.animation_player.play("grow")
yield(get_tree().create_timer(0.5), "timeout") yield(get_tree().create_timer(0.5), "timeout")
$FamiCutscene/FamiHuman.visible = false $FamiCutscene/FamiHuman.visible = false
func _on_2083_energy_changed(amount) -> void:
sg_energy.value = amount

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=2] [gd_scene load_steps=9 format=2]
[ext_resource path="res://objects/enemy/boss/sg2083.tscn" type="PackedScene" id=1] [ext_resource path="res://objects/enemy/boss/sg2083.tscn" type="PackedScene" id=1]
[ext_resource path="res://tilesets/t_laboratory.tres" type="TileSet" id=2] [ext_resource path="res://tilesets/t_laboratory.tres" type="TileSet" id=2]
@ -7,10 +7,12 @@
[ext_resource path="res://ui/theme.tres" type="Theme" id=5] [ext_resource path="res://ui/theme.tres" type="Theme" id=5]
[ext_resource path="res://tilesets/t_station.tres" type="TileSet" id=6] [ext_resource path="res://tilesets/t_station.tres" type="TileSet" id=6]
[ext_resource path="res://cutscenes/fami_cutscene.tscn" type="PackedScene" id=7] [ext_resource path="res://cutscenes/fami_cutscene.tscn" type="PackedScene" id=7]
[ext_resource path="res://objects/lore/boss/fami.tscn" type="PackedScene" id=8]
[node name="Map" type="Node2D" groups=["map"]] [node name="Map" type="Node2D" groups=["map"]]
pause_mode = 1 pause_mode = 1
script = ExtResource( 3 ) script = ExtResource( 3 )
lore_entries = [ ExtResource( 8 ) ]
[node name="GUI" type="CanvasLayer" parent="."] [node name="GUI" type="CanvasLayer" parent="."]
@ -25,6 +27,25 @@ margin_bottom = 192.0
size_flags_horizontal = 3 size_flags_horizontal = 3
alignment = 2 alignment = 2
[node name="HBoxContainer2" type="HBoxContainer" parent="GUI/Control/VBoxContainer"]
margin_top = 168.0
margin_right = 126.0
margin_bottom = 178.0
[node name="Label" type="Label" parent="GUI/Control/VBoxContainer/HBoxContainer2"]
margin_right = 49.0
margin_bottom = 10.0
text = " Energy"
[node name="SGEnergy" type="HSlider" parent="GUI/Control/VBoxContainer/HBoxContainer2"]
unique_name_in_owner = true
margin_left = 53.0
margin_right = 126.0
margin_bottom = 10.0
size_flags_horizontal = 3
value = 100.0
scrollable = false
[node name="HBoxContainer" type="HBoxContainer" parent="GUI/Control/VBoxContainer"] [node name="HBoxContainer" type="HBoxContainer" parent="GUI/Control/VBoxContainer"]
margin_top = 182.0 margin_top = 182.0
margin_right = 126.0 margin_right = 126.0
@ -92,9 +113,12 @@ position = Vector2( 0, 12 )
famira_path = NodePath("../Famira") famira_path = NodePath("../Famira")
[node name="Camera2D" type="Camera2D" parent="2083"] [node name="Camera2D" type="Camera2D" parent="2083"]
position = Vector2( 0, -4 )
offset = Vector2( 0, -8 ) offset = Vector2( 0, -8 )
anchor_mode = 0 anchor_mode = 0
current = true current = true
limit_top = 8
limit_bottom = 192
[node name="Famira" parent="." instance=ExtResource( 4 )] [node name="Famira" parent="." instance=ExtResource( 4 )]
visible = false visible = false
@ -102,5 +126,6 @@ position = Vector2( 160, 179 )
sg2083_path = NodePath("../2083") sg2083_path = NodePath("../2083")
[connection signal="cutscene_finished" from="FamiCutscene" to="." method="_on_cutscene_finished"] [connection signal="cutscene_finished" from="FamiCutscene" to="." method="_on_cutscene_finished"]
[connection signal="energy_changed" from="2083" to="." method="_on_2083_energy_changed"]
[connection signal="health_changed" from="2083" to="." method="_on_2083_health_changed"] [connection signal="health_changed" from="2083" to="." method="_on_2083_health_changed"]
[connection signal="health_changed" from="Famira" to="." method="_on_Famira_health_changed"] [connection signal="health_changed" from="Famira" to="." method="_on_Famira_health_changed"]

View file

@ -3,6 +3,7 @@ extends KinematicBody2D
signal died() signal died()
signal health_changed(amount) signal health_changed(amount)
signal energy_changed(amount)
enum State {DEAD, STAND, FORWARD, BACK, DUCK, BEAM, INACTIVE} enum State {DEAD, STAND, FORWARD, BACK, DUCK, BEAM, INACTIVE}
@ -12,17 +13,23 @@ const SmallExplosion = preload("res://objects/enemy/boss/2600_small_explosion.ts
export var hp: float = 100.0 export var hp: float = 100.0
export var max_energy: float = 100.0
export var energy_recovery: float = 5.0
export var shot_speed: float = 50.0 export var shot_speed: float = 50.0
export var move_speed: float = 30.0 export var move_speed: float = 30.0
export var safe_from_breath: bool = false export var safe_from_breath: bool = false
export var make_explosions: bool = false export var make_explosions: bool = false
export var bullet_damage: float = 1.0 export var bullet_damage: float = 1.0
export var bullet_energy: float = 5.0
export var beam_energy: float = 50.0
export var duck_energy: float = 10.0
export var explosion_rect: Rect2 export var explosion_rect: Rect2
export var famira_path: NodePath export var famira_path: NodePath
var state: int = State.STAND var state: int = State.STAND
var knockback: float = 0.0 var knockback: float = 0.0
var energy: float = max_energy
onready var bullet_positions = $"%BulletPositions" onready var bullet_positions = $"%BulletPositions"
@ -35,7 +42,8 @@ func _physics_process(delta: float) -> void:
State.DEAD: State.DEAD:
return return
State.STAND: State.STAND:
if Input.is_action_pressed("move_down"): if Input.is_action_pressed("move_down") and energy >= duck_energy:
set_energy(energy - duck_energy)
state = State.DUCK state = State.DUCK
anims.play("Duck") anims.play("Duck")
elif Input.is_action_pressed("move_right"): elif Input.is_action_pressed("move_right"):
@ -53,18 +61,25 @@ func _physics_process(delta: float) -> void:
move_and_slide(Vector2(-move_speed, 0.0)) move_and_slide(Vector2(-move_speed, 0.0))
move_and_slide(Vector2(-knockback, 0.0)) move_and_slide(Vector2(-knockback, 0.0))
knockback *= pow(0.1, delta) knockback *= pow(0.1, delta)
set_energy(energy + energy_recovery * delta)
func _input(event: InputEvent) -> void: func _input(event: InputEvent) -> void:
if state == State.DEAD: if state == State.DEAD:
return return
if event.is_action_pressed("shoot") and (state == State.STAND or state == State.FORWARD or state == State.BACK): if event.is_action_pressed("shoot") and (state == State.STAND or state == State.FORWARD or state == State.BACK) and energy >= bullet_energy:
shoot() shoot()
if event.is_action_pressed("jump") and state == State.STAND: if event.is_action_pressed("jump") and state == State.STAND and energy >= beam_energy:
beam() beam()
func set_energy(value: float) -> void:
energy = clamp(value, 0.0, max_energy)
emit_signal("energy_changed", energy)
func shoot() -> void: func shoot() -> void:
set_energy(energy - bullet_energy)
Audio.play_sound(Audio.a_bullet_barrage,Audio.ac_collectible) Audio.play_sound(Audio.a_bullet_barrage,Audio.ac_collectible)
for pos in bullet_positions.get_children(): for pos in bullet_positions.get_children():
var bullet = Bullet.instance() var bullet = Bullet.instance()
@ -77,6 +92,8 @@ func shoot() -> void:
func beam() -> void: func beam() -> void:
state = State.BEAM state = State.BEAM
var tween = create_tween()
tween.tween_method(self, "set_energy", energy, energy - beam_energy, 0.9)
anims.play("Beam") anims.play("Beam")

View file

@ -1607,7 +1607,7 @@ update_scale = false
[node name="KneeBack" type="Sprite" parent="Axle"] [node name="KneeBack" type="Sprite" parent="Axle"]
modulate = Color( 0.74902, 0.74902, 0.74902, 1 ) modulate = Color( 0.74902, 0.74902, 0.74902, 1 )
position = Vector2( 6.25089, 28.1233 ) position = Vector2( 6.25088, 28.1233 )
scale = Vector2( 1, -1 ) scale = Vector2( 1, -1 )
z_index = -1 z_index = -1
texture = ExtResource( 8 ) texture = ExtResource( 8 )