X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fexamples%2Fentity-component-functions.scm;fp=src%2Fexamples%2Fentity-component-functions.scm;h=43316fc743647947e4cc8fdbd4d08d4987b9bb93;hb=2b3814bf3f335a56c17b733caf90c17dbe229e91;hp=0000000000000000000000000000000000000000;hpb=9b261e3a07d92edf68979b46f756413a0ac9247a;p=gacela.git diff --git a/src/examples/entity-component-functions.scm b/src/examples/entity-component-functions.scm new file mode 100644 index 0000000..43316fc --- /dev/null +++ b/src/examples/entity-component-functions.scm @@ -0,0 +1,70 @@ +;;; Gacela, a GNU Guile extension for fast games development +;;; Copyright (C) 2013 by Javier Sancho Fernandez +;;; +;;; This program is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program. If not, see . + + +(define-module (gacela examples entity-component-functions) + #:use-module (gacela system) + #:use-module (ice-9 receive)) + + +(define-component a x y) +(define-component b) + +(define (entity-component-functions) + (let ((entities '()) + (components '()) + (key #f)) + (receive (e c k) ((new-entity (make-a 1 2) (make-b)) entities components) + (set! entities e) + (set! components c) + (set! key k) + (display k) (newline)) + (format #t "New entity with a and b:~%~a~%~a~%~%" entities components) + + (receive (e c k) ((new-entity (make-a 10 20)) entities components) + (set! entities e) + (set! components c) + (display k) (newline)) + (format #t "New entity with a:~%~a~%~a~%~%" entities components) + + (receive (e c) (modify-entities (list (set-entity-components key (make-a 50 50)) (remove-entity-components key 'b)) entities components) + (set! entities e) + (set! components c)) + (format #t "First entity removes b and changes a:~%~a~%~a~%~%" entities components) + + (receive (e c) ((remove-entity key) entities components) + (set! entities e) + (set! components c)) + (format #t "Removes first entity:~%~a~%~a~%~%" entities components) + + (receive (e c k) ((new-entity (make-a 1 2) (make-b)) entities components) + (set! entities e) + (set! components c) + (set! key k) + (display k) (newline)) + (format #t "New entity with a and b:~%~a~%~a~%~%" entities components) + + (receive (e c) (modify-entities (list (set-entity-components key (make-a 50 50)) (remove-entity-components key 'b) (new-entity (make-a 1000 1000))) entities components) + (set! entities e) + (set! components c)) + (format #t "Last entity removes b and changes a, and new entity with a:~%~a~%~a~%~%" entities components) + + (receive (e c) (modify-entities (list (remove-entity key)) entities components) + (set! entities e) + (set! components c)) + (format #t "Remove last entity:~%~a~%~a~%~%" entities components))) + +(export entity-component-functions)