persecucion_mortal.lua: pasado a "objetos"
This commit is contained in:
@@ -6,7 +6,57 @@ jugador = {
|
||||
color = COLOR_YELLOW,
|
||||
color_fondo = COLOR_RED,
|
||||
sprite = chr(250),
|
||||
comptador = 0
|
||||
comptador = 0,
|
||||
|
||||
actualitza = function(self)
|
||||
self.comptador = self.comptador + 1
|
||||
self:anima()
|
||||
self:mou()
|
||||
self:comprova_bordes()
|
||||
end,
|
||||
|
||||
mou = function(self)
|
||||
if self.comptador % 30 == 0 then
|
||||
self.x = self.x + self.vx
|
||||
self.y = self.y + self.vy
|
||||
end
|
||||
end,
|
||||
|
||||
comprova_bordes = function (self)
|
||||
if self.x > pantalla_borde_dret then
|
||||
self.vx = self.vx * -1
|
||||
self.x = pantalla_borde_dret
|
||||
end
|
||||
|
||||
if self.x < pantalla_borde_esquerre then
|
||||
self.vx = self.vx * -1
|
||||
self.x = pantalla_borde_esquerre
|
||||
end
|
||||
|
||||
if self.y > pantalla_borde_baix then
|
||||
self.vy = self.vy * -1
|
||||
self.y = pantalla_borde_baix
|
||||
end
|
||||
|
||||
if self.y < pantalla_borde_dalt then
|
||||
self.vy = self.vy * -1
|
||||
self.y = pantalla_borde_dalt
|
||||
end
|
||||
end,
|
||||
|
||||
dibuixa = function(self)
|
||||
paper(self.color_fondo)
|
||||
ink(self.color)
|
||||
print(self.sprite, self.x, self.y)
|
||||
end,
|
||||
|
||||
anima = function(self)
|
||||
if self.comptador % 60 < 30 then
|
||||
self.sprite = chr(250)
|
||||
else
|
||||
self.sprite = chr(251)
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
pantalla_borde_dalt = 0
|
||||
@@ -21,59 +71,9 @@ function init()
|
||||
end
|
||||
|
||||
function update()
|
||||
actualitza_jugador()
|
||||
jugador:actualitza()
|
||||
|
||||
paper(COLOR_RED)
|
||||
cls()
|
||||
dibuixa_jugador()
|
||||
end
|
||||
|
||||
function actualitza_jugador()
|
||||
jugador.comptador = jugador.comptador + 1
|
||||
anima_jugador()
|
||||
mou_jugador()
|
||||
comprova_bordes_jugador()
|
||||
end
|
||||
|
||||
function mou_jugador()
|
||||
if jugador.comptador % 30 == 0 then
|
||||
jugador.x = jugador.x + jugador.vx
|
||||
jugador.y = jugador.y + jugador.vy
|
||||
end
|
||||
end
|
||||
|
||||
function comprova_bordes_jugador()
|
||||
if jugador.x > pantalla_borde_dret then
|
||||
jugador.vx = jugador.vx * -1
|
||||
jugador.x = pantalla_borde_dret
|
||||
end
|
||||
|
||||
if jugador.x < pantalla_borde_esquerre then
|
||||
jugador.vx = jugador.vx * -1
|
||||
jugador.x = pantalla_borde_esquerre
|
||||
end
|
||||
|
||||
if jugador.y > pantalla_borde_baix then
|
||||
jugador.vy = jugador.vy * -1
|
||||
jugador.y = pantalla_borde_baix
|
||||
end
|
||||
|
||||
if jugador.y < pantalla_borde_dalt then
|
||||
jugador.vy = jugador.vy * -1
|
||||
jugador.y = pantalla_borde_dalt
|
||||
end
|
||||
end
|
||||
|
||||
function dibuixa_jugador()
|
||||
paper(jugador.color_fondo)
|
||||
ink(jugador.color)
|
||||
print(jugador.sprite, jugador.x, jugador.y)
|
||||
end
|
||||
|
||||
function anima_jugador()
|
||||
if jugador.comptador % 60 < 30 then
|
||||
jugador.sprite = chr(250)
|
||||
else
|
||||
jugador.sprite = chr(251)
|
||||
end
|
||||
jugador:dibuixa()
|
||||
end
|
||||
Reference in New Issue
Block a user