Advertisement
xerpi

Untitled

Apr 9th, 2011
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.78 KB | None | 0 0
  1. mira={img=image.load("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("enemy.png"),x=240,y=11,w=0,h=0,x2=50,y2=300,dir="l"}
  6.  
  7. ntimer = 1
  8.  
  9. x = 90
  10. y = 60
  11. enemigo.w=enemigo.img:width()
  12. enemigo.h=enemigo.img:height()
  13.  
  14.  
  15. fondo = image.load("fondo.png")
  16.  
  17.  
  18.  
  19. function object:move()
  20. if self.dir=="r" then
  21.     self.x=self.x+self.vel
  22. elseif self.dir=="l" then
  23.     self.x=self.x-self.vel
  24. elseif self.dir=="u" then
  25.     self.y=self.y-self.vel
  26. elseif self.dir=="d" then
  27.     self.y=self.y+self.vel
  28. end
  29. if self.dir=="r" and self.x>=self.x2+1 then
  30.     self.dir="l"
  31. end
  32. if self.dir=="l" and self.x<=self.x1-1 then
  33.     self.dir="r"
  34. end
  35. if self.dir=="d" and self.y>=self.y2+1 then
  36.     self.dir="u"
  37. end
  38. if self.dir=="u" and self.y<=self.y1-1 then
  39.     self.dir="d"
  40. end
  41. end
  42.  
  43.  
  44. function colision(objeto1,objeto2)
  45. if controls.press("circle") then
  46.  
  47. if objeto1.x+objeto1.w >= objeto2.x and
  48.     objeto1.x <= objeto2.x +objeto2.w and
  49.     objeto1.y + objeto1.h >= objeto1.y and
  50.     objeto1.y <= objeto2.y + objeto2.h then
  51.             screen.print(100,100,"COLISIONANDO",1.2,color.new(0,0,255),0x0)
  52. end
  53. end
  54. end
  55.  
  56. while true do
  57. controls.read()
  58. fondo:blit(0,0)
  59. enemigo.img:blit(enemigo.x,enemigo.y)
  60. --Una funcion que me he creado para mover los rectangulos constantemente
  61. if ntimer == 1 then
  62.     enemigo.y = enemigo.y + 2
  63. elseif ntimer == 2 then
  64.     enemigo.y = enemigo.y - 2
  65. end
  66. if enemigo.y == 122 then
  67.     ntimer = 2
  68. elseif enemigo.y == 10 then
  69.     ntimer = 1
  70. end
  71.  
  72.  
  73.  
  74.  
  75. if math.abs(controls.analogy())>20 then mira.y = mira.y + controls.analogy()/40 end
  76. if math.abs(controls.analogx())>20 then mira.x = mira.x + controls.analogx()/40 end
  77.  
  78. if controls.press("cross") then idiota() end
  79. enemigo:move()
  80. colision(mira,enemigo)
  81. mira.img:blit(mira.x,mira.y)
  82. screen.flip()
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement