Update camera based on PlayerInfo singleton. Add player enemy interractions and health!
This commit is contained in:
parent
b7c034d877
commit
9c8eb77b96
|
|
@ -20,6 +20,11 @@ _global_script_classes=[ {
|
|||
"path": "res://src/playerC/resources/FrameSounds.gd"
|
||||
}, {
|
||||
"base": "Node",
|
||||
"class": "HealthComponent",
|
||||
"language": "GDScript",
|
||||
"path": "res://src/components/Health_Component.gd"
|
||||
}, {
|
||||
"base": "Node",
|
||||
"class": "MovementComponent",
|
||||
"language": "GDScript",
|
||||
"path": "res://src/movement_component.gd"
|
||||
|
|
@ -52,6 +57,7 @@ _global_script_classes=[ {
|
|||
_global_script_class_icons={
|
||||
"Actor": "",
|
||||
"FrameSoundEffects": "",
|
||||
"HealthComponent": "",
|
||||
"MovementComponent": "",
|
||||
"State": "",
|
||||
"StateAnimatedActor": "",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ var grid_position = Vector2()
|
|||
var grid_size = Vector2()
|
||||
var t = 0.0
|
||||
|
||||
onready var parent = get_node("../Player")
|
||||
onready var parent = PlayerInfo
|
||||
#onready var parent = $Player
|
||||
|
||||
func _ready():
|
||||
|
|
@ -52,8 +52,8 @@ func update_grid_position():
|
|||
|
||||
func calculate_grid_position():
|
||||
# this needs to heavily round off the parents position
|
||||
var x_offset = floor(parent.position.x / grid_size.x)
|
||||
var y_offset = floor(parent.position.y / grid_size.y)
|
||||
var x_offset = floor(parent.player_position.x / grid_size.x)
|
||||
var y_offset = floor(parent.player_position.y / grid_size.y)
|
||||
var x = round(x_offset)
|
||||
#var x = (((grid_position.x * grid_size.x) + ((grid_position.x + 1) * grid_size.x))/2)
|
||||
var y = round(y_offset)
|
||||
|
|
@ -64,7 +64,7 @@ func calculate_grid_position():
|
|||
func jump_to_grid_position():
|
||||
#var x_pos = (((grid_position.x * grid_size.x) + ((grid_position.x + 1) * grid_size.x))/2)
|
||||
# rounding or flooring position seems to just cause a lot of jitter
|
||||
var x_pos = (parent.position.x - grid_size.x/2)
|
||||
var x_pos = (parent.player_position.x - grid_size.x/2)
|
||||
# if (x_pos - grid_size.x/2) < 0:
|
||||
# x_pos = grid_size.x/2
|
||||
# if x_pos < 0:
|
||||
|
|
|
|||
26
src/components/Health_Component.gd
Normal file
26
src/components/Health_Component.gd
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
class_name HealthComponent
|
||||
extends Node
|
||||
|
||||
export var max_health: int = 0
|
||||
var health :int = 100
|
||||
|
||||
|
||||
signal health_depleted()
|
||||
|
||||
func take_damage(damage_amount :int):
|
||||
if damage_amount < 0:
|
||||
print("ERROR: Only positive numbers in health component functions.")
|
||||
health -= damage_amount
|
||||
|
||||
if health <= 0:
|
||||
emit_signal("health_depleted")
|
||||
health = 0
|
||||
|
||||
func heal(heal_amount :int):
|
||||
if heal_amount < 0:
|
||||
print("ERROR: Only positive numbers in health component functions.")
|
||||
return
|
||||
health += heal_amount
|
||||
|
||||
if health > max_health:
|
||||
health = max_health
|
||||
6
src/components/Health_Component.tscn
Normal file
6
src/components/Health_Component.tscn
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://src/components/Health_Component.gd" type="Script" id=1]
|
||||
|
||||
[node name="Health_Component" type="Node"]
|
||||
script = ExtResource( 1 )
|
||||
|
|
@ -13,8 +13,10 @@ var call_function: FuncRef
|
|||
func _ready():
|
||||
if hurtbox_entered_function:
|
||||
call_function = funcref(owner, hurtbox_entered_function)
|
||||
else:
|
||||
print("Warning: No hurtbox function defined on ", owner.name)
|
||||
|
||||
func set_hittbox(enabled: bool):
|
||||
func set_hurtbox(enabled: bool):
|
||||
for child in get_children():
|
||||
if child is CollisionShape2D:
|
||||
child.set_deferred("disabled", !enabled)
|
||||
|
|
|
|||
15
src/enemyC/EnemyC.gd
Normal file
15
src/enemyC/EnemyC.gd
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
extends Actor
|
||||
|
||||
|
||||
|
||||
func _on_attack_state_exited():
|
||||
$Hitbox_Component.set_hitbox(false)
|
||||
|
||||
|
||||
func _on_attack_frame_reached(state_name, animation_name, frame_number):
|
||||
if frame_number == 2 and animation_name == 'attack':
|
||||
print("I quit attacking.")
|
||||
$Hitbox_Component.set_hitbox(true)
|
||||
if frame_number == 0 and animation_name == 'attack':
|
||||
print("I attack now!")
|
||||
$Hitbox_Component.set_hitbox(false)
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
[gd_scene load_steps=29 format=2]
|
||||
[gd_scene load_steps=30 format=2]
|
||||
|
||||
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://src/enemyC/enemyC_movement_component.gd" type="Script" id=2]
|
||||
[ext_resource path="res://src/enemyC/attack.gd" type="Script" id=3]
|
||||
[ext_resource path="res://src/components/Hitbox_Component.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://src/components/GenericSender.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://src/enemyC/EnemyC.gd" type="Script" id=6]
|
||||
|
||||
[sub_resource type="StreamTexture" id=1]
|
||||
load_path = "res://.import/botEnemy.png-46efd539a38730ff15fb4ddb087329c6.stex"
|
||||
|
|
@ -119,13 +120,14 @@ extents = Vector2( 9, 3.5 )
|
|||
height = 10.0
|
||||
|
||||
[node name="EnemyC" instance=ExtResource( 1 )]
|
||||
script = ExtResource( 6 )
|
||||
actor_type = "Enemy"
|
||||
|
||||
[node name="AnimatedSprite" parent="." index="0"]
|
||||
position = Vector2( 11, -7 )
|
||||
frames = SubResource( 20 )
|
||||
animation = "idle"
|
||||
frame = 1
|
||||
frame = 0
|
||||
__meta__ = {
|
||||
"_aseprite_wizard_config_": {
|
||||
"layer": "",
|
||||
|
|
@ -161,6 +163,10 @@ script = ExtResource( 3 )
|
|||
debug_state = true
|
||||
timeout_seconds = 2.0
|
||||
animation_sequence = [ "attack" ]
|
||||
emitter_frame_subscriptions = {
|
||||
0: "attack",
|
||||
2: "attack"
|
||||
}
|
||||
fall_node = NodePath("../fall")
|
||||
idle_node = NodePath("../idle")
|
||||
|
||||
|
|
@ -199,3 +205,6 @@ receiver_node_name = "GenericReceiver"
|
|||
[node name="CollisionShape2D" type="CollisionShape2D" parent="GenericSender" index="0"]
|
||||
position = Vector2( 48, 0 )
|
||||
shape = SubResource( 24 )
|
||||
|
||||
[connection signal="frame_reached" from="movement_state_machine/attack" to="." method="_on_attack_frame_reached"]
|
||||
[connection signal="state_exited" from="movement_state_machine/attack" to="." method="_on_attack_state_exited"]
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ func enter() -> void:
|
|||
print(owner.name, " Move Component: ", move_component.desired_movement_vector.x)
|
||||
|
||||
func process_frame(_delta: float) -> State:
|
||||
.process_frame(_delta)
|
||||
if move_component.wants_shoot() == false and state_timeout.time_left == 0:
|
||||
return idle_state
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,22 @@ func shoot_projectile():
|
|||
|
||||
func gotcha(damage):
|
||||
print("oh! You got me for ", damage)
|
||||
$Hurtbox_Component.set_hurtbox(false)
|
||||
$Health_Component.take_damage(damage)
|
||||
if $Health_Component.health > 0:
|
||||
movement_state_machine.change_state($movement_state_machine/hurt)
|
||||
yield( get_tree().create_timer(2 + $movement_state_machine/hurt.timeout_seconds), "timeout")
|
||||
$Hurtbox_Component.set_hurtbox(true)
|
||||
|
||||
func _on_hurt_state_exited():
|
||||
pass
|
||||
#$Hurtbox_Component.set_hurtbox(true)
|
||||
#actually await may be better here.
|
||||
|
||||
func _on_Health_Component_health_depleted():
|
||||
# die I guess.
|
||||
queue_free()
|
||||
|
||||
|
||||
func heylookatme(sender):
|
||||
print("does it work!")
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=92 format=2]
|
||||
[gd_scene load_steps=93 format=2]
|
||||
|
||||
[ext_resource path="res://src/playerC/Player-KinematicBody2D.gd" type="Script" id=1]
|
||||
[ext_resource path="res://src/playerC/states/idle.gd" type="Script" id=2]
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
[ext_resource path="res://src/state_modifier.gd" type="Script" id=13]
|
||||
[ext_resource path="res://src/playerC/sm.gd" type="Script" id=14]
|
||||
[ext_resource path="res://src/components/GenericReceiver.tscn" type="PackedScene" id=15]
|
||||
[ext_resource path="res://src/components/Health_Component.tscn" type="PackedScene" id=16]
|
||||
|
||||
[sub_resource type="Resource" id=148]
|
||||
script = ExtResource( 11 )
|
||||
|
|
@ -538,3 +539,8 @@ default_color = Color( 1, 0.607843, 0, 1 )
|
|||
|
||||
[node name="GenericReceiver" parent="." instance=ExtResource( 15 )]
|
||||
body_entered_function = "heylookatme"
|
||||
|
||||
[node name="Health_Component" parent="." instance=ExtResource( 16 )]
|
||||
|
||||
[connection signal="state_exited" from="movement_state_machine/hurt" to="." method="_on_hurt_state_exited"]
|
||||
[connection signal="health_depleted" from="Health_Component" to="." method="_on_Health_Component_health_depleted"]
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ extends MovementComponent
|
|||
|
||||
export var player_number: int = 1
|
||||
|
||||
func process_physics(delta):
|
||||
PlayerInfo.player_position = owner.global_position
|
||||
|
||||
# Return the desired direction of movement for the character
|
||||
# in the range [-1, 1], where positive values indicate a desire
|
||||
# to move to the right and negative values to the left.
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@ export var timeout_seconds: float = 0.0
|
|||
|
||||
signal state_entered()
|
||||
signal state_exited()
|
||||
signal frame_reached(state_name, animation_name, frame_number)
|
||||
export(Dictionary) var emitter_frame_subscriptions
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
var modifier_stack_ref: Array # Well this didn't work
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ extends State
|
|||
export var move_speed: float = 60
|
||||
|
||||
export(Array, String) var animation_sequence
|
||||
|
||||
signal frame_reached(state_name, animation_name, frame_number)
|
||||
export(Dictionary) var emitter_frame_subscriptions
|
||||
var frame_signal_emitted: bool = false
|
||||
|
||||
# this just wouldn't work well. Maybe I can try a resource
|
||||
# export(Array, NodePath) var transition_state_nodes
|
||||
|
||||
|
|
@ -98,7 +103,12 @@ func process_frame(_delta: float) -> State:
|
|||
# Singal based frame call.
|
||||
if emitter_frame_subscriptions.has(animations.frame):
|
||||
if emitter_frame_subscriptions[animations.frame] == animations.animation:
|
||||
emit_signal("frame_reached", self.name, animations.animation, animations.frame)
|
||||
if frame_signal_emitted == false:
|
||||
emit_signal("frame_reached", self.name, animations.animation, animations.frame)
|
||||
# Try to only so this once.
|
||||
frame_signal_emitted = true
|
||||
else:
|
||||
frame_signal_emitted = false
|
||||
|
||||
return null
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user