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