-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfighter.gd
133 lines (122 loc) · 4.23 KB
/
fighter.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
extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
enum Event
{
ENTERING,
RUNNING,
LEAVING
}
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var state_prev = null
var state = _ground
# a = light punch, b = medium punch, c = heavy punch, p = any punch
# x = any button, m = any direction
# A = at least light punch, B = at least medium punch, C = at least heavy punch
# d = light kick, e = medium kick, f = heavy kick, k = any kick
# D = at least light kick, E = at least medium kick, F = at least heavy kick
# P = at least some punch
# K = at least some kick
# numpad direction:
# ^
# 7 8 9
# < 4 5 6 >
# 1 2 3
# v
var _ground_move_list:Array[InputReader.Move] = [
InputReader.Move.new("Walk Forward",["WF"], ""),
InputReader.Move.new("Walk Back",["WB"], ""),
InputReader.Move.new("Crouch",["CR"], ""),
InputReader.Move.new("Crouch Back",["CRB"], ""),
InputReader.Move.new("Dash Forward",["DF"], ""),
InputReader.Move.new("Dash Back",["DB"], ""),
InputReader.Move.new("Punch Light",[], "(mmAmA|mmAmm)$"),
InputReader.Move.new("Punch Medium",[], "(mmBmB|mmBmm)$"),
InputReader.Move.new("Punch Heavy",[], "(mmCmC|mmCmm)$"),
InputReader.Move.new("Kick Light",[], "(mmDmD|mmDmm)$"),
InputReader.Move.new("Kick Medium",[], "(mmDmE|mmEmm)$"),
InputReader.Move.new("Kick Heavy",[], "(mmFmF|mmFmm)$"),
InputReader.Move.new("Grab",[], "(mm[ad]mad|mmad)$"),
InputReader.Move.new("Jump",["JU"], ""),
InputReader.Move.new("Jump Forward",["JUF"], ""),
InputReader.Move.new("Jump Back",["JUB"], ""),
InputReader.Move.new("Fireball Light",["QCF","HCF"], "(mmama|mmamm)$"),
InputReader.Move.new("Fireball Medium",["QCF","HCF"], "(mmbmb|mmbmm)$"),
InputReader.Move.new("Fireball Heavy",["QCF","HCF"], "(mmcmc|mmcmm)$"),
InputReader.Move.new("Fireball Ex",["QCF","HCF"], "(mmpp|mmpmpp)$"),
InputReader.Move.new("Dragon Punch Light",["DP"], "(mmama|mmamm)$"),
InputReader.Move.new("Dragon Punch Medium",["DP"], "(mmbmb|mmbmm)$"),
InputReader.Move.new("Dragon Punch Heavy",["DP"], "(mmcmc|mmcmm)$"),
InputReader.Move.new("Dragon Punch Ex",["DP"], "(mmpp|mmpmpp)$"),
InputReader.Move.new("Round House",["FCF"], "(mmkmk|mmkmm)$"),
InputReader.Move.new("Giga Punch",["SF"], "(mmPm|mmPmP)$"),
InputReader.Move.new("Giga Kick",["SF"], "(mmKm|mmKmK)$")
]
var _air_move_list:Array[InputReader.Move] = [
InputReader.Move.new("Jump Kick Light",[], "(mmdmd|mmdm)$"),
InputReader.Move.new("Jump Kick Medium",[], "(mmeme|mmem)$"),
InputReader.Move.new("Jump Kick Heavy",[], "(mmfmf|mmfm)$"),
InputReader.Move.new("Air Round House",["FCF"], "(mmkmk|mmkm)$")
]
func _physics_process(delta):
$InputRreader.update_input_buffer()
# FSM stuff
state.call(Event.RUNNING, delta)
if state != state_prev:
if state_prev:
state_prev.call(Event.LEAVING)
state.call(Event.ENTERING)
print(state)
state_prev = state
func _ground(event:Event, delta=0.0):
match(event):
Event.RUNNING:
var moves:Array[String] = $InputRreader.get_moves(_ground_move_list)
velocity = Vector2.ZERO
if not is_on_floor():
state = _falling
elif moves.size() >0:
match(moves.back()):
"Jump":
state=_jump
"Jump Forward":
velocity.x = SPEED
state=_jump
"Jump Back":
velocity.x = -SPEED
state=_jump
"Walk Forward":
velocity.x = SPEED
move_and_slide()
"Walk Back":
velocity.x = -SPEED
move_and_slide()
var not_mapped:
if "Crouch" not in not_mapped:
print(not_mapped)
func _jump(event:Event, delta=0.0):
match(event):
Event.ENTERING:
velocity.y = JUMP_VELOCITY
move_and_slide()
Event.RUNNING:
if not is_on_floor():
# Add the gravity.
velocity.y += gravity * delta
state = _falling
else:
state = _ground
move_and_slide()
func _falling(event:Event, delta=0.0):
match(event):
Event.RUNNING:
var moves:Array[String] = $InputRreader.get_moves(_air_move_list)
if not is_on_floor():
# Add the gravity.
velocity.y += gravity * delta
if moves.size() >0:
print(moves.back())
else:
state = _ground
move_and_slide()