-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_isometric_objects_behavior.c
248 lines (218 loc) · 9.01 KB
/
game_isometric_objects_behavior.c
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include "game_isometric_objects.h"
#include "game_map.h"
#include "keyboard.h"
t_isometric_obj *p_isometric_obj;
t_isometric_obj *p_isometric_subobj_1, *p_isometric_subobj_2;
byte nframes = 0;
byte player_last_orientation = ISOMETRIC_ORIENTATION_W;
void orient_guardian(byte new_orientation)
{
// auxiliar function to set graphic sprites frames subsets according to the orientation of the guardian body
// p_isometric_subobj_1 and p_isometric_subobj_2 must be previuosly set to point to trunk and feet isometric objects repectively
if((new_orientation == ISOMETRIC_ORIENTATION_N) || (new_orientation == ISOMETRIC_ORIENTATION_E))
{
sprite_set_frames_subset(&(p_isometric_subobj_1->sprite), GAME_SPRITE_FIRST_FRAME_GUARDIAN_TRUNK_MOVING_N_E, GAME_SPRITE_LAST_FRAME_GUARDIAN_TRUNK_MOVING_N_E);
sprite_set_frames_subset(&(p_isometric_subobj_2->sprite), GAME_SPRITE_FIRST_FRAME_HUMAN_FEET_MOVING_N_E, GAME_SPRITE_LAST_FRAME_HUMAN_FEET_MOVING_N_E);
}
else
{
sprite_set_frames_subset(&(p_isometric_subobj_1->sprite), GAME_SPRITE_FIRST_FRAME_GUARDIAN_TRUNK_MOVING_S_W, GAME_SPRITE_LAST_FRAME_GUARDIAN_TRUNK_MOVING_S_W);
sprite_set_frames_subset(&(p_isometric_subobj_2->sprite), GAME_SPRITE_FIRST_FRAME_HUMAN_FEET_MOVING_S_W, GAME_SPRITE_LAST_FRAME_HUMAN_FEET_MOVING_S_W);
}
if((new_orientation == ISOMETRIC_ORIENTATION_N) || (new_orientation == ISOMETRIC_ORIENTATION_W))
{
sprite_set_required_graphic_state(&(p_isometric_subobj_1->sprite), SPRITE_GRAPHIC_STATE_FLIPPED_LEFT);
sprite_set_required_graphic_state(&(p_isometric_subobj_2->sprite), SPRITE_GRAPHIC_STATE_FLIPPED_LEFT);
}
else
{
sprite_set_required_graphic_state(&(p_isometric_subobj_1->sprite), SPRITE_GRAPHIC_STATE_FLIPPED_RIGHT);
sprite_set_required_graphic_state(&(p_isometric_subobj_2->sprite), SPRITE_GRAPHIC_STATE_FLIPPED_RIGHT);
}
}
void behavior_player_set_pointers(t_isometric_obj **pp_isometric_obj_player)
{
p_isometric_obj = *pp_isometric_obj_player;
p_isometric_subobj_1 = pp_isometric_obj_player[1];
p_isometric_subobj_2 = pp_isometric_obj_player[2];
}
void behavior_player_update_subobject_positions(t_isometric_obj *p_isometric_subobj, byte pos_x, byte pos_y, byte pos_z)
{
p_isometric_subobj->physics.last_pos_x = p_isometric_subobj->physics.box3d.pos_x;
p_isometric_subobj->physics.last_pos_y = p_isometric_subobj->physics.box3d.pos_y;
p_isometric_subobj->physics.last_pos_z = p_isometric_subobj->physics.box3d.pos_z;
p_isometric_subobj->physics.box3d.pos_x = pos_x;
p_isometric_subobj->physics.box3d.pos_y = pos_y;
p_isometric_subobj->physics.box3d.pos_z = pos_z;
}
#define DELTA_SPEED_PLAYER (1)
void behavior_controller_player(t_isometric_obj **pp_isometric_obj_player)
{
behavior_player_set_pointers(pp_isometric_obj_player);
// asignar posicion de pies y tronco
behavior_player_update_subobject_positions(p_isometric_subobj_1, pp_isometric_obj_player[0]->physics.box3d.pos_x, pp_isometric_obj_player[0]->physics.box3d.pos_y, pp_isometric_obj_player[0]->physics.box3d.pos_z + (13 - 10));
behavior_player_update_subobject_positions(p_isometric_subobj_2, pp_isometric_obj_player[0]->physics.box3d.pos_x, pp_isometric_obj_player[0]->physics.box3d.pos_y, pp_isometric_obj_player[0]->physics.box3d.pos_z - (13 - 3));
nframes++;
// Comprobacion de salidas
if((game_map_rooms_table[game_map_actual_room].exits & GAME_MAP_ROOM_FLAG_EXIT_N) &&
(p_isometric_obj->physics.flags & PHYS_BOX3D_FLAG_TOUCH_N) && (p_isometric_obj->physics.p_phys_obj_touching_n == &phys_box3d_wall_n) &&
(p_isometric_obj->physics.box3d.pos_x > (half_isometric_max_x_3d - 5)) && (p_isometric_obj->physics.box3d.pos_x < (half_isometric_max_x_3d + 5)))
{
game_map_move_player_2_room(game_map_rooms_table[game_map_actual_room].room_to_n,
p_isometric_obj->physics.box3d.pos_x, isometric_max_y_3d - p_isometric_obj->physics.box3d.width_y, p_isometric_obj->physics.box3d.pos_z);
}
if((game_map_rooms_table[game_map_actual_room].exits & GAME_MAP_ROOM_FLAG_EXIT_S) &&
(p_isometric_obj->physics.flags & PHYS_BOX3D_FLAG_TOUCH_S) && (p_isometric_obj->physics.p_phys_obj_touching_s == &phys_box3d_wall_s) &&
(p_isometric_obj->physics.box3d.pos_x > (half_isometric_max_x_3d - 5)) && (p_isometric_obj->physics.box3d.pos_x < (half_isometric_max_x_3d + 5)))
{
game_map_move_player_2_room(game_map_rooms_table[game_map_actual_room].room_to_s,
p_isometric_obj->physics.box3d.pos_x, p_isometric_obj->physics.box3d.width_y, p_isometric_obj->physics.box3d.pos_z);
}
if(keyboard_is_key_pressed_1())
{
if(p_isometric_obj->physics.flags & PHYS_BOX3D_FLAG_TOUCH_D)
{
p_isometric_obj->physics.speed_y = p_isometric_obj->physics.p_phys_obj_touching_d->speed_y - DELTA_SPEED_PLAYER;
}
if(player_last_orientation != ISOMETRIC_ORIENTATION_N)
{
player_last_orientation = ISOMETRIC_ORIENTATION_N;
orient_guardian(player_last_orientation);
}
else
{
if(!(nframes & 1)) sprite_next_frame(&(p_isometric_subobj_2->sprite));
}
}
if(keyboard_is_key_pressed_q())
{
if(p_isometric_obj->physics.flags & PHYS_BOX3D_FLAG_TOUCH_D)
{
p_isometric_obj->physics.speed_y = p_isometric_obj->physics.p_phys_obj_touching_d->speed_y + DELTA_SPEED_PLAYER;
}
if(player_last_orientation != ISOMETRIC_ORIENTATION_S)
{
player_last_orientation = ISOMETRIC_ORIENTATION_S;
orient_guardian(player_last_orientation);
}
else
{
if(!(nframes & 1)) sprite_next_frame(&(p_isometric_subobj_2->sprite));
}
}
if(keyboard_is_key_pressed_3())
{
if(p_isometric_obj->physics.flags & PHYS_BOX3D_FLAG_TOUCH_D)
{
p_isometric_obj->physics.speed_x = p_isometric_obj->physics.p_phys_obj_touching_d->speed_x - DELTA_SPEED_PLAYER;
}
if(player_last_orientation != ISOMETRIC_ORIENTATION_E)
{
player_last_orientation = ISOMETRIC_ORIENTATION_E;
orient_guardian(player_last_orientation);
}
else
{
if(!(nframes & 1)) sprite_next_frame(&(p_isometric_subobj_2->sprite));
}
}
if(keyboard_is_key_pressed_2())
{
if(p_isometric_obj->physics.flags & PHYS_BOX3D_FLAG_TOUCH_D)
{
p_isometric_obj->physics.speed_x = p_isometric_obj->physics.p_phys_obj_touching_d->speed_x + DELTA_SPEED_PLAYER;
}
if(player_last_orientation != ISOMETRIC_ORIENTATION_W)
{
player_last_orientation = ISOMETRIC_ORIENTATION_W;
orient_guardian(player_last_orientation);
}
else
{
if(!(nframes & 1)) sprite_next_frame(&(p_isometric_subobj_2->sprite));
}
}
if(keyboard_is_key_pressed_4())
{
if(p_isometric_obj->physics.flags & PHYS_BOX3D_FLAG_TOUCH_D)
{
p_isometric_obj->physics.speed_z = 3;
}
if(!(nframes & 1)) sprite_next_frame(&(p_isometric_subobj_2->sprite));
}
if(keyboard_is_key_pressed_5())
{
if(!(nframes & 1)) sprite_next_frame(&(p_isometric_subobj_2->sprite));
}
}
void behavior_player_init(t_isometric_obj **pp_isometric_obj_player)
{
behavior_player_set_pointers(pp_isometric_obj_player);
// Initialization after entering a room. Set orientation according to previous room
orient_guardian(player_last_orientation);
p_isometric_obj->behavior = behavior_controller_player;
behavior_controller_player(pp_isometric_obj_player);
}
#define BEHAVIOR_CINEMATIC_UPDOWN_SPEEDZ ((int8)(p_isometric_obj->behavior_variables.b_1))
#define BEHAVIOR_CINEMATIC_UPDOWN_DELAY_COUNTER (p_isometric_obj->behavior_variables.b_2)
void behavior_cinematic_updown(t_isometric_obj **pp_isometric_obj)
{
p_isometric_obj = *pp_isometric_obj;
// Variables initialization
if(p_isometric_obj->behavior_variables.b_0 == 0)
{
p_isometric_obj->behavior_variables.b_0 = 1;
BEHAVIOR_CINEMATIC_UPDOWN_SPEEDZ = -1;
}
if(BEHAVIOR_CINEMATIC_UPDOWN_SPEEDZ < 0)
{
/*if(p_isometric_obj->physics.flags & PHYS_BOX3D_FLAG_TOUCH_D)
{
p_isometric_obj->physics.speed_z = 0;
}
else */if(p_isometric_obj->physics.box3d.pos_z <= 10)
{
p_isometric_obj->physics.speed_z = BEHAVIOR_CINEMATIC_UPDOWN_SPEEDZ = 0;
BEHAVIOR_CINEMATIC_UPDOWN_DELAY_COUNTER = 32;
}
else
{
p_isometric_obj->physics.speed_z = BEHAVIOR_CINEMATIC_UPDOWN_SPEEDZ;
}
}
else if(BEHAVIOR_CINEMATIC_UPDOWN_SPEEDZ > 0)
{
/*if((p_isometric_obj->physics.flags & PHYS_BOX3D_FLAG_TOUCH_U) && (p_isometric_obj->physics.p_phys_obj_touching_u->flags & PHYS_BOX3D_FLAG_TOUCH_U ))
{
p_isometric_obj->physics.speed_z = 0;
}
else */if(p_isometric_obj->physics.box3d.pos_z >= 20)
{
p_isometric_obj->physics.speed_z = BEHAVIOR_CINEMATIC_UPDOWN_SPEEDZ = 0;
BEHAVIOR_CINEMATIC_UPDOWN_DELAY_COUNTER = 32;
}
else
{
p_isometric_obj->physics.speed_z = BEHAVIOR_CINEMATIC_UPDOWN_SPEEDZ;
}
}
else
{
if(!(BEHAVIOR_CINEMATIC_UPDOWN_DELAY_COUNTER--))
{
if(p_isometric_obj->physics.box3d.pos_z >= 20)
p_isometric_obj->physics.speed_z = BEHAVIOR_CINEMATIC_UPDOWN_SPEEDZ = -1;
else
p_isometric_obj->physics.speed_z = BEHAVIOR_CINEMATIC_UPDOWN_SPEEDZ = 1;
}
else
p_isometric_obj->physics.speed_z = 0;
}
}
// void behavior_gate_init(t_isometric_obj **pp_isometric_obj)
// {
// p_isometric_obj = *pp_isometric_obj;
// p_isometric_obj->sprite.required_graphic_state = p_isometric_obj->bahavior_parameter;
// sprite_set_pos_from_posref(&(p_isometric_obj->sprite));
// p_isometric_obj->behavior = NULL;
// }