Skip to content
Snippets Groups Projects
Commit 8177f4c8 authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

FPS movement.

parent 71a6ae86
Branches
Tags
No related merge requests found
...@@ -64,22 +64,29 @@ ...@@ -64,22 +64,29 @@
l2)) l2))
l1))) l1)))
(define pi 3.141592653589793)
(define tau (* 2 pi))
(define-class <point> () (define-class <v3> ()
(x #:accessor x (x #:accessor x #:init-keyword #:x)
#:init-keyword #:x (y #:accessor y #:init-keyword #:y)
#:init-value 0) (z #:accessor z #:init-keyword #:z))
(y #:accessor y
#:init-keyword #:y
#:init-value 0))
(define (make-point x y) (define* (v3 #:optional (x 0) (y 0) (z 0))
(make <point> #:x x #:y y)) (make <v3> #:x x #:y y #:z z))
(define pi 3.141592653589793) (define-method (+ (v <v3>) (u <v3>))
(define tau (* 2 pi)) (v3 (+ (x v) (x u))
(+ (y v) (y u))
(+ (z v) (z u))))
(define-method (* (a <number>) (v <v3>))
(v3 (* a (x v))
(* a (y v))
(* a (z v))))
(define-class <player> (<point>) (define-class <player> ()
(pos #:accessor p #:init-form (v3 1 1))
(angle #:accessor a #:init-value 0) (angle #:accessor a #:init-value 0)
(feild-of-view #:accessor fov #:init-value (/ tau 6))) (feild-of-view #:accessor fov #:init-value (/ tau 6)))
...@@ -87,7 +94,6 @@ ...@@ -87,7 +94,6 @@
(define t (gettimeofday)) (define t (gettimeofday))
(+ (cdr t) (* 1000000 (car t)))) (+ (cdr t) (* 1000000 (car t))))
(define current-tile-size (make-parameter 50)) (define current-tile-size (make-parameter 50))
(define current-renderer (make-parameter #f)) (define current-renderer (make-parameter #f))
...@@ -155,11 +161,19 @@ ...@@ -155,11 +161,19 @@
(fold (lambda (key ret) (fold (lambda (key ret)
(case key (case key
((x q) 'game-end) ((x q) 'game-end)
;; Det här börjar vara fånigt... ((w) (set! (p player) = (+ (* dt 0.000003
((w) (set! (y player) = (- (* dt 0.000003))) ret) (v3 (cos (a player))
((s) (set! (y player) = (+ (* dt 0.000003))) ret) (sin (a player))))))
((a) (set! (x player) = (- (* dt 0.000003))) ret) ret)
((d) (set! (x player) = (+ (* dt 0.000003))) ret) ((s) (set! (p player) = (+ (* dt 0.000003 -1
(v3 (cos (a player))
(sin (a player)))))) ret)
;; ((a) (set! (p player) = (+ (* dt 0.000003 -1
;; (v3 (sin (a player))
;; (cos (a player)))))) ret)
;; ((d) (set! (p player) = (+ (* dt 0.000003
;; (v3 (sin (a player))
;; (cos (a player)))))) ret)
((j) (set! (a player) = (- (* dt 0.000003))) ret) ((j) (set! (a player) = (- (* dt 0.000003))) ret)
((p) (set! (a player) = (+ (* dt 0.000003))) ret) ((p) (set! (a player) = (+ (* dt 0.000003))) ret)
(else ret) (else ret)
...@@ -184,7 +198,7 @@ ...@@ -184,7 +198,7 @@
(make-rect* (x pt) (y pt) (make-rect* (x pt) (y pt)
1 1) 1 1)
#f)) #f))
(map (lambda (p) (apply make-point p)) (map (lambda (p) (apply v3 p))
(cross-product (iota board-width) (iota board-height))))) (cross-product (iota board-width) (iota board-height)))))
(set-draw-color 0 0 0) (set-draw-color 0 0 0)
...@@ -203,12 +217,12 @@ ...@@ -203,12 +217,12 @@
(set-draw-color #xFF 0 0) (set-draw-color #xFF 0 0)
(fill-rect (fill-rect
(- (x player) 0.1) (- (x (p player)) 0.1)
(- (y player) 0.1) (- (y (p player)) 0.1)
0.2 0.2) 0.2 0.2)
(let ((x (x player)) (let ((x (x (p player)))
(y (y player))) (y (y (p player))))
(for-each (for-each
(lambda (a) (lambda (a)
(apply draw-line x y (apply draw-line x y
...@@ -229,9 +243,9 @@ ...@@ -229,9 +243,9 @@
(set-draw-color 0 #xFF 0) (set-draw-color 0 #xFF 0)
(draw-line (draw-line
(x player) (y player) (x (p player)) (y (p player))
(+ (cos (a player)) (x player)) (+ (cos (a player)) (x (p player)))
(+ (sin (a player)) (y player))) (+ (sin (a player)) (y (p player))))
;; (present) ;; (present)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment