cartridges/picotron/wolfenstein_src/main.lua

76 lines
1.5 KiB
Lua
Raw Permalink Normal View History

2026-02-10 13:39:32 +01:00
--[[pod_format="raw",created="2026-02-10 12:09:44",modified="2026-02-10 12:27:08",revision=2]]
2024-09-23 13:34:10 +02:00
player = {
2024-10-08 14:02:03 +02:00
origin = {
2026-02-10 22:30:41 +01:00
x = nil,
2026-02-11 21:44:35 +01:00
y = nil,
2024-10-08 14:02:03 +02:00
},
2026-02-11 21:44:35 +01:00
dir = nil,
2024-09-23 13:34:10 +02:00
}
col_bg = 1
col_ground = 6
2026-02-10 22:30:41 +01:00
fov = (120 / 180) * math.pi -- 120 horizontal
2024-09-23 13:34:10 +02:00
function _init()
2026-02-11 21:44:35 +01:00
for i = 0, 31 do
for j = 0, 31 do
if mget(i, j) == 5 then -- player id
2024-10-08 14:02:03 +02:00
player.origin.x = i + 0.5
player.origin.y = j + 0.5
2026-02-10 22:30:41 +01:00
player.dir = 0
2024-09-23 13:34:10 +02:00
break
end
end
2026-02-11 21:44:35 +01:00
if player.x then
break
end
2024-09-23 13:34:10 +02:00
end
2024-10-08 14:02:03 +02:00
end
2026-02-11 21:44:35 +01:00
function cast_ray(origin, angle) end
2026-02-10 13:39:32 +01:00
function draw_minimap()
local tile_size = 4
2026-02-10 22:30:41 +01:00
local offset = 20
map(0, 0, offset, offset, 31, 31, 0x0000, tile_size, tile_size)
-- player
local px = offset + (player.origin.x * tile_size)
local py = offset + (player.origin.y * tile_size)
circfill(px, py, 1, 5)
local len = 3
local px2 = px + math.cos(player.dir) * len
local py2 = py + math.sin(player.dir) * len
line(px, py, px2, py2, 6)
2024-09-23 13:34:10 +02:00
end
function _draw()
cls(col_bg)
rectfill(0, 135, 480, 270, col_ground)
2026-02-11 21:44:35 +01:00
local angle_step = (fov / 480) / 360 * math.pi
for x = 0, 480 - 1 do
local angle = (player.dir - (fov / 2) + x * angle_step) % (2 * math.pi)
2024-10-08 14:02:03 +02:00
local bloc, dist = cast_ray(player.origin, angle)
end
2026-02-10 13:39:32 +01:00
draw_minimap()
2024-09-23 13:34:10 +02:00
end
2026-02-10 13:48:32 +01:00
function _update()
2026-02-10 22:30:41 +01:00
local speed = 0.1
2026-02-11 21:44:35 +01:00
if btn(0) then
player.dir -= speed
end
if btn(1) then
player.dir += speed
end
if btn(2) then
2026-02-10 22:30:41 +01:00
player.origin.x += math.cos(player.dir) * speed
player.origin.y += math.sin(player.dir) * speed
end
2026-02-11 21:44:35 +01:00
if btn(3) then
2026-02-10 22:30:41 +01:00
player.origin.x -= math.cos(player.dir) * speed
player.origin.y -= math.sin(player.dir) * speed
end
2026-02-10 13:48:32 +01:00
end