Still working on a hit/hurtbox interactions.
This commit is contained in:
parent
225e42957f
commit
2ccd8bcb8b
11
src/actor.gd
11
src/actor.gd
|
|
@ -27,6 +27,7 @@ var sound_effects_dict: Dictionary
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
movement_state_machine.init_animated_actor(self, movement_animations, movement_component)
|
movement_state_machine.init_animated_actor(self, movement_animations, movement_component)
|
||||||
|
movement_component.attack_function = funcref(self, "attack")
|
||||||
# movement_component.player_number = player_number
|
# movement_component.player_number = player_number
|
||||||
|
|
||||||
# Experimenting with sound based resources I did this and it worked
|
# Experimenting with sound based resources I did this and it worked
|
||||||
|
|
@ -70,3 +71,13 @@ func play_sound_frame(animation: String, frame: int ):
|
||||||
sound_effect_player.stream = sound_effects_dict[sound_index]
|
sound_effect_player.stream = sound_effects_dict[sound_index]
|
||||||
sound_effect_player.play()
|
sound_effect_player.play()
|
||||||
print(self.name, " Playing SE: ", sound_index)
|
print(self.name, " Playing SE: ", sound_index)
|
||||||
|
|
||||||
|
func attack():
|
||||||
|
#print(self.name, ": It's not inheritence, it's funcrefs")
|
||||||
|
if movement_state_machine.current_state.name != 'attack':
|
||||||
|
if($movement_state_machine/attack):
|
||||||
|
movement_state_machine.change_state($movement_state_machine/attack)
|
||||||
|
if ($Hitbox_Component/CollisionShape2D):
|
||||||
|
#print(self.name, ": Found a hitbox")
|
||||||
|
var hit_box = $Hitbox_Component
|
||||||
|
hit_box.set_hitbox(true)
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ func set_hitbox(enabled: bool):
|
||||||
|
|
||||||
func shoot_projectile():
|
func shoot_projectile():
|
||||||
var is_shooting = false
|
var is_shooting = false
|
||||||
is_shooting = gun.shoot(direction.x)
|
is_shooting = gun.shoot(transform.x.x)
|
||||||
|
|
||||||
|
|
||||||
func _on_Hurtbox_body_entered(body):
|
func _on_Hurtbox_body_entered(body):
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
[gd_scene load_steps=26 format=2]
|
[gd_scene load_steps=27 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
|
[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/enemyC_movement_component.gd" type="Script" id=2]
|
||||||
[ext_resource path="res://src/state_animated_actor.gd" type="Script" id=3]
|
[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]
|
||||||
|
|
||||||
[sub_resource type="StreamTexture" id=1]
|
[sub_resource type="StreamTexture" id=1]
|
||||||
load_path = "res://.import/botEnemy.png-46efd539a38730ff15fb4ddb087329c6.stex"
|
load_path = "res://.import/botEnemy.png-46efd539a38730ff15fb4ddb087329c6.stex"
|
||||||
|
|
@ -110,7 +111,7 @@ animations = [ {
|
||||||
[sub_resource type="RectangleShape2D" id=22]
|
[sub_resource type="RectangleShape2D" id=22]
|
||||||
extents = Vector2( 10, 16 )
|
extents = Vector2( 10, 16 )
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id=21]
|
[sub_resource type="RectangleShape2D" id=23]
|
||||||
extents = Vector2( 9, 3.5 )
|
extents = Vector2( 9, 3.5 )
|
||||||
|
|
||||||
[node name="EnemyC" instance=ExtResource( 1 )]
|
[node name="EnemyC" instance=ExtResource( 1 )]
|
||||||
|
|
@ -120,7 +121,7 @@ actor_type = "Enemy"
|
||||||
position = Vector2( 11, -7 )
|
position = Vector2( 11, -7 )
|
||||||
frames = SubResource( 20 )
|
frames = SubResource( 20 )
|
||||||
animation = "idle"
|
animation = "idle"
|
||||||
frame = 1
|
frame = 0
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_aseprite_wizard_config_": {
|
"_aseprite_wizard_config_": {
|
||||||
"layer": "",
|
"layer": "",
|
||||||
|
|
@ -153,8 +154,11 @@ animation_sequence = [ "idle" ]
|
||||||
|
|
||||||
[node name="attack" type="Node" parent="movement_state_machine" index="2"]
|
[node name="attack" type="Node" parent="movement_state_machine" index="2"]
|
||||||
script = ExtResource( 3 )
|
script = ExtResource( 3 )
|
||||||
timeout_seconds = 3.0
|
debug_state = true
|
||||||
|
timeout_seconds = 2.0
|
||||||
animation_sequence = [ "attack" ]
|
animation_sequence = [ "attack" ]
|
||||||
|
fall_node = NodePath("../fall")
|
||||||
|
idle_node = NodePath("../idle")
|
||||||
|
|
||||||
[node name="move" parent="movement_state_machine" index="3"]
|
[node name="move" parent="movement_state_machine" index="3"]
|
||||||
animation_sequence = [ "walk" ]
|
animation_sequence = [ "walk" ]
|
||||||
|
|
@ -176,11 +180,10 @@ enabled = true
|
||||||
cast_to = Vector2( 21, 0 )
|
cast_to = Vector2( 21, 0 )
|
||||||
collision_mask = 2
|
collision_mask = 2
|
||||||
|
|
||||||
[node name="Hitbox_Component" type="Area2D" parent="." index="8"]
|
[node name="Hitbox_Component" parent="." index="8" instance=ExtResource( 4 )]
|
||||||
collision_layer = 128
|
|
||||||
collision_mask = 0
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox_Component" index="0"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox_Component" index="0"]
|
||||||
modulate = Color( 1, 0.596078, 0.121569, 1 )
|
modulate = Color( 1, 0.596078, 0.121569, 1 )
|
||||||
position = Vector2( 18, -8.5 )
|
position = Vector2( 18, -8.5 )
|
||||||
shape = SubResource( 21 )
|
shape = SubResource( 23 )
|
||||||
|
disabled = true
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ func process_physics(delta):
|
||||||
#print(owner.name, " wants to attack")
|
#print(owner.name, " wants to attack")
|
||||||
stop()
|
stop()
|
||||||
wants_to_attack = true
|
wants_to_attack = true
|
||||||
|
if attack_function.is_valid():
|
||||||
|
attack_function.call_func()
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
wants_to_attack = false
|
wants_to_attack = false
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
class_name MovementComponent
|
class_name MovementComponent
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
## Movement component
|
||||||
|
# attempts to interact with movement of the scene root without knowing what
|
||||||
|
# it is. It can be perhaps a static body or kinematicbody
|
||||||
|
# it doesn't actually move a node, that's what the state machine does
|
||||||
|
# but it does keep track of velocity
|
||||||
|
# I can't give it an actor node or a direct reference.
|
||||||
|
# It can use a number of detection components to help inform decisions.
|
||||||
|
|
||||||
export var debug_component: bool = false
|
export var debug_component: bool = false
|
||||||
|
|
||||||
onready var desired_movement_vector: Vector2 = Vector2(0,0)
|
onready var desired_movement_vector: Vector2 = Vector2(0,0)
|
||||||
|
|
@ -13,6 +21,8 @@ var velocity = Vector2(0,0)
|
||||||
#Can't use floats here, switched to constants.
|
#Can't use floats here, switched to constants.
|
||||||
#enum directions {UP = -1, DOWN = 1, LEFT, RIGHT}
|
#enum directions {UP = -1, DOWN = 1, LEFT, RIGHT}
|
||||||
|
|
||||||
|
var attack_function: FuncRef
|
||||||
|
|
||||||
const UP = -1.0
|
const UP = -1.0
|
||||||
const DOWN = 1.0
|
const DOWN = 1.0
|
||||||
const LEFT = -1.0
|
const LEFT = -1.0
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ onready var gun = $Gun
|
||||||
# if movement_animations.frames.get_animation_loop(movement_animations.animation) == false:
|
# if movement_animations.frames.get_animation_loop(movement_animations.animation) == false:
|
||||||
# movement_state_machine.current_state.animation_index += 1
|
# movement_state_machine.current_state.animation_index += 1
|
||||||
|
|
||||||
func _on_Hurtbox_area_entered(area):
|
func _on_Hurtbox_area_entered():
|
||||||
print("Ouch.",area)
|
#print("Ouch.",area)
|
||||||
movement_state_machine.change_state($Controllers/state_machine/hurt)
|
movement_state_machine.change_state($movement_state_machine/hurt)
|
||||||
|
|
||||||
func set_hurtbox(enabled: bool):
|
func set_hurtbox(enabled: bool):
|
||||||
pass
|
pass
|
||||||
|
|
@ -28,7 +28,8 @@ func set_hurtbox(enabled: bool):
|
||||||
|
|
||||||
func shoot_projectile():
|
func shoot_projectile():
|
||||||
var is_shooting = false
|
var is_shooting = false
|
||||||
is_shooting = gun.shoot(movement_component.get_movement_direction())
|
print("Direction: ", transform.x.x)
|
||||||
|
is_shooting = gun.shoot(int(transform.x.x))
|
||||||
|
|
||||||
#func play_sound():
|
#func play_sound():
|
||||||
# sound_effects.stream = "res://assets/Sounds/crappy pew.wav"
|
# sound_effects.stream = "res://assets/Sounds/crappy pew.wav"
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ onready var idle_state: State = get_node(idle_node)
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
.enter()
|
.enter()
|
||||||
parent.velocity.x = 0
|
move_component.velocity.x = 0
|
||||||
parent.set_hurtbox(false)
|
#parent.set_hurtbox(false)
|
||||||
#TODO: Error check if timer was actually instanced
|
#TODO: Error check if timer was actually instanced
|
||||||
state_timeout.start()
|
state_timeout.start()
|
||||||
|
|
||||||
|
|
@ -25,12 +25,13 @@ func process_frame(delta: float) -> State:
|
||||||
|
|
||||||
|
|
||||||
func process_physics(delta: float) -> State:
|
func process_physics(delta: float) -> State:
|
||||||
parent.velocity.y += gravity * delta
|
move_component.velocity.y += gravity * delta
|
||||||
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||||
if (parent.direction.x > 0):
|
move_component.velocity = parent.transform.x * move_speed
|
||||||
parent.velocity.x = 1 * move_speed
|
# if (parent.direction.x > 0):
|
||||||
else:
|
# parent.velocity.x = 1 * move_speed
|
||||||
parent.velocity.x = -1 * move_speed
|
# else:
|
||||||
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
# parent.velocity.x = -1 * move_speed
|
||||||
|
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user