;;; Licensed under the Apache License, Version 2.0 (the "License"); ;;; you may not use this file except in compliance with the License. ;;; You may obtain a copy of the License at ;;; ;;; http://www.apache.org/licenses/LICENSE-2.0 ;;; ;;; Unless required by applicable law or agreed to in writing, software ;;; distributed under the License is distributed on an "AS IS" BASIS, ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ;;; See the License for the specific language governing permissions and ;;; limitations under the License. (define-module (game main) #:use-module (chickadee) #:use-module (chickadee math rect) #:use-module (chickadee math vector) #:use-module (chickadee graphics color) #:use-module (chickadee graphics sprite) #:use-module (chickadee graphics texture) #:use-module (chickadee graphics text) #:use-module (chickadee graphics tile-map) #:use-module (system repl coop-server) #:export (launch-game)) (define sprite-position (vec2 156.0 176.0)) (define sprite-texture #f) (define tile-atlas #f) (define hero-atlas #f) (define text-position (vec2 0.0 280.0)) (define tile-index 0) (define tile-map #f) (define repl #f) (define (load) (set! sprite-texture (load-image "assets/images/chickadee.png")) (set! tile-atlas (split-texture (load-image "assets/images/simples_pimples.png" #:transparent-color black) 16 16)) (set! hero-atlas (split-texture (load-image "assets/images/lr_penguin2.png") 32 32)) (set! tile-map (load-tile-map "assets/levels/level1.tmx")) (set! repl (spawn-coop-repl-server))) (define (update dt) (poll-coop-repl-server repl) (set-vec2-y! sprite-position (floor-remainder (+ (vec2-y sprite-position) (* 50.0 dt)) 400.0)) (set-vec2-x! text-position (floor-remainder (+ (vec2-x text-position) (* 25.0 dt)) 640.0)) ) (define (draw-tile i) (let ((x (* 16 (remainder i 40))) (y (* 16 (quotient i 40)))) (draw-sprite (texture-atlas-ref tile-atlas (+ i 3000 )) (vec2 x y) #:scale (vec2 1.0 1.0))) ) (define (draw-hero i) (let ((x (* 64 (remainder i 8))) (y (* 32 (quotient i 8))) (id (tile-id)) ) (draw-sprite (texture-atlas-ref hero-atlas i) (vec2 (+ x 16) y) #:scale (vec2 1.0 1.0)) (draw-text (format #f "~2d" i) (vec2 x y) #:color white)) ) (define (draw _alpha) (draw-sprite sprite-texture sprite-position) (draw-text "Hello, Chickadee!" text-position ) (let ((hero-position (vec2+ text-position (vec2 -8.0 16.0))) (hero-index (+ 56 (remainder (inexact->exact (floor (vec2-x text-position))) 8)))) (draw-sprite (texture-atlas-ref hero-atlas hero-index) hero-position)) (draw-tile-map tile-map) ;;(do ((i 0 (+ i 1))) ;; ((>= i 1000)) ;; (draw-tile i)) (do ((i 0 (+ i 1))) ((>= i 64)) (draw-hero i))) (define (launch-game args) (run-game #:load (lambda () (load)) #:update (lambda (dt) (update dt)) #:draw (lambda (alpha) (draw alpha))))