diff options
| author | Ben Beltran <ben@nsovocal.com> | 2012-04-16 09:39:52 -0500 |
|---|---|---|
| committer | Ben Beltran <ben@nsovocal.com> | 2012-04-16 09:39:52 -0500 |
| commit | 10a0e290ac07524dc129cc2b227b0f9e95df0f8e (patch) | |
| tree | ed518c45c45d96e37e28640f745496fffb8e1325 /scripts/main_actor.lua | |
first commit
Diffstat (limited to 'scripts/main_actor.lua')
| -rw-r--r-- | scripts/main_actor.lua | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/scripts/main_actor.lua b/scripts/main_actor.lua new file mode 100644 index 0000000..07b5f4d --- /dev/null +++ b/scripts/main_actor.lua @@ -0,0 +1,112 @@ +--Configuration for the Main Actor +this.actorname = "Main Character" +this.enemy = enemy_neutral +this.controllable = true +this.jumpstrength = 14 +this.speed = 6 +this.shotlimit = 3 +this.physics = true +this.currentweapon = 0 + +--Experimental Configuration for new Physics Engine. +this.jump_strength = 10 +this.walk_speed = 10 +this.walk_acc = .1 + +print(">>> Entity Created - "..this.actorname); + +function this.jump(this) + if not this:get_jumplock() + --and this:can_move(up,this:get_x()-this:get_ownspeed(),this:get_y()+this:get_vertical_speed()) + and not this:can_move(down,this:get_x()-this:get_ownspeed(),this:get_y()) then + this:set_vertical_speed(this:get_vertical_speed()-this.jumpstrength) + end +end + +function this.centermap(this) + + + --This is the map center. Set it. + this:set_map_sx(this:get_x() - this:get_cfg_screen_width()/2) + this:set_map_sy(this:get_y() - this:get_cfg_screen_height()/2) + + --Unless of course we're at one of the edges. + if this:get_map_sx() < 0 then + this:set_map_sx(0) + elseif this:get_map_sx() + this:get_cfg_screen_width() >= this:get_cfg_max_map_w()*this:get_cfg_tile_w() then + this:set_map_sx(this:get_cfg_max_map_w()*this:get_cfg_tile_w() - this:get_cfg_screen_width()) + end + + if this:get_map_sy() < 0 then + this:set_map_sy(0) + elseif this:get_map_sy() + this:get_cfg_screen_height() >= this:get_cfg_max_map_h()*this:get_cfg_tile_h() then + this:set_map_sy(this:get_cfg_max_map_h()*this:get_cfg_tile_h() - this:get_cfg_screen_height()) + end +end + +function this.handleinput(this) + if (this:get_leftkey() > 0 and (this:get_leftkey() > this:get_rightkey() or this:get_rightkey() == 0)) then + this:accelerate(-this.walk_acc, -this.walk_speed) + --this:set_ownspeed(-this.speed) + this:set_oldclip(1) + this:set_currentdirection(left) + end + + if (this:get_rightkey() > 0 and (this:get_rightkey() > this:get_leftkey() or this:get_leftkey() == 0)) then + this:accelerate(this.walk_acc, this.walk_speed) + --this:set_ownspeed(this.speed) + this:set_oldclip(2) + this:set_currentdirection(right) + end + + if (this:get_rightkey() == 0 and this:get_leftkey() == 0) then + this:decelerate(this.walk_acc) + --this:set_ownspeed(0) + --this:set_walk_time(0) + end + + if (this:get_xkey() > 0) then + if not this:get_jumplock() then + this:jump() + this:set_jumplock(true) + end + else + this:set_jumplock(false) + if(this:get_vertical_speed() < -1) then + this:set_vertical_speed(-1) + end + end + + if (this:get_zkey() > 0) then + if not this:get_shootlock() and this:get_shotcount() < this.shotlimit then + if this.currentweapon == 0 then + this:add_bullet("./sprites/shotsprite.png","./scripts/shot.lua") + end + if this.currentweapon == 1 then + this:add_bullet("./sprites/shotsprite.png","./scripts/shot-crawl.lua") + end + if this.currentweapon == 2 then + this:add_bullet("./sprites/shotsprite.png","./scripts/shot-wave.lua") + end + this:set_shootlock(true) + end + else + this:set_shootlock(false) + end + + if (this:get_ckey() > 0) then + if not this:get_switchlock() then + this.currentweapon = (this.currentweapon + 1) % 3 + print ("current weapon is: "..this.currentweapon) + this:set_switchlock(true) + end + else + this:set_switchlock(false) + end +end + +function this.act(this) + this:centermap() + this:handleinput() +end +--END
\ No newline at end of file |