Advertisement
xerpi

Untitled

Apr 1st, 2011
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | None | 0 0
  1. --creamos dos objetos
  2. pers={x=10,y=10,w=20,h=20}
  3. obj={x=100,y=50,w=60,h=60}
  4.  
  5. function dibujar(objeto,color)
  6. draw.fillrect(objeto.x,objeto.y,objeto.w,objeto.h,color)
  7. end
  8.  
  9. function colision(objeto1,objeto2)
  10. if objeto1.x+objeto1.w >= objeto2.x and
  11.     objeto1.x <= objeto2.x +objeto2.w and
  12.     objeto1.y + objeto1.h >= objeto2.y and
  13.     objeto1.y <= objeto2.y + objeto2.h then
  14.         screen.print(100,100,"COLISIONANDO",1.2,color.new(0,0,255),0x0)
  15. end
  16. end
  17.  
  18. while true do
  19. controls.read()
  20.  
  21. --dibujamos objetos
  22. dibujar(obj,color.new(255,0,0))
  23. dibujar(pers,color.new(0,0,255))
  24.  
  25. --para k no se salga de la pantalla
  26. if pers.x <=0 then pers.x=0 end
  27. if pers.y <=0 then pers.y=0 end
  28. if pers.x+pers.w >=480 then pers.x=480-pers.w end
  29. if pers.y+pers.h >=480 then pers.y=272-pers.h end
  30.  
  31. --comprobamos colisión
  32. colision(pers,obj)
  33.  
  34. --movemos por la pantalla
  35. if math.abs(controls.analogx())>20 then pers.x = pers.x + controls.analogx()/50 end
  36. if math.abs(controls.analogy())>20 then pers.y = pers.y + controls.analogy()/50 end
  37.  
  38. if controls.select() then xerpi() end
  39. screen.flip()
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement