2024-05-17 23:49:31 +02:00
|
|
|
;;; 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)
|
2024-05-19 18:48:18 +02:00
|
|
|
#:use-module (chickadee math rect)
|
2024-05-17 23:49:31 +02:00
|
|
|
#:use-module (chickadee math vector)
|
2024-05-19 18:48:18 +02:00
|
|
|
#:use-module (chickadee graphics color)
|
2024-05-17 23:49:31 +02:00
|
|
|
#:use-module (chickadee graphics sprite)
|
|
|
|
#:use-module (chickadee graphics texture)
|
2024-05-19 18:48:18 +02:00
|
|
|
#:use-module (chickadee graphics text)
|
|
|
|
#:use-module (chickadee graphics tile-map)
|
2024-05-17 23:49:31 +02:00
|
|
|
#:use-module (system repl coop-server)
|
|
|
|
#:export (launch-game))
|
|
|
|
|
2024-05-19 18:48:18 +02:00
|
|
|
(define sprite-position (vec2 156.0 176.0))
|
2024-05-17 23:49:31 +02:00
|
|
|
(define sprite-texture #f)
|
2024-05-19 18:48:18 +02:00
|
|
|
(define tile-atlas #f)
|
|
|
|
(define hero-atlas #f)
|
|
|
|
(define text-position (vec2 0.0 280.0))
|
|
|
|
(define tile-index 0)
|
|
|
|
(define tile-map #f)
|
2024-05-17 23:49:31 +02:00
|
|
|
(define repl #f)
|
|
|
|
|
2024-05-19 18:48:18 +02:00
|
|
|
|
2024-05-17 23:49:31 +02:00
|
|
|
(define (load)
|
|
|
|
(set! sprite-texture (load-image "assets/images/chickadee.png"))
|
2024-05-19 18:48:18 +02:00
|
|
|
(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"))
|
2024-05-17 23:49:31 +02:00
|
|
|
(set! repl (spawn-coop-repl-server)))
|
|
|
|
|
2024-05-19 18:48:18 +02:00
|
|
|
(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))
|
|
|
|
)
|
|
|
|
|
2024-05-17 23:49:31 +02:00
|
|
|
|
|
|
|
(define (draw _alpha)
|
2024-05-19 18:48:18 +02:00
|
|
|
(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)))
|
2024-05-17 23:49:31 +02:00
|
|
|
|
|
|
|
(define (launch-game args)
|
2024-05-19 18:48:18 +02:00
|
|
|
(run-game #:load (lambda () (load))
|
|
|
|
#:update (lambda (dt) (update dt))
|
|
|
|
#:draw (lambda (alpha) (draw alpha))))
|