Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mira={img=image.load("imagenes/segun.png"),x=50,y=50,w=0,h=0}
- mira.w=mira.img:width()
- mira.h=mira.img:height()
- enemigo={img=image.load("imagenes/enemy.png"),x1=0,y1=0,x=0,y=0,x2=440,y2=0,dir="r",vel=8}
- enemigo.w=enemigo.img:width()
- enemigo.h=enemigo.img:height()
- fondo = image.load("imagenes/fondo.png")
- disparo = sound.load("sonidos/disparo.wav")
- function move(object)
- if object.dir=="r" then
- object.x=object.x+object.vel
- elseif object.dir=="l" then
- object.x=object.x-object.vel
- elseif object.dir=="u" then
- object.y=object.y-object.vel
- elseif object.dir=="d" then
- object.y=object.y+object.vel
- end
- if object.dir=="r" and object.x>=object.x2+1 then
- object.dir="l"
- end
- if object.dir=="l" and object.x<=object.x1-1 then
- object.dir="r"
- end
- if object.dir=="d" and object.y>=object.y2+1 then
- object.dir="u"
- end
- if object.dir=="u" and object.y<=object.y1-1 then
- object.dir="d"
- end
- end
- function colision(objeto1,objeto2)
- if controls.press("r") then
- sound.play(disparo)
- if objeto1.x+objeto1.w >= objeto2.x and
- objeto1.x <= objeto2.x +objeto2.w and
- objeto1.y + objeto1.h >= objeto1.y and
- objeto1.y <= objeto2.y + objeto2.h then
- os.message("Avanza al siguiente nivel")
- dofile("niveles/nivel2.lua")
- end
- end
- end
- while true do
- controls.read()
- fondo:blit(0,0)
- enemigo.img:blit(enemigo.x,enemigo.y)
- if math.abs(controls.analogy())>20 then mira.y = mira.y + controls.analogy()/10 end
- if math.abs(controls.analogx())>20 then mira.x = mira.x + controls.analogx()/10 end
- move(enemigo)
- colision(mira,enemigo)
- mira.x = math.min(math.max(0,mira.x), 480-mira.w/2)
- mira.y = math.min(math.max(0,mira.y), 272-mira.n/2)
- mira.img:blit(mira.x,mira.y)
- screen.flip()
- if controls.press("select") then idiota() end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement