lisp-game-jam/game.scm
2024-05-24 17:38:39 -04:00

87 lines
2.4 KiB
Scheme

;;; Copyright (C) 2024 David Thompson <dave@spritely.institute>
;;;
;;; 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.
;;; Commentary:
;;;
;;; Example game showing off several common game programming things.
;;;
;;; Code:
(import (scheme base)
(scheme inexact)
(hoot debug)
(hoot ffi)
(hoot hashtables)
(hoot match)
(dom canvas)
(dom console)
(dom document)
(dom element)
(dom event)
(dom image)
(dom media)
(dom window)
(math)
(math rect)
(math vector)
(ces entity)
(ces system)
(ces system sprite-renderer)
(ces system keyboard-reader)
(ces system tilemap-renderer)
(ces system-manager)
(ces entity-manager)
(game-core)
(game game-objects))
(log-to-console! "Getting canvas")
(define canvas (get-element-by-id "canvas"))
(define context (get-context canvas "2d"))
(log-to-console! "Creating canvas renderer")
#;(define canvas-renderer
(create-rendering-system context
(lambda (_)
(request-animation-frame draw-callback))))
(define dt (/ 1000.0 60.0)) ; aim for updating at 60Hz
(log-to-console! "Creating entity manager")
(define e-manager
(create-entity-manager))
(log-to-console! "Creating system manager")
(define s-manager
(create-system-manager))
(define image:player (make-image "assets/images/ball.png"))
#; (define game
(make-game e-manager
s-manager
0
dt))
;;(start-game! game dt)
;; Canvas and event loop setup
;; Preserved for reference.
;;(set-element-width! canvas (exact game-width))
;;(set-element-height! canvas (exact game-height))
;;(add-event-listener! (current-document) "keydown"
;; (procedure->external on-key-down))
;;(add-event-listener! (current-document) "keyup"
;; (procedure->external on-key-up))
;;(timeout update-callback dt)
;;(define draw-callback (procedure->external draw))