primer commit

This commit is contained in:
2022-02-19 20:13:18 +01:00
commit c6526cd5d0
2 changed files with 424 additions and 0 deletions

View File

@@ -0,0 +1,196 @@
laberinto = {}
primera_fila = 2
ultima_fila = 28
primera_columna = 1
ultima_columna = 38
jugador = {
x = primera_columna,
y = primera_fila,
velocitat = 0
}
malos = {{
x = 0,
y = 0,
velocitat = 0,
dx = 0,
dy = 0
}, {
x = 0,
y = 0,
velocitat = 0,
dx = 0,
dy = 0
}, {
x = 0,
y = 0,
velocitat = 0,
dx = 0,
dy = 0
}, {
x = 0,
y = 0,
velocitat = 0,
dx = 0,
dy = 0
}, {
x = 0,
y = 0,
velocitat = 0,
dx = 0,
dy = 0
}}
rellotge = 0
num_malos = 1
function init()
mode(1)
color(10, 15, 15)
cls()
crea_laberinto()
pinta_laberinto()
crea_malos()
-- play("o4v5l1crcl4dcferl1crcl4dcgfr")
-- print("hola",0,0)
end
function update()
rellotge = rellotge + 1
mou_jugador()
pinta_laberinto()
pinta_jugador()
pinta_malos()
end
function crea_laberinto()
-- Rellenalo todo a partir de la primera_fila-1
for i = 0, 1199 do
if i < ((primera_fila - 1) * 40) then
laberinto[i] = 0x20
-- laberinto[i] = 0xD8
else
laberinto[i] = 0x8F
end
end
-- Pon camino en la primera y última fila
for i = primera_columna, ultima_columna do
laberinto[(40 * primera_fila) + i] = 0x20
laberinto[(40 * ultima_fila) + i] = 0x20
end
-- Pon camino en la primera y última columna
for i = primera_fila, ultima_fila do
laberinto[(40 * i) + primera_columna] = 0x20
laberinto[(40 * i) + ultima_columna] = 0x20
end
-- Crea filas aleatorios
i = primera_fila
while i < ultima_fila - 1 do
if rnd(10) % 10 > 4 then
-- 60% de probabilidad de pintar la fila entera
for j = primera_columna, ultima_columna do
laberinto[(40 * i) + j] = 0x20
end
else
-- 40% de probabilidad de pintar solo un segmento
longitud = max(15, rnd(ultima_columna - primera_columna) + 1)
-- ink(0)
-- print(i, 0, i)
inicio = rnd(ultima_columna - longitud) + primera_columna
for j = 1, longitud do
laberinto[(40 * i) + j + inicio] = 0x20
-- print("X", j + inicio, i + 1)
end
-- print(inicio, 5, i)
-- print(longitud, 10, i)
end
i = i + rnd(3) + 3
end
-- Crea columnas aleatorias
i = primera_columna
while i < ultima_columna - 1 do
if rnd(10) % 10 > 4 then
-- 60% de probabilidad de pintar la columna entera
for j = primera_fila, ultima_fila do
laberinto[(40 * j) + i] = 0x20
end
else
-- 40% de probabilidad de pintar solo un segmento
longitud = max(5, rnd(ultima_fila - primera_fila) + 1)
-- ink(0)
-- print(i, i, 0)
inicio = rnd(ultima_fila - longitud) + primera_fila - 1
for j = 1, longitud do
laberinto[(40 * (j + inicio)) + i] = 0x20
-- print("X", i, j + inicio)
end
-- print(inicio, i, 1)
-- print(longitud, i, 2)
-- print(longitud + inicio, i, 3)
end
i = i + rnd(2) + 2
end
end
function pinta_laberinto()
for i = 0, 1199 do
ink(10)
print(chr(laberinto[i]), i % 40, flr(i / 40))
-- Crea el efecto 3D pintando un caracter encima
if laberinto[i] == 0x8F then
-- color(15,10)
-- print(chr(0xCF), i % 40, flr(i / 40)-1)
-- print(chr(0xCF), i % 40, flr(i / 40)-2)
end
end
end
function pinta_jugador()
ink(0)
print(chr(0xF8), jugador.x, jugador.y)
end
function mou_jugador()
if jugador.velocitat == 0 then
if btn(KEY_UP) then
coloca_jugador(jugador.x, jugador.y - 1)
elseif btn(KEY_DOWN) then
coloca_jugador(jugador.x, jugador.y + 1)
end
if btn(KEY_LEFT) then
coloca_jugador(jugador.x - 1, jugador.y)
elseif btn(KEY_RIGHT) then
coloca_jugador(jugador.x + 1, jugador.y)
end
else
-- if jugador.velocitat > 0 then
jugador.velocitat = jugador.velocitat - 1
-- end
end
end
function coloca_jugador(x, y)
if laberinto[y * 40 + x] == 0x20 then
jugador.x = x
jugador.y = y
jugador.velocitat = 8
end
end
function pinta_malos()
ink(4)
for i = 1, num_malos do
print(chr(0x07), malos[i].x, malos[i].y)
end
end
function crea_malos()
for i = 1, num_malos do
malos[i].x = ultima_columna
malos[i].y = primera_fila
malos[i].dx = 0
malos[i].dy = 0
end
end

228
space/space.lua Normal file
View File

@@ -0,0 +1,228 @@
function init_player()
setchar(244, 0x00, 0x00, 0x00, 0x00, 0x18, 0x7E, 0xFF, 0xFF)
player = {
x = 10,
y = 14
}
end
function init_bullet()
setchar(145, 0x08, 0x10, 0x08, 0x10, 0x08, 0x10, 0x08, 0x10)
bullet = {
x = 0,
y = 0,
enabled = false
}
end
function init_explosion()
setchar(146, 0x10, 0x54, 0x28, 0xC6, 0x28, 0x54, 0x10, 0x00)
explosion = {
x = 0,
y = 0,
enabled = false,
counter = 0
}
end
function init_enemies()
setchar(16, 0x7E, 0xDB, 0xFF, 0x66, 0x3C, 0x66, 0x81, 0x00)
-- setchar(16, 0x7E, 0xDB, 0x66, 0x3C, 0x66, 0x81, 0x66, 0x00)
enemies = {}
local index = 1
for i = 1, 8 do
for j = 1, 5 do
local e = {
x = (i * 2),
y = j + 1,
enabled = true
}
enemies[index] = e
index = index + 1
end
end
enemy_desp = 1
enemy_speed = 80
end
function create_bullet(x, y)
bullet.x = x
bullet.y = y
bullet.enabled = true
end
function delete_bullet()
bullet.enabled = false
end
function create_explosion(x, y)
explosion.x = x
explosion.y = y
explosion.enabled = true
explosion.counter = 50
end
function delete_explosion()
explosion.enabled = false
end
function update_player()
if clock % 5 == 0 then
-- dreta
if btn(KEY_RIGHT) and player.x < 19 then
player.x = player.x + 1
end
-- esquerra
if btn(KEY_LEFT) and player.x > 0 then
player.x = player.x - 1
end
end
-- dispara
if btn(KEY_SPACE) and bullet.enabled == false then
create_bullet(player.x, player.y - 1)
end
-- reset
if btn(KEY_R) then
init()
end
end
function update_enemies()
if clock % enemy_speed == 0 then
sound(80, 50)
local border_reached = false
if enemy_desp ~= 0 then -- moviment horitzontal
for i = 1, #enemies do
if enemies[i].enabled == true then
enemies[i].x = enemies[i].x + enemy_desp
if enemies[i].x == 0 or enemies[i].x == 19 then
border_reached = true
end
end
end
if border_reached == true then
last_enemy_desp = enemy_desp
enemy_desp = 0
end
elseif enemy_desp == 0 then -- moviment vertical
for i = 1, #enemies do
if enemies[i].enabled == true then
enemies[i].y = enemies[i].y + 1
end
end
enemy_desp = -last_enemy_desp
end
end
end
function update_bullet()
if clock % 10 == 0 and bullet.enabled == true then
bullet.y = bullet.y - 1
if bullet.y == 0 then
delete_bullet()
end
for i = 1, #enemies do
if enemies[i].enabled == true then
if bullet.y == enemies[i].y and bullet.x == enemies[i].x then
create_explosion(bullet.x, bullet.y)
delete_bullet()
enemies[i].enabled = false
score = score + 10
sound(400, 40)
enemy_speed = enemy_speed - 2
end
end
end
end
end
function update_explosion()
if explosion.enabled == true then
if explosion.counter > 0 then
explosion.counter = explosion.counter - 1
else
delete_explosion()
end
end
end
function draw_player()
ink(COLOR_GREEN)
paper(COLOR_BLACK)
print("\244", player.x, player.y)
end
function draw_enemies()
ink(COLOR_LIGHT_GREEN)
paper(COLOR_BLACK)
for i = 1, #enemies do
if enemies[i].enabled == true then
print("\16", enemies[i].x, enemies[i].y)
end
end
end
function draw_bullet()
if bullet.enabled == true then
ink(COLOR_CYAN)
paper(COLOR_BLACK)
print("\145", bullet.x, bullet.y)
end
end
function draw_explosion()
if explosion.enabled == true then
ink(COLOR_RED)
paper(COLOR_BLACK)
print("\146", explosion.x, explosion.y)
end
end
function draw_hud()
ink(COLOR_LIGHT_GRAY)
paper(COLOR_BLACK)
print(" ", 0, 0)
print("SCORE: ", 0, 0)
print(score, 6, 0)
end
function draw_debug()
ink(COLOR_BLACK)
paper(COLOR_WHITE)
locate(0, 0)
print(player.x)
end
function init()
setmode(2)
clock = 0
score = 0
paper(COLOR_BLACK)
ink(COLOR_RED)
init_player()
init_enemies()
init_bullet()
init_explosion()
end
function update()
clock = clock + 1
update_player()
update_enemies()
update_bullet()
update_explosion()
paper(COLOR_BLACK)
cls()
draw_player()
draw_enemies()
draw_bullet()
draw_explosion()
draw_hud()
-- draw_debug()
end