Add game-objects.scm
This commit is contained in:
parent
dd5f0ef6f3
commit
234f1343ad
4 changed files with 42 additions and 19 deletions
3
Makefile
3
Makefile
|
@ -5,7 +5,8 @@ modules := \
|
|||
$(wildcard modules/ces/system/*.scm) \
|
||||
$(wildcard modules/dom/*.scm) \
|
||||
$(wildcard modules/math/*.scm) \
|
||||
$(wildcard modules/lib/*.scm)
|
||||
$(wildcard modules/lib/*.scm) \
|
||||
$(wildcard modules/game/*.scm)
|
||||
|
||||
game.wasm: game.scm $(modules)
|
||||
guild compile-wasm -L modules -o $@ $<
|
||||
|
|
3
game.scm
3
game.scm
|
@ -42,7 +42,8 @@
|
|||
(ces system tilemap-renderer)
|
||||
(ces system-manager)
|
||||
(ces entity-manager)
|
||||
(game-core))
|
||||
(game-core)
|
||||
(game game-objects))
|
||||
|
||||
(log-to-console! "Getting canvas")
|
||||
(define canvas (get-element-by-id "canvas"))
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
(define-module (ces component game-object)
|
||||
#:pure
|
||||
#:use-module (scheme base)
|
||||
#:export (game-object?
|
||||
make-game-object
|
||||
game-object-entity-id
|
||||
game-object-sprite
|
||||
game-object-pos-x
|
||||
game-object-pos-y))
|
||||
|
||||
(define-record-type <game-object>
|
||||
(make-game-object entity-id sprite pos-x pos-y)
|
||||
game-object?
|
||||
(entity-id game-object-entity-id)
|
||||
(sprite game-object-sprite)
|
||||
(pos-x game-object-pos-x)
|
||||
(pos-y game-object-pos-y))
|
38
modules/game/game-objects.scm
Normal file
38
modules/game/game-objects.scm
Normal file
|
@ -0,0 +1,38 @@
|
|||
(define-module (game game-objects)
|
||||
#: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)
|
||||
#:export (add-game-object-components
|
||||
game-object?
|
||||
create-game-object!))
|
||||
|
||||
(define (add-position entity entity-id x y)
|
||||
(set-component entity 'position (create-position entity-id x y)))
|
||||
|
||||
(define (add-hitbox entity entity-id x y w h)
|
||||
(set-component entity 'hitbox (make-hitbox entity-id x y w h)))
|
||||
|
||||
(define (add-sprite entity entity-id sprite w h)
|
||||
(set-component entity 'sprite (make-sprite entity-id sprite w h)))
|
||||
|
||||
(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))
|
||||
|
||||
(define (game-object? entity)
|
||||
(has-components? entity 'position 'hitbox 'sprite))
|
||||
|
||||
(define (create-game-object! x y width height sprite)
|
||||
(let* ((e-manager (get-entity-manager))
|
||||
(entity (create-entity! e-manager)))
|
||||
(reset-entity! e-manager
|
||||
(add-game-object-components entity x y width height sprite))))
|
Loading…
Reference in a new issue