Advertisement
xerpi

Untitled

Apr 10th, 2011
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.75 KB | None | 0 0
  1. mira={img=image.load("imagenes/segun.png"),x=50,y=50,w=0,h=0}
  2. mira.w=mira.img:width()
  3. mira.h=mira.img:height()
  4.  
  5. enemigo={img=image.load("imagenes/enemy.png"),x1=0,y1=0,x=0,y=0,x2=440,y2=0,dir="r",vel=8}
  6. enemigo.w=enemigo.img:width()
  7. enemigo.h=enemigo.img:height()
  8.  
  9. fondo = image.load("imagenes/fondo.png")
  10. disparo = sound.load("sonidos/disparo.wav")
  11.  
  12. function move(object)
  13. if object.dir=="r" then
  14.     object.x=object.x+object.vel
  15. elseif object.dir=="l" then
  16.     object.x=object.x-object.vel
  17. elseif object.dir=="u" then
  18.     object.y=object.y-object.vel
  19. elseif object.dir=="d" then
  20.     object.y=object.y+object.vel
  21. end
  22. if object.dir=="r" and object.x>=object.x2+1 then
  23.     object.dir="l"
  24. end
  25. if object.dir=="l" and object.x<=object.x1-1 then
  26.     object.dir="r"
  27. end
  28. if object.dir=="d" and object.y>=object.y2+1 then
  29.     object.dir="u"
  30. end
  31. if object.dir=="u" and object.y<=object.y1-1 then
  32.     object.dir="d"
  33. end
  34. end
  35.  
  36.  
  37. function colision(objeto1,objeto2)
  38. if controls.press("r") then
  39. sound.play(disparo)
  40. if objeto1.x+objeto1.w >= objeto2.x and
  41.     objeto1.x <= objeto2.x +objeto2.w and
  42.     objeto1.y + objeto1.h >= objeto1.y and
  43.     objeto1.y <= objeto2.y + objeto2.h then
  44. os.message("Avanza al siguiente nivel")
  45. dofile("niveles/nivel2.lua")
  46. end
  47. end
  48. end
  49.  
  50. while true do
  51. controls.read()
  52. fondo:blit(0,0)
  53. enemigo.img:blit(enemigo.x,enemigo.y)
  54.  
  55. if math.abs(controls.analogy())>20 then mira.y = mira.y + controls.analogy()/10 end
  56. if math.abs(controls.analogx())>20 then mira.x = mira.x + controls.analogx()/10 end
  57.  
  58. move(enemigo)
  59.  
  60. colision(mira,enemigo)
  61.  
  62.  
  63. mira.x = math.min(math.max(0,mira.x), 480-mira.w/2)
  64. mira.y = math.min(math.max(0,mira.y), 272-mira.n/2)
  65.  
  66. mira.img:blit(mira.x,mira.y)
  67.  
  68. screen.flip()
  69. if controls.press("select") then idiota() end
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement