forked from AlyssonDaPaz/Mega-Man-X8-16-bit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDash.gd
152 lines (126 loc) · 3.86 KB
/
Dash.gd
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
extends Movement
class_name Dash
export var dash_duration := 0.55
export var upgraded := false
export var invulnerability_duration := 0.0
export var leeway := 0.1
onready var particles = character.get_node("animatedSprite").get_node("Dash Smoke Particles")
onready var dash_particle = get_node("dash_particle")
var ghost_particle
var sprite_effect
var _dash
var emitted_dash := false
var left_ground_timer := 0.0
var can_dash := true
export var shot_pos_adjust := Vector2 (18,4)
func get_shot_adust_position() -> Vector2:
return shot_pos_adjust
func _ready() -> void:
sprite_effect = get_node("duringImage")
ghost_particle = get_node("particles2D")
func get_activation_leeway_time() -> float:
return leeway
func _Setup() -> void:
Event.emit_signal("dash")
set_direction(get_pressed_direction())
update_bonus_horizontal_only_conveyor()
emit_particles(particles, true)
character.reduce_hitbox()
invulnerable(true)
emitted_dash = false
changed_animation = false
left_ground_timer = 0
can_dash = true
deactivate_low_jumpcasts()
jumpcast_timer = 0
func emit_dash_particle():
if not emitted_dash:
if get_pressed_direction() != 0:
_dash = dash_particle.emit(get_pressed_direction())
else:
_dash = dash_particle.emit(character.get_facing_direction())
emitted_dash = true
func _Update(_delta: float) -> void:
process_invulnerability()
increase_left_ground_timer(_delta)
if can_dash and should_dash():
on_dash()
force_movement(horizontal_velocity)
emit_dash_particle()
if not character.is_on_floor():
character.set_vertical_speed(0)
else:
can_dash = false
if left_ground_timer == 0.0: #not left_ground:
left_ground_timer = 0.01
character.set_vertical_speed(0)
invulnerable(false)
change_animation_if_falling("fall")
set_movement_and_direction(horizontal_velocity)
process_gravity(_delta)
func increase_left_ground_timer(_delta: float) -> void:
if left_ground_timer > 0.0:
left_ground_timer += _delta
func process_gravity(delta:float, gravity := default_gravity, _s = "null") -> void:
.process_gravity(delta,gravity)
activate_low_jumpcasts_after_delay(delta)
func on_dash() -> void: #override
pass
func synchronize_sprite_effect():
if invulnerability_duration > 0:
sprite_effect.frames = character.animatedSprite.frames
sprite_effect.frame = character.animatedSprite.frame
sprite_effect.set_scale(Vector2(character.get_facing_direction(), 1))
ghost_particle.set_scale(Vector2(character.get_facing_direction(), 1))
func change_animation_if_falling(_s) -> void:
EndAbility()
character.start_dashfall()
func _Interrupt():
if not changed_animation:
character.call_deferred("increase_hitbox")
emit_particles(particles,false)
invulnerable(false)
._Interrupt()
func invulnerable(state : bool):
if upgraded and invulnerability_duration > 0:
if state:
character.add_invulnerability(name)
else:
character.remove_invulnerability(name)
sprite_effect.visible = state
ghost_particle.emitting = state
func process_invulnerability():
if upgraded and invulnerability_duration > 0:
synchronize_sprite_effect()
if timer > invulnerability_duration:
invulnerable (false)
func should_dash() -> bool:
return character.is_on_floor()
func _StartCondition() -> bool:
if facing_a_wall():
return false
if should_dash():
return true
return false
func _EndCondition() -> bool:
if facing_a_wall():
return true
if character.is_on_floor():
if left_ground_timer > 0.1:
on_touch_floor()
return true
if not Is_Input_Happening():
return true
elif Has_time_ran_out():
return true
elif character.facing_right and character.has_just_pressed_left():
last_time_pressed = 0.0
return true
elif not character.facing_right and character.has_just_pressed_right():
last_time_pressed = 0.0
return true
return false
func Has_time_ran_out() -> bool:
return dash_duration < timer
func stop_particles():
particles.visible = false