]> git.jsancho.org Git - gacela.git/commitdiff
More declarative way of making games
authorJavier Sancho <jsf@jsancho.org>
Tue, 16 Sep 2014 13:37:49 +0000 (15:37 +0200)
committerJavier Sancho <jsf@jsancho.org>
Tue, 16 Sep 2014 13:37:49 +0000 (15:37 +0200)
* src/examples/asteroids.scm: Declarative asteroids game

* src/game.scm: Functions renamed to a more declarative way, erasing
                'make-'

src/examples/asteroids.scm
src/game.scm

index ff607f462553b43685925882de8be4dd136f12f9..1915e450b6042da74b5dee41b2d92469b3966d29 100644 (file)
 ;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
-(define-module (gacela examples asteroids)
-  #:use-module (gacela game))
+(define-module (gacela examples asteroids))
+;  #:use-module (gacela game))
 
 
-(define asteroids (make-game "Asteroids"))
-(define player (make-entity))
-(add-component player (make-transform))
-(add-component player (make-mesh))
-(add-entity asteroids player)
+(define asteroids (game "Asteroids"))
+(define player (entity))
+(set! player (add-component player (transform)))
+(set! player (add-component player (mesh)))
+(set! asteroids (add-entity asteroids player))
 
 (define asteroids
-  (make-game "Asteroids"
-   (make-entity
-    (make-transform)
-    (make-mesh))))
+  (game "Asteroids"
+   (entity
+    (transform)
+    (mesh))))
index 5a8b7d31dfe956998b68c4a121e353b914adf67e..c3aab9f58f942ccc5efae3d6528f39a827ec7074 100644 (file)
 
 ;;; Working with entities
 
-(define-record-type entity
+(define-record-type entity-type
   (make-entity-record id components)
   entity?
   (id entity-id)
+  (game entity-game set-entity-game!)
   (components entity-components set-entity-components!))
 
 (set-record-type-printer! entity
            (entity-id record)
            (entity-components record))))
 
-(define (make-entity . components)
+(define (entity . components)
   (make-entity-record
    (gensym)
+   #f
    components))
 
-(export make-entity
+(export entity
        entity?
        entity-id)
 
 
 ;;; Game Definition
 
-(define-record-type game
+(define-record-type game-type
   (make-game-record name entities)
   game?
   (name game-name set-game-name!)
              '()
              (game-entities record))))))
 
-(define (make-game name . entities)
+(define (game name . entities)
   (make-game-record
    name
    (alist->vhash
     (map (lambda (e) (cons (entity-id e) e))
         entities))))
 
-(export make-game
+(export game
        game?)