diff options
-rw-r--r-- | chickadee/graphics/tiled.scm | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/chickadee/graphics/tiled.scm b/chickadee/graphics/tiled.scm index 8da86b5..46dfea3 100644 --- a/chickadee/graphics/tiled.scm +++ b/chickadee/graphics/tiled.scm @@ -197,8 +197,8 @@ (define (point->tile tile-map x y) "Translate the pixel coordinates (X, Y) into tile coordinates." - (values (floor (/ x (tile-map-tile-width tile-map))) - (floor (/ y (tile-map-tile-height tile-map))))) + (values (inexact->exact (floor (/ x (tile-map-tile-width tile-map)))) + (inexact->exact (floor (/ y (tile-map-tile-height tile-map)))))) (define (load-tile-map file-name) "Load the Tiled TMX formatted map in FILE-NAME." @@ -464,31 +464,36 @@ (define %null-vec2 (vec2 0.0 0.0)) (define %default-scale (vec2 1.0 1.0)) -(define %matrix (make-null-matrix4)) -(define %region (make-rect 0.0 0.0 0.0 0.0)) +(define *matrix* (make-null-matrix4)) +(define *position* (vec2 0.0 0.0)) +(define *region* (make-rect 0.0 0.0 0.0 0.0)) ;; Make a default region that is as big as the viewport. (define (default-region tile-map position) (let ((vp (current-viewport))) - (set-rect-x! %region (- (vec2-x position))) - (set-rect-y! %region (- (vec2-y position))) - (set-rect-width! %region (viewport-width vp)) - (set-rect-height! %region (viewport-height vp)) - %region)) + (set-rect-x! *region* (vec2-x position)) + (set-rect-y! *region* (vec2-y position)) + (set-rect-width! *region* (viewport-width vp)) + (set-rect-height! *region* (viewport-height vp)) + *region*)) (define* (draw-tile-map tile-map #:key layers + (camera %null-vec2) (position %null-vec2) - (region (default-region tile-map position)) + (region (default-region tile-map camera)) (origin %null-vec2) (scale %default-scale) (rotation 0.0)) "Draw TILE-MAP. By default, all layers are drawn. The LAYERS argument may be used to specify a list of layers to draw, instead." - (matrix4-2d-transform! %matrix + (vec2-copy! camera *position*) + (vec2-mult! *position* -1.0) + (vec2-add! *position* position) + (matrix4-2d-transform! *matrix* #:origin origin - #:position position + #:position *position* #:rotation rotation #:scale scale) - (draw-tile-map* tile-map %matrix region #:layers layers)) + (draw-tile-map* tile-map *matrix* region #:layers layers)) |