aboutsummaryrefslogtreecommitdiff
path: root/actor.cpp
blob: 12e5353c2c8cc4104d1a67a6c4bb05677ba21f12 (plain)
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
#include "stdafx.h"

Actor::Actor(int xpos, int ypos, const char *spritepath, const char *scriptpath, Map *map, Audio *audio, Game_overwatch *ow, CLuaVirtualMachine& vm) : CLuaScript(vm){
	this->init(xpos,ypos,spritepath,scriptpath,NULL,LEFT,true,map,audio,ow,vm);
}

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){
	this->init(xpos,ypos,spritepath,scriptpath,dad,dir,phys,map,audio,ow,vm);
}

Actor::~Actor(){
	SDL_FreeSurface(sprite);
	if(parent != NULL){
		parent->remove_bullet();
	}
	overwatch->move_out(this);
}

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){
	//Set Values from constructor
	x = xpos;
	y = ypos;
	overwatch = ow;
	audio = aud;
	currentmap = map;
	physics = phys;
	parent = dad;
	currentdirection = dir;
    walk_time = 0;
	
	//sprite
	SDL_Surface *raw_sprite = IMG_Load(spritepath);
    sprite = SDL_DisplayFormat(raw_sprite);
    SDL_FreeSurface(raw_sprite);
    Uint32 colorkey = SDL_MapRGB(sprite->format, 255, 0, 255);
    SDL_SetColorKey(sprite, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey);	//le ponemos al buddy el colorkey para las transparencias
    w = sprite->w/SPRITE_FRAMES_W;												 //el ancho de nuestro spritesheet
    h = sprite->h/SPRITE_FRAMES_H;												 //lo alto de nuestro spritesheet
	
	//Lua API.
	m_iMethodBase = RegisterFunction ("get_x");
	RegisterFunction ("get_y");
	RegisterFunction ("get_w");
	RegisterFunction ("get_h");
	RegisterFunction ("get_clip_x");
	RegisterFunction ("get_clip_y");
	RegisterFunction ("get_currentframe");
	RegisterFunction ("get_oldclip");
	RegisterFunction ("get_vertical_speed");
	RegisterFunction ("get_falltime");
	RegisterFunction ("get_speed");
	RegisterFunction ("get_ownspeed");
	RegisterFunction ("get_totalspeed");
	RegisterFunction ("set_x");
	RegisterFunction ("set_y");
	RegisterFunction ("set_w");
	RegisterFunction ("set_h");
	RegisterFunction ("set_clip_x");
	RegisterFunction ("set_clip_y");
	RegisterFunction ("set_currentframe");
	RegisterFunction ("set_oldclip");
	RegisterFunction ("set_vertical_speed");
	RegisterFunction ("set_falltime");
	RegisterFunction ("set_speed");
	RegisterFunction ("set_ownspeed");
	RegisterFunction ("set_totalspeed");
	RegisterFunction ("get_currentdirection");
	RegisterFunction ("set_currentdirection");
	RegisterFunction ("can_move");
	RegisterFunction ("get_collision");
	RegisterFunction ("set_collision");
	RegisterFunction ("get_map_sx");
	RegisterFunction ("get_map_sy");
	RegisterFunction ("set_map_sx");
	RegisterFunction ("set_map_sy");
	RegisterFunction ("get_cfg_max_map_w");
	RegisterFunction ("get_cfg_max_map_h");
	RegisterFunction ("get_cfg_screen_width");
	RegisterFunction ("get_cfg_screen_height");
	RegisterFunction ("get_leftkey");
	RegisterFunction ("get_rightkey");
	RegisterFunction ("get_zkey");
	RegisterFunction ("get_xkey");
	RegisterFunction ("get_jumplock");
	RegisterFunction ("get_shootlock");
	RegisterFunction ("set_jumplock");
	RegisterFunction ("set_shootlock");
	RegisterFunction ("set_dying");
	RegisterFunction ("add_bullet");
	RegisterFunction ("get_shotcount");
	RegisterFunction ("set_physics");
	RegisterFunction ("set_enemy");
	RegisterFunction ("set_controllable");
	RegisterFunction ("get_ckey");
	RegisterFunction ("get_switchlock");
	RegisterFunction ("set_switchlock");
	RegisterFunction ("set_noclip");
	RegisterFunction ("load_clip");
	RegisterFunction ("play_sfx");
	RegisterFunction ("play_bgm");
	RegisterFunction ("stop_bgm");
    RegisterFunction ("get_cfg_tile_w");
	RegisterFunction ("get_cfg_tile_h");
    RegisterFunction ("accelerate");
    RegisterFunction ("get_walk_time");
    RegisterFunction ("set_walk_time");
    RegisterFunction ("decelerate");
	
	
	//lua compile.
	this->CompileFile("scripts/globals.lua");
	this->CompileFile (scriptpath);
	
	//lua sync.
	this->SelectScriptFunction ("sync");
	this->Go ();

	
	//default values.
	oldclip = 0;
	vertical_speed = 0.0;
	falltime = 0.0;
	speed = 0.0;
	ownspeed = 0.0;
	clip_x = 0;
	clip_y = 0;
	currentframe = 0;
	jumplock = false;
	shootlock = false;
	dying = false;
	shotcount = 0;
	
	//using ENUM direction as colliding vector index.
	colliding[UP], colliding[DOWN], colliding[LEFT], colliding[RIGHT] = false;
	
	overwatch->move_in(this);
}

//The Lua ScriptCalling Index.
int Actor::ScriptCalling (CLuaVirtualMachine& vm,  int iFunctionNumber){
	switch (iFunctionNumber - m_iMethodBase)
	{
		case 0:
			return lget_x(vm);
			break;
		
		case 1:
			return lget_y(vm);
			break;
		
		case 2:
			return lget_w(vm);
			break;
			
		case 3:
			return lget_h(vm);
			break;
			
		case 4:
			return lget_clip_x(vm);
			break;
			
		case 5:
			return lget_clip_y(vm);
			break;
			
		case 6:
			return lget_currentframe(vm);
			break;
			
		case 7:
			return lget_oldclip(vm);
			break;
			
		case 8:
			return lget_vertical_speed(vm);
			break;
			
		case 9:
			return lget_falltime(vm);
			break;
			
		case 10:
			return lget_speed(vm);
			break;
			
		case 11:
			return lget_ownspeed(vm);
			break;
			
		case 12:
			return lget_totalspeed(vm);
			break;
		case 13:
			return lset_x(vm);
			break;
			
		case 14:
			return lset_y(vm);
			break;
			
		case 15:
			return lset_w(vm);
			break;
			
		case 16:
			return lset_h(vm);
			break;
			
		case 17:
			return lset_clip_x(vm);
			break;
			
		case 18:
			return lset_clip_y(vm);
			break;
			
		case 19:
			return lset_currentframe(vm);
			break;
			
		case 20:
			return lset_oldclip(vm);
			break;
			
		case 21:
			return lset_vertical_speed(vm);
			break;
			
		case 22:
			return lset_falltime(vm);
			break;
			
		case 23:
			return lset_speed(vm);
			break;
			
		case 24:
			return lset_ownspeed(vm);
			break;
			
		case 25:
			return lset_totalspeed(vm);
			break;
			
		case 26:
			return lget_currentdirection(vm);
			break;
			
		case 27:
			return lset_currentdirection(vm);
			break;
			
		case 28:
			return lcan_move(vm);
			break;
			
		case 29:
			return lget_collision(vm);
			break;
			
		case 30:
			return lset_collision(vm);
			break;
			
		case 31:
			return lget_map_sx(vm);
			break;
			
		case 32:
			return lget_map_sy(vm);
			break;
			
		case 33:
			return lset_map_sx(vm);
			break;
			
		case 34:
			return lset_map_sy(vm);
			break;
			
		case 35:
			return lget_cfg_max_map_w(vm);
			break;
			
		case 36:
			return lget_cfg_max_map_h(vm);
			break;
			
		case 37:
			return lget_cfg_screen_width(vm);
			break;
			
		case 38:
			return lget_cfg_screen_height(vm);
			break;
			
		case 39:
			return lget_leftkey(vm);
			break;
			
		case 40:
			return lget_rightkey(vm);
			break;
			
		case 41:
			return lget_zkey(vm);
			break;
			
		case 42:
			return lget_xkey(vm);
			break;
			
		case 43:
			return lget_jumplock(vm);
			break;
			
		case 44:
			return lget_shootlock(vm);
			break;
			
		case 45:
			return lset_jumplock(vm);
			break;
			
		case 46:
			return lset_shootlock(vm);
			break;
			
		case 47:
			return lset_dying(vm);
			break;
			
		case 48:
			return ladd_bullet(vm);
			break;
			
		case 49:
			return lget_shotcount(vm);
			break;
		
		case 50:
			return lset_physics(vm);
			break;
			
		case 51:
			return lset_enemy(vm);
			break;
			
		case 52:
			return lset_controllable(vm);
			break;
			
		case 53:
			return lget_ckey(vm);
			break;
			
		case 54:
			return lget_switchlock(vm);
			break;
			
		case 55:
			return lset_switchlock(vm);
			break;
			
		case 56:
			return lset_noclip(vm);
			break;
			
		case 57:
			return lload_clip(vm);
			break;
			
		case 58:
			return lplay_sfx(vm);
			break;
			
		case 59:
			return lplay_bgm(vm);
			break;
			
		case 60:
			return lstop_bgm(vm);
			break;
            
        case 61:
			return lget_cfg_tile_w(vm);
			break;
			
		case 62:
			return lget_cfg_tile_h(vm);
			break;
        case 63:
			return laccelerate(vm);
			break;
        case 64:
			return lget_walk_time(vm);
			break;
        case 65:
			return lset_walk_time(vm);
			break;
        case 66:
			return ldecelerate(vm);
			break;
	}
	return 0;
   }

void Actor::HandleReturns (CLuaVirtualMachine& vm, const char *strFunc){
	
}

void Actor::animate(){
	
	//check for conditions.
	if (ownspeed != 0) {
		animating = true;
	}else{
		animating = false;
	}
	
	
	//then do stuff
	if (animating) {
		if(currentframe <= MOVEMENT_FREQ){
			currentframe++;
		}else{
			currentframe = 0;
		}
		
		if(currentframe==0){
			if(clip_x >= (w*SPRITE_FRAMES_W)-w){
				animup = false;               
			}
			if(clip_x == 0){
				animup = true;
			}
			if(animup){clip_x += w;}else{ clip_x -= w;}
		}   
	}
}

void Actor::move(){
	if (!colliding[DOWN]) {
		speed = 0;
	}
	totalspeed = speed + ownspeed;
	if (noclip) {
		x += totalspeed;
	}else{
		if (totalspeed > 0 &&  this->can_move(RIGHT, x, y) ) {
			x += totalspeed;
		}
		if (totalspeed < 0 &&  this->can_move(LEFT, x, y) ) {
			x += totalspeed;
		}
	}
}

bool Actor::can_move(Direction direction, int xpos, int ypos){
	if(direction == UP){
		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]){
			return false;
		}
	}
	if(direction == RIGHT){
		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]){
			return false;
		}
	}
	if(direction == DOWN){
		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]){
			return false;
		}
	}
	if(direction == LEFT){
		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]){
			return false;
		}
	}
	return true;
}

bool Actor::can_die(){

	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){
		return true;
	}
	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){
		return true;
	}
	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){
		return true;
	}
	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){
		return true;
	}
	return false;
}

void Actor::add_bullet(const char* sprite, const char* script){
	shotcount++;
	if (currentdirection == LEFT) {
		new Actor(x-14, y+10,sprite, script, this, LEFT, false, currentmap, audio, overwatch, m_vm);
	}
	if (currentdirection == RIGHT) {
		new Actor(x+w+4, y+10,sprite, script, this, RIGHT, false, currentmap, audio, overwatch, m_vm);
	}
}

void Actor::remove_bullet(){
	shotcount--;
}

void Actor::accelerate(float accel, float max_speed){
    
    if ( (accel > 0 && ownspeed == max_speed && max_speed < 0) || (accel < 0 && ownspeed == max_speed && max_speed > 0) ){
        walk_time = 0;
    }
    
    //reset the time if we were deccelerating.
    if (walk_time < 0) {
        walk_time = 0;
    }
    
    walk_time += 1; //increase the time, because we are accelerating.
    
    if((ownspeed >= max_speed && max_speed > 0) || (ownspeed <= max_speed && max_speed < 0)){
        ownspeed = max_speed;
    }else{
        ownspeed = ownspeed + accel*walk_time;
    }
}

void Actor::decelerate(float accel){
    if(ownspeed != 0 && falltime == 0){
        if (walk_time > 0) {
            walk_time = 0;
        }
        walk_time -= 1; //increase the time, because we are accelerating.
        
        //Stay at 0
        if (ownspeed > 0) {
            ownspeed = ownspeed + accel*walk_time;
            if (ownspeed < 0){
                ownspeed = 0;       //if we go too far, just settle with 0.
            }
        }
        if (ownspeed < 0) {
            ownspeed = ownspeed - accel*walk_time;
            if (ownspeed > 0){
                ownspeed = 0;       //if we go too far, just settle with 0.
            }
        }
    }
}

//internal accessors

int Actor::get_x(void){ return x; }
void Actor::set_x(int newval){ x = newval; }
int Actor::get_y(void){ return y; }
void Actor::set_y(int newval){ y = newval; }
int Actor::get_w(void){ return w; }
void Actor::set_w(int newval){ w = newval; }
int Actor::get_h(void){ return h; }
void Actor::set_h(int newval){ h = newval; }
int Actor::get_clip_x(void){ return clip_x; }
void Actor::set_clip_x(int newval){ clip_x = newval; }
int Actor::get_clip_y(void){ return clip_y; }
void Actor::set_clip_y(int newval){ clip_y = newval; }
int Actor::get_currentframe(void){ return currentframe; }
void Actor::set_currentframe(int newval){ currentframe = newval; }
int Actor::get_oldclip(void){ return oldclip; }
void Actor::set_oldclip(int newval){ oldclip = newval; }
float Actor::get_vertical_speed(void){ return vertical_speed; }
void Actor::set_vertical_speed(float newval){ vertical_speed = newval;}
float Actor::get_vertical_acc(void){ return vertical_acc; }
void Actor::set_vertical_acc(float newval){ vertical_acc = newval;}
float Actor::get_falltime(void){ return falltime; }
void Actor::set_falltime(float newval){ falltime = newval; }
SDL_Surface * Actor::get_sprite(void){ return sprite; }
float Actor::get_speed(void){ return speed; }
void Actor::set_speed(float newval){ speed = newval;}
float Actor::get_ownspeed(void){ return ownspeed; }
void Actor::set_ownspeed(float newval){ ownspeed = newval;}
float Actor::get_totalspeed(void){ return totalspeed; }
void Actor::set_totalspeed(float newval){ totalspeed = newval;}
float Actor::get_horizontal_acc(void){ return vertical_acc; }
void Actor::set_horizontal_acc(float newval){ vertical_acc = newval;}
Direction Actor::get_currentdirection(void){ return currentdirection; }
Enemy Actor::get_enemy(void){ return enemy; }
int Actor::get_leftkey(void){ return leftkey; }
void Actor::set_leftkey(int newval){ leftkey = newval; }
int Actor::get_rightkey(void){ return rightkey; }
void Actor::set_rightkey(int newval){ rightkey = newval; }
int Actor::get_zkey(void){ return zkey; }
void Actor::set_zkey(int newval){ zkey = newval; }
int Actor::get_xkey(void){ return xkey; }
void Actor::set_xkey(int newval){ xkey = newval; }
bool Actor::get_physics(void){ return physics; }
void Actor::set_physics(bool newval){ physics = newval; }
void Actor::set_collision(bool col, int corner){
	colliding[corner] = col;
}
bool Actor::get_controllable(void){ return controllable; }
bool Actor::get_collision(int corner){
	return colliding[corner];
}
bool Actor::get_dying(void){ return dying; }
void Actor::set_dying(bool newval){ dying = newval; }
void Actor::set_ckey(int newval){ ckey = newval; }
bool Actor::get_noclip(void){ return noclip; }

//lua accessors (get)
int Actor::lget_x(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, x);
	return 1;
}

int Actor::lget_y(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, y);
	return 1;
}

int Actor::lget_w(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, w);
	return 1;
}

int Actor::lget_h(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, h);
	return 1;
}

int Actor::lget_clip_x(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, clip_x);
	return 1;
}

int Actor::lget_clip_y(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, clip_y);
	return 1;
}

int Actor::lget_currentframe(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, currentframe);
	return 1;
}

int Actor::lget_oldclip(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, oldclip);
	return 1;
}

int Actor::lget_vertical_speed(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, vertical_speed);
	return 1;
}

int Actor::lget_falltime(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, falltime);
	return 1;
}

int Actor::lget_speed(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, speed);
	return 1;
}

int Actor::lget_ownspeed(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, ownspeed);
	return 1;
}

int Actor::lget_totalspeed(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, totalspeed);
	return 1;
}

int Actor::lget_currentdirection(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, currentdirection);
	return 1;
}

int Actor::lget_collision(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushboolean (state, colliding[(int) lua_tonumber (state, -1)]);
	return 1;
}

int Actor::lget_map_sx(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, currentmap->get_sx());
	return 1;
}

int Actor::lget_map_sy(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, currentmap->get_sy());
	return 1;
}

int Actor::lget_cfg_max_map_w(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, MAX_MAP_W);
	return 1;
}

int Actor::lget_cfg_max_map_h(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, MAX_MAP_H);
	return 1;
}

int Actor::lget_cfg_tile_h(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, TILE_HEIGHT);
	return 1;
}

int Actor::lget_cfg_screen_height(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, SCREEN_HEIGHT);
	return 1;
}

int Actor::lget_leftkey(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, leftkey);
	return 1;
}

int Actor::lget_rightkey(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, rightkey);
	return 1;
}

int Actor::lget_zkey(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, zkey);
	return 1;
}

int Actor::lget_xkey(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, xkey);
	return 1;
}

int Actor::lget_jumplock(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushboolean (state, jumplock);
	return 1;
}

int Actor::lget_shootlock(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushboolean (state, shootlock);
	return 1;
}

int Actor::lget_shotcount(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, shotcount);
	return 1;
}

int Actor::lget_ckey(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, ckey);
	return 1;
}

int Actor::lget_switchlock(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushboolean (state, switchlock);
	return 1;
}

int Actor::lget_cfg_tile_w(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, TILE_WIDTH);
	return 1;
}

int Actor::lget_cfg_screen_width(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, SCREEN_WIDTH);
	return 1;
}

int Actor::lget_walk_time(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushnumber (state, walk_time);
	return 1;
}

//lua accessors (set)
int Actor::lset_x(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	x = (int) lua_tonumber (state, -1);
	return 0;
}

int Actor::lset_y(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	y = (int) lua_tonumber (state, -1);
	return 0;
}

int Actor::lset_w(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	w = (int) lua_tonumber (state, -1);
	return 0;
}

int Actor::lset_h(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	h = (int) lua_tonumber (state, -1);
	return 0;
}

int Actor::lset_clip_x(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	clip_x = (int) lua_tonumber (state, -1);
	return 0;
}

int Actor::lset_clip_y(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	clip_y = (int) lua_tonumber (state, -1);
	return 0;
}

int Actor::lset_currentframe(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	currentframe = (int) lua_tonumber (state, -1);
	return 0;
}

int Actor::lset_oldclip(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	oldclip = (int) lua_tonumber (state, -1);
	return 0;
}

int Actor::lset_vertical_speed(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	vertical_speed = (float) lua_tonumber (state, -1);
	return 0;
}

int Actor::lset_falltime(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	falltime = (float) lua_tonumber (state, -1);
	return 0;
}

int Actor::lset_speed(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	speed = (float) lua_tonumber (state, -1);
	return 0;
}

int Actor::lset_ownspeed(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	ownspeed = (float) lua_tonumber (state, -1);
	return 0;
}

int Actor::lset_totalspeed(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	totalspeed = (float) lua_tonumber (state, -1);
	return 0;
}

int Actor::lset_currentdirection(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	currentdirection = (Direction) lua_tonumber (state, -1);
	return 0;
}

int Actor::lset_collision(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	colliding[(int) lua_tonumber (state, -1)] = (bool) lua_toboolean(state, -2);
	return 0;
}

int Actor::lset_map_sx(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	currentmap->set_sx((int) lua_tonumber (state, -1));
	return 0;
}

int Actor::lset_map_sy(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	currentmap->set_sy((int) lua_tonumber (state, -1));
	return 0;
}

int Actor::lset_jumplock(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	jumplock = (bool) lua_toboolean (state, -1);
	return 0;
}

int Actor::lset_shootlock(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	shootlock = (bool) lua_toboolean (state, -1);
	return 0;
}

int Actor::lset_dying(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	dying = (bool) lua_toboolean (state, -1);
	return 0;
}

int Actor::lset_physics(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	physics = (bool) lua_toboolean (state, -1);
	return 0;
}

int Actor::lset_enemy(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	enemy = (Enemy) lua_tonumber (state, -1);
	return 0;
}

int Actor::lset_controllable(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	controllable = (bool) lua_toboolean (state, -1);
	return 0;
}

int Actor::lset_switchlock(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	switchlock = (bool) lua_toboolean (state, -1);
	return 0;
}

int Actor::lset_noclip(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	noclip = (bool) lua_toboolean (state, -1);
	return 0;
}

int Actor::lset_walk_time(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	walk_time = (int) lua_tonumber (state, -1);
	return 0;
}


//misc lua methods

int Actor::lcan_move(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;
	lua_pushboolean(state,this->can_move((Direction) lua_tonumber (state, -3), (int) lua_tonumber (state, -2), (int) lua_tonumber (state, -1)));
	return 1;	
}

int Actor::ladd_bullet(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;	
	this->add_bullet((const char*) lua_tostring (state, -2), (const char*) lua_tostring (state, -1));
	return 1;
}

int Actor::lload_clip(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;	
	audio->load_clip((const char*) lua_tostring (state, -1));
	return 1;
}

int Actor::lplay_sfx(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;	
	audio->play_sfx((const char*) lua_tostring (state, -1));
	return 1;
}

int Actor::lplay_bgm(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;	
	audio->play_bgm((const char*) lua_tostring (state, -1));
	return 1;
}

int Actor::lstop_bgm(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;	
	audio->stop_bgm((const char*) lua_tostring (state, -1));
	return 1;
}

int Actor::laccelerate(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;	
	this->accelerate((float)  lua_tonumber (state, -2), (float)  lua_tonumber (state, -1));
	return 1;
}

int Actor::ldecelerate(CLuaVirtualMachine& vm){
	lua_State *state = (lua_State *) vm;	
	this->decelerate((float)  lua_tonumber (state, -1));
	return 1;
}