79 lines
1.6 KiB
Lua
79 lines
1.6 KiB
Lua
jugador = {
|
|
x = 0,
|
|
y = 0,
|
|
vx = 1,
|
|
vy = 1,
|
|
color = COLOR_YELLOW,
|
|
color_fondo = COLOR_RED,
|
|
sprite = chr(250),
|
|
comptador = 0
|
|
}
|
|
|
|
pantalla_borde_dalt = 0
|
|
pantalla_borde_baix = 29
|
|
pantalla_borde_esquerre = 0
|
|
pantalla_borde_dret = 39
|
|
|
|
function init()
|
|
mode(1)
|
|
paper(COLOR_BLACK)
|
|
ink(COLOR_RED)
|
|
end
|
|
|
|
function update()
|
|
actualitza_jugador()
|
|
|
|
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
|
|
end |