Compare commits

..

2 Commits

13 changed files with 225 additions and 15 deletions

View File

@ -176,7 +176,7 @@ __meta__ = {
position = Vector2( 93, 54 )
[node name="PlayerC" parent="." instance=ExtResource( 2 )]
position = Vector2( 137, 54 )
position = Vector2( 144, 226 )
player_number = 2
[node name="CameraControl" type="Position2D" parent="."]

View File

@ -167,6 +167,12 @@ shoot_2={
"deadzone": 0.5,
"events": [ ]
}
dash_1={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":78,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":1,"pressure":0.0,"pressed":false,"script":null)
]
}
[layer_names]

View File

@ -62,3 +62,7 @@ func wants_jump() -> bool:
# Return a boolean indicating if the character wants to attack
func wants_shoot() -> bool:
return false
# Return a boolean indicating if the character wants to dash
func wants_dash() -> bool:
return false

View File

@ -5,8 +5,8 @@ extends MovementComponent
export var player_number: int = 1
func process_physics(delta):
PlayerInfo.player_position = owner.global_position
#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

View File

@ -4,11 +4,17 @@ export var player_number: int = 1
onready var player_hurtbox = $Hurtbox_Component/CollisionShape2D
onready var gun = $Gun
func _ready() -> void:
PlayerInfo.player_health = $Health_Component.health
movement_component.player_number = player_number
var portrait = preload("res://assets/MManPortrait.png")
func hit_Receiver(damage):
$Hurtbox_Component.set_hurtbox(false)
$Health_Component.take_damage(damage)
@ -20,4 +26,11 @@ func hit_Receiver(damage):
func _on_attack_do_attack():
pass # Replace with function body.
var is_shooting = false
print("Direction: ", transform.x.x)
is_shooting = gun.shoot(int(transform.x.x))
func _on_Health_Component_health_depleted():
queue_free()

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=113 format=2]
[gd_scene load_steps=116 format=2]
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
[ext_resource path="res://src/playerD/movement_component.gd" type="Script" id=2]
@ -10,6 +10,9 @@
[ext_resource path="res://src/playerD/states/jump.gd" type="Script" id=8]
[ext_resource path="res://src/state_modifier.gd" type="Script" id=9]
[ext_resource path="res://src/playerD/states/attack.gd" type="Script" id=10]
[ext_resource path="res://src/playerD/states/dash.gd" type="Script" id=11]
[ext_resource path="res://src/playerD/states/hurt.gd" type="Script" id=12]
[ext_resource path="res://src/Gun.gd" type="Script" id=13]
[sub_resource type="StreamTexture" id=90]
load_path = "res://.import/Mega.png-93dfe0790902b932f7b46f7b23c5d4e7.stex"
@ -418,7 +421,7 @@ animations = [ {
"speed": 10.0
}, {
"frames": [ SubResource( 101 ), SubResource( 101 ), SubResource( 101 ), SubResource( 102 ), SubResource( 103 ), SubResource( 104 ), SubResource( 105 ), SubResource( 105 ), SubResource( 105 ) ],
"loop": true,
"loop": false,
"name": "dash",
"speed": 10.0
}, {
@ -458,7 +461,7 @@ animations = [ {
"speed": 10.0
}, {
"frames": [ SubResource( 161 ), SubResource( 162 ), SubResource( 163 ) ],
"loop": true,
"loop": false,
"name": "shoot",
"speed": 10.0
}, {
@ -522,6 +525,7 @@ script = ExtResource( 4 )
animation_sequence = [ "idle" ]
jump_node = NodePath("../jump")
attack_node = NodePath("../attack")
dash_node = NodePath("../dash")
[node name="fall" parent="movement_state_machine" index="1"]
script = ExtResource( 6 )
@ -566,9 +570,25 @@ modifier_type = "Animation Suffix"
timeout_seconds = 2.2
animation_suffix = true
[node name="hurt" type="Node" parent="movement_state_machine" index="5"]
script = ExtResource( 12 )
timeout_seconds = 1.0
move_speed = -10.0
animation_sequence = [ "stand" ]
idle_node = NodePath("../idle")
[node name="dash" type="Node" parent="movement_state_machine" index="6"]
script = ExtResource( 11 )
move_speed = 120.0
animation_sequence = [ "dash" ]
fall_node = NodePath("../fall")
idle_node = NodePath("../idle")
attack_node = NodePath("../attack")
jump_node = NodePath("../jump")
[node name="Hurtbox_Component" parent="." index="4"]
collision_layer = 16
collision_mask = 0
collision_mask = 128
hurtbox_entered_function = "hit_Receiver"
[node name="CollisionShape2D" parent="Hurtbox_Component" index="0"]
@ -578,4 +598,19 @@ shape = SubResource( 89 )
[node name="Health_Component" parent="." index="6" instance=ExtResource( 7 )]
max_health = 100
[node name="Gun" type="Position2D" parent="." index="7"]
physics_interpolation_mode = 1
position = Vector2( 25, -5 )
script = ExtResource( 13 )
[node name="Cooldown" type="Timer" parent="Gun" index="0"]
wait_time = 0.5
one_shot = true
[node name="Line2D" type="Line2D" parent="Gun" index="1"]
points = PoolVector2Array( -5, 0, 5, 0 )
width = 2.0
default_color = Color( 1, 0.607843, 0, 1 )
[connection signal="do_attack" from="movement_state_machine/attack" to="." method="_on_attack_do_attack"]
[connection signal="health_depleted" from="Health_Component" to="." method="_on_Health_Component_health_depleted"]

View File

@ -47,6 +47,12 @@ func wants_shoot() -> bool:
else:
return false
func wants_dash() -> bool:
if Input.is_action_just_pressed("dash_" + str(player_number)):
return true
else:
return false
## Other needed variables
# desired_movement_vector: Vector2 - Used to store desired movement depending on the state

View File

@ -17,18 +17,48 @@ var can_fire = true
signal do_attack()
func enter() -> void:
.enter()
#.enter()
##TODO: Turn this to clear only the animation modifiers.
modifier_stack_ref.clear()
mod_animation_sequence.clear()
#mod_animation_sequence = animation_sequence.duplicate(true)
mod_animation_sequence.append_array(animation_sequence)
# Reset animation suffix in case there isn't one
animation_suffix = ''
animation_index = 0
current_animation_sequence = 0
#var enter_animation = ''
var enter_frame = 0
if debug_state:
print(parent.name, " entering State: ", self.name)
move_component.current_movement_state = self.name
emit_signal("state_entered")
state_timeout.start()
can_fire = true
# if modifier_stack_ref.has($"../draw_weapon") == false:
# $"../draw_weapon".enter()
# modifier_stack_ref.push_front($"../draw_weapon")
push_animation_state_modifier(weapon_state_modifier)
if debug_state:
print("Previous State Info: ", previous_animation_name, " ",
previous_state_frame_number, " ", previous_state_name)
match previous_animation_name:
"idle":
animations.play("shoot")
"run":
animations.play("run_shoot")
animations.frame = previous_state_frame_number
"jump":
animations.play("jump_shoot")
animations.frame = previous_state_frame_number
_:
print("Warning!: Attack state encountered unhandled prev animation: ", previous_animation_name)
func process_frame(delta: float) -> State:
if animations.frame == 2:
animations.stop()
if state_timeout.time_left == 0:
# if animations.frame == 2:
# animations.stop()
if state_timeout.time_left == 0 and animations.animation == "shoot":
return idle_state
return null
@ -44,9 +74,18 @@ func process_physics(delta: float) -> State:
move_actor_as_desired(delta)
if move_component.velocity.x != 0.0:
if previous_state_name == "move" and move_component.velocity.x == 0.0:
return idle_state
if previous_state_name == "idle" and move_component.velocity.x != 0.0:
return move_state
if move_component.get_movement_direction() != 0.0:
parent.transform.x.x = move_component.get_movement_direction()
# if move_component.velocity.x != 0.0:
# return move_state
if !parent.is_on_floor():
return fall_state
@ -56,6 +95,7 @@ func process_physics(delta: float) -> State:
func exit() -> void:
# force timer reset
weapon_state_modifier.state_timeout.start()
push_animation_state_modifier(weapon_state_modifier)
#$"../draw_weapon".state_timeout.start()
return

View File

@ -0,0 +1,33 @@
extends StateAnimatedActor
export (NodePath) var fall_node
export (NodePath) var idle_node
export (NodePath) var attack_node
export (NodePath) var jump_node
onready var jump_state: State = get_node(jump_node)
onready var fall_state: State = get_node(fall_node)
onready var idle_state: State = get_node(idle_node)
onready var attack_state: State = get_node(attack_node)
func process_physics(delta: float) -> State:
# if move_component.wants_shoot():
# return attack_state
if move_component.wants_jump():
return jump_state
move_component.velocity.y += gravity * delta
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
move_component.velocity.x = parent.transform.x.x * move_speed
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
if move_component.velocity.x == 0.0 or animations.playing == false:
if !parent.is_on_floor():
return fall_state
else:
return idle_state
return null

View File

@ -0,0 +1,37 @@
extends StateAnimatedActor
export (NodePath) var idle_node
onready var idle_state: State = get_node(idle_node)
func enter() -> void:
.enter()
move_component.velocity.x = 0
#parent.set_hurtbox(false)
#TODO: Error check if timer was actually instanced
state_timeout.start()
func process_input(_event: InputEvent) -> State:
# move_component.wants_jump()
move_component.get_movement_direction()
return null
func process_frame(delta: float) -> State:
if state_timeout.time_left == 0:
return idle_state
return null
func process_physics(delta: float) -> State:
move_component.velocity.y += gravity * delta
#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

View File

@ -4,11 +4,13 @@ export (NodePath) var fall_node
export (NodePath) var move_node
export (NodePath) var jump_node
export (NodePath) var attack_node
export (NodePath) var dash_node
onready var fall_state: State = get_node(fall_node)
onready var move_state: State = get_node(move_node)
onready var jump_state: State = get_node(jump_node)
onready var attack_state: State = get_node(attack_node)
onready var dash_state: State = get_node(dash_node)
func enter() -> void:
.enter()
@ -22,6 +24,10 @@ func process_physics(delta: float) -> State:
if move_component.wants_jump() and parent.is_on_floor():
return jump_state
if move_component.wants_dash() and parent.is_on_floor():
return dash_state
if move_component.wants_shoot():
return attack_state

View File

@ -41,6 +41,11 @@ var animations: AnimatedSprite
var move_component: MovementComponent
var parent: KinematicBody2D
#animation_name :String, frame_number : int, animation_sequence :Array
var previous_animation_name : String
var previous_state_frame_number : int
var previous_state_name: String
#var animation_sequence_timer: Timer

View File

@ -1,5 +1,28 @@
class_name StateMachineAnimatedActor extends StateMachine
func change_state(new_state: State) -> void:
if current_state:
current_state.exit()
# Set parameters for information
if new_state is StateAnimatedActor and current_state is StateAnimatedActor:
set_previous_animation( current_state, new_state)
current_state = new_state
current_state.enter()
if(state_modifiers.size() > 0 and debug_state_machine):
print("Active Modifiers:")
for mods in state_modifiers:
print(mods.name)
func set_previous_animation( old_state: StateAnimatedActor, new_state: StateAnimatedActor ) -> void:
new_state.previous_animation_name = old_state.mod_animation_sequence[old_state.current_animation_sequence]
new_state.previous_state_frame_number = old_state.animations.frame
new_state.previous_state_name = old_state.name
#animation_name :String, frame_number : int, animation_sequence :Array
return
# Initialize the state machine by giving each child state a reference to the
# parent object it belongs to and enter the default starting_state.
func init_animated_actor(parent: KinematicBody2D, animations: AnimatedSprite, move_component: MovementComponent) -> void:
@ -106,6 +129,8 @@ func _on_AnimatedSprite_animation_finished():
# if debug_state_machine:
# print("Pop State Modifier: ", state_modifiers[-1].name)
# state_modifiers.pop_back()
##TODO:
# consider just stopping the animation and index increment here.
if current_state.animations.frames.get_animation_loop(
current_state.animations.animation) == false:
if current_state.animation_sequence.size() > 0: