Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --creamos dos objetos
- pers={x=10,y=10,w=20,h=20}
- obj={x=100,y=50,w=60,h=60}
- function dibujar(objeto,color)
- draw.fillrect(objeto.x,objeto.y,objeto.w,objeto.h,color)
- end
- function colision(objeto1,objeto2)
- if objeto1.x+objeto1.w >= objeto2.x and
- objeto1.x <= objeto2.x +objeto2.w and
- objeto1.y + objeto1.h >= objeto2.y and
- objeto1.y <= objeto2.y + objeto2.h then
- screen.print(100,100,"COLISIONANDO",1.2,color.new(0,0,255),0x0)
- end
- end
- while true do
- controls.read()
- --dibujamos objetos
- dibujar(obj,color.new(255,0,0))
- dibujar(pers,color.new(0,0,255))
- --para k no se salga de la pantalla
- if pers.x <=0 then pers.x=0 end
- if pers.y <=0 then pers.y=0 end
- if pers.x+pers.w >=480 then pers.x=480-pers.w end
- if pers.y+pers.h >=480 then pers.y=272-pers.h end
- --comprobamos colisión
- colision(pers,obj)
- --movemos por la pantalla
- if math.abs(controls.analogx())>20 then pers.x = pers.x + controls.analogx()/50 end
- if math.abs(controls.analogy())>20 then pers.y = pers.y + controls.analogy()/50 end
- if controls.select() then xerpi() end
- screen.flip()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement