Commit da8f4893 authored by Filip Polbratt's avatar Filip Polbratt

merge

parents 83d9c6c3 d806c89e
(define-module (class)
:use-module (oop goops)
:use-module (util)
:export (vector-length v3 make-player))
:export (vector-length v3 make-player make-ray))
(define-class <v3> ()
(x #:accessor x #:init-keyword #:x)
......@@ -35,3 +35,27 @@
(define (make-player x y a)
(make <player> #:x x #:y y #:a a))
(define-class <ray> ()
(angle #:acessor a #:init-keyword #:a)
(length #:accessor length #:init-keyword #:length #:init-value #f)
(vec #:accessor vec #:init-keyword #:v)
(pos-on-wall #:accessor pos-on-wall)
(hit-coord #:accessor hit #:init-keyword #:hit)
)
(export a length vec pos-on-wall hit)
(define-method (initialize (self <ray>) args)
(next-method)
(unless (length self)
(set! (length self) (vector-length (vec self))))
(set! (pos-on-wall self)
(if (> 0.1 (x (vec self)))
(- (y (vec self)) (floor (y (vec self))))
(- (x (vec self)) (floor (x (vec self)))))))
(define (make-ray . args)
(apply make <ray> args))
......@@ -95,10 +95,9 @@
(if (or (not (and (<= 0 nx board-width)
(<= 0 ny board-height)))
(eq? 'wall (array-ref game-map iy ix)))
(cons
(min (- dx (floor dx))
(- dy (floor dy)))
(v3 dx dy))
(make-ray #:a a
#:v (v3 dx dy)
#:hit (v3 ix iy))
(loop (+ dx (* 0.1 (cos a))) (+ dy (* 0.1 (sin a)))))))))
(iota ray-count (- (a player) (/ (fov player) 2))
(/ (fov player) ray-count)))))
......@@ -143,8 +142,8 @@
0.2 0.2)
(let ((pp (p player)))
(for-each (lambda (p)
(let ((v (+ pp (cdr p))))
(for-each (lambda (ray)
(let ((v (+ pp (vec ray))))
(draw-line (x pp) (y pp)
(x v) (y v))))
cached-rays
......@@ -172,28 +171,29 @@
(set-draw-color 0 #xEE #xEE)
(for-each (lambda (i r r+)
(let ((pos-on-wall (car r))
(ray (cdr r)))
(let* ((l (vector-length ray))
(segment-height (- 480 (* 70 l))))
(render-copy
(current-renderer)
brick-texture
#:dstrect (list (int (* i (/ 640 ray-count)))
(int (/ (- 480 segment-height) 2))
(int (1+ (/ 640 ray-count)))
(int segment-height))
#:srcrect (list (inexact->exact (round (* 56 (car r+)))) 0
(inexact->exact (round (* 56 (car r)))) 56)
)
#;
(render-fill-rect
(current-renderer)
(make-rect (int (* i (/ 640 ray-count)))
(int (/ (- 480 segment-height) 2))
(int (1+ (/ 640 ray-count)))
(int segment-height))))))
(let* ((l (length r))
(segment-height (- 480 (* 70 l))))
(set-draw-color 0
(int (min #xFF (- #x100 (* #x100 (/ l 7)))))
(int (min #xFF (- #x100 (* #x100 (/ l 7))))))
(render-copy
(current-renderer)
brick-texture
#:dstrect (list (int (* i (/ 640 ray-count)))
(int (/ (- 480 segment-height) 2))
(int (1+ (/ 640 ray-count)))
(int segment-height))
#:srcrect (list (inexact->exact (round (* 56 (pos-on-wall r)))) 0
(inexact->exact (round (* 56 (pos-on-wall r+)))) 56)
)
#;
(render-fill-rect
(current-renderer)
(make-rect (int (* i (/ 640 ray-count)))
(int (/ (- 480 segment-height) 2))
(int (1+ (/ 640 ray-count)))
(int segment-height)))))
(iota ray-count)
cached-rays
(cdr cached-rays)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment