Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mira={img=image.load("segun.png"),x=50,y=50,w=0,h=0}
- mira.w=mira.img:width()
- mira.h=mira.img:height()
- enemigo={img=image.load("enemy.png"),x=240,y=11,w=0,h=0,x2=50,y2=300,dir="l"}
- ntimer = 1
- x = 90
- y = 60
- enemigo.w=enemigo.img:width()
- enemigo.h=enemigo.img:height()
- fondo = image.load("fondo.png")
- function object:move()
- if self.dir=="r" then
- self.x=self.x+self.vel
- elseif self.dir=="l" then
- self.x=self.x-self.vel
- elseif self.dir=="u" then
- self.y=self.y-self.vel
- elseif self.dir=="d" then
- self.y=self.y+self.vel
- end
- if self.dir=="r" and self.x>=self.x2+1 then
- self.dir="l"
- end
- if self.dir=="l" and self.x<=self.x1-1 then
- self.dir="r"
- end
- if self.dir=="d" and self.y>=self.y2+1 then
- self.dir="u"
- end
- if self.dir=="u" and self.y<=self.y1-1 then
- self.dir="d"
- end
- end
- function colision(objeto1,objeto2)
- if controls.press("circle") then
- 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
- screen.print(100,100,"COLISIONANDO",1.2,color.new(0,0,255),0x0)
- end
- end
- end
- while true do
- controls.read()
- fondo:blit(0,0)
- enemigo.img:blit(enemigo.x,enemigo.y)
- --Una funcion que me he creado para mover los rectangulos constantemente
- if ntimer == 1 then
- enemigo.y = enemigo.y + 2
- elseif ntimer == 2 then
- enemigo.y = enemigo.y - 2
- end
- if enemigo.y == 122 then
- ntimer = 2
- elseif enemigo.y == 10 then
- ntimer = 1
- end
- if math.abs(controls.analogy())>20 then mira.y = mira.y + controls.analogy()/40 end
- if math.abs(controls.analogx())>20 then mira.x = mira.x + controls.analogx()/40 end
- if controls.press("cross") then idiota() end
- enemigo:move()
- colision(mira,enemigo)
- mira.img:blit(mira.x,mira.y)
- screen.flip()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement