]> git.jsancho.org Git - gacela.git/blobdiff - gacela_tetris.lisp
(no commit message)
[gacela.git] / gacela_tetris.lisp
index 3397a91612ad0612bdfd56a42aee653bd5a70d16..5435e96bfb8678bb6b651d52dcb6b3ee54a83eb3 100644 (file)
@@ -1,6 +1,6 @@
 (in-package :gacela)
 
-(setq *zoom* -50)
+(set-game-properties :title "Gacela Tetris" :fps 15)
 
 (defun tetramine-i ()
   (let ((color '(1 0 0)))
 
 (defun draw-cell (cell)
   (cond ((null cell) nil)
-       (t (draw-color cell) (draw-square :size 0.9))))
+       (t (with-color cell (draw-square :size 20)))))
 
 (defun draw-row (row)
-  (mapcar (lambda (cell) (draw-cell cell) (translate 2 0)) row))
+  (mapcar (lambda (cell) (draw-cell cell) (translate 23 0)) row))
 
 (defun draw-grid (grid)
-  (mapcar (lambda (row) (draw-row row) (translate (* -2 (length row)) -2)) grid))
+  (mapcar (lambda (row) (draw-row row) (translate (* -23 (length row)) -23)) grid))
 
 (defun join-rows (source destination &optional (offset 0))
   (cond ((null source) destination)
 
 (defun remove-rows-completed (grid)
   (let ((res (remove-if (lambda (x) (row-completed x)) grid)))
+    (inc-points (- (length grid) (length res)))
     (labels ((fill (grid n)
                   (cond ((< n 1) grid)
                         (t (fill (cons (make-list 14) grid) (- n 1))))))
            (fill res (- 20 (length res))))))
 
+(let ((points 0) (lines 0))
+  (defun get-points ()
+    points)
+
+  (defun get-lines ()
+    lines)
+
+  (defun inc-points (l)
+    (incf points
+         (labels ((more-lines-better (n)
+                                     (cond ((= n 0) n)
+                                           (t (+ n (more-lines-better (- n 1)))))))
+                 (* (more-lines-better l) 10)))
+    (incf lines l)))
+
 (let ((tetramine (random-tetramine)) (x 6) (y 0)
       (next (random-tetramine))
       (timer (make-timer))
       (grid (make-list 20 :initial-element (make-list 14)))
-      (background (draw-image-function "fondo_tetris.png")))
+      (background (load-texture "fondo_tetris.png"))
+;      (background (load-texture "../../nehe/lesson06/data/nehe.bmp"))
+      (font (load-font "lazy.ttf" :size 20))
+      (game-over))
+
+  (defun game ()
+    (if game-over (game-over) (tetramine)))
+
+  (defun game-over ()
+    (translate -100 0)
+    (render-text "Game Over" font :size 50))
+
   (defun tetramine ()
     (cond ((eq (timer-state timer) 'stopped) (start-timer timer)))
 
                      (> (+ y 1 (length tetramine)) 20))
                  (setq grid (remove-rows-completed (join-grids tetramine grid x y)))
                  (setq tetramine next x 6 y 0)
+                 (cond ((collide-grids tetramine grid x y) (setq game-over t)))
                  (setq next (random-tetramine)))
                 (t (incf y) (start-timer timer)))))
-
-    (funcall background 0.086)))
-;    (translate -25 19)
-;    (draw-grid (join-grids tetramine grid x y))
-;    (translate 40 40)
-;    (draw-grid next)))
-
-(run-game "Gacela Tetris" (tetramine))
+    (draw-texture background)
+    (translate -288 218)
+    (draw-grid (join-grids tetramine grid x y))
+    (translate 440 440)
+    (draw-grid next)
+    (translate -40 -100)
+    (render-text (format nil "Points: ~d" (get-points)) font)
+    (translate 0 -30)
+    (render-text (format nil "Lines: ~d" (get-lines)) font)))
+
+(let ((frame 0.0) (fps (make-timer)) (update (make-timer)))
+  (start-timer update)
+  (start-timer fps)
+  (run-game
+   (game)
+   (incf frame)
+   (cond ((> (get-time update) 1000) (print (/ frame (/ (get-time fps) 1000.0))) (start-timer update))))
+  (quit-game))