Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit e6c6f7c8 authored by Insta-x's avatar Insta-x
Browse files

ammo bar

parent 904c4dc5
No related branches found
No related tags found
1 merge request!20main menu
[gd_scene load_steps=24 format=3 uid="uid://dgtcwxlnywi84"]
[gd_scene load_steps=26 format=3 uid="uid://dgtcwxlnywi84"]
[ext_resource type="Script" path="res://scripts/grovekeeper.gd" id="1_75nxq"]
[ext_resource type="Shader" path="res://shaders/outline.gdshader" id="1_rvav7"]
......@@ -241,6 +241,22 @@ font_size = 10
outline_size = 2
outline_color = Color(0, 0, 0, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_msbq6"]
bg_color = Color(0.169245, 0.169245, 0.169245, 1)
corner_radius_top_left = 4
corner_radius_top_right = 4
corner_radius_bottom_right = 4
corner_radius_bottom_left = 4
anti_aliasing = false
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_s5c8w"]
bg_color = Color(1, 1, 0, 1)
corner_radius_top_left = 4
corner_radius_top_right = 4
corner_radius_bottom_right = 4
corner_radius_bottom_left = 4
anti_aliasing = false
[node name="Grovekeeper" type="CharacterBody2D" node_paths=PackedStringArray("hurtbox")]
collision_layer = 2
script = ExtResource("1_75nxq")
......@@ -332,14 +348,15 @@ shape = SubResource("CircleShape2D_tqguy")
[node name="HealthBar" type="ProgressBar" parent="."]
offset_left = -22.0
offset_top = -46.0
offset_top = -50.0
offset_right = 22.0
offset_bottom = -32.0
offset_bottom = -36.0
theme_override_styles/background = SubResource("StyleBoxFlat_k3tkm")
theme_override_styles/fill = SubResource("StyleBoxFlat_57ouj")
step = 1.0
value = 50.0
show_percentage = false
metadata/_edit_group_ = true
[node name="HealthLabel" type="Label" parent="HealthBar"]
layout_mode = 1
......@@ -352,4 +369,17 @@ text = "HP: 100"
label_settings = SubResource("LabelSettings_3yqcj")
horizontal_alignment = 1
[node name="AmmoBar" type="ProgressBar" parent="."]
offset_left = -22.0
offset_top = -34.0
offset_right = 22.0
offset_bottom = -30.0
theme_override_styles/background = SubResource("StyleBoxFlat_msbq6")
theme_override_styles/fill = SubResource("StyleBoxFlat_s5c8w")
max_value = 20.0
step = 1.0
value = 10.0
show_percentage = false
metadata/_edit_group_ = true
[connection signal="area_entered" from="PickupableArea" to="." method="_on_pickupable_area_area_entered"]
......@@ -7,12 +7,17 @@ extends Actor
@export var build_controller: BuildController
var inventory: InventoryDataResource = preload("res://scripts/inventory/player_inventory_data.tres")
var _ammo := 10 :
set(value):
_ammo = clampi(value, 0, 20)
_ammo_bar.value = _ammo
@onready var rig: CanvasGroup = $Rig
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var projectile_shooter: ProjectileShooter = $ProjectileShooter
@onready var _health_bar: ProgressBar = $HealthBar
@onready var _health_label: Label = $HealthBar/HealthLabel
@onready var _ammo_bar: ProgressBar = $AmmoBar
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
......@@ -39,6 +44,7 @@ func _ready() -> void:
projectile_shooter.actor_stats = stats
# HACK: Should be _unhandled_input
func _input(event: InputEvent) -> void:
if event.is_action_pressed("interact_item"):
get_viewport().set_input_as_handled()
......@@ -50,8 +56,10 @@ func _input(event: InputEvent) -> void:
return
if event.is_action_pressed("fire"):
get_viewport().set_input_as_handled()
projectile_shooter.fire()
if _ammo > 0:
get_viewport().set_input_as_handled()
projectile_shooter.fire()
_ammo -= 1
return
if event.is_action_pressed("hotbar_left"):
......@@ -119,6 +127,10 @@ func get_vector(axis: Vector2) -> Vector2:
return vector
func _on_died() -> void:
get_tree().change_scene_to_file("res://rooms/main_menu.tscn")
func _on_pickupable_area_area_entered(area: Pickupable) -> void:
area.collect(inventory)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment