wolf: move with direction
This commit is contained in:
parent
803a8b8d91
commit
43cc2a179e
1 changed files with 26 additions and 10 deletions
|
|
@ -9,6 +9,7 @@ player = {
|
||||||
|
|
||||||
col_bg = 1
|
col_bg = 1
|
||||||
col_ground = 6
|
col_ground = 6
|
||||||
|
fov = (120 / 180) * math.pi -- 120 horizontal
|
||||||
|
|
||||||
function _init()
|
function _init()
|
||||||
for i=0,31 do
|
for i=0,31 do
|
||||||
|
|
@ -16,13 +17,12 @@ function _init()
|
||||||
if mget(i,j) == 5 then -- player id
|
if mget(i,j) == 5 then -- player id
|
||||||
player.origin.x = i + 0.5
|
player.origin.x = i + 0.5
|
||||||
player.origin.y = j + 0.5
|
player.origin.y = j + 0.5
|
||||||
player.dir = math.pi / 2
|
player.dir = 0
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if (player.x) break
|
if (player.x) break
|
||||||
end
|
end
|
||||||
print("player: ("..player.origin.x..", "..player.origin.y..")")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function cast_ray(origin, angle)
|
function cast_ray(origin, angle)
|
||||||
|
|
@ -31,14 +31,23 @@ end
|
||||||
|
|
||||||
function draw_minimap()
|
function draw_minimap()
|
||||||
local tile_size = 4
|
local tile_size = 4
|
||||||
map(0, 0, 20, 20, 31, 31, 0x0000, tile_size, tile_size)
|
local offset = 20
|
||||||
circfill(20 + (player.origin.x * tile_size), 20 + (player.origin.y * tile_size), 2, 5)
|
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)
|
||||||
end
|
end
|
||||||
|
|
||||||
function _draw()
|
function _draw()
|
||||||
cls(col_bg)
|
cls(col_bg)
|
||||||
rectfill(0, 135, 480, 270, col_ground)
|
rectfill(0, 135, 480, 270, col_ground)
|
||||||
local fov = 120 -- horizontal
|
|
||||||
local angle_step=(fov / 480) / 360 * math.pi
|
local angle_step=(fov / 480) / 360 * math.pi
|
||||||
for x=0,480-1 do
|
for x=0,480-1 do
|
||||||
local angle = (player.dir-(fov/2) + x * angle_step) % (2 * math.pi)
|
local angle = (player.dir-(fov/2) + x * angle_step) % (2 * math.pi)
|
||||||
|
|
@ -48,8 +57,15 @@ function _draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function _update()
|
function _update()
|
||||||
if (btn(0)) player.origin.x -= 2
|
local speed = 0.1
|
||||||
if (btn(1)) player.origin.x += 2
|
if (btn(0)) player.dir -= speed
|
||||||
if (btn(2)) player.origin.y -= 2
|
if (btn(1)) player.dir += speed
|
||||||
if (btn(3)) player.origin.y += 2
|
if (btn(2)) then
|
||||||
|
player.origin.x += math.cos(player.dir) * speed
|
||||||
|
player.origin.y += math.sin(player.dir) * speed
|
||||||
|
end
|
||||||
|
if (btn(3)) then
|
||||||
|
player.origin.x -= math.cos(player.dir) * speed
|
||||||
|
player.origin.y -= math.sin(player.dir) * speed
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue