-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ml
executable file
·190 lines (159 loc) · 3.36 KB
/
types.ml
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
type vector2d = {
x:float;
y:float
}
type bounds = {
w:float;
h:float
}
type allegiance =
| Player
| Enemy
| Neutral
module Html = Dom_html
type animation_frame = {
offset : vector2d;
bounds : bounds
}
type sprite = {
frames : animation_frame array;
img : Html.imageElement Js.t;
index : int;
time_delay : float;
curr_time : float
}
type troop_type =
| Foot
| Cavalry
type troop = {
trp_type : troop_type;
trp_damage : float;
trp_speed : float;
}
(* requires: tower id be position in tower array in state *)
type tower = {
twr_id : int;
twr_pos : vector2d;
twr_size : bounds;
twr_sprite : sprite;
twr_troop_info : troop;
twr_troops : float;
twr_troops_max : float;
twr_troops_regen_speed : float;
twr_team : allegiance;
selector_offset : vector2d;
count_label_offset : vector2d;
is_disabled : bool;
}
type movement = {
start_tower : int;
end_tower : int;
mvmt_troops : int;
mvmt_sprite : sprite;
mvmt_team : allegiance;
progress : float;
damage : float;
speed : float;
}
type effect =
| Stun of float (* An attack *)
| Regen_incr of float (* A buff if > 1.0, an attack if < 1.0*)
| Kill of int
type timer = {
curr_time : float;
speed : float;
limit : float;
}
type skill = {
allegiance : allegiance;
mana_cost : int ;
effect : effect ;
regen_timer : timer;
tower_id : int;
sprite: sprite;
anim_timer : timer;
}
type move = {
mv_start : int;
mv_end : int;
mv_troops : int
}
type command =
| Move of allegiance * int * int (* tuple of tower indices*)
| Skill of skill
| Null
type mouse_state =
| Pressed
| Released
| Moved
type input = {
mouse_pos : vector2d;
mouse_state : mouse_state;
}
(* UI *)
type color = {r : int; g : int; b : int; a : float}
type button_state =
| Disabled
| Neutral
| Depressed
| Clicked
type label_property = {
mutable text : string;
mutable color : color;
mutable font_size : int;
}
type button_property = {
mutable btn_state: button_state;
mutable btn_sprite: sprite;
mutable btn_label: label_property;
mutable btn_label_offset : vector2d;
}
type spell_box_state =
| Neutral
| Selected (* Depressed *)
| Regenerating
| Disabled
type spell_box_property = {
mutable spell_box_state : spell_box_state;
mutable spell_box_sprite : sprite;
mutable spell_box_front_image : sprite option;
mutable spell_box_front_image_offset : vector2d;
}
type ui_element =
| Button of button_property * vector2d * bounds * string option
| Label of label_property * vector2d * bounds
| Panel of sprite * vector2d * bounds
| SpellBox of spell_box_property * vector2d * bounds * skill
type state = {
towers : tower array;
num_towers : int;
player_score : int;
enemy_score : int;
movements : movement list;
player_skill : skill option;
enemy_skill : skill option;
player_mana : float;
enemy_mana : float
}
type interface = (string * (ui_element ref)) list
(* Transitions *)
type task =
| Victory of float * interface
| FadeIn of float * float * float
| Update
| FadeOut of float * float * float
| SwitchScene of string
type scene = {
mutable name : string;
mutable tasks : task list;
mutable state : state ;
mutable interface : interface;
mutable input : input;
mutable highlight_towers : int list;
mutable next : string option;
mutable background : sprite;
}
type difficulty =
| Easy
| Medium
| Hard