Add basic game manager
This commit is contained in:
parent
942570a6bb
commit
61769a8165
4 changed files with 76 additions and 4 deletions
BIN
assets/backgrounds/background.png
Normal file
BIN
assets/backgrounds/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 454 B |
22
modules/game/game-manager.scm
Normal file
22
modules/game/game-manager.scm
Normal file
|
@ -0,0 +1,22 @@
|
|||
(define-module (game game-manager)
|
||||
#:pure
|
||||
#:use-module (scheme base)
|
||||
#:use-module (ces system html-canvas-renderer)
|
||||
#:use-module (game level-manager)
|
||||
#:export (init-game-entities
|
||||
init-game-systems))
|
||||
|
||||
(define canvas (get-element-by-id "canvas"))
|
||||
(define context (get-context canvas "2d"))
|
||||
|
||||
(define room-background (make-image "assets/backgrounds/background.png"))
|
||||
|
||||
(define (init-game-entities)
|
||||
"Returns a list of initial game entities. "
|
||||
(list (create-player!)
|
||||
(create-room! room-background 0 0 128 64)))
|
||||
|
||||
(define (init-game-systems)
|
||||
"Returns a list of initial game systems.
|
||||
Note: Systems are executed sequentially. "
|
||||
(list (create-html-canvas-renderer context)))
|
|
@ -8,6 +8,7 @@
|
|||
#:use-module (ces entity)
|
||||
#:use-module (ces entity-manager)
|
||||
#:use-module (game-core)
|
||||
#:use-module (dom image)
|
||||
#:export (add-game-object-components
|
||||
game-object?
|
||||
create-game-object!))
|
||||
|
@ -23,10 +24,10 @@
|
|||
|
||||
(define (add-game-object-components entity x y width height sprite)
|
||||
(let* ((entity-id (game-entity-id entity))
|
||||
(e-pos (add-position entity entity-id x y))
|
||||
(e-hit (add-hitbox entity entity-id x y width height))
|
||||
(e-sprite (add-sprite entity entity-id sprite width height)))
|
||||
e-sprite))
|
||||
(entity (add-position entity entity-id x y))
|
||||
(entity (add-hitbox entity entity-id x y width height))
|
||||
(entity (add-sprite entity entity-id sprite width height)))
|
||||
entity))
|
||||
|
||||
(define (game-object? entity)
|
||||
(has-components? entity 'position 'hitbox 'sprite))
|
||||
|
|
49
modules/game/level-manager.scm
Normal file
49
modules/game/level-manager.scm
Normal file
|
@ -0,0 +1,49 @@
|
|||
(define-module (game level-manager)
|
||||
#:pure
|
||||
#:use-module (scheme base)
|
||||
#:use-module (ces component)
|
||||
#:use-module (ces component hitbox)
|
||||
#:use-module (ces component position)
|
||||
#:use-module (ces component sprite)
|
||||
#:use-module (ces entity)
|
||||
#:use-module (ces entity-manager)
|
||||
#:use-module (game-core)
|
||||
#:use-module (game game-objects)
|
||||
#:export ())
|
||||
|
||||
;; Player
|
||||
(define (player? entity)
|
||||
(and (game-object? entity)
|
||||
(has-components? entity 'keyboard-input)))
|
||||
|
||||
(define player-sprite (make-image "assets/sprites/player.png"))
|
||||
(define (create-player!)
|
||||
(let ((initial-entity (create-game-object! 0 0 16 16 player-sprite)))
|
||||
(add-component initial-entity 'keyboard-input
|
||||
(make-inputs '() '() '()))))
|
||||
|
||||
;; Room
|
||||
(define (room? entity)
|
||||
(has-components? entity 'hitbox 'sprite)) ;; + 'room-objects ?
|
||||
;; As it stands a game object is technically also a room.
|
||||
;; This will not be the case in the future -- especially once tilemaps work.
|
||||
|
||||
(define (add-background entity entity-id image width height)
|
||||
(set-component entity 'sprite (make-sprite entity-id image width height)))
|
||||
|
||||
(define (add-bounding-box entity entity-id x y width height)
|
||||
(set-component entity 'hitbox (make-hitbox entity-id x y width height)))
|
||||
|
||||
(define (add-room-components entity background x y width height)
|
||||
(let* ((room-entity-id (game-entity-id entity))
|
||||
(entity (add-background entity room-entity-id sprite width height))
|
||||
(entity (add-bounding-box entity room-entity-id x y width height)))))
|
||||
|
||||
(define (create-room! background x y width height)
|
||||
(let* ((e-manager (get-entity-manager))
|
||||
(entity (create-entity! e-manager)))
|
||||
(reset-entity! e-manager
|
||||
(add-room-components entity background x y width height))))
|
||||
|
||||
;; Floor
|
||||
;; A floor is a list of rooms
|
Loading…
Reference in a new issue