Advertisement
xerpi

ee

Jul 30th, 2011
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.39 KB | None | 0 0
  1. function reiniciar()
  2. objetos:reset()
  3. vida1=50
  4. vida2=50
  5. juga1.x=20
  6. juga1.y=166
  7. juga2.x=400
  8. juga2.y=140
  9. end
  10.  
  11. --Los colores
  12. rojo=color.new(255,0,0)
  13. amarillo=color.new(255,255,0)
  14. verde=color.new(0,255,0)
  15. negro= color.new(0,0,0)
  16. azul=color.new(0,0,255)
  17. --Menu
  18. elegida=1
  19. tam=1.35
  20. --Opciones
  21. selec=1
  22.  
  23. explosion = anim.create("explosion.gif")
  24. explosion:start()
  25. mina=image.create(5,5, amarillo)
  26.  
  27. --Cargamos los sprites de los jugadores
  28. P1 = image.load("up1.png")
  29. P2 = image.load("right1.png")
  30. P3 = image.load("down1.png")
  31. P4 = image.load("left1.png")
  32.  
  33. J1 = image.load("up2.png")
  34. J2 = image.load("right2.png")
  35. J3 = image.load("down2.png")
  36. J4 = image.load("left2.png")
  37.  
  38. current = P1
  39. actual = J1
  40.  
  41. --Elegimos las posiciones de los muros
  42. muro1= {x=0,y=50,w=480,h=4}
  43. muro2= {x=350,y=130,w=4,h=100}
  44. muro3= {x=350,y=130,w=130,h=4}
  45. muro4= {x=60,y=120,w=4,h=40}
  46. muro5= {x=60,y=160,w=60,h=4}
  47. muro6= {x=120,y=160,w=4,h=120}
  48. muro7={x=0,y=50,w=4,h=222}
  49. muro8={x=476,y=50,w=4,h=222}
  50. muro9={x=0,y=268,w=480,h=4}
  51. muro10={x=240, y=180, w=50, h=4}
  52. --Posiciones de los jugadores
  53. juga1 = {x=20,y=166,w=32,h=32, oldx=0, oldy=0}
  54. juga2 = {x=400,y=140,w=32,h=32, oldx=0, oldy=0}
  55.  
  56. --Parametros
  57. vida1=50
  58. vida2=50
  59.  
  60. --fondo
  61. suelo = image.load("suelo.png")
  62. municion= image.load("municion.png")
  63. salud=image.load("salud.png")
  64. caja1= {x=250, y=190, w=20, h=20, estado=0}
  65. caja2= {x=250, y=190, w=20, h=20, estado=0}
  66. caja3= {x=250, y=160, w=20, h=20, estado=0}
  67. caja4= {x=250, y=160, w=20, h=20, estado=0}
  68.  
  69. ganadas1=0
  70. ganadas2=0
  71.  
  72.  
  73. function arma()
  74. Armas1={"Magnum","Rifle","Metralleta","Lanzamisiles"}
  75. Armas2={"Magnum","Rifle","Metralleta","Lanzamisiles"}
  76. var=1;
  77. vor=1;
  78.  while true do
  79.  controls.read()
  80. if controls.press("left") then var=var-1 elseif controls.press("right") then var=var+1 end
  81. if controls.press("square") then vor=vor-1 elseif controls.press("circle") then vor=vor+1 end
  82. if var>4 then var=1 elseif var<1 then var=4 end
  83. if vor>4 then vor=1 elseif vor<1 then vor=4 end
  84.  
  85. screen.print(160,50,"<--- "..Armas1[var].." --->",1,rojo,0x0);
  86. screen.print(180,30,"Jugador 1 ",verde)
  87. screen.print(165,80,"Partidas ganadas:  " .. ganadas1, rojo)
  88.  
  89. screen.print(160,190,"<--- "..Armas2[vor].." --->",1,rojo,0x0);
  90. screen.print(180,160,"Jugador 2  ",verde)
  91. screen.print(165,220,"Partidas ganadas:  " .. ganadas2, rojo)
  92.  
  93. if controls.select() then multijugador() end
  94. screen.flip()
  95. end
  96. end
  97. function colision(obj1, obj2)
  98.     if obj1.x+obj1.w>obj2.x
  99.     and obj1.x<obj2.x+obj2.w
  100.     and obj1.y+obj1.h>obj2.y
  101.     and obj1.y<obj2.y+obj2.h then
  102.         return true
  103.     end
  104. return false
  105. end
  106.  
  107.  
  108.  
  109. function multijugador()
  110. objetos = timer.new() --Crea un temprizador
  111.  
  112. objetos:start() --Lo inicia
  113.  
  114. if var==1 then
  115. balas1=30
  116. tiempo1=12
  117. daño1=8
  118. movi1=3.25
  119. apariencia=image.create(5,5, amarillo)
  120. end
  121.  
  122. if var==2 then --Rifle
  123. balas1=20
  124. tiempo1=18
  125. daño1=15
  126. movi1=2.5
  127. apariencia=image.create(5,10, amarillo)
  128.  
  129. end
  130. if var==3 then --Metralleta
  131. balas1=50
  132. tiempo1=14
  133. daño1=6
  134. movi1=2.25
  135. apariencia=image.create(5,5, amarillo)
  136. end
  137. if var==4 then
  138. balas1=7
  139. tiempo1=8
  140. daño1=30
  141. movi1=2
  142. apariencia=image.load("der.png")
  143.  
  144. end
  145.  
  146.  
  147. if vor==1 then
  148. balas2=30
  149.  
  150. tiempo2=12
  151. daño2=8
  152. movi2=3.25
  153. detal=image.create(5,5, amarillo)
  154.  
  155. end
  156.  
  157. if vor==2 then --Rifle
  158. balas2=20
  159. tiempo2=18
  160. daño2=15
  161. movi2=2.5
  162. detal=image.create(5,10, amarillo)
  163. end
  164.  
  165. if vor==3 then --Metralleta
  166. balas2=50
  167. tiempo2=14
  168. daño2=6
  169. movi2=2.25
  170. detal=image.create(5,5, amarillo)
  171. end
  172.  
  173. if vor==4 then
  174. balas2=7
  175. tiempo2=8
  176. daño2=30
  177. movi2=2
  178. detal=image.load("der.png")
  179. end
  180.  
  181.  
  182.  
  183. ver1=image.create(5,5, verde)
  184.  
  185.  
  186. --Accion de disparar
  187. disparo1 =  weapon.create(apariencia,tiempo1)
  188. weapon.action(disparo1,"start")
  189. disparo2 =  weapon.create(detal,tiempo2)
  190. weapon.action(disparo2,"start")
  191. disparo3 =  weapon.create(apariencia,0)
  192. weapon.action(disparo3,"start")
  193.  
  194. disparo4 =  weapon.create(detal,0)
  195. weapon.action(disparo4,"start")
  196.  
  197.  
  198. while true do
  199. controls.read()
  200. juga1.oldx=juga1.x
  201. juga1.oldy=juga1.y
  202. juga2.oldx=juga2.x
  203. juga2.oldy=juga2.y
  204.  
  205. for a = 0, 14 do
  206. for b = 1.57,8 do
  207. suelo:blit(32 * a, 32 * b)
  208. end
  209. end
  210.  
  211.  
  212. if controls.triangle() and vida2>=0 and vida1>=0 then actual =J1 juga2.y=juga2.y-movi2
  213. elseif controls.cross() and vida2>=0 and vida1>=0 then actual =J3 juga2.y=juga2.y+movi2
  214. elseif controls.circle() and vida2>=0 and vida1>=0 then actual =J2 juga2.x=juga2.x+movi2
  215. elseif controls.square() and vida2>=0 and vida1>=0 then actual =J4 juga2.x=juga2.x-movi2 end
  216.  
  217. if controls.press("select") and vida1>0 and vida2>=0 then weapon.shoot(disparo4,juga2.x+10,juga2.y+20,"up") end
  218. if controls.press("r") and actual==J1 and vida2>=0 and vida1>=0 and balas2>0 then balas2=balas2-1 weapon.shoot(disparo2,juga2.x+10,juga2.y,"up") end
  219. if controls.press("r") and actual==J2 and vida2>=0 and vida1>=0 and balas2>0 then balas2=balas2-1 weapon.shoot(disparo2,juga2.x+25,juga2.y+10,"right") end
  220. if controls.press("r") and actual==J3 and vida2>=0 and vida1>=0 and balas2>0 then balas2=balas2-1 weapon.shoot(disparo2,juga2.x+10,juga2.y+25,"down") end
  221. if controls.press("r") and actual==J4 and vida2>=0 and vida1>=0 and balas2>0 then balas2=balas2-1 weapon.shoot(disparo2,juga2.x,juga2.y+10,"left") end
  222.  
  223. if controls.analogy()>120 and vida1>0 and vida2>=0 then weapon.shoot(disparo3,juga1.x+10,juga1.y+20,"up") end
  224. if controls.press("l") and current==P1 and vida2>=0 and vida1>=0 and balas1>0 then balas1=balas1-1 weapon.shoot(disparo1,juga1.x+10,juga1.y,"up") end
  225. if controls.press("l") and current==P2 and vida2>=0 and vida1>=0 and balas1>0 then balas1=balas1-1 weapon.shoot(disparo1,juga1.x+25,juga1.y+10,"right") end
  226. if controls.press("l") and current==P3 and vida2>=0 and vida1>=0 and balas1>0 then balas1=balas1-1 weapon.shoot(disparo1,juga1.x+10,juga1.y+25,"down") end
  227. if controls.press("l") and current==P4 and vida2>=0 and vida1>=0 and balas1>0 then balas1=balas1-1 weapon.shoot(disparo1,juga1.x,juga1.y+10,"left") end
  228.  
  229. if controls.up() and vida2>=0 and vida1>=0 then current =P1 juga1.y=juga1.y-movi1
  230. elseif controls.down() and vida2>=0 and vida1>=0 then current =P3 juga1.y=juga1.y+movi1
  231. elseif controls.right() and vida2>=0 and vida1>=0 then current =P2 juga1.x=juga1.x+movi1
  232. elseif controls.left() and vida2>=0 and vida1>=0 then current =P4 juga1.x=juga1.x-movi1 end
  233.  
  234. if objetos:time()>12000 and objetos:time()<20000 and caja1.estado==0 then municion:blit(caja1.x,caja1.y) end
  235. if objetos:time()>30000 and objetos:time()<45000 and caja2.estado==0 then salud:blit(caja2.x,caja2.y) end
  236. if objetos:time()>50000 and objetos:time()<65000 and caja3.estado==0 then municion:blit(caja3.x,caja3.y) end
  237. if objetos:time()>75000 and objetos:time()<90000 and caja4.estado==0 then salud:blit(caja4.x,caja4.y) end
  238.  
  239.  
  240. --Mostrando personajes
  241. current:blit( juga1.x,juga1.y)
  242. actual:blit(juga2.x,juga2.y)
  243.  
  244.  
  245. --Mostrando la informacion sobre los jugadores
  246. screen.print(80,10, "Jugador 1:",rojo)
  247. screen.print(10,30, "Balas: " .. balas1, verde)
  248. screen.print(100,30, "Vida:",verde)
  249. screen.print(300,10, "Jugador 2 : ",rojo)
  250. screen.print(260,30, "Balas: " .. balas2, verde)
  251. screen.print(360,30, "Vida : ",verde)
  252. draw.fillrect(150,30,math.max(0,vida1),10,rojo)
  253. draw.rect(150,30,51,11,color.new(255,255,255))
  254. draw.fillrect(410,30,math.max(0,vida2),10,rojo)
  255. draw.rect(410,30,51,11,color.new(255,255,255))
  256.  
  257. --Los limites de la pantalla
  258. draw.fillrect(0,50,480,4,color.new(255,255,255))
  259. draw.fillrect(0,50,4,222,color.new(255,255,255))
  260. draw.fillrect(476,50,4,222,color.new(255,255,255))
  261. draw.fillrect(0,268,480,4,color.new(255,255,255))
  262.  
  263. --Los muros
  264. draw.fillrect(350,130,4,100,color.new(255,255,255))
  265. draw.fillrect(350,130,130,4,color.new(255,255,255))
  266. draw.fillrect(60,120,4,40,color.new(255,255,255))
  267. draw.fillrect(60,160,60,4,color.new(255,255,255))
  268. draw.fillrect(120,160,4,120,color.new(255,255,255))
  269. draw.fillrect(240,180,50,4,color.new(255,255,255))
  270.  
  271. --Mostramos las balas
  272. weapon.blit(disparo1)
  273. weapon.blit(disparo2)
  274. weapon.blit(disparo3)
  275. weapon.blit(disparo4)
  276.  
  277.  
  278. --Las colisiones:
  279.  
  280. --/De las balas del jugador 1
  281.  
  282. colision,x1,y1 = weapon.collision(disparo1, 0,50,480,4,true)
  283.  
  284. if colision then detal1=explosion:blit(x,y) end
  285. weapon.collision(disparo1,0,50,480,4,true)
  286. weapon.collision(disparo1,350,130,4,100,true)
  287. weapon.collision(disparo1,350,130,130,4,true)
  288. weapon.collision(disparo1,60,120,4,40,true)
  289. weapon.collision(disparo1,60,160,60,4,true)
  290. weapon.collision(disparo1,120,160,4,120,true)
  291. weapon.collision(disparo1,240,180,50,4,true)
  292. if weapon.collision(disparo1,juga2.x,juga2.y,32,32,true) then vida2=vida2-daño1 end
  293. if weapon.collision(disparo3,juga2.x,juga2.y,32,32,true) then vida2=vida2-1 end
  294.  
  295. --/De las balas del jugador 2
  296. weapon.collision(disparo2,0,50,480,4,true)
  297. weapon.collision(disparo2,350,130,4,100,true)
  298. weapon.collision(disparo2,350,130,130,4,true)
  299. weapon.collision(disparo2,60,120,4,40,true)
  300. weapon.collision(disparo2,60,160,60,4,true)
  301. weapon.collision(disparo2,120,160,4,120,true)
  302. weapon.collision(disparo2,240,180,50,4,true)
  303. --weapon.collision(disparo2,muro10,true)
  304. if weapon.collision(disparo2,juga1.x,juga1.y,32,32,true) then vida1=vida1-daño2 end
  305. if weapon.collision(disparo4,juga1.x,juga1.y,32,32,true) then vida1=vida1-1 end
  306.  
  307.  
  308.  
  309. if vida1>0 and vida2<=0 then screen.print(150,140, "Jugador 1 ha ganado") screen.print(150,160, "Pulsa X para reiniciar") end
  310. if vida2>0 and vida1<=0 then screen.print(150,140, "Jugador 2 ha ganado") screen.print(150,160, "Pulsa X para reiniciar") end
  311. if vida1<=0 and vida2<=0 then screen.print(200,140, "EMPATE") screen.print(150,160, "Pulsa X para reiniciar") end
  312.  
  313. if vida1<=0 and controls.cross() then ganadas2=ganadas2+1 reiniciar() arma() end
  314. if vida2<=0 and controls.cross() then ganadas1=ganadas1+1  reiniciar() arma() end
  315.  
  316. --/De los jugadores
  317. if objetos:time()>12000 and caja1.estado==0 and objetos:time()<20000 and colision (juga1,caja1) then balas1=balas1+2 balas1=balas1*2 caja1.estado=caja1.estado+1 end
  318. if objetos:time()>12000 and caja1.estado==0 and objetos:time()<20000 and colision (juga2,caja1) then balas2=balas2+2 balas2=balas2*2 caja1.estado=caja1.estado+1 end
  319. if objetos:time()>30000 and caja2.estado==0 and vida1<31 and objetos:time()<40000 and colision (juga1,caja2) then vida1=vida1+20 caja2.estado=caja2.estado+1 end
  320. if objetos:time()>30000 and caja2.estado==0 and vida2<31 and objetos:time()<50000 and colision (juga2,caja2) then vida2=vida1+20 caja2.estado=caja2.estado+1 end
  321.  
  322. if objetos:time()>50000 and caja3.estado==0 and objetos:time()<65000 and colision (juga1,caja3) then balas1=balas1+2 balas1=balas1*2  caja3.estado=caja1.estado+1 end
  323. if objetos:time()>50000 and caja3.estado==0 and objetos:time()<65000 and colision (juga2,caja3) then balas2=balas2 balas2=balas2*2 caja3.estado=caja1.estado+1 end
  324. if objetos:time()>75000 and caja4.estado==0 and vida1<31 and objetos:time()<90000 and colision (juga1,caja4) then vida1=vida1+20 caja4.estado=caja2.estado+1 end
  325. if objetos:time()>75000 and caja4.estado==0 and vida2<31 and objetos:time()<90000 and colision (juga2,caja4) then vida2=vida1+20 caja4.estado=caja2.estado+1 end
  326.  
  327.  
  328. if colision(juga1,muro1) then juga1.y=juga1.oldy juga1.x=juga1.oldx end
  329. if colision(juga1,muro2) then juga1.x=juga1.oldx juga1.y=juga1.oldy end
  330. if colision(juga1,muro3) then juga1.y=juga1.oldy juga1.x=juga1.oldx end
  331. if colision(juga1,muro4) then juga1.x=juga1.oldx juga1.y=juga1.oldy end
  332. if colision(juga1,muro5) then juga1.y=juga1.oldy juga1.x=juga1.oldx end
  333. if colision(juga1,muro6) then juga1.x=juga1.oldx juga1.y=juga1.oldy end
  334. if colision(juga1,muro7) then juga1.x=juga1.oldx juga1.y=juga1.oldy end
  335. if colision(juga1,muro8) then juga1.x=juga1.oldx juga1.y=juga1.oldy end
  336. if colision(juga1,muro9) then juga1.x=juga1.oldx juga1.y=juga1.oldy end
  337. if colision(juga1,muro10) then juga1.x=juga1.oldx juga1.y=juga1.oldy end
  338.  
  339. if colision(juga2,muro1) then juga2.y=juga2.oldy juga2.x=juga2.oldx end
  340. if colision(juga2,muro2) then juga2.x=juga2.oldx juga2.y=juga2.oldy end
  341. if colision(juga2,muro3) then juga2.y=juga2.oldy juga2.x=juga2.oldx end
  342. if colision(juga2,muro4) then juga2.x=juga2.oldx juga2.y=juga2.oldy end
  343. if colision(juga2,muro5) then juga2.y=juga2.oldy juga2.x=juga2.oldx end
  344. if colision(juga2,muro6) then juga2.x=juga2.oldx juga2.y=juga2.oldy end
  345. if colision(juga2,muro7) then juga2.y=juga2.oldy juga2.x=juga2.oldx end
  346. if colision(juga2,muro8) then juga2.x=juga2.oldx juga2.y=juga2.oldy end
  347. if colision(juga2,muro9) then juga2.y=juga2.oldy juga2.x=juga2.oldx end
  348. if colision(juga2,muro10) then juga2.x=juga2.oldx juga2.y=juga2.oldy end
  349.  
  350. if controls.start() then broke() end
  351. screen.flip()
  352. end
  353. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement