X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fgame.scm;fp=src%2Fgame.scm;h=5a8b7d31dfe956998b68c4a121e353b914adf67e;hb=3b22fd3f425de9419f98bacf2d1c4675058389ed;hp=0000000000000000000000000000000000000000;hpb=929ba6a645c92ebea58c8c93c412197b56aa775f;p=gacela.git diff --git a/src/game.scm b/src/game.scm new file mode 100644 index 0000000..5a8b7d3 --- /dev/null +++ b/src/game.scm @@ -0,0 +1,85 @@ +;;; Gacela, a GNU Guile extension for fast games development +;;; Copyright (C) 2014 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 game) + #:use-module (gacela engine) + #:use-module (ice-9 vlist) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-9) + #:use-module (srfi srfi-9 gnu)) + + +;;; Working with entities + +(define-record-type entity + (make-entity-record id components) + entity? + (id entity-id) + (components entity-components set-entity-components!)) + +(set-record-type-printer! entity + (lambda (record port) + (format port "#<[entity ~a] ~a>" + (entity-id record) + (entity-components record)))) + +(define (make-entity . components) + (make-entity-record + (gensym) + components)) + +(export make-entity + entity? + entity-id) + + +;;; Game Definition + +(define-record-type game + (make-game-record name entities) + game? + (name game-name set-game-name!) + (entities game-entities set-game-entities!)) + +(set-record-type-printer! game + (lambda (record port) + (format port "#<[Game: ~a] ~a>" + (game-name record) + (map + (lambda (id) + (cdr (vhash-assoc id (game-entities record)))) + (vhash-fold + (lambda (key value result) + (lset-union eqv? (list key) result)) + '() + (game-entities record)))))) + +(define (make-game name . entities) + (make-game-record + name + (alist->vhash + (map (lambda (e) (cons (entity-id e) e)) + entities)))) + +(export make-game + game?) + + +;;; Working with games + +(define (add-entity game entity) + #f)