Begin work on floor casting
This commit is contained in:
parent
790b2a58bf
commit
f12058bb6f
2 changed files with 172 additions and 112 deletions
BIN
assets/textures/floors/1.png
Normal file
BIN
assets/textures/floors/1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
|
@ -16,6 +16,10 @@
|
|||
(var wall-textures (love.filesystem.getDirectoryItems "assets/textures/walls"))
|
||||
(var (tex-height tex-width) (values 64 64))
|
||||
|
||||
(var floors [])
|
||||
(var floor-textures (love.filesystem.getDirectoryItems "assets/textures/floors"))
|
||||
(var (tex-height tex-width) (values 64 64))
|
||||
|
||||
(var skybox [])
|
||||
(var skybox-textures (love.filesystem.getDirectoryItems "assets/textures/skybox"))
|
||||
|
||||
|
@ -26,6 +30,13 @@
|
|||
(tset wall :h (love.graphics.getHeight (. wall :t)))
|
||||
(table.insert walls wall))
|
||||
|
||||
(each [_ v (ipairs floor-textures)]
|
||||
(local floor {})
|
||||
(tset floor :t (love.graphics.newImage (.. "assets/textures/floors/" v)))
|
||||
(tset floor :w (love.graphics.getWidth (. floor :t)))
|
||||
(tset floor :h (love.graphics.getHeight (. floor :t)))
|
||||
(table.insert floors floor))
|
||||
|
||||
(each [_ v (ipairs skybox-textures)]
|
||||
(local skyb {})
|
||||
(tset skyb :t (love.graphics.newImage (.. "assets/textures/skybox/" v)))
|
||||
|
@ -41,17 +52,52 @@
|
|||
; ### Offset experimentation ###
|
||||
(var (offst-x offst-y) (values 0 0))
|
||||
|
||||
{
|
||||
:draw (fn love.draw []
|
||||
(state.setDirX dirx)
|
||||
(state.setDirY diry)
|
||||
; Mouse-Look
|
||||
(love.graphics.translate offst-x offst-y)
|
||||
(fn floor-casting [wall-dists]
|
||||
(for [y (math.floor (/ screen-height 2)) (- screen-height 1)]
|
||||
|
||||
; "Skybox"
|
||||
; Draw a big thing before everything else
|
||||
; (love.graphics.draw (. skybox 1 :t) -20 -20)
|
||||
; Distance to floor row
|
||||
(var floor-dist (/ screen-height (- (* 2 y) screen-height)))
|
||||
|
||||
; Calculate step distances for row
|
||||
(var (step-x step-y) (values (/ (* floor-dist planex) screen-width)
|
||||
(/ (* floor-dist planey) screen-width)))
|
||||
|
||||
; Starting position for leftmost pixel of this row
|
||||
(var (floor-x floor-y) (values
|
||||
(+ posx (* dirx floor-dist) (* step-x (/ screen-width -2)))
|
||||
(+ posy (* diry floor-dist) (* step-y (/ screen-width -2)))))
|
||||
|
||||
; Draw each pixel across this row
|
||||
(for [x 0 screen-width]
|
||||
; Only draw if actually visible
|
||||
(when (< floor-dist (. wall-dists x))
|
||||
|
||||
; Get pixel of texture to draw
|
||||
; (set tex-x (- (. tex-num :w) tex-x 1))
|
||||
(var (tex-x tex-y) (values
|
||||
(math.floor (- floor-x (* (. floors 1 :w) (math.floor floor-x))))
|
||||
(math.floor (- floor-y (* (. floors 1 :h) (math.floor floor-y))))))
|
||||
|
||||
; Set lighting/fog
|
||||
; (var fog-dist (- 1 (/ (. wall-dists x) 10)))
|
||||
; (var light-dist (- 0.8 (/ (. wall-dists x) 5)))
|
||||
; (love.graphics.setColor light-dist light-dist light-dist fog-dist)
|
||||
|
||||
; Draw texture-pixel to world coordinate
|
||||
(var tex-num (. floors 1))
|
||||
(love.graphics.draw (. tex-num :t)
|
||||
(love.graphics.newQuad tex-x tex-y 1 1 (. tex-num :w) (. tex-num :h))
|
||||
x y))
|
||||
|
||||
; Step forward a pixel
|
||||
(set (floor-x floor-y) (values
|
||||
(+ floor-x step-x) (+ floor-y step-y)))))
|
||||
)
|
||||
|
||||
(fn sky-casting [])
|
||||
|
||||
(fn wall-casting []
|
||||
(var wall-dist [])
|
||||
; WALL CASTING
|
||||
(for [i 0 screen-width]
|
||||
; Calculate ray position and direction
|
||||
|
@ -145,7 +191,7 @@
|
|||
;; Draw the texture, accounting for "fog"
|
||||
(var fog-dist (- 1 (/ perp-wall-dist 10)))
|
||||
(var light-dist (- 0.8 (/ perp-wall-dist 5)))
|
||||
(love.graphics.setColor light-dist light-dist light-dist fog-dist)
|
||||
; (love.graphics.setColor light-dist light-dist light-dist fog-dist)
|
||||
; (love.graphics.draw (. tex-num :t)
|
||||
; (love.graphics.newQuad tex-x 0 1 (. tex-num :h) (. tex-num :w) (. tex-num :h))
|
||||
; i draw-start 0 1 (/ line-height (. tex-num :h)))
|
||||
|
@ -158,8 +204,22 @@
|
|||
(love.graphics.newQuad tex-x 0 1 (. tex-num :h) (. tex-num :w) (. tex-num :h))
|
||||
i (- draw-start (* line-height q)) 0 1 (/ line-height (. tex-num :h)))
|
||||
)
|
||||
(tset wall-dist i perp-wall-dist)
|
||||
; )
|
||||
)
|
||||
wall-dist
|
||||
)
|
||||
|
||||
{
|
||||
:draw (fn love.draw []
|
||||
(state.setDirX dirx)
|
||||
(state.setDirY diry)
|
||||
; Mouse-Look
|
||||
(love.graphics.translate offst-x offst-y)
|
||||
|
||||
; (sky-casting)
|
||||
(var wall-dists (wall-casting))
|
||||
(floor-casting wall-dists)
|
||||
(overlay.overlay offst-x offst-y)
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue