From f07bd0c1169dabf2bb4736b285aef6e20460c332 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 11 Sep 2023 08:22:17 +0200 Subject: [PATCH] space.lua: cambiado setmode a mode --- persecucion_mortal/persecucion_mortal.lua | 79 +++++++++++++++++++++++ space/space.lua | 2 +- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 persecucion_mortal/persecucion_mortal.lua diff --git a/persecucion_mortal/persecucion_mortal.lua b/persecucion_mortal/persecucion_mortal.lua new file mode 100644 index 0000000..ad9bafd --- /dev/null +++ b/persecucion_mortal/persecucion_mortal.lua @@ -0,0 +1,79 @@ +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 \ No newline at end of file diff --git a/space/space.lua b/space/space.lua index a77a2e1..7e21a90 100644 --- a/space/space.lua +++ b/space/space.lua @@ -197,7 +197,7 @@ function draw_debug() end function init() - setmode(2) + mode(2) clock = 0 score = 0 paper(COLOR_BLACK)