collisions, enemies, knockback, rolling

This commit is contained in:
mightypanders
2021-04-04 19:20:44 +02:00
parent 650a5a4a83
commit 01490a7f01
14 changed files with 1306 additions and 17 deletions

View File

@ -1,27 +1,78 @@
extends KinematicBody2D
var velocity = Vector2.ZERO
var roll_vector = Vector2.ZERO
const MAX_SPEED = 80
const ROLL_SPEED = MAX_SPEED*1.5
const ACCELERATION = 500
const FRICTION = 500
enum states{
MOVE,
ROLL,
ATTACK
}
var state = states.MOVE
onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get('parameters/playback')
onready var swordHitbox = $HitBoxPivot/SwordHitbox
func _ready():
animationTree.active = true
swordHitbox.knockbackvector = roll_vector
func _physics_process(delta):
match state:
states.MOVE:
do_move(delta)
states.ATTACK:
do_attack(delta)
states.ROLL:
do_roll(delta)
func do_roll(delta):
animationState.travel('Roll')
velocity = roll_vector * ROLL_SPEED
move_sprite()
pass
func do_attack(_delta):
animationState.travel('Attack')
velocity = Vector2.ZERO
func set_facing_direction(input_vector):
animationTree.set("parameters/Walk/blend_position",input_vector)
animationTree.set("parameters/Idle/blend_position",input_vector)
animationTree.set("parameters/Attack/blend_position",input_vector)
animationTree.set("parameters/Roll/blend_position",input_vector)
func do_move(delta):
var input_vector=Vector2.ZERO
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
input_vector.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
input_vector.y = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
input_vector = input_vector.normalized()
if input_vector != Vector2.ZERO:
animationTree.set("parameters/Walk/blend_position",input_vector)
animationTree.set("parameters/Idle/blend_position",input_vector)
roll_vector = input_vector
swordHitbox.knockbackvector = roll_vector
set_facing_direction(input_vector)
animationState.travel("Walk")
velocity = velocity.move_toward(input_vector*MAX_SPEED,ACCELERATION*delta)
else:
animationState.travel("Idle")
velocity = velocity.move_toward(Vector2.ZERO, FRICTION*delta)
velocity = move_and_slide(velocity)
move_sprite()
if Input.is_action_just_pressed("attack"):
state = states.ATTACK
if Input.is_action_just_pressed('roll'):
state = states.ROLL
func move_sprite():
velocity = move_and_slide(velocity)
func attack_animation_finished():
state = states.MOVE
func roll_animation_finished():
velocity = velocity / 2
state = states.MOVE

View File

@ -1,12 +1,230 @@
[gd_scene load_steps=28 format=2]
[gd_scene load_steps=53 format=2]
[ext_resource path="res://assets/Player/Player.png" type="Texture" id=1]
[ext_resource path="res://script/player/Player.gd" type="Script" id=2]
[ext_resource path="res://assets/Boxes/Hitbox.tscn" type="PackedScene" id=3]
[ext_resource path="res://assets/Player/SwordHitbox.gd" type="Script" id=4]
[sub_resource type="CapsuleShape2D" id=1]
radius = 4.32415
height = 8.80055
[sub_resource type="Animation" id=26]
resource_name = "Attack_Down"
length = 0.4
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.2, 0.3 ),
"transitions": PoolRealArray( 1, 1, 1, 1 ),
"update": 1,
"values": [ 36, 37, 38, 39 ]
}
tracks/1/type = "method"
tracks/1/path = NodePath(".")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0.4 ),
"transitions": PoolRealArray( 1 ),
"values": [ {
"args": [ ],
"method": "attack_animation_finished"
} ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("HitBoxPivot:rotation_degrees")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ 90.0 ]
}
tracks/3/type = "value"
tracks/3/path = NodePath("HitBoxPivot/SwordHitbox/CollisionShape2D:disabled")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/keys = {
"times": PoolRealArray( 0.1, 0.4 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ false, true ]
}
[sub_resource type="Animation" id=27]
resource_name = "Attack_Left"
length = 0.4
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.2, 0.3 ),
"transitions": PoolRealArray( 1, 1, 1, 1 ),
"update": 1,
"values": [ 32, 33, 34, 35 ]
}
tracks/1/type = "method"
tracks/1/path = NodePath(".")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0.4 ),
"transitions": PoolRealArray( 1 ),
"values": [ {
"args": [ ],
"method": "attack_animation_finished"
} ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("HitBoxPivot:rotation_degrees")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ 180.0 ]
}
tracks/3/type = "value"
tracks/3/path = NodePath("HitBoxPivot/SwordHitbox/CollisionShape2D:disabled")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/keys = {
"times": PoolRealArray( 0.1, 0.4 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ false, true ]
}
[sub_resource type="Animation" id=28]
resource_name = "Attack_Right"
length = 0.4
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.2, 0.3 ),
"transitions": PoolRealArray( 1, 1, 1, 1 ),
"update": 1,
"values": [ 24, 25, 26, 27 ]
}
tracks/1/type = "method"
tracks/1/path = NodePath(".")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0.4 ),
"transitions": PoolRealArray( 1 ),
"values": [ {
"args": [ ],
"method": "attack_animation_finished"
} ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("HitBoxPivot:rotation_degrees")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ 0.0 ]
}
tracks/3/type = "value"
tracks/3/path = NodePath("HitBoxPivot/SwordHitbox/CollisionShape2D:disabled")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/keys = {
"times": PoolRealArray( 0.1, 0.4 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ false, true ]
}
[sub_resource type="Animation" id=29]
resource_name = "Attack_Up"
length = 0.4
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.2, 0.3 ),
"transitions": PoolRealArray( 1, 1, 1, 1 ),
"update": 1,
"values": [ 28, 29, 30, 31 ]
}
tracks/1/type = "method"
tracks/1/path = NodePath(".")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0.4 ),
"transitions": PoolRealArray( 1 ),
"values": [ {
"args": [ ],
"method": "attack_animation_finished"
} ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("HitBoxPivot:rotation_degrees")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ 270.0 ]
}
tracks/3/type = "value"
tracks/3/path = NodePath("HitBoxPivot/SwordHitbox/CollisionShape2D:disabled")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/keys = {
"times": PoolRealArray( 0.1, 0.4 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ false, true ]
}
[sub_resource type="Animation" id=8]
resource_name = "Idle_Left"
length = 0.1
@ -74,6 +292,126 @@ tracks/0/keys = {
"values": [ 18 ]
}
[sub_resource type="Animation" id=38]
resource_name = "Roll_Down"
length = 0.5
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
"update": 1,
"values": [ 55, 56, 57, 58, 59 ]
}
tracks/1/type = "method"
tracks/1/path = NodePath(".")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0.5 ),
"transitions": PoolRealArray( 1 ),
"values": [ {
"args": [ ],
"method": "roll_animation_finished"
} ]
}
[sub_resource type="Animation" id=39]
resource_name = "Roll_Left"
length = 0.5
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
"update": 1,
"values": [ 50, 51, 52, 53, 54 ]
}
tracks/1/type = "method"
tracks/1/path = NodePath(".")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0.5 ),
"transitions": PoolRealArray( 1 ),
"values": [ {
"args": [ ],
"method": "roll_animation_finished"
} ]
}
[sub_resource type="Animation" id=40]
resource_name = "Roll_Right"
length = 0.5
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
"update": 1,
"values": [ 40, 41, 42, 43, 44 ]
}
tracks/1/type = "method"
tracks/1/path = NodePath(".")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0.5 ),
"transitions": PoolRealArray( 1 ),
"values": [ {
"args": [ ],
"method": "roll_animation_finished"
} ]
}
[sub_resource type="Animation" id=41]
resource_name = "Roll_Up"
length = 0.5
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
"update": 1,
"values": [ 45, 46, 47, 48, 49 ]
}
tracks/1/type = "method"
tracks/1/path = NodePath(".")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0.5 ),
"transitions": PoolRealArray( 1 ),
"values": [ {
"args": [ ],
"method": "roll_animation_finished"
} ]
}
[sub_resource type="Animation" id=4]
resource_name = "Walk_Down"
length = 0.6
@ -142,6 +480,31 @@ tracks/0/keys = {
"values": [ 7, 8, 9, 10, 11, 6 ]
}
[sub_resource type="AnimationNodeAnimation" id=30]
animation = "Attack_Left"
[sub_resource type="AnimationNodeAnimation" id=31]
animation = "Attack_Down"
[sub_resource type="AnimationNodeAnimation" id=32]
animation = "Attack_Right"
[sub_resource type="AnimationNodeAnimation" id=33]
animation = "Attack_Up"
[sub_resource type="AnimationNodeBlendSpace2D" id=34]
blend_point_0/node = SubResource( 30 )
blend_point_0/pos = Vector2( -1, 0 )
blend_point_1/node = SubResource( 31 )
blend_point_1/pos = Vector2( 0, 1.1 )
blend_point_2/node = SubResource( 32 )
blend_point_2/pos = Vector2( 1, 0 )
blend_point_3/node = SubResource( 33 )
blend_point_3/pos = Vector2( 0, -1.1 )
min_space = Vector2( -1, -1.1 )
max_space = Vector2( 1, 1.1 )
blend_mode = 1
[sub_resource type="AnimationNodeAnimation" id=10]
animation = "Idle_down"
@ -171,6 +534,31 @@ min_space = Vector2( -1, -1.1 )
max_space = Vector2( 1, 1.1 )
blend_mode = 1
[sub_resource type="AnimationNodeAnimation" id=42]
animation = "Roll_Down"
[sub_resource type="AnimationNodeAnimation" id=43]
animation = "Roll_Right"
[sub_resource type="AnimationNodeAnimation" id=44]
animation = "Roll_Up"
[sub_resource type="AnimationNodeAnimation" id=45]
animation = "Roll_Left"
[sub_resource type="AnimationNodeBlendSpace2D" id=46]
blend_point_0/node = SubResource( 42 )
blend_point_0/pos = Vector2( 0, 1.1 )
blend_point_1/node = SubResource( 43 )
blend_point_1/pos = Vector2( 1, 0 )
blend_point_2/node = SubResource( 44 )
blend_point_2/pos = Vector2( 0, -1.1 )
blend_point_3/node = SubResource( 45 )
blend_point_3/pos = Vector2( -1, 0 )
min_space = Vector2( -1, -1.1 )
max_space = Vector2( 1, 1.1 )
blend_mode = 1
[sub_resource type="AnimationNodeAnimation" id=19]
animation = "Walk_Down"
@ -200,26 +588,44 @@ blend_mode = 1
[sub_resource type="AnimationNodeStateMachineTransition" id=25]
[sub_resource type="AnimationNodeStateMachineTransition" id=35]
[sub_resource type="AnimationNodeStateMachineTransition" id=36]
[sub_resource type="AnimationNodeStateMachineTransition" id=47]
[sub_resource type="AnimationNodeStateMachineTransition" id=48]
[sub_resource type="AnimationNodeStateMachine" id=16]
states/Attack/node = SubResource( 34 )
states/Attack/position = Vector2( 567, 254 )
states/Idle/node = SubResource( 15 )
states/Idle/position = Vector2( 629, 126 )
states/Roll/node = SubResource( 46 )
states/Roll/position = Vector2( 841, 254 )
states/Walk/node = SubResource( 23 )
states/Walk/position = Vector2( 807, 126 )
transitions = [ "Idle", "Walk", SubResource( 24 ), "Walk", "Idle", SubResource( 25 ) ]
states/Walk/position = Vector2( 880, 58 )
transitions = [ "Idle", "Walk", SubResource( 24 ), "Walk", "Idle", SubResource( 25 ), "Idle", "Attack", SubResource( 35 ), "Attack", "Idle", SubResource( 36 ), "Idle", "Roll", SubResource( 47 ), "Roll", "Idle", SubResource( 48 ) ]
start_node = "Idle"
[sub_resource type="AnimationNodeStateMachinePlayback" id=17]
[sub_resource type="AnimationNodeStateMachinePlayback" id=18]
[sub_resource type="CapsuleShape2D" id=37]
radius = 11.5633
height = 8.25464
[node name="Player" type="KinematicBody2D"]
z_index = 1
collision_layer = 2
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 0, -8.04334 )
texture = ExtResource( 1 )
hframes = 60
frame = 54
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( -1.41422, 0.440334 )
@ -230,10 +636,18 @@ __meta__ = {
}
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/Attack_Down = SubResource( 26 )
anims/Attack_Left = SubResource( 27 )
anims/Attack_Right = SubResource( 28 )
anims/Attack_Up = SubResource( 29 )
anims/Idle_Left = SubResource( 8 )
anims/Idle_Right = SubResource( 2 )
anims/Idle_Up = SubResource( 3 )
anims/Idle_down = SubResource( 9 )
anims/Roll_Down = SubResource( 38 )
anims/Roll_Left = SubResource( 39 )
anims/Roll_Right = SubResource( 40 )
anims/Roll_Up = SubResource( 41 )
anims/Walk_Down = SubResource( 4 )
anims/Walk_Left = SubResource( 5 )
anims/Walk_Right = SubResource( 6 )
@ -242,8 +656,25 @@ anims/Walk_Up = SubResource( 7 )
[node name="AnimationTree" type="AnimationTree" parent="."]
tree_root = SubResource( 16 )
anim_player = NodePath("../AnimationPlayer")
active = true
parameters/playback = SubResource( 17 )
parameters/Attack/blend_position = Vector2( 0.008641, 0.490582 )
parameters/Idle/blend_position = Vector2( 0, 0 )
parameters/Idle/4/playback = SubResource( 18 )
parameters/Roll/blend_position = Vector2( -0.0016892, -0.00504589 )
parameters/Walk/blend_position = Vector2( 0, 0 )
[node name="HitBoxPivot" type="Position2D" parent="."]
position = Vector2( 0, -4 )
rotation = 3.14159
[node name="SwordHitbox" parent="HitBoxPivot" instance=ExtResource( 3 )]
position = Vector2( 14.5055, 1.68754 )
collision_mask = 8
script = ExtResource( 4 )
[node name="CollisionShape2D" parent="HitBoxPivot/SwordHitbox" index="0"]
position = Vector2( 0, -2.207 )
shape = SubResource( 37 )
disabled = true
[editable path="HitBoxPivot/SwordHitbox"]