Commit 8177f4c8 authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

FPS movement.

parent 71a6ae86
......@@ -64,22 +64,29 @@
l2))
l1)))
(define pi 3.141592653589793)
(define tau (* 2 pi))
(define-class <point> ()
(x #:accessor x
#:init-keyword #:x
#:init-value 0)
(y #:accessor y
#:init-keyword #:y
#:init-value 0))
(define-class <v3> ()
(x #:accessor x #:init-keyword #:x)
(y #:accessor y #:init-keyword #:y)
(z #:accessor z #:init-keyword #:z))
(define (make-point x y)
(make <point> #:x x #:y y))
(define* (v3 #:optional (x 0) (y 0) (z 0))
(make <v3> #:x x #:y y #:z z))
(define pi 3.141592653589793)
(define tau (* 2 pi))
(define-method (+ (v <v3>) (u <v3>))
(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)
(feild-of-view #:accessor fov #:init-value (/ tau 6)))
......@@ -87,7 +94,6 @@
(define t (gettimeofday))
(+ (cdr t) (* 1000000 (car t))))
(define current-tile-size (make-parameter 50))
(define current-renderer (make-parameter #f))
......@@ -155,11 +161,19 @@
(fold (lambda (key ret)
(case key
((x q) 'game-end)
;; Det här börjar vara fånigt...
((w) (set! (y player) = (- (* dt 0.000003))) ret)
((s) (set! (y player) = (+ (* dt 0.000003))) ret)
((a) (set! (x player) = (- (* dt 0.000003))) ret)
((d) (set! (x player) = (+ (* dt 0.000003))) ret)
((w) (set! (p player) = (+ (* dt 0.000003
(v3 (cos (a player))
(sin (a player))))))
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)
((p) (set! (a player) = (+ (* dt 0.000003))) ret)
(else ret)
......@@ -184,7 +198,7 @@
(make-rect* (x pt) (y pt)
1 1)
#f))
(map (lambda (p) (apply make-point p))
(map (lambda (p) (apply v3 p))
(cross-product (iota board-width) (iota board-height)))))
(set-draw-color 0 0 0)
......@@ -203,12 +217,12 @@
(set-draw-color #xFF 0 0)
(fill-rect
(- (x player) 0.1)
(- (y player) 0.1)
(- (x (p player)) 0.1)
(- (y (p player)) 0.1)
0.2 0.2)
(let ((x (x player))
(y (y player)))
(let ((x (x (p player)))
(y (y (p player))))
(for-each
(lambda (a)
(apply draw-line x y
......@@ -229,9 +243,9 @@
(set-draw-color 0 #xFF 0)
(draw-line
(x player) (y player)
(+ (cos (a player)) (x player))
(+ (sin (a player)) (y player)))
(x (p player)) (y (p player))
(+ (cos (a player)) (x (p player)))
(+ (sin (a player)) (y (p player))))
;; (present)
......
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