Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------- weaponlib v1.5 - (c) 2011 xerpi -------------------------
- weapon={}
- function weapon.create(tableimg,vel,tiempo)
- weaponobj = {img={},size={width={},height={}}, tim = tiempo, tim_act = timer.new(),vel = vel , status = "stop",current=1,maxshoots=100}
- weaponobj.img["up"] = tableimg["up"] or "none"
- weaponobj.img["down"] = tableimg["down"] or "none"
- weaponobj.img["right"] = tableimg["right"] or "none"
- weaponobj.img["left"] = tableimg["left"] or "none"
- weaponobj.size.width["up"] = (tableimg["up"] or image.create(0,0) ):width() or 0
- weaponobj.size.width["down"] = (tableimg["down"] or image.create(0,0) ):width() or 0
- weaponobj.size.width["right"] = (tableimg["right"] or image.create(0,0) ):width() or 0
- weaponobj.size.width["left"] = (tableimg["left"] or image.create(0,0) ):width() or 0
- weaponobj.size.height["up"] = (tableimg["up"] or image.create(0,0) ):height() or 0
- weaponobj.size.height["down"] = (tableimg["down"] or image.create(0,0) ):height() or 0
- weaponobj.size.height["right"] = (tableimg["right"] or image.create(0,0) ):height() or 0
- weaponobj.size.height["left"] = (tableimg["left"] or image.create(0,0) ):height() or 0
- weaponobj.bullets={
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},
- {x=0,y=0,dir="",status="dead"}, {x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"},{x=0,y=0,dir="",status="dead"}
- }
- return weaponobj
- end
- function weapon.toblit(obj,num)
- if obj and obj.bullets[num].status == "alive" and obj.img[obj.bullets[num].dir] != "none" then
- local direction = obj.bullets[num].dir
- obj.img[obj.bullets[num].dir]:blit(obj.bullets[num].x,obj.bullets[num].y)
- if obj.bullets[num].dir == "up" then
- obj.bullets[num].y = obj.bullets[num].y - obj.vel;
- elseif obj.bullets[num].dir == "down" then
- obj.bullets[num].y = obj.bullets[num].y + obj.vel;
- elseif obj.bullets[num].dir == "right" then
- obj.bullets[num].x = obj.bullets[num].x + obj.vel;
- elseif obj.bullets[num].dir == "left" then
- obj.bullets[num].x = obj.bullets[num].x - obj.vel;
- end
- if obj.bullets[num].y+obj.size.height[direction] < 0 or obj.bullets[num].y >272 or obj.bullets[num].x+obj.size.width[direction] < 0 or obj.bullets[num].x >480 then
- obj.bullets[num].status = "dead"
- end
- end
- end
- function weapon.tocoll(obj,num,x,y,w,h,deadcollision)
- local cw, ch = obj.size.width[obj.bullets[num].dir], obj.size.height[obj.bullets[num].dir]
- if obj.bullets[num].status == "alive" then
- if obj.bullets[num].x + cw >= x and obj.bullets[num].x <= x+w and
- obj.bullets[num].y + ch >= y and obj.bullets[num].y <= y+h then
- if deadcollision then obj.bullets[num].status = "dead" end
- return true
- end
- end
- end
- function weapon.blit(obj)
- weapon.toblit(obj,1) weapon.toblit(obj,2) weapon.toblit(obj,3) weapon.toblit(obj,4) weapon.toblit(obj,5)
- weapon.toblit(obj,6) weapon.toblit(obj,7) weapon.toblit(obj,8) weapon.toblit(obj,9) weapon.toblit(obj,10)
- weapon.toblit(obj,11) weapon.toblit(obj,12) weapon.toblit(obj,13) weapon.toblit(obj,14) weapon.toblit(obj,15)
- weapon.toblit(obj,16) weapon.toblit(obj,17) weapon.toblit(obj,18) weapon.toblit(obj,19) weapon.toblit(obj,20)
- weapon.toblit(obj,21) weapon.toblit(obj,22) weapon.toblit(obj,23) weapon.toblit(obj,24) weapon.toblit(obj,25)
- weapon.toblit(obj,26) weapon.toblit(obj,27) weapon.toblit(obj,28) weapon.toblit(obj,29) weapon.toblit(obj,30)
- weapon.toblit(obj,31) weapon.toblit(obj,32) weapon.toblit(obj,33) weapon.toblit(obj,34) weapon.toblit(obj,35)
- weapon.toblit(obj,36) weapon.toblit(obj,37) weapon.toblit(obj,38) weapon.toblit(obj,39) weapon.toblit(obj,40)
- weapon.toblit(obj,41) weapon.toblit(obj,42) weapon.toblit(obj,43) weapon.toblit(obj,44) weapon.toblit(obj,45)
- weapon.toblit(obj,46) weapon.toblit(obj,47) weapon.toblit(obj,48) weapon.toblit(obj,49) weapon.toblit(obj,50)
- weapon.toblit(obj,51) weapon.toblit(obj,52) weapon.toblit(obj,53) weapon.toblit(obj,54) weapon.toblit(obj,55)
- weapon.toblit(obj,56) weapon.toblit(obj,57) weapon.toblit(obj,58) weapon.toblit(obj,59) weapon.toblit(obj,60)
- weapon.toblit(obj,61) weapon.toblit(obj,62) weapon.toblit(obj,63) weapon.toblit(obj,64) weapon.toblit(obj,65)
- weapon.toblit(obj,66) weapon.toblit(obj,67) weapon.toblit(obj,68) weapon.toblit(obj,69) weapon.toblit(obj,70)
- weapon.toblit(obj,71) weapon.toblit(obj,72) weapon.toblit(obj,73) weapon.toblit(obj,74) weapon.toblit(obj,75)
- weapon.toblit(obj,76) weapon.toblit(obj,77) weapon.toblit(obj,78) weapon.toblit(obj,79) weapon.toblit(obj,80)
- weapon.toblit(obj,81) weapon.toblit(obj,82) weapon.toblit(obj,83) weapon.toblit(obj,84) weapon.toblit(obj,85)
- weapon.toblit(obj,86) weapon.toblit(obj,87) weapon.toblit(obj,88) weapon.toblit(obj,89) weapon.toblit(obj,90)
- weapon.toblit(obj,91) weapon.toblit(obj,92) weapon.toblit(obj,93) weapon.toblit(obj,94) weapon.toblit(obj,95)
- weapon.toblit(obj,96) weapon.toblit(obj,97) weapon.toblit(obj,98) weapon.toblit(obj,99) weapon.toblit(obj,100)
- end
- function weapon.shoot(obj,x,y,dir,funct,sonido)
- if obj.status == "stop" then obj.status = "run" obj.tim_act:start() end
- if obj.status == "run" then
- if obj.tim_act:time() >= obj.tim then
- if sonido then sonido:play() end
- obj.bullets[obj.current]={x=x,y=y,dir=dir,status="alive"}
- obj.current=obj.current+1
- if obj.current >obj.maxshoots then obj.current = 1 end
- obj.tim_act:reset()
- if funct then funct() end
- end
- end
- end
- function weapon.collision(obj,x,y,w,h,deadcollision)
- if weapon.tocoll(obj,1,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,2,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,3,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,4,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,5,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,6,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,7,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,8,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,9,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,10,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,11,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,12,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,13,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,14,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,15,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,16,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,17,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,18,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,19,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,20,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,21,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,22,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,23,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,24,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,25,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,26,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,27,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,28,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,29,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,30,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,31,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,32,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,33,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,34,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,35,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,36,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,37,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,38,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,39,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,40,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,41,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,42,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,43,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,44,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,45,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,46,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,47,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,48,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,49,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,50,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,51,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,52,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,53,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,54,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,55,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,56,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,57,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,58,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,59,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,60,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,61,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,62,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,63,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,64,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,65,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,66,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,67,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,68,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,69,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,70,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,71,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,72,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,73,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,74,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,75,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,76,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,77,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,78,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,79,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,80,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,81,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,82,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,83,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,84,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,85,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,86,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,87,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,88,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,89,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,90,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,91,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,92,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,93,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,94,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,95,x,y,w,h,deadcollision) then return true end
- if weapon.tocoll(obj,96,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,97,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,98,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,99,x,y,w,h,deadcollision) then return true end if weapon.tocoll(obj,100,x,y,w,h,deadcollision) then return true end
- end
- function weapon.action(obj,action)
- if action == "start" then obj.status = "run" obj.tim_act:start() end
- if action == "stop" then obj.status = "stop" obj.tim_act:reset() obj.tim_act:stop() end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement