Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function reiniciar()
- objetos:reset()
- vida1=50
- vida2=50
- juga1.x=20
- juga1.y=166
- juga2.x=400
- juga2.y=140
- end
- --Los colores
- rojo=color.new(255,0,0)
- amarillo=color.new(255,255,0)
- verde=color.new(0,255,0)
- negro= color.new(0,0,0)
- azul=color.new(0,0,255)
- --Menu
- elegida=1
- tam=1.35
- --Opciones
- selec=1
- explosion = anim.create("explosion.gif")
- explosion:start()
- mina=image.create(5,5, amarillo)
- --Cargamos los sprites de los jugadores
- P1 = image.load("up1.png")
- P2 = image.load("right1.png")
- P3 = image.load("down1.png")
- P4 = image.load("left1.png")
- J1 = image.load("up2.png")
- J2 = image.load("right2.png")
- J3 = image.load("down2.png")
- J4 = image.load("left2.png")
- current = P1
- actual = J1
- --Elegimos las posiciones de los muros
- muro1= {x=0,y=50,w=480,h=4}
- muro2= {x=350,y=130,w=4,h=100}
- muro3= {x=350,y=130,w=130,h=4}
- muro4= {x=60,y=120,w=4,h=40}
- muro5= {x=60,y=160,w=60,h=4}
- muro6= {x=120,y=160,w=4,h=120}
- muro7={x=0,y=50,w=4,h=222}
- muro8={x=476,y=50,w=4,h=222}
- muro9={x=0,y=268,w=480,h=4}
- muro10={x=240, y=180, w=50, h=4}
- --Posiciones de los jugadores
- juga1 = {x=20,y=166,w=32,h=32, oldx=0, oldy=0}
- juga2 = {x=400,y=140,w=32,h=32, oldx=0, oldy=0}
- --Parametros
- vida1=50
- vida2=50
- --fondo
- suelo = image.load("suelo.png")
- municion= image.load("municion.png")
- salud=image.load("salud.png")
- caja1= {x=250, y=190, w=20, h=20, estado=0}
- caja2= {x=250, y=190, w=20, h=20, estado=0}
- caja3= {x=250, y=160, w=20, h=20, estado=0}
- caja4= {x=250, y=160, w=20, h=20, estado=0}
- ganadas1=0
- ganadas2=0
- function arma()
- Armas1={"Magnum","Rifle","Metralleta","Lanzamisiles"}
- Armas2={"Magnum","Rifle","Metralleta","Lanzamisiles"}
- var=1;
- vor=1;
- while true do
- controls.read()
- if controls.press("left") then var=var-1 elseif controls.press("right") then var=var+1 end
- if controls.press("square") then vor=vor-1 elseif controls.press("circle") then vor=vor+1 end
- if var>4 then var=1 elseif var<1 then var=4 end
- if vor>4 then vor=1 elseif vor<1 then vor=4 end
- screen.print(160,50,"<--- "..Armas1[var].." --->",1,rojo,0x0);
- screen.print(180,30,"Jugador 1 ",verde)
- screen.print(165,80,"Partidas ganadas: " .. ganadas1, rojo)
- screen.print(160,190,"<--- "..Armas2[vor].." --->",1,rojo,0x0);
- screen.print(180,160,"Jugador 2 ",verde)
- screen.print(165,220,"Partidas ganadas: " .. ganadas2, rojo)
- if controls.select() then multijugador() end
- screen.flip()
- end
- end
- function colision(obj1, obj2)
- if obj1.x+obj1.w>obj2.x
- and obj1.x<obj2.x+obj2.w
- and obj1.y+obj1.h>obj2.y
- and obj1.y<obj2.y+obj2.h then
- return true
- end
- return false
- end
- function multijugador()
- objetos = timer.new() --Crea un temprizador
- objetos:start() --Lo inicia
- if var==1 then
- balas1=30
- tiempo1=12
- daño1=8
- movi1=3.25
- apariencia=image.create(5,5, amarillo)
- end
- if var==2 then --Rifle
- balas1=20
- tiempo1=18
- daño1=15
- movi1=2.5
- apariencia=image.create(5,10, amarillo)
- end
- if var==3 then --Metralleta
- balas1=50
- tiempo1=14
- daño1=6
- movi1=2.25
- apariencia=image.create(5,5, amarillo)
- end
- if var==4 then
- balas1=7
- tiempo1=8
- daño1=30
- movi1=2
- apariencia=image.load("der.png")
- end
- if vor==1 then
- balas2=30
- tiempo2=12
- daño2=8
- movi2=3.25
- detal=image.create(5,5, amarillo)
- end
- if vor==2 then --Rifle
- balas2=20
- tiempo2=18
- daño2=15
- movi2=2.5
- detal=image.create(5,10, amarillo)
- end
- if vor==3 then --Metralleta
- balas2=50
- tiempo2=14
- daño2=6
- movi2=2.25
- detal=image.create(5,5, amarillo)
- end
- if vor==4 then
- balas2=7
- tiempo2=8
- daño2=30
- movi2=2
- detal=image.load("der.png")
- end
- ver1=image.create(5,5, verde)
- --Accion de disparar
- disparo1 = weapon.create(apariencia,tiempo1)
- weapon.action(disparo1,"start")
- disparo2 = weapon.create(detal,tiempo2)
- weapon.action(disparo2,"start")
- disparo3 = weapon.create(apariencia,0)
- weapon.action(disparo3,"start")
- disparo4 = weapon.create(detal,0)
- weapon.action(disparo4,"start")
- while true do
- controls.read()
- juga1.oldx=juga1.x
- juga1.oldy=juga1.y
- juga2.oldx=juga2.x
- juga2.oldy=juga2.y
- for a = 0, 14 do
- for b = 1.57,8 do
- suelo:blit(32 * a, 32 * b)
- end
- end
- if controls.triangle() and vida2>=0 and vida1>=0 then actual =J1 juga2.y=juga2.y-movi2
- elseif controls.cross() and vida2>=0 and vida1>=0 then actual =J3 juga2.y=juga2.y+movi2
- elseif controls.circle() and vida2>=0 and vida1>=0 then actual =J2 juga2.x=juga2.x+movi2
- elseif controls.square() and vida2>=0 and vida1>=0 then actual =J4 juga2.x=juga2.x-movi2 end
- if controls.press("select") and vida1>0 and vida2>=0 then weapon.shoot(disparo4,juga2.x+10,juga2.y+20,"up") end
- 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
- 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
- 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
- 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
- if controls.analogy()>120 and vida1>0 and vida2>=0 then weapon.shoot(disparo3,juga1.x+10,juga1.y+20,"up") end
- 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
- 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
- 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
- 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
- if controls.up() and vida2>=0 and vida1>=0 then current =P1 juga1.y=juga1.y-movi1
- elseif controls.down() and vida2>=0 and vida1>=0 then current =P3 juga1.y=juga1.y+movi1
- elseif controls.right() and vida2>=0 and vida1>=0 then current =P2 juga1.x=juga1.x+movi1
- elseif controls.left() and vida2>=0 and vida1>=0 then current =P4 juga1.x=juga1.x-movi1 end
- if objetos:time()>12000 and objetos:time()<20000 and caja1.estado==0 then municion:blit(caja1.x,caja1.y) end
- if objetos:time()>30000 and objetos:time()<45000 and caja2.estado==0 then salud:blit(caja2.x,caja2.y) end
- if objetos:time()>50000 and objetos:time()<65000 and caja3.estado==0 then municion:blit(caja3.x,caja3.y) end
- if objetos:time()>75000 and objetos:time()<90000 and caja4.estado==0 then salud:blit(caja4.x,caja4.y) end
- --Mostrando personajes
- current:blit( juga1.x,juga1.y)
- actual:blit(juga2.x,juga2.y)
- --Mostrando la informacion sobre los jugadores
- screen.print(80,10, "Jugador 1:",rojo)
- screen.print(10,30, "Balas: " .. balas1, verde)
- screen.print(100,30, "Vida:",verde)
- screen.print(300,10, "Jugador 2 : ",rojo)
- screen.print(260,30, "Balas: " .. balas2, verde)
- screen.print(360,30, "Vida : ",verde)
- draw.fillrect(150,30,math.max(0,vida1),10,rojo)
- draw.rect(150,30,51,11,color.new(255,255,255))
- draw.fillrect(410,30,math.max(0,vida2),10,rojo)
- draw.rect(410,30,51,11,color.new(255,255,255))
- --Los limites de la pantalla
- draw.fillrect(0,50,480,4,color.new(255,255,255))
- draw.fillrect(0,50,4,222,color.new(255,255,255))
- draw.fillrect(476,50,4,222,color.new(255,255,255))
- draw.fillrect(0,268,480,4,color.new(255,255,255))
- --Los muros
- draw.fillrect(350,130,4,100,color.new(255,255,255))
- draw.fillrect(350,130,130,4,color.new(255,255,255))
- draw.fillrect(60,120,4,40,color.new(255,255,255))
- draw.fillrect(60,160,60,4,color.new(255,255,255))
- draw.fillrect(120,160,4,120,color.new(255,255,255))
- draw.fillrect(240,180,50,4,color.new(255,255,255))
- --Mostramos las balas
- weapon.blit(disparo1)
- weapon.blit(disparo2)
- weapon.blit(disparo3)
- weapon.blit(disparo4)
- --Las colisiones:
- --/De las balas del jugador 1
- colision,x1,y1 = weapon.collision(disparo1, 0,50,480,4,true)
- if colision then detal1=explosion:blit(x,y) end
- weapon.collision(disparo1,0,50,480,4,true)
- weapon.collision(disparo1,350,130,4,100,true)
- weapon.collision(disparo1,350,130,130,4,true)
- weapon.collision(disparo1,60,120,4,40,true)
- weapon.collision(disparo1,60,160,60,4,true)
- weapon.collision(disparo1,120,160,4,120,true)
- weapon.collision(disparo1,240,180,50,4,true)
- if weapon.collision(disparo1,juga2.x,juga2.y,32,32,true) then vida2=vida2-daño1 end
- if weapon.collision(disparo3,juga2.x,juga2.y,32,32,true) then vida2=vida2-1 end
- --/De las balas del jugador 2
- weapon.collision(disparo2,0,50,480,4,true)
- weapon.collision(disparo2,350,130,4,100,true)
- weapon.collision(disparo2,350,130,130,4,true)
- weapon.collision(disparo2,60,120,4,40,true)
- weapon.collision(disparo2,60,160,60,4,true)
- weapon.collision(disparo2,120,160,4,120,true)
- weapon.collision(disparo2,240,180,50,4,true)
- --weapon.collision(disparo2,muro10,true)
- if weapon.collision(disparo2,juga1.x,juga1.y,32,32,true) then vida1=vida1-daño2 end
- if weapon.collision(disparo4,juga1.x,juga1.y,32,32,true) then vida1=vida1-1 end
- if vida1>0 and vida2<=0 then screen.print(150,140, "Jugador 1 ha ganado") screen.print(150,160, "Pulsa X para reiniciar") end
- if vida2>0 and vida1<=0 then screen.print(150,140, "Jugador 2 ha ganado") screen.print(150,160, "Pulsa X para reiniciar") end
- if vida1<=0 and vida2<=0 then screen.print(200,140, "EMPATE") screen.print(150,160, "Pulsa X para reiniciar") end
- if vida1<=0 and controls.cross() then ganadas2=ganadas2+1 reiniciar() arma() end
- if vida2<=0 and controls.cross() then ganadas1=ganadas1+1 reiniciar() arma() end
- --/De los jugadores
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- if colision(juga1,muro1) then juga1.y=juga1.oldy juga1.x=juga1.oldx end
- if colision(juga1,muro2) then juga1.x=juga1.oldx juga1.y=juga1.oldy end
- if colision(juga1,muro3) then juga1.y=juga1.oldy juga1.x=juga1.oldx end
- if colision(juga1,muro4) then juga1.x=juga1.oldx juga1.y=juga1.oldy end
- if colision(juga1,muro5) then juga1.y=juga1.oldy juga1.x=juga1.oldx end
- if colision(juga1,muro6) then juga1.x=juga1.oldx juga1.y=juga1.oldy end
- if colision(juga1,muro7) then juga1.x=juga1.oldx juga1.y=juga1.oldy end
- if colision(juga1,muro8) then juga1.x=juga1.oldx juga1.y=juga1.oldy end
- if colision(juga1,muro9) then juga1.x=juga1.oldx juga1.y=juga1.oldy end
- if colision(juga1,muro10) then juga1.x=juga1.oldx juga1.y=juga1.oldy end
- if colision(juga2,muro1) then juga2.y=juga2.oldy juga2.x=juga2.oldx end
- if colision(juga2,muro2) then juga2.x=juga2.oldx juga2.y=juga2.oldy end
- if colision(juga2,muro3) then juga2.y=juga2.oldy juga2.x=juga2.oldx end
- if colision(juga2,muro4) then juga2.x=juga2.oldx juga2.y=juga2.oldy end
- if colision(juga2,muro5) then juga2.y=juga2.oldy juga2.x=juga2.oldx end
- if colision(juga2,muro6) then juga2.x=juga2.oldx juga2.y=juga2.oldy end
- if colision(juga2,muro7) then juga2.y=juga2.oldy juga2.x=juga2.oldx end
- if colision(juga2,muro8) then juga2.x=juga2.oldx juga2.y=juga2.oldy end
- if colision(juga2,muro9) then juga2.y=juga2.oldy juga2.x=juga2.oldx end
- if colision(juga2,muro10) then juga2.x=juga2.oldx juga2.y=juga2.oldy end
- if controls.start() then broke() end
- screen.flip()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement