-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.gd
More file actions
118 lines (81 loc) · 2.68 KB
/
player.gd
File metadata and controls
118 lines (81 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
var Sword_On_Cooldown = false
var facingDirection = 0
var lastFaced = 1
func _ready() -> void:
$Sword.visible = false
$Sword/Area2D/CollisionShape2D.disabled = true
func die():
get_tree().reload_current_scene()
func attack():
var swordPos = $Sword.position
if lastFaced == 1:
$Sword.scale.x = 1
swordPos = $ShankPositionRight.position
else:
$Sword.scale.x = -1
swordPos = $ShankPositionLeft.position
$Sword.position = swordPos
if not Sword_On_Cooldown:
$Sword.visible = true
$Sword/Area2D/CollisionShape2D.disabled = false
if not $SwordSound.playing:
$SwordSound.play()
await get_tree().create_timer(0.5).timeout
$Sword.visible = false
$Sword/Area2D/CollisionShape2D.disabled = true
Sword_On_Cooldown = true
async_hide_sword()
func async_hide_sword() -> void:
await get_tree().create_timer(0.3).timeout
$Sword.visible = false
$Sword/Area2D/CollisionShape2D.disabled = true
await get_tree().create_timer(0.3).timeout
Sword_On_Cooldown = false
func _physics_process(delta: float) -> void:
var level = get_tree().current_scene
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
if position.y >= 525:
die()
if Input.is_action_just_pressed("attack") and level.swordIsUsable:
attack()
elif Input.is_action_just_pressed("attack") and not level.swordIsUsable:
if not $TrySacrificedAbility.playing:
$TrySacrificedAbility.play()
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
if Input.is_action_just_pressed("reset"):
die()
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var left = -1
var right = 1
if Input.is_action_pressed("left") and level.canGoLeft:
velocity.x = left * SPEED
facingDirection = -1
$AnimatedSprite2D.play("walk_left")
lastFaced = -1
elif Input.is_action_just_pressed("left") and not level.canGoLeft:
if not $TrySacrificedAbility.playing:
$TrySacrificedAbility.play()
elif Input.is_action_pressed("right") and level.canGoRight:
velocity.x = right * SPEED
facingDirection = 1
$AnimatedSprite2D.play("walk_right")
lastFaced = 1
elif Input.is_action_just_pressed("right") and not level.canGoRight:
if not $TrySacrificedAbility.playing:
$TrySacrificedAbility.play()
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
facingDirection = 0
$AnimatedSprite2D.play("default")
move_and_slide()
func _on_area_2d_area_entered(area: Area2D) -> void:
if not area.is_in_group("transfer") and not area.is_in_group("sword"):
die()