Generalized interactable template. Created health pickup derived class.

This commit is contained in:
Nitsud Yarg 2024-06-22 15:14:27 -07:00
parent a556afbe5f
commit e4a6188d89
15 changed files with 164 additions and 36 deletions

BIN
assets/quick_health.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 566 B

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/quick_health.png-ab4d63b30abc1b0088589c308b6afa54.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/quick_health.png"
dest_files=[ "res://.import/quick_health.png-ab4d63b30abc1b0088589c308b6afa54.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -24,15 +24,20 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://src/components/Health_Component.gd"
}, {
"base": "Interactable",
"class": "HealthPickup",
"language": "GDScript",
"path": "res://src/Interactables/HealthPickup.gd"
}, {
"base": "Area2D",
"class": "Interactable",
"language": "GDScript",
"path": "res://src/components/Interactable_Component.gd"
"path": "res://src/templates/Interactable/Interactable_Component.gd"
}, {
"base": "Node2D",
"class": "Interactable_Receiver",
"language": "GDScript",
"path": "res://src/components/Interactable_Receiver.gd"
"path": "res://src/templates/Interactable/Interactable_Receiver.gd"
}, {
"base": "Node",
"class": "MovementComponent",
@ -73,6 +78,7 @@ _global_script_class_icons={
"Actor": "",
"FrameSoundEffects": "",
"HealthComponent": "",
"HealthPickup": "",
"Interactable": "",
"Interactable_Receiver": "",
"MovementComponent": "",

View File

@ -0,0 +1,14 @@
extends Interactable
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
onready var sprite: Sprite = $Sprite
func trigger_interaction():
# This is something that should maybe be extended for every differant interactible.
# They could inherit from this base class and implement this function.
sprite.frame = 1

View File

@ -0,0 +1,21 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://src/templates/Interactable/Interactable_Component.tscn" type="PackedScene" id=1]
[ext_resource path="res://src/Interactables/Chest.gd" type="Script" id=2]
[ext_resource path="res://assets/High Forest/Assets/Interior-01.png" type="Texture" id=3]
[sub_resource type="RectangleShape2D" id=1]
[node name="Chest" instance=ExtResource( 1 )]
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="." index="0"]
texture = ExtResource( 3 )
vframes = 2
region_enabled = true
region_rect = Rect2( 49, 80, 30, 64 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="1"]
modulate = Color( 0.0313726, 1, 0, 1 )
position = Vector2( 0, 3 )
shape = SubResource( 1 )

View File

@ -0,0 +1,12 @@
class_name HealthPickup
extends Interactable
onready var health_icon: AnimatedSprite = $AnimatedSprite
func trigger_interaction():
# This is something that should maybe be extended for every differant interactible.
# They could inherit from this base class and implement this function.
# sprite.frame = 1
queue_free()

View File

@ -0,0 +1,19 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://src/Interactables/HealthPickup.gd" type="Script" id=1]
[ext_resource path="res://src/templates/Interactable/Interactable_Component.tscn" type="PackedScene" id=2]
[ext_resource path="res://src/Interactables/QuickHealthPickup.tres" type="SpriteFrames" id=3]
[sub_resource type="CircleShape2D" id=1]
radius = 6.0
[node name="HealthPickup" instance=ExtResource( 2 )]
script = ExtResource( 1 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="." index="0"]
frames = ExtResource( 3 )
frame = 1
playing = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="1"]
shape = SubResource( 1 )

View File

@ -0,0 +1,27 @@
[gd_resource type="SpriteFrames" load_steps=6 format=2]
[ext_resource path="res://assets/quick_health.png" type="Texture" id=1]
[sub_resource type="AtlasTexture" id=1]
atlas = ExtResource( 1 )
region = Rect2( 0, 0, 15, 13 )
[sub_resource type="AtlasTexture" id=2]
atlas = ExtResource( 1 )
region = Rect2( 15, 0, 15, 13 )
[sub_resource type="AtlasTexture" id=3]
atlas = ExtResource( 1 )
region = Rect2( 30, 0, 15, 13 )
[sub_resource type="AtlasTexture" id=4]
atlas = ExtResource( 1 )
region = Rect2( 45, 0, 15, 13 )
[resource]
animations = [ {
"frames": [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ) ],
"loop": true,
"name": "default",
"speed": 5.0
} ]

View File

@ -1,9 +1,10 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=8 format=2]
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/Tiles/Assets/Demo TileSet.tres" type="TileSet" id=2]
[ext_resource path="res://assets/Backgrounds/bgmuck.png" type="Texture" id=3]
[ext_resource path="res://src/components/Interactable_Component.tscn" type="PackedScene" id=4]
[ext_resource path="res://src/Interactables/Chest.tscn" type="PackedScene" id=4]
[ext_resource path="res://src/Interactables/HealthPickup.tscn" type="PackedScene" id=5]
[ext_resource path="res://assets/Music/platformer_level03_loop.ogg" type="AudioStream" id=6]
[ext_resource path="res://src/enemyC/EnemyC.tscn" type="PackedScene" id=7]
@ -73,5 +74,11 @@ __meta__ = {
}
actor_type = "NPC"
[node name="Interactable_Component" parent="." instance=ExtResource( 4 )]
position = Vector2( 186, 144 )
[node name="HealthPickup" parent="." instance=ExtResource( 5 )]
position = Vector2( 226, 153 )
[node name="Chest2" parent="." instance=ExtResource( 4 )]
position = Vector2( 319, 112 )
[node name="Chest" parent="." instance=ExtResource( 4 )]
position = Vector2( 187, 144 )

View File

@ -1,24 +0,0 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://assets/High Forest/Assets/Interior-01.png" type="Texture" id=1]
[ext_resource path="res://src/components/Interactable_Component.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1]
[node name="Interactable_Component" type="Area2D"]
script = ExtResource( 2 )
sprite_node = NodePath("Sprite")
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )
vframes = 2
region_enabled = true
region_rect = Rect2( 49, 80, 30, 64 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
modulate = Color( 0.290196, 1, 0, 1 )
position = Vector2( -1, 3 )
shape = SubResource( 1 )
[connection signal="body_entered" from="." to="." method="_on_Interactable_Component_body_entered"]
[connection signal="body_exited" from="." to="." method="_on_Interactable_Component_body_exited"]

View File

@ -26,7 +26,11 @@ func hit_Receiver(damage):
func touch_the_thing(the_thing: Interactable) -> bool:
print("You see! a THING...", the_thing.name)
if the_thing is HealthPickup:
# Do some healthy stuff.
the_thing.trigger_interaction()
return false
return true
func _on_attack_do_attack():
var is_shooting = false

View File

@ -15,7 +15,7 @@
[ext_resource path="res://src/Gun.gd" type="Script" id=13]
[ext_resource path="res://src/playerD/states/roll.gd" type="Script" id=14]
[ext_resource path="res://src/state_animated_actor.gd" type="Script" id=15]
[ext_resource path="res://src/components/Interactable_Receiver.gd" type="Script" id=16]
[ext_resource path="res://src/templates/Interactable/Interactable_Receiver.gd" type="Script" id=16]
[sub_resource type="StreamTexture" id=90]
load_path = "res://.import/Mega.png-93dfe0790902b932f7b46f7b23c5d4e7.stex"

View File

@ -17,9 +17,8 @@ extends Area2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
export (NodePath) var sprite_node
onready var sprite: Sprite = get_node(sprite_node)
export var type_name :String
# Called when the node enters the scene tree for the first time.
func _ready():
@ -28,8 +27,7 @@ func _ready():
func trigger_interaction():
# This is something that should maybe be extended for every differant interactible.
# They could inherit from this base class and implement this function.
sprite.frame = 1
# sprite.frame = 1
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.

View File

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/templates/Interactable/Interactable_Component.gd" type="Script" id=2]
[node name="Interactable_Template" type="Area2D"]
script = ExtResource( 2 )
[connection signal="body_entered" from="." to="." method="_on_Interactable_Component_body_entered"]
[connection signal="body_exited" from="." to="." method="_on_Interactable_Component_body_exited"]