diff --git a/src/actor.gd b/src/actor.gd index c03b674..7b6e695 100644 --- a/src/actor.gd +++ b/src/actor.gd @@ -27,6 +27,7 @@ var sound_effects_dict: Dictionary func _ready() -> void: movement_state_machine.init_animated_actor(self, movement_animations, movement_component) + movement_component.attack_function = funcref(self, "attack") # movement_component.player_number = player_number # 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.play() 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) diff --git a/src/enemyB/Enemy2-KinematicBody2D.gd b/src/enemyB/Enemy2-KinematicBody2D.gd index c4d7a76..1e6841d 100644 --- a/src/enemyB/Enemy2-KinematicBody2D.gd +++ b/src/enemyB/Enemy2-KinematicBody2D.gd @@ -68,7 +68,7 @@ func set_hitbox(enabled: bool): func shoot_projectile(): var is_shooting = false - is_shooting = gun.shoot(direction.x) + is_shooting = gun.shoot(transform.x.x) func _on_Hurtbox_body_entered(body): diff --git a/src/enemyC/EnemyC.tscn b/src/enemyC/EnemyC.tscn index 1f1fd7d..a2ab4f6 100644 --- a/src/enemyC/EnemyC.tscn +++ b/src/enemyC/EnemyC.tscn @@ -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/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] load_path = "res://.import/botEnemy.png-46efd539a38730ff15fb4ddb087329c6.stex" @@ -110,7 +111,7 @@ animations = [ { [sub_resource type="RectangleShape2D" id=22] extents = Vector2( 10, 16 ) -[sub_resource type="RectangleShape2D" id=21] +[sub_resource type="RectangleShape2D" id=23] extents = Vector2( 9, 3.5 ) [node name="EnemyC" instance=ExtResource( 1 )] @@ -120,7 +121,7 @@ actor_type = "Enemy" position = Vector2( 11, -7 ) frames = SubResource( 20 ) animation = "idle" -frame = 1 +frame = 0 __meta__ = { "_aseprite_wizard_config_": { "layer": "", @@ -153,8 +154,11 @@ animation_sequence = [ "idle" ] [node name="attack" type="Node" parent="movement_state_machine" index="2"] script = ExtResource( 3 ) -timeout_seconds = 3.0 +debug_state = true +timeout_seconds = 2.0 animation_sequence = [ "attack" ] +fall_node = NodePath("../fall") +idle_node = NodePath("../idle") [node name="move" parent="movement_state_machine" index="3"] animation_sequence = [ "walk" ] @@ -176,11 +180,10 @@ enabled = true cast_to = Vector2( 21, 0 ) collision_mask = 2 -[node name="Hitbox_Component" type="Area2D" parent="." index="8"] -collision_layer = 128 -collision_mask = 0 +[node name="Hitbox_Component" parent="." index="8" instance=ExtResource( 4 )] [node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox_Component" index="0"] modulate = Color( 1, 0.596078, 0.121569, 1 ) position = Vector2( 18, -8.5 ) -shape = SubResource( 21 ) +shape = SubResource( 23 ) +disabled = true diff --git a/src/enemyC/enemyC_movement_component.gd b/src/enemyC/enemyC_movement_component.gd index 3f42c9e..1b754bd 100644 --- a/src/enemyC/enemyC_movement_component.gd +++ b/src/enemyC/enemyC_movement_component.gd @@ -16,6 +16,8 @@ func process_physics(delta): #print(owner.name, " wants to attack") stop() wants_to_attack = true + if attack_function.is_valid(): + attack_function.call_func() return else: wants_to_attack = false diff --git a/src/movement_component.gd b/src/movement_component.gd index 24aaa0b..2531fa8 100644 --- a/src/movement_component.gd +++ b/src/movement_component.gd @@ -1,6 +1,14 @@ class_name MovementComponent 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 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. #enum directions {UP = -1, DOWN = 1, LEFT, RIGHT} +var attack_function: FuncRef + const UP = -1.0 const DOWN = 1.0 const LEFT = -1.0 diff --git a/src/playerC/Player-KinematicBody2D.gd b/src/playerC/Player-KinematicBody2D.gd index 4ef5f1d..2fc85d9 100644 --- a/src/playerC/Player-KinematicBody2D.gd +++ b/src/playerC/Player-KinematicBody2D.gd @@ -17,9 +17,9 @@ onready var gun = $Gun # if movement_animations.frames.get_animation_loop(movement_animations.animation) == false: # movement_state_machine.current_state.animation_index += 1 -func _on_Hurtbox_area_entered(area): - print("Ouch.",area) - movement_state_machine.change_state($Controllers/state_machine/hurt) +func _on_Hurtbox_area_entered(): + #print("Ouch.",area) + movement_state_machine.change_state($movement_state_machine/hurt) func set_hurtbox(enabled: bool): pass @@ -28,7 +28,8 @@ func set_hurtbox(enabled: bool): func shoot_projectile(): 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(): # sound_effects.stream = "res://assets/Sounds/crappy pew.wav" diff --git a/src/playerC/states/hurt.gd b/src/playerC/states/hurt.gd index 4785693..c667711 100644 --- a/src/playerC/states/hurt.gd +++ b/src/playerC/states/hurt.gd @@ -6,8 +6,8 @@ onready var idle_state: State = get_node(idle_node) func enter() -> void: .enter() - parent.velocity.x = 0 - parent.set_hurtbox(false) + move_component.velocity.x = 0 + #parent.set_hurtbox(false) #TODO: Error check if timer was actually instanced state_timeout.start() @@ -25,12 +25,13 @@ func process_frame(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)) - if (parent.direction.x > 0): - parent.velocity.x = 1 * move_speed - else: - parent.velocity.x = -1 * move_speed - parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1)) + move_component.velocity = parent.transform.x * move_speed +# if (parent.direction.x > 0): +# parent.velocity.x = 1 * move_speed +# else: +# parent.velocity.x = -1 * move_speed + move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1)) return null