aboutsummaryrefslogtreecommitdiff
path: root/actor.cpp
diff options
context:
space:
mode:
authorBen Beltran <ben@nsovocal.com>2012-04-16 09:39:52 -0500
committerBen Beltran <ben@nsovocal.com>2012-04-16 09:39:52 -0500
commit10a0e290ac07524dc129cc2b227b0f9e95df0f8e (patch)
treeed518c45c45d96e37e28640f745496fffb8e1325 /actor.cpp
first commit
Diffstat (limited to 'actor.cpp')
-rwxr-xr-xactor.cpp1020
1 files changed, 1020 insertions, 0 deletions
diff --git a/actor.cpp b/actor.cpp
new file mode 100755
index 0000000..12e5353
--- /dev/null
+++ b/actor.cpp
@@ -0,0 +1,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;
+} \ No newline at end of file