Skip to content

Commit

Permalink
Part 2
Browse files Browse the repository at this point in the history
Player attack
  • Loading branch information
MateuSai committed Jul 21, 2021
1 parent bd8fe99 commit 3db20d9
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source_md5="39b3d8583205c90284cd60f0e018f29d"
dest_md5="52cfea7aa3d138927af2e1c7588f90dd"
dest_md5="4ce9d0860f904c4c550d375db85f5dbe"

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source_md5="290f29e73374ffb00e4aa61a383c707f"
dest_md5="c84a1eb2d5df3915de49fddf1e67b6cc"
dest_md5="24e0abbb82a08a4daf6d28c1acdb3c38"

Binary file modified .import/weapon_sword_1.png-e17b5819c65b4aa28788a53c68a37d70.stex
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
Expand All @@ -30,5 +30,5 @@ process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
detect_3d=false
svg/scale=1.0
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
Expand All @@ -30,5 +30,5 @@ process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
detect_3d=false
svg/scale=1.0
11 changes: 11 additions & 0 deletions Characters/Player/Player.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
extends Character

onready var sword: Node2D = get_node("Sword")
onready var sword_animation_player: AnimationPlayer = sword.get_node("SwordAnimationPlayer")


func _process(_delta: float) -> void:
var mouse_direction: Vector2 = (get_global_mouse_position() - global_position).normalized()
Expand All @@ -9,6 +12,14 @@ func _process(_delta: float) -> void:
elif mouse_direction.x < 0 and not animated_sprite.flip_h:
animated_sprite.flip_h = true

sword.rotation = mouse_direction.angle()
if sword.scale.y == 1 and mouse_direction.x < 0:
sword.scale.y = -1
elif sword.scale.y == -1 and mouse_direction.x > 0:
sword.scale.y = 1
if Input.is_action_just_pressed("ui_attack") and not sword_animation_player.is_playing():
sword_animation_player.play("attack")


func get_input() -> void:
mov_direction = Vector2.ZERO
Expand Down
102 changes: 92 additions & 10 deletions Characters/Player/Player.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[gd_scene load_steps=21 format=2]
[gd_scene load_steps=25 format=2]

[ext_resource path="res://Characters/Character.tscn" type="PackedScene" id=1]
[ext_resource path="res://Art/v1.1 dungeon crawler 16x16 pixel pack/heroes/knight/knight_idle_spritesheet.png" type="Texture" id=2]
[ext_resource path="res://Art/v1.1 dungeon crawler 16x16 pixel pack/heroes/knight/knight_run_spritesheet.png" type="Texture" id=3]
[ext_resource path="res://Characters/Player/Player.gd" type="Script" id=4]
[ext_resource path="res://Characters/Player/PlayerFSM.gd" type="Script" id=5]
[ext_resource path="res://Art/v1.1 dungeon crawler 16x16 pixel pack/heroes/knight/weapon_sword_1.png" type="Texture" id=6]
[ext_resource path="res://Art/v1.1 dungeon crawler 16x16 pixel pack/effects (new)/slash_effect_anim_spritesheet.png" type="Texture" id=7]

[sub_resource type="AtlasTexture" id=1]
atlas = ExtResource( 2 )
Expand Down Expand Up @@ -67,8 +69,63 @@ animations = [ {
"speed": 5.0
} ]

[sub_resource type="Animation" id=14]
resource_name = "idle"
[sub_resource type="CircleShape2D" id=14]
radius = 4.0

[sub_resource type="Animation" id=15]
resource_name = "attack"
length = 1.25
step = 0.05
tracks/0/type = "value"
tracks/0/path = NodePath("Node2D:rotation_degrees")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.15, 0.8, 1.25 ),
"transitions": PoolRealArray( 1, 1, 1, 1 ),
"update": 0,
"values": [ -90.0, 120.0, 120.0, -90.0 ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("Node2D/Sprite:rotation_degrees")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.05, 0.15, 0.8, 1.25 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
"update": 0,
"values": [ -45.0, 40.0, 50.0, 50.0, -45.0 ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("SlashSprite:visible")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0, 0.3 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ true, false ]
}
tracks/3/type = "value"
tracks/3/path = NodePath("SlashSprite:frame")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/keys = {
"times": PoolRealArray( 0, 0.1, 0.2 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 1,
"values": [ 0, 1, 2 ]
}

[sub_resource type="Animation" id=16]
length = 0.6
loop = true
tracks/0/type = "value"
Expand Down Expand Up @@ -96,8 +153,7 @@ tracks/1/keys = {
"values": [ 0, 1, 2, 3, 4, 5 ]
}

[sub_resource type="Animation" id=15]
resource_name = "move"
[sub_resource type="Animation" id=17]
length = 0.6
loop = true
tracks/0/type = "value"
Expand Down Expand Up @@ -126,16 +182,42 @@ tracks/1/keys = {
}

[node name="Player" instance=ExtResource( 1 )]
collision_layer = 2
collision_mask = 5
script = ExtResource( 4 )

[node name="FiniteStateMachine" parent="." index="0"]
script = ExtResource( 5 )

[node name="AnimatedSprite" parent="." index="1"]
frames = SubResource( 13 )
animation = "move"
frame = 1
animation = "idle"

[node name="CollisionShape2D" parent="." index="2"]
position = Vector2( 0, 3 )
shape = SubResource( 14 )

[node name="Sword" type="Node2D" parent="." index="3"]

[node name="Node2D" type="Node2D" parent="Sword" index="0"]
rotation = -1.5708

[node name="Sprite" type="Sprite" parent="Sword/Node2D" index="0"]
position = Vector2( 7, 3 )
rotation = -0.785398
texture = ExtResource( 6 )
offset = Vector2( 5, -4 )

[node name="SlashSprite" type="Sprite" parent="Sword" index="1"]
visible = false
position = Vector2( 18, 0 )
texture = ExtResource( 7 )
hframes = 3
frame = 2

[node name="SwordAnimationPlayer" type="AnimationPlayer" parent="Sword" index="2"]
anims/attack = SubResource( 15 )

[node name="AnimationPlayer" parent="." index="3"]
anims/idle = SubResource( 14 )
anims/move = SubResource( 15 )
[node name="AnimationPlayer" parent="." index="4"]
anims/idle = SubResource( 16 )
anims/move = SubResource( 17 )
14 changes: 14 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ window/size/test_height=720
window/stretch/mode="2d"
window/stretch/aspect="keep"

[input]

ui_attack={
"deadzone": 0.5,
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
]
}

[layer_names]

2d_physics/layer_1="World"
2d_physics/layer_2="Player"
2d_physics/layer_3="Enemy"

[physics]

common/enable_pause_aware_picking=true
Expand Down

0 comments on commit 3db20d9

Please sign in to comment.