Added janky dash. Gun and hurt.
This commit is contained in:
parent
75560648bf
commit
28aac7f4f6
|
|
@ -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="."]
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}, {
|
||||
|
|
@ -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"]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
33
src/playerD/states/dash.gd
Normal file
33
src/playerD/states/dash.gd
Normal 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
|
||||
37
src/playerD/states/hurt.gd
Normal file
37
src/playerD/states/hurt.gd
Normal 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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -129,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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user