]> git.jsancho.org Git - gacela.git/blobdiff - games/asteroids/asteroids.scm
Reorganize examples
[gacela.git] / games / asteroids / asteroids.scm
index 6d477e5bedc35ee5982a53560f2e16b2057c5844..902fd549bec2825b5b5d52961b601510c1f33edb 100644 (file)
@@ -1,49 +1,44 @@
-(set-game-properties! #:title "Gacela Asteroids")
+;;; Gacela, a GNU Guile extension for fast games development
+;;; Copyright (C) 2014 by Javier Sancho Fernandez <jsf at jsancho dot org>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
 
-(define max-x (/ (cdr (assoc 'width (get-game-properties))) 2))
-(define min-x (- max-x))
-(define max-y (/ (cdr (assoc 'height (get-game-properties))) 2))
-(define min-y (- max-y))
 
-(define draw-asteroid
-  (let ((asteroid (load-texture "Asteroid.png")))
-    (lambda (a)
-      (to-origin)
-      (translate (car a) (cadr a))
-      (draw-texture asteroid))))
+(define-module (gacela examples asteroids))
+;  #:use-module (gacela game))
 
-(define (move-asteroid a)
-  (let* ((x (car a)) (y (cadr a))
-        (vx (caddr a)) (vy (cadddr a))
-        (nx (+ x vx)) (ny (+ y vy)))
-    (cond ((> nx max-x) (set! vx -1))
-         ((< nx min-x) (set! vx 1)))
-    (cond ((> ny max-y) (set! vy -1))
-         ((< ny min-y) (set! vy 1)))
-    (list (+ x vx) (+ y vy) vx vy)))
 
-(define draw-ship
-  (let ((ship1 (load-texture "Ship1.png"))
-       (ship2 (load-texture "Ship2.png")))
-    (lambda (s)
-      (to-origin)
-      (translate (car s) (cadr s))
-      (rotate (caddr s))
-      (draw-texture ship1))))
+(define asteroids (game "Asteroids"))
+(define player (entity))
+(set! player (add-component player (name "player")))
+(set! player (add-component player (transform)))
+(set! player (add-component player (mesh)))
+(set! asteroids (add-entity asteroids player))
+(define rock (entity))
+(set! rock (add-component rock (name "rock")))
+(set! rock (add-component rock (transform)))
+(set! rock (add-component rock (mesh)))
+(set! asteroids (add-entity asteroids rock))
 
-(define (move-ship s)
-  (let ((x (car s)) (y (cadr s))
-       (angle (caddr s))
-       (vx (cadddr s)) (vy (cadddr (cdr s))))
-    (cond ((key? 'left) (set! angle (+ angle 5)))
-         ((key? 'right) (set! angle (- angle 5))))
-    (cond ((key? 'up) (set! y (+ y 3))))
-    (list x y angle vx vy)))
 
-(let ((asteroids '((100 100 1 1) (-100 -100 -1 1)))
-      (ship '(0 0 0 0 0)))
-  (run-game
-   (set! asteroids (map move-asteroid asteroids))
-   (set! ship (move-ship ship))
-   (for-each draw-asteroid asteroids)
-   (draw-ship ship)))
+(define asteroids
+  (game "Asteroids"
+   (entity
+    (name "player")
+    (transform)
+    (mesh))
+   (entity
+    (name "rock")
+    (transform)
+    (mesh))))