summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2d/sprite.scm30
1 files changed, 11 insertions, 19 deletions
diff --git a/2d/sprite.scm b/2d/sprite.scm
index 45eb790..4dafc44 100644
--- a/2d/sprite.scm
+++ b/2d/sprite.scm
@@ -31,10 +31,8 @@
sprite-texture
sprite-position
set-sprite-position!
- sprite-scale-x
- set-sprite-scale-x!
- sprite-scale-y
- set-sprite-scale-y!
+ sprite-scale
+ set-sprite-scale!
sprite-rotation
set-sprite-rotation!
set-sprite-scale!
@@ -44,30 +42,23 @@
;; The <sprite> object represents a texture with a given position, scale,
;; rotation, and color.
(define-record-type <sprite>
- (%make-sprite texture position scale-x scale-y rotation color)
+ (%make-sprite texture position scale rotation color)
sprite?
(texture sprite-texture)
(position sprite-position set-sprite-position!)
- (scale-x sprite-scale-x set-sprite-scale-x!)
- (scale-y sprite-scale-y set-sprite-scale-y!)
+ (scale sprite-scale set-sprite-scale!)
(rotation sprite-rotation set-sprite-rotation!)
(color sprite-color set-sprite-color!))
-(define (set-sprite-scale! sprite scale)
- "Sets sprite scale-x and scale-y to the same value."
- (set-sprite-scale-x! sprite scale)
- (set-sprite-scale-y! sprite scale))
-
(define* (make-sprite texture #:optional #:key (position #(0 0))
- (scale-x 1) (scale-y 1) (rotation 0) (color '(1 1 1)))
+ (scale #(1 1)) (rotation 0) (color '(1 1 1)))
"Makes a new sprite object."
- (%make-sprite texture position scale-x scale-y rotation color))
+ (%make-sprite texture position scale rotation color))
(define* (load-sprite filename #:optional #:key (position #(0 0))
- (scale-x 1) (scale-y 1) (rotation 0) (color '(1 1 1)))
+ (scale #(1 1)) (rotation 0) (color '(1 1 1)))
"Loads a sprite from file."
- (make-sprite (load-texture filename) #:position position
- #:scale-x scale-x #:scale-y scale-y
+ (make-sprite (load-texture filename) #:position position #:scale scale
#:rotation rotation #:color color))
(define (draw-sprite sprite)
@@ -75,11 +66,12 @@
(let* ((texture (sprite-texture sprite))
(width (texture-width texture))
(height (texture-height texture))
- (pos (sprite-position sprite)))
+ (pos (sprite-position sprite))
+ (scale (sprite-scale sprite)))
(with-gl-push-matrix
(gl-translate (vx pos) (vy pos) 0)
(gl-rotate (sprite-rotation sprite) 0 0 1)
- (gl-scale (sprite-scale-x sprite) (sprite-scale-y sprite) 0)
+ (gl-scale (vx scale) (vy scale) 0)
;; Render a textured quad center on the sprite position.
(texture-quad texture
(- (/ width 2)) (- (/ height 2))