From 9d050e6ba7c40c8ed92aa1eeab7a98d89ca85970 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 4 Jun 2019 17:12:36 -0400 Subject: render: tiled: Add point->tile. * chickadee/render/tiled.scm (point->tile): New procedure. * doc/api.texi (Tiled): Document it. * examples/tiled.scm: Render tile coordinates in bottom-left corner. --- examples/tiled.scm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/tiled.scm b/examples/tiled.scm index 5ff2b7f..e6099df 100644 --- a/examples/tiled.scm +++ b/examples/tiled.scm @@ -1,17 +1,23 @@ (use-modules (chickadee) (chickadee math vector) (chickadee math rect) + (chickadee render font) (chickadee render tiled) - (ice-9 match)) + (ice-9 format) + (ice-9 match) + (srfi srfi-11)) (define map #f) (define camera #v(0.0 0.0)) +(define text-position #v(4.0 4.0)) +(define text "0, 0") (define (load) (set! map (load-tile-map "maps/example.tmx"))) (define (draw alpha) - (draw-tile-map map #:position camera)) + (draw-tile-map map #:position camera) + (draw-text text text-position)) (define inc 8.0) (define (key-press key scancode modifiers repeat?) @@ -23,9 +29,14 @@ ('q (abort-game)) (_ #t))) +(define (mouse-move x y x-rel y-rel buttons) + (let-values (((tx ty) (point->tile map x y))) + (set! text (format #f "~d, ~d" tx ty)))) + (run-game #:window-width 320 #:window-height 240 #:window-title "tile map demo" #:load load #:draw draw - #:key-press key-press) + #:key-press key-press + #:mouse-move mouse-move) -- cgit v1.2.3