summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game.scm64
1 files changed, 34 insertions, 30 deletions
diff --git a/game.scm b/game.scm
index e40a582..5f6c3e9 100644
--- a/game.scm
+++ b/game.scm
@@ -115,6 +115,31 @@
"image" "new"
(ref string) -> (ref extern))
+ (define-syntax-rule (define-type name
+ constructor
+ predicate
+ (field getter setter) ...)
+ (begin
+ (define (constructor field ...)
+ (vector 'name field ...))
+ (define (predicate obj)
+ (match obj
+ (#('name field ...) #t)
+ (_ #f)))
+ (define (getter obj)
+ (match obj
+ (#('name field ...)
+ field)))
+ ...
+ (define setter
+ (let ((i (1+ (- (length '(field ...))
+ (length (memq 'field '(field ...)))))))
+ (lambda (obj val)
+ (match obj
+ (#('name field ...)
+ (vector-set! obj i val))))))
+ ...))
+
;; TODO: Add basic fmod as inline wasm function
;; Hoot's exact and inexact aren't working right. These next two
@@ -164,19 +189,23 @@
((> x max) max)
(else x)))
+ (define-type vec2
+ make-vec2
+ vec2?
+ (bv vec2-bv set-vec2-bv!))
(define (vec2 x y)
- (let ((v (make-bytevector 16)))
+ (let ((v (make-vec2 (make-bytevector 16))))
(set-vec2-x! v x)
(set-vec2-y! v y)
v))
(define (vec2-x v)
- (f64-ref v 0))
+ (f64-ref (vec2-bv v) 0))
(define (vec2-y v)
- (f64-ref v 8))
+ (f64-ref (vec2-bv v) 8))
(define (set-vec2-x! v x)
- (f64-set! v 0 x))
+ (f64-set! (vec2-bv v) 0 x))
(define (set-vec2-y! v y)
- (f64-set! v 8 y))
+ (f64-set! (vec2-bv v) 8 y))
(define (vec2-add! v w)
(set-vec2-x! v (+ (vec2-x v) (vec2-x w)))
(set-vec2-y! v (+ (vec2-y v) (vec2-y w))))
@@ -262,31 +291,6 @@
(define sound:enemy-shoot (load-sound-effect "audio/enemy-shoot.wav"))
(define sound:bullet-hit (load-sound-effect "audio/bullet-hit.wav"))
- (define-syntax-rule (define-type name
- constructor
- predicate
- (field getter setter) ...)
- (begin
- (define (constructor field ...)
- (vector 'name field ...))
- (define (predicate obj)
- (match obj
- (#('name field ...) #t)
- (_ #f)))
- (define (getter obj)
- (match obj
- (#('name field ...)
- field)))
- ...
- (define setter
- (let ((i (1+ (- (length '(field ...))
- (length (memq 'field '(field ...)))))))
- (lambda (obj val)
- (match obj
- (#('name field ...)
- (vector-set! obj i val))))))
- ...))
-
;; Scripting
(define (make-scheduler max-tasks)
(vector 0 0 max-tasks (make-vector max-tasks)))