]>
Commit | Line | Data |
---|---|---|
1 | #include "stdafx.h"\r | |
2 | \r | |
3 | Actor::Actor(int xpos, int ypos, const char *spritepath, const char *scriptpath, Map *map, Audio *audio, Game_overwatch *ow, CLuaVirtualMachine& vm) : CLuaScript(vm){\r | |
4 | this->init(xpos,ypos,spritepath,scriptpath,NULL,LEFT,true,map,audio,ow,vm);\r | |
5 | }\r | |
6 | \r | |
7 | Actor::Actor(int xpos, int ypos, const char *spritepath, const char *scriptpath, Actor *dad, Direction dir, bool phys, Map *map, Audio *audio, Game_overwatch *ow, CLuaVirtualMachine& vm) : CLuaScript(vm){\r | |
8 | this->init(xpos,ypos,spritepath,scriptpath,dad,dir,phys,map,audio,ow,vm);\r | |
9 | }\r | |
10 | \r | |
11 | Actor::~Actor(){\r | |
12 | SDL_FreeSurface(sprite);\r | |
13 | if(parent != NULL){\r | |
14 | parent->remove_bullet();\r | |
15 | }\r | |
16 | overwatch->move_out(this);\r | |
17 | }\r | |
18 | \r | |
19 | void Actor::init(int xpos, int ypos, const char *spritepath, const char *scriptpath, Actor *dad, Direction dir, bool phys, Map *map, Audio *aud, Game_overwatch *ow, CLuaVirtualMachine& vm){\r | |
20 | //Set Values from constructor\r | |
21 | x = xpos;\r | |
22 | y = ypos;\r | |
23 | overwatch = ow;\r | |
24 | audio = aud;\r | |
25 | currentmap = map;\r | |
26 | physics = phys;\r | |
27 | parent = dad;\r | |
28 | currentdirection = dir;\r | |
29 | walk_time = 0;\r | |
30 | \r | |
31 | //sprite\r | |
32 | SDL_Surface *raw_sprite = IMG_Load(spritepath);\r | |
33 | sprite = SDL_DisplayFormat(raw_sprite);\r | |
34 | SDL_FreeSurface(raw_sprite);\r | |
35 | Uint32 colorkey = SDL_MapRGB(sprite->format, 255, 0, 255);\r | |
36 | SDL_SetColorKey(sprite, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey); //le ponemos al buddy el colorkey para las transparencias\r | |
37 | w = sprite->w/SPRITE_FRAMES_W; //el ancho de nuestro spritesheet\r | |
38 | h = sprite->h/SPRITE_FRAMES_H; //lo alto de nuestro spritesheet\r | |
39 | \r | |
40 | //Lua API.\r | |
41 | m_iMethodBase = RegisterFunction ("get_x");\r | |
42 | RegisterFunction ("get_y");\r | |
43 | RegisterFunction ("get_w");\r | |
44 | RegisterFunction ("get_h");\r | |
45 | RegisterFunction ("get_clip_x");\r | |
46 | RegisterFunction ("get_clip_y");\r | |
47 | RegisterFunction ("get_currentframe");\r | |
48 | RegisterFunction ("get_oldclip");\r | |
49 | RegisterFunction ("get_vertical_speed");\r | |
50 | RegisterFunction ("get_falltime");\r | |
51 | RegisterFunction ("get_speed");\r | |
52 | RegisterFunction ("get_ownspeed");\r | |
53 | RegisterFunction ("get_totalspeed");\r | |
54 | RegisterFunction ("set_x");\r | |
55 | RegisterFunction ("set_y");\r | |
56 | RegisterFunction ("set_w");\r | |
57 | RegisterFunction ("set_h");\r | |
58 | RegisterFunction ("set_clip_x");\r | |
59 | RegisterFunction ("set_clip_y");\r | |
60 | RegisterFunction ("set_currentframe");\r | |
61 | RegisterFunction ("set_oldclip");\r | |
62 | RegisterFunction ("set_vertical_speed");\r | |
63 | RegisterFunction ("set_falltime");\r | |
64 | RegisterFunction ("set_speed");\r | |
65 | RegisterFunction ("set_ownspeed");\r | |
66 | RegisterFunction ("set_totalspeed");\r | |
67 | RegisterFunction ("get_currentdirection");\r | |
68 | RegisterFunction ("set_currentdirection");\r | |
69 | RegisterFunction ("can_move");\r | |
70 | RegisterFunction ("get_collision");\r | |
71 | RegisterFunction ("set_collision");\r | |
72 | RegisterFunction ("get_map_sx");\r | |
73 | RegisterFunction ("get_map_sy");\r | |
74 | RegisterFunction ("set_map_sx");\r | |
75 | RegisterFunction ("set_map_sy");\r | |
76 | RegisterFunction ("get_cfg_max_map_w");\r | |
77 | RegisterFunction ("get_cfg_max_map_h");\r | |
78 | RegisterFunction ("get_cfg_screen_width");\r | |
79 | RegisterFunction ("get_cfg_screen_height");\r | |
80 | RegisterFunction ("get_leftkey");\r | |
81 | RegisterFunction ("get_rightkey");\r | |
82 | RegisterFunction ("get_zkey");\r | |
83 | RegisterFunction ("get_xkey");\r | |
84 | RegisterFunction ("get_jumplock");\r | |
85 | RegisterFunction ("get_shootlock");\r | |
86 | RegisterFunction ("set_jumplock");\r | |
87 | RegisterFunction ("set_shootlock");\r | |
88 | RegisterFunction ("set_dying");\r | |
89 | RegisterFunction ("add_bullet");\r | |
90 | RegisterFunction ("get_shotcount");\r | |
91 | RegisterFunction ("set_physics");\r | |
92 | RegisterFunction ("set_enemy");\r | |
93 | RegisterFunction ("set_controllable");\r | |
94 | RegisterFunction ("get_ckey");\r | |
95 | RegisterFunction ("get_switchlock");\r | |
96 | RegisterFunction ("set_switchlock");\r | |
97 | RegisterFunction ("set_noclip");\r | |
98 | RegisterFunction ("load_clip");\r | |
99 | RegisterFunction ("play_sfx");\r | |
100 | RegisterFunction ("play_bgm");\r | |
101 | RegisterFunction ("stop_bgm");\r | |
102 | RegisterFunction ("get_cfg_tile_w");\r | |
103 | RegisterFunction ("get_cfg_tile_h");\r | |
104 | RegisterFunction ("accelerate");\r | |
105 | RegisterFunction ("get_walk_time");\r | |
106 | RegisterFunction ("set_walk_time");\r | |
107 | RegisterFunction ("decelerate");\r | |
108 | \r | |
109 | \r | |
110 | //lua compile.\r | |
111 | this->CompileFile("scripts/globals.lua");\r | |
112 | this->CompileFile (scriptpath);\r | |
113 | \r | |
114 | //lua sync.\r | |
115 | this->SelectScriptFunction ("sync");\r | |
116 | this->Go ();\r | |
117 | \r | |
118 | \r | |
119 | //default values.\r | |
120 | oldclip = 0;\r | |
121 | vertical_speed = 0.0;\r | |
122 | falltime = 0.0;\r | |
123 | speed = 0.0;\r | |
124 | ownspeed = 0.0;\r | |
125 | clip_x = 0;\r | |
126 | clip_y = 0;\r | |
127 | currentframe = 0;\r | |
128 | jumplock = false;\r | |
129 | shootlock = false;\r | |
130 | dying = false;\r | |
131 | shotcount = 0;\r | |
132 | \r | |
133 | //using ENUM direction as colliding vector index.\r | |
134 | colliding[UP], colliding[DOWN], colliding[LEFT], colliding[RIGHT] = false;\r | |
135 | \r | |
136 | overwatch->move_in(this);\r | |
137 | }\r | |
138 | \r | |
139 | //The Lua ScriptCalling Index.\r | |
140 | int Actor::ScriptCalling (CLuaVirtualMachine& vm, int iFunctionNumber){\r | |
141 | switch (iFunctionNumber - m_iMethodBase)\r | |
142 | {\r | |
143 | case 0:\r | |
144 | return lget_x(vm);\r | |
145 | break;\r | |
146 | \r | |
147 | case 1:\r | |
148 | return lget_y(vm);\r | |
149 | break;\r | |
150 | \r | |
151 | case 2:\r | |
152 | return lget_w(vm);\r | |
153 | break;\r | |
154 | \r | |
155 | case 3:\r | |
156 | return lget_h(vm);\r | |
157 | break;\r | |
158 | \r | |
159 | case 4:\r | |
160 | return lget_clip_x(vm);\r | |
161 | break;\r | |
162 | \r | |
163 | case 5:\r | |
164 | return lget_clip_y(vm);\r | |
165 | break;\r | |
166 | \r | |
167 | case 6:\r | |
168 | return lget_currentframe(vm);\r | |
169 | break;\r | |
170 | \r | |
171 | case 7:\r | |
172 | return lget_oldclip(vm);\r | |
173 | break;\r | |
174 | \r | |
175 | case 8:\r | |
176 | return lget_vertical_speed(vm);\r | |
177 | break;\r | |
178 | \r | |
179 | case 9:\r | |
180 | return lget_falltime(vm);\r | |
181 | break;\r | |
182 | \r | |
183 | case 10:\r | |
184 | return lget_speed(vm);\r | |
185 | break;\r | |
186 | \r | |
187 | case 11:\r | |
188 | return lget_ownspeed(vm);\r | |
189 | break;\r | |
190 | \r | |
191 | case 12:\r | |
192 | return lget_totalspeed(vm);\r | |
193 | break;\r | |
194 | case 13:\r | |
195 | return lset_x(vm);\r | |
196 | break;\r | |
197 | \r | |
198 | case 14:\r | |
199 | return lset_y(vm);\r | |
200 | break;\r | |
201 | \r | |
202 | case 15:\r | |
203 | return lset_w(vm);\r | |
204 | break;\r | |
205 | \r | |
206 | case 16:\r | |
207 | return lset_h(vm);\r | |
208 | break;\r | |
209 | \r | |
210 | case 17:\r | |
211 | return lset_clip_x(vm);\r | |
212 | break;\r | |
213 | \r | |
214 | case 18:\r | |
215 | return lset_clip_y(vm);\r | |
216 | break;\r | |
217 | \r | |
218 | case 19:\r | |
219 | return lset_currentframe(vm);\r | |
220 | break;\r | |
221 | \r | |
222 | case 20:\r | |
223 | return lset_oldclip(vm);\r | |
224 | break;\r | |
225 | \r | |
226 | case 21:\r | |
227 | return lset_vertical_speed(vm);\r | |
228 | break;\r | |
229 | \r | |
230 | case 22:\r | |
231 | return lset_falltime(vm);\r | |
232 | break;\r | |
233 | \r | |
234 | case 23:\r | |
235 | return lset_speed(vm);\r | |
236 | break;\r | |
237 | \r | |
238 | case 24:\r | |
239 | return lset_ownspeed(vm);\r | |
240 | break;\r | |
241 | \r | |
242 | case 25:\r | |
243 | return lset_totalspeed(vm);\r | |
244 | break;\r | |
245 | \r | |
246 | case 26:\r | |
247 | return lget_currentdirection(vm);\r | |
248 | break;\r | |
249 | \r | |
250 | case 27:\r | |
251 | return lset_currentdirection(vm);\r | |
252 | break;\r | |
253 | \r | |
254 | case 28:\r | |
255 | return lcan_move(vm);\r | |
256 | break;\r | |
257 | \r | |
258 | case 29:\r | |
259 | return lget_collision(vm);\r | |
260 | break;\r | |
261 | \r | |
262 | case 30:\r | |
263 | return lset_collision(vm);\r | |
264 | break;\r | |
265 | \r | |
266 | case 31:\r | |
267 | return lget_map_sx(vm);\r | |
268 | break;\r | |
269 | \r | |
270 | case 32:\r | |
271 | return lget_map_sy(vm);\r | |
272 | break;\r | |
273 | \r | |
274 | case 33:\r | |
275 | return lset_map_sx(vm);\r | |
276 | break;\r | |
277 | \r | |
278 | case 34:\r | |
279 | return lset_map_sy(vm);\r | |
280 | break;\r | |
281 | \r | |
282 | case 35:\r | |
283 | return lget_cfg_max_map_w(vm);\r | |
284 | break;\r | |
285 | \r | |
286 | case 36:\r | |
287 | return lget_cfg_max_map_h(vm);\r | |
288 | break;\r | |
289 | \r | |
290 | case 37:\r | |
291 | return lget_cfg_screen_width(vm);\r | |
292 | break;\r | |
293 | \r | |
294 | case 38:\r | |
295 | return lget_cfg_screen_height(vm);\r | |
296 | break;\r | |
297 | \r | |
298 | case 39:\r | |
299 | return lget_leftkey(vm);\r | |
300 | break;\r | |
301 | \r | |
302 | case 40:\r | |
303 | return lget_rightkey(vm);\r | |
304 | break;\r | |
305 | \r | |
306 | case 41:\r | |
307 | return lget_zkey(vm);\r | |
308 | break;\r | |
309 | \r | |
310 | case 42:\r | |
311 | return lget_xkey(vm);\r | |
312 | break;\r | |
313 | \r | |
314 | case 43:\r | |
315 | return lget_jumplock(vm);\r | |
316 | break;\r | |
317 | \r | |
318 | case 44:\r | |
319 | return lget_shootlock(vm);\r | |
320 | break;\r | |
321 | \r | |
322 | case 45:\r | |
323 | return lset_jumplock(vm);\r | |
324 | break;\r | |
325 | \r | |
326 | case 46:\r | |
327 | return lset_shootlock(vm);\r | |
328 | break;\r | |
329 | \r | |
330 | case 47:\r | |
331 | return lset_dying(vm);\r | |
332 | break;\r | |
333 | \r | |
334 | case 48:\r | |
335 | return ladd_bullet(vm);\r | |
336 | break;\r | |
337 | \r | |
338 | case 49:\r | |
339 | return lget_shotcount(vm);\r | |
340 | break;\r | |
341 | \r | |
342 | case 50:\r | |
343 | return lset_physics(vm);\r | |
344 | break;\r | |
345 | \r | |
346 | case 51:\r | |
347 | return lset_enemy(vm);\r | |
348 | break;\r | |
349 | \r | |
350 | case 52:\r | |
351 | return lset_controllable(vm);\r | |
352 | break;\r | |
353 | \r | |
354 | case 53:\r | |
355 | return lget_ckey(vm);\r | |
356 | break;\r | |
357 | \r | |
358 | case 54:\r | |
359 | return lget_switchlock(vm);\r | |
360 | break;\r | |
361 | \r | |
362 | case 55:\r | |
363 | return lset_switchlock(vm);\r | |
364 | break;\r | |
365 | \r | |
366 | case 56:\r | |
367 | return lset_noclip(vm);\r | |
368 | break;\r | |
369 | \r | |
370 | case 57:\r | |
371 | return lload_clip(vm);\r | |
372 | break;\r | |
373 | \r | |
374 | case 58:\r | |
375 | return lplay_sfx(vm);\r | |
376 | break;\r | |
377 | \r | |
378 | case 59:\r | |
379 | return lplay_bgm(vm);\r | |
380 | break;\r | |
381 | \r | |
382 | case 60:\r | |
383 | return lstop_bgm(vm);\r | |
384 | break;\r | |
385 | \r | |
386 | case 61:\r | |
387 | return lget_cfg_tile_w(vm);\r | |
388 | break;\r | |
389 | \r | |
390 | case 62:\r | |
391 | return lget_cfg_tile_h(vm);\r | |
392 | break;\r | |
393 | case 63:\r | |
394 | return laccelerate(vm);\r | |
395 | break;\r | |
396 | case 64:\r | |
397 | return lget_walk_time(vm);\r | |
398 | break;\r | |
399 | case 65:\r | |
400 | return lset_walk_time(vm);\r | |
401 | break;\r | |
402 | case 66:\r | |
403 | return ldecelerate(vm);\r | |
404 | break;\r | |
405 | }\r | |
406 | return 0;\r | |
407 | }\r | |
408 | \r | |
409 | void Actor::HandleReturns (CLuaVirtualMachine& vm, const char *strFunc){\r | |
410 | \r | |
411 | }\r | |
412 | \r | |
413 | void Actor::animate(){\r | |
414 | \r | |
415 | //check for conditions.\r | |
416 | if (ownspeed != 0) {\r | |
417 | animating = true;\r | |
418 | }else{\r | |
419 | animating = false;\r | |
420 | }\r | |
421 | \r | |
422 | \r | |
423 | //then do stuff\r | |
424 | if (animating) {\r | |
425 | if(currentframe <= MOVEMENT_FREQ){\r | |
426 | currentframe++;\r | |
427 | }else{\r | |
428 | currentframe = 0;\r | |
429 | }\r | |
430 | \r | |
431 | if(currentframe==0){\r | |
432 | if(clip_x >= (w*SPRITE_FRAMES_W)-w){\r | |
433 | animup = false; \r | |
434 | }\r | |
435 | if(clip_x == 0){\r | |
436 | animup = true;\r | |
437 | }\r | |
438 | if(animup){clip_x += w;}else{ clip_x -= w;}\r | |
439 | } \r | |
440 | }\r | |
441 | }\r | |
442 | \r | |
443 | void Actor::move(){\r | |
444 | if (!colliding[DOWN]) {\r | |
445 | speed = 0;\r | |
446 | }\r | |
447 | totalspeed = speed + ownspeed;\r | |
448 | if (noclip) {\r | |
449 | x += totalspeed;\r | |
450 | }else{\r | |
451 | if (totalspeed > 0 && this->can_move(RIGHT, x, y) ) {\r | |
452 | x += totalspeed;\r | |
453 | }\r | |
454 | if (totalspeed < 0 && this->can_move(LEFT, x, y) ) {\r | |
455 | x += totalspeed;\r | |
456 | }\r | |
457 | }\r | |
458 | }\r | |
459 | \r | |
460 | bool Actor::can_move(Direction direction, int xpos, int ypos){\r | |
461 | if(direction == UP){\r | |
462 | if(currentmap->get_passability((xpos+5-currentmap->get_sx()),(ypos-1-currentmap->get_sy())) == 1 || currentmap->get_passability((xpos+w-5-currentmap->get_sx()),(ypos-1-currentmap->get_sy())) == 1 || colliding[UP]){\r | |
463 | return false;\r | |
464 | }\r | |
465 | }\r | |
466 | if(direction == RIGHT){\r | |
467 | if(currentmap->get_passability((xpos+w-currentmap->get_sx()),(ypos+(h*.25)-currentmap->get_sy())) == 1 || currentmap->get_passability((xpos+w-currentmap->get_sx()),(ypos+h-1-currentmap->get_sy())) == 1 || colliding[RIGHT]){\r | |
468 | return false;\r | |
469 | }\r | |
470 | }\r | |
471 | if(direction == DOWN){\r | |
472 | if(currentmap->get_passability((xpos+5-currentmap->get_sx()),(ypos+h-currentmap->get_sy())) == 1 || currentmap->get_passability((xpos+w-5-currentmap->get_sx()),(ypos+h-currentmap->get_sy())) == 1 || colliding[DOWN]){\r | |
473 | return false;\r | |
474 | }\r | |
475 | }\r | |
476 | if(direction == LEFT){\r | |
477 | if(currentmap->get_passability((xpos-currentmap->get_sx()),(ypos+(h*.25)-currentmap->get_sy())) == 1 || currentmap->get_passability((xpos-currentmap->get_sx()),(ypos+h-1-currentmap->get_sy())) == 1 || colliding[LEFT]){\r | |
478 | return false;\r | |
479 | }\r | |
480 | }\r | |
481 | return true;\r | |
482 | }\r | |
483 | \r | |
484 | bool Actor::can_die(){\r | |
485 | \r | |
486 | if(currentmap->get_tile((x-currentmap->get_sx()),(y-1-currentmap->get_sy())) == 2 || currentmap->get_tile((x+w-currentmap->get_sx()),(y-1-currentmap->get_sy())) == 2){\r | |
487 | return true;\r | |
488 | }\r | |
489 | if(currentmap->get_tile((x+1+w-currentmap->get_sx()),(y-currentmap->get_sy())) == 2 || currentmap->get_tile((x+1+w-currentmap->get_sx()),(y+h-currentmap->get_sy())) == 2){\r | |
490 | return true;\r | |
491 | }\r | |
492 | if(currentmap->get_tile((x-currentmap->get_sx()),(y+1+h-currentmap->get_sy())) == 2 || currentmap->get_tile((x+w-currentmap->get_sx()),(y+1+h-currentmap->get_sy())) == 2){\r | |
493 | return true;\r | |
494 | }\r | |
495 | if(currentmap->get_tile((x-1-currentmap->get_sx()),(y-currentmap->get_sy())) == 2 || currentmap->get_tile((x-1-currentmap->get_sx()),(y+h-currentmap->get_sy())) == 2){\r | |
496 | return true;\r | |
497 | }\r | |
498 | return false;\r | |
499 | }\r | |
500 | \r | |
501 | void Actor::add_bullet(const char* sprite, const char* script){\r | |
502 | shotcount++;\r | |
503 | if (currentdirection == LEFT) {\r | |
504 | new Actor(x-14, y+10,sprite, script, this, LEFT, false, currentmap, audio, overwatch, m_vm);\r | |
505 | }\r | |
506 | if (currentdirection == RIGHT) {\r | |
507 | new Actor(x+w+4, y+10,sprite, script, this, RIGHT, false, currentmap, audio, overwatch, m_vm);\r | |
508 | }\r | |
509 | }\r | |
510 | \r | |
511 | void Actor::remove_bullet(){\r | |
512 | shotcount--;\r | |
513 | }\r | |
514 | \r | |
515 | void Actor::accelerate(float accel, float max_speed){\r | |
516 | \r | |
517 | if ( (accel > 0 && ownspeed == max_speed && max_speed < 0) || (accel < 0 && ownspeed == max_speed && max_speed > 0) ){\r | |
518 | walk_time = 0;\r | |
519 | }\r | |
520 | \r | |
521 | //reset the time if we were deccelerating.\r | |
522 | if (walk_time < 0) {\r | |
523 | walk_time = 0;\r | |
524 | }\r | |
525 | \r | |
526 | walk_time += 1; //increase the time, because we are accelerating.\r | |
527 | \r | |
528 | if((ownspeed >= max_speed && max_speed > 0) || (ownspeed <= max_speed && max_speed < 0)){\r | |
529 | ownspeed = max_speed;\r | |
530 | }else{\r | |
531 | ownspeed = ownspeed + accel*walk_time;\r | |
532 | }\r | |
533 | }\r | |
534 | \r | |
535 | void Actor::decelerate(float accel){\r | |
536 | if(ownspeed != 0 && falltime == 0){\r | |
537 | if (walk_time > 0) {\r | |
538 | walk_time = 0;\r | |
539 | }\r | |
540 | walk_time -= 1; //increase the time, because we are accelerating.\r | |
541 | \r | |
542 | //Stay at 0\r | |
543 | if (ownspeed > 0) {\r | |
544 | ownspeed = ownspeed + accel*walk_time;\r | |
545 | if (ownspeed < 0){\r | |
546 | ownspeed = 0; //if we go too far, just settle with 0.\r | |
547 | }\r | |
548 | }\r | |
549 | if (ownspeed < 0) {\r | |
550 | ownspeed = ownspeed - accel*walk_time;\r | |
551 | if (ownspeed > 0){\r | |
552 | ownspeed = 0; //if we go too far, just settle with 0.\r | |
553 | }\r | |
554 | }\r | |
555 | }\r | |
556 | }\r | |
557 | \r | |
558 | //internal accessors\r | |
559 | \r | |
560 | int Actor::get_x(void){ return x; }\r | |
561 | void Actor::set_x(int newval){ x = newval; }\r | |
562 | int Actor::get_y(void){ return y; }\r | |
563 | void Actor::set_y(int newval){ y = newval; }\r | |
564 | int Actor::get_w(void){ return w; }\r | |
565 | void Actor::set_w(int newval){ w = newval; }\r | |
566 | int Actor::get_h(void){ return h; }\r | |
567 | void Actor::set_h(int newval){ h = newval; }\r | |
568 | int Actor::get_clip_x(void){ return clip_x; }\r | |
569 | void Actor::set_clip_x(int newval){ clip_x = newval; }\r | |
570 | int Actor::get_clip_y(void){ return clip_y; }\r | |
571 | void Actor::set_clip_y(int newval){ clip_y = newval; }\r | |
572 | int Actor::get_currentframe(void){ return currentframe; }\r | |
573 | void Actor::set_currentframe(int newval){ currentframe = newval; }\r | |
574 | int Actor::get_oldclip(void){ return oldclip; }\r | |
575 | void Actor::set_oldclip(int newval){ oldclip = newval; }\r | |
576 | float Actor::get_vertical_speed(void){ return vertical_speed; }\r | |
577 | void Actor::set_vertical_speed(float newval){ vertical_speed = newval;}\r | |
578 | float Actor::get_vertical_acc(void){ return vertical_acc; }\r | |
579 | void Actor::set_vertical_acc(float newval){ vertical_acc = newval;}\r | |
580 | float Actor::get_falltime(void){ return falltime; }\r | |
581 | void Actor::set_falltime(float newval){ falltime = newval; }\r | |
582 | SDL_Surface * Actor::get_sprite(void){ return sprite; }\r | |
583 | float Actor::get_speed(void){ return speed; }\r | |
584 | void Actor::set_speed(float newval){ speed = newval;}\r | |
585 | float Actor::get_ownspeed(void){ return ownspeed; }\r | |
586 | void Actor::set_ownspeed(float newval){ ownspeed = newval;}\r | |
587 | float Actor::get_totalspeed(void){ return totalspeed; }\r | |
588 | void Actor::set_totalspeed(float newval){ totalspeed = newval;}\r | |
589 | float Actor::get_horizontal_acc(void){ return vertical_acc; }\r | |
590 | void Actor::set_horizontal_acc(float newval){ vertical_acc = newval;}\r | |
591 | Direction Actor::get_currentdirection(void){ return currentdirection; }\r | |
592 | Enemy Actor::get_enemy(void){ return enemy; }\r | |
593 | int Actor::get_leftkey(void){ return leftkey; }\r | |
594 | void Actor::set_leftkey(int newval){ leftkey = newval; }\r | |
595 | int Actor::get_rightkey(void){ return rightkey; }\r | |
596 | void Actor::set_rightkey(int newval){ rightkey = newval; }\r | |
597 | int Actor::get_zkey(void){ return zkey; }\r | |
598 | void Actor::set_zkey(int newval){ zkey = newval; }\r | |
599 | int Actor::get_xkey(void){ return xkey; }\r | |
600 | void Actor::set_xkey(int newval){ xkey = newval; }\r | |
601 | bool Actor::get_physics(void){ return physics; }\r | |
602 | void Actor::set_physics(bool newval){ physics = newval; }\r | |
603 | void Actor::set_collision(bool col, int corner){\r | |
604 | colliding[corner] = col;\r | |
605 | }\r | |
606 | bool Actor::get_controllable(void){ return controllable; }\r | |
607 | bool Actor::get_collision(int corner){\r | |
608 | return colliding[corner];\r | |
609 | }\r | |
610 | bool Actor::get_dying(void){ return dying; }\r | |
611 | void Actor::set_dying(bool newval){ dying = newval; }\r | |
612 | void Actor::set_ckey(int newval){ ckey = newval; }\r | |
613 | bool Actor::get_noclip(void){ return noclip; }\r | |
614 | \r | |
615 | //lua accessors (get)\r | |
616 | int Actor::lget_x(CLuaVirtualMachine& vm){\r | |
617 | lua_State *state = (lua_State *) vm;\r | |
618 | lua_pushnumber (state, x);\r | |
619 | return 1;\r | |
620 | }\r | |
621 | \r | |
622 | int Actor::lget_y(CLuaVirtualMachine& vm){\r | |
623 | lua_State *state = (lua_State *) vm;\r | |
624 | lua_pushnumber (state, y);\r | |
625 | return 1;\r | |
626 | }\r | |
627 | \r | |
628 | int Actor::lget_w(CLuaVirtualMachine& vm){\r | |
629 | lua_State *state = (lua_State *) vm;\r | |
630 | lua_pushnumber (state, w);\r | |
631 | return 1;\r | |
632 | }\r | |
633 | \r | |
634 | int Actor::lget_h(CLuaVirtualMachine& vm){\r | |
635 | lua_State *state = (lua_State *) vm;\r | |
636 | lua_pushnumber (state, h);\r | |
637 | return 1;\r | |
638 | }\r | |
639 | \r | |
640 | int Actor::lget_clip_x(CLuaVirtualMachine& vm){\r | |
641 | lua_State *state = (lua_State *) vm;\r | |
642 | lua_pushnumber (state, clip_x);\r | |
643 | return 1;\r | |
644 | }\r | |
645 | \r | |
646 | int Actor::lget_clip_y(CLuaVirtualMachine& vm){\r | |
647 | lua_State *state = (lua_State *) vm;\r | |
648 | lua_pushnumber (state, clip_y);\r | |
649 | return 1;\r | |
650 | }\r | |
651 | \r | |
652 | int Actor::lget_currentframe(CLuaVirtualMachine& vm){\r | |
653 | lua_State *state = (lua_State *) vm;\r | |
654 | lua_pushnumber (state, currentframe);\r | |
655 | return 1;\r | |
656 | }\r | |
657 | \r | |
658 | int Actor::lget_oldclip(CLuaVirtualMachine& vm){\r | |
659 | lua_State *state = (lua_State *) vm;\r | |
660 | lua_pushnumber (state, oldclip);\r | |
661 | return 1;\r | |
662 | }\r | |
663 | \r | |
664 | int Actor::lget_vertical_speed(CLuaVirtualMachine& vm){\r | |
665 | lua_State *state = (lua_State *) vm;\r | |
666 | lua_pushnumber (state, vertical_speed);\r | |
667 | return 1;\r | |
668 | }\r | |
669 | \r | |
670 | int Actor::lget_falltime(CLuaVirtualMachine& vm){\r | |
671 | lua_State *state = (lua_State *) vm;\r | |
672 | lua_pushnumber (state, falltime);\r | |
673 | return 1;\r | |
674 | }\r | |
675 | \r | |
676 | int Actor::lget_speed(CLuaVirtualMachine& vm){\r | |
677 | lua_State *state = (lua_State *) vm;\r | |
678 | lua_pushnumber (state, speed);\r | |
679 | return 1;\r | |
680 | }\r | |
681 | \r | |
682 | int Actor::lget_ownspeed(CLuaVirtualMachine& vm){\r | |
683 | lua_State *state = (lua_State *) vm;\r | |
684 | lua_pushnumber (state, ownspeed);\r | |
685 | return 1;\r | |
686 | }\r | |
687 | \r | |
688 | int Actor::lget_totalspeed(CLuaVirtualMachine& vm){\r | |
689 | lua_State *state = (lua_State *) vm;\r | |
690 | lua_pushnumber (state, totalspeed);\r | |
691 | return 1;\r | |
692 | }\r | |
693 | \r | |
694 | int Actor::lget_currentdirection(CLuaVirtualMachine& vm){\r | |
695 | lua_State *state = (lua_State *) vm;\r | |
696 | lua_pushnumber (state, currentdirection);\r | |
697 | return 1;\r | |
698 | }\r | |
699 | \r | |
700 | int Actor::lget_collision(CLuaVirtualMachine& vm){\r | |
701 | lua_State *state = (lua_State *) vm;\r | |
702 | lua_pushboolean (state, colliding[(int) lua_tonumber (state, -1)]);\r | |
703 | return 1;\r | |
704 | }\r | |
705 | \r | |
706 | int Actor::lget_map_sx(CLuaVirtualMachine& vm){\r | |
707 | lua_State *state = (lua_State *) vm;\r | |
708 | lua_pushnumber (state, currentmap->get_sx());\r | |
709 | return 1;\r | |
710 | }\r | |
711 | \r | |
712 | int Actor::lget_map_sy(CLuaVirtualMachine& vm){\r | |
713 | lua_State *state = (lua_State *) vm;\r | |
714 | lua_pushnumber (state, currentmap->get_sy());\r | |
715 | return 1;\r | |
716 | }\r | |
717 | \r | |
718 | int Actor::lget_cfg_max_map_w(CLuaVirtualMachine& vm){\r | |
719 | lua_State *state = (lua_State *) vm;\r | |
720 | lua_pushnumber (state, MAX_MAP_W);\r | |
721 | return 1;\r | |
722 | }\r | |
723 | \r | |
724 | int Actor::lget_cfg_max_map_h(CLuaVirtualMachine& vm){\r | |
725 | lua_State *state = (lua_State *) vm;\r | |
726 | lua_pushnumber (state, MAX_MAP_H);\r | |
727 | return 1;\r | |
728 | }\r | |
729 | \r | |
730 | int Actor::lget_cfg_tile_h(CLuaVirtualMachine& vm){\r | |
731 | lua_State *state = (lua_State *) vm;\r | |
732 | lua_pushnumber (state, TILE_HEIGHT);\r | |
733 | return 1;\r | |
734 | }\r | |
735 | \r | |
736 | int Actor::lget_cfg_screen_height(CLuaVirtualMachine& vm){\r | |
737 | lua_State *state = (lua_State *) vm;\r | |
738 | lua_pushnumber (state, SCREEN_HEIGHT);\r | |
739 | return 1;\r | |
740 | }\r | |
741 | \r | |
742 | int Actor::lget_leftkey(CLuaVirtualMachine& vm){\r | |
743 | lua_State *state = (lua_State *) vm;\r | |
744 | lua_pushnumber (state, leftkey);\r | |
745 | return 1;\r | |
746 | }\r | |
747 | \r | |
748 | int Actor::lget_rightkey(CLuaVirtualMachine& vm){\r | |
749 | lua_State *state = (lua_State *) vm;\r | |
750 | lua_pushnumber (state, rightkey);\r | |
751 | return 1;\r | |
752 | }\r | |
753 | \r | |
754 | int Actor::lget_zkey(CLuaVirtualMachine& vm){\r | |
755 | lua_State *state = (lua_State *) vm;\r | |
756 | lua_pushnumber (state, zkey);\r | |
757 | return 1;\r | |
758 | }\r | |
759 | \r | |
760 | int Actor::lget_xkey(CLuaVirtualMachine& vm){\r | |
761 | lua_State *state = (lua_State *) vm;\r | |
762 | lua_pushnumber (state, xkey);\r | |
763 | return 1;\r | |
764 | }\r | |
765 | \r | |
766 | int Actor::lget_jumplock(CLuaVirtualMachine& vm){\r | |
767 | lua_State *state = (lua_State *) vm;\r | |
768 | lua_pushboolean (state, jumplock);\r | |
769 | return 1;\r | |
770 | }\r | |
771 | \r | |
772 | int Actor::lget_shootlock(CLuaVirtualMachine& vm){\r | |
773 | lua_State *state = (lua_State *) vm;\r | |
774 | lua_pushboolean (state, shootlock);\r | |
775 | return 1;\r | |
776 | }\r | |
777 | \r | |
778 | int Actor::lget_shotcount(CLuaVirtualMachine& vm){\r | |
779 | lua_State *state = (lua_State *) vm;\r | |
780 | lua_pushnumber (state, shotcount);\r | |
781 | return 1;\r | |
782 | }\r | |
783 | \r | |
784 | int Actor::lget_ckey(CLuaVirtualMachine& vm){\r | |
785 | lua_State *state = (lua_State *) vm;\r | |
786 | lua_pushnumber (state, ckey);\r | |
787 | return 1;\r | |
788 | }\r | |
789 | \r | |
790 | int Actor::lget_switchlock(CLuaVirtualMachine& vm){\r | |
791 | lua_State *state = (lua_State *) vm;\r | |
792 | lua_pushboolean (state, switchlock);\r | |
793 | return 1;\r | |
794 | }\r | |
795 | \r | |
796 | int Actor::lget_cfg_tile_w(CLuaVirtualMachine& vm){\r | |
797 | lua_State *state = (lua_State *) vm;\r | |
798 | lua_pushnumber (state, TILE_WIDTH);\r | |
799 | return 1;\r | |
800 | }\r | |
801 | \r | |
802 | int Actor::lget_cfg_screen_width(CLuaVirtualMachine& vm){\r | |
803 | lua_State *state = (lua_State *) vm;\r | |
804 | lua_pushnumber (state, SCREEN_WIDTH);\r | |
805 | return 1;\r | |
806 | }\r | |
807 | \r | |
808 | int Actor::lget_walk_time(CLuaVirtualMachine& vm){\r | |
809 | lua_State *state = (lua_State *) vm;\r | |
810 | lua_pushnumber (state, walk_time);\r | |
811 | return 1;\r | |
812 | }\r | |
813 | \r | |
814 | //lua accessors (set)\r | |
815 | int Actor::lset_x(CLuaVirtualMachine& vm){\r | |
816 | lua_State *state = (lua_State *) vm;\r | |
817 | x = (int) lua_tonumber (state, -1);\r | |
818 | return 0;\r | |
819 | }\r | |
820 | \r | |
821 | int Actor::lset_y(CLuaVirtualMachine& vm){\r | |
822 | lua_State *state = (lua_State *) vm;\r | |
823 | y = (int) lua_tonumber (state, -1);\r | |
824 | return 0;\r | |
825 | }\r | |
826 | \r | |
827 | int Actor::lset_w(CLuaVirtualMachine& vm){\r | |
828 | lua_State *state = (lua_State *) vm;\r | |
829 | w = (int) lua_tonumber (state, -1);\r | |
830 | return 0;\r | |
831 | }\r | |
832 | \r | |
833 | int Actor::lset_h(CLuaVirtualMachine& vm){\r | |
834 | lua_State *state = (lua_State *) vm;\r | |
835 | h = (int) lua_tonumber (state, -1);\r | |
836 | return 0;\r | |
837 | }\r | |
838 | \r | |
839 | int Actor::lset_clip_x(CLuaVirtualMachine& vm){\r | |
840 | lua_State *state = (lua_State *) vm;\r | |
841 | clip_x = (int) lua_tonumber (state, -1);\r | |
842 | return 0;\r | |
843 | }\r | |
844 | \r | |
845 | int Actor::lset_clip_y(CLuaVirtualMachine& vm){\r | |
846 | lua_State *state = (lua_State *) vm;\r | |
847 | clip_y = (int) lua_tonumber (state, -1);\r | |
848 | return 0;\r | |
849 | }\r | |
850 | \r | |
851 | int Actor::lset_currentframe(CLuaVirtualMachine& vm){\r | |
852 | lua_State *state = (lua_State *) vm;\r | |
853 | currentframe = (int) lua_tonumber (state, -1);\r | |
854 | return 0;\r | |
855 | }\r | |
856 | \r | |
857 | int Actor::lset_oldclip(CLuaVirtualMachine& vm){\r | |
858 | lua_State *state = (lua_State *) vm;\r | |
859 | oldclip = (int) lua_tonumber (state, -1);\r | |
860 | return 0;\r | |
861 | }\r | |
862 | \r | |
863 | int Actor::lset_vertical_speed(CLuaVirtualMachine& vm){\r | |
864 | lua_State *state = (lua_State *) vm;\r | |
865 | vertical_speed = (float) lua_tonumber (state, -1);\r | |
866 | return 0;\r | |
867 | }\r | |
868 | \r | |
869 | int Actor::lset_falltime(CLuaVirtualMachine& vm){\r | |
870 | lua_State *state = (lua_State *) vm;\r | |
871 | falltime = (float) lua_tonumber (state, -1);\r | |
872 | return 0;\r | |
873 | }\r | |
874 | \r | |
875 | int Actor::lset_speed(CLuaVirtualMachine& vm){\r | |
876 | lua_State *state = (lua_State *) vm;\r | |
877 | speed = (float) lua_tonumber (state, -1);\r | |
878 | return 0;\r | |
879 | }\r | |
880 | \r | |
881 | int Actor::lset_ownspeed(CLuaVirtualMachine& vm){\r | |
882 | lua_State *state = (lua_State *) vm;\r | |
883 | ownspeed = (float) lua_tonumber (state, -1);\r | |
884 | return 0;\r | |
885 | }\r | |
886 | \r | |
887 | int Actor::lset_totalspeed(CLuaVirtualMachine& vm){\r | |
888 | lua_State *state = (lua_State *) vm;\r | |
889 | totalspeed = (float) lua_tonumber (state, -1);\r | |
890 | return 0;\r | |
891 | }\r | |
892 | \r | |
893 | int Actor::lset_currentdirection(CLuaVirtualMachine& vm){\r | |
894 | lua_State *state = (lua_State *) vm;\r | |
895 | currentdirection = (Direction) lua_tonumber (state, -1);\r | |
896 | return 0;\r | |
897 | }\r | |
898 | \r | |
899 | int Actor::lset_collision(CLuaVirtualMachine& vm){\r | |
900 | lua_State *state = (lua_State *) vm;\r | |
901 | colliding[(int) lua_tonumber (state, -1)] = (bool) lua_toboolean(state, -2);\r | |
902 | return 0;\r | |
903 | }\r | |
904 | \r | |
905 | int Actor::lset_map_sx(CLuaVirtualMachine& vm){\r | |
906 | lua_State *state = (lua_State *) vm;\r | |
907 | currentmap->set_sx((int) lua_tonumber (state, -1));\r | |
908 | return 0;\r | |
909 | }\r | |
910 | \r | |
911 | int Actor::lset_map_sy(CLuaVirtualMachine& vm){\r | |
912 | lua_State *state = (lua_State *) vm;\r | |
913 | currentmap->set_sy((int) lua_tonumber (state, -1));\r | |
914 | return 0;\r | |
915 | }\r | |
916 | \r | |
917 | int Actor::lset_jumplock(CLuaVirtualMachine& vm){\r | |
918 | lua_State *state = (lua_State *) vm;\r | |
919 | jumplock = (bool) lua_toboolean (state, -1);\r | |
920 | return 0;\r | |
921 | }\r | |
922 | \r | |
923 | int Actor::lset_shootlock(CLuaVirtualMachine& vm){\r | |
924 | lua_State *state = (lua_State *) vm;\r | |
925 | shootlock = (bool) lua_toboolean (state, -1);\r | |
926 | return 0;\r | |
927 | }\r | |
928 | \r | |
929 | int Actor::lset_dying(CLuaVirtualMachine& vm){\r | |
930 | lua_State *state = (lua_State *) vm;\r | |
931 | dying = (bool) lua_toboolean (state, -1);\r | |
932 | return 0;\r | |
933 | }\r | |
934 | \r | |
935 | int Actor::lset_physics(CLuaVirtualMachine& vm){\r | |
936 | lua_State *state = (lua_State *) vm;\r | |
937 | physics = (bool) lua_toboolean (state, -1);\r | |
938 | return 0;\r | |
939 | }\r | |
940 | \r | |
941 | int Actor::lset_enemy(CLuaVirtualMachine& vm){\r | |
942 | lua_State *state = (lua_State *) vm;\r | |
943 | enemy = (Enemy) lua_tonumber (state, -1);\r | |
944 | return 0;\r | |
945 | }\r | |
946 | \r | |
947 | int Actor::lset_controllable(CLuaVirtualMachine& vm){\r | |
948 | lua_State *state = (lua_State *) vm;\r | |
949 | controllable = (bool) lua_toboolean (state, -1);\r | |
950 | return 0;\r | |
951 | }\r | |
952 | \r | |
953 | int Actor::lset_switchlock(CLuaVirtualMachine& vm){\r | |
954 | lua_State *state = (lua_State *) vm;\r | |
955 | switchlock = (bool) lua_toboolean (state, -1);\r | |
956 | return 0;\r | |
957 | }\r | |
958 | \r | |
959 | int Actor::lset_noclip(CLuaVirtualMachine& vm){\r | |
960 | lua_State *state = (lua_State *) vm;\r | |
961 | noclip = (bool) lua_toboolean (state, -1);\r | |
962 | return 0;\r | |
963 | }\r | |
964 | \r | |
965 | int Actor::lset_walk_time(CLuaVirtualMachine& vm){\r | |
966 | lua_State *state = (lua_State *) vm;\r | |
967 | walk_time = (int) lua_tonumber (state, -1);\r | |
968 | return 0;\r | |
969 | }\r | |
970 | \r | |
971 | \r | |
972 | //misc lua methods\r | |
973 | \r | |
974 | int Actor::lcan_move(CLuaVirtualMachine& vm){\r | |
975 | lua_State *state = (lua_State *) vm;\r | |
976 | lua_pushboolean(state,this->can_move((Direction) lua_tonumber (state, -3), (int) lua_tonumber (state, -2), (int) lua_tonumber (state, -1)));\r | |
977 | return 1; \r | |
978 | }\r | |
979 | \r | |
980 | int Actor::ladd_bullet(CLuaVirtualMachine& vm){\r | |
981 | lua_State *state = (lua_State *) vm; \r | |
982 | this->add_bullet((const char*) lua_tostring (state, -2), (const char*) lua_tostring (state, -1));\r | |
983 | return 1;\r | |
984 | }\r | |
985 | \r | |
986 | int Actor::lload_clip(CLuaVirtualMachine& vm){\r | |
987 | lua_State *state = (lua_State *) vm; \r | |
988 | audio->load_clip((const char*) lua_tostring (state, -1));\r | |
989 | return 1;\r | |
990 | }\r | |
991 | \r | |
992 | int Actor::lplay_sfx(CLuaVirtualMachine& vm){\r | |
993 | lua_State *state = (lua_State *) vm; \r | |
994 | audio->play_sfx((const char*) lua_tostring (state, -1));\r | |
995 | return 1;\r | |
996 | }\r | |
997 | \r | |
998 | int Actor::lplay_bgm(CLuaVirtualMachine& vm){\r | |
999 | lua_State *state = (lua_State *) vm; \r | |
1000 | audio->play_bgm((const char*) lua_tostring (state, -1));\r | |
1001 | return 1;\r | |
1002 | }\r | |
1003 | \r | |
1004 | int Actor::lstop_bgm(CLuaVirtualMachine& vm){\r | |
1005 | lua_State *state = (lua_State *) vm; \r | |
1006 | audio->stop_bgm((const char*) lua_tostring (state, -1));\r | |
1007 | return 1;\r | |
1008 | }\r | |
1009 | \r | |
1010 | int Actor::laccelerate(CLuaVirtualMachine& vm){\r | |
1011 | lua_State *state = (lua_State *) vm; \r | |
1012 | this->accelerate((float) lua_tonumber (state, -2), (float) lua_tonumber (state, -1));\r | |
1013 | return 1;\r | |
1014 | }\r | |
1015 | \r | |
1016 | int Actor::ldecelerate(CLuaVirtualMachine& vm){\r | |
1017 | lua_State *state = (lua_State *) vm; \r | |
1018 | this->decelerate((float) lua_tonumber (state, -1));\r | |
1019 | return 1;\r | |
1020 | } |