]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/tetris/gl/gl.factor
Harmonize spelling
[factor.git] / extra / tetris / gl / gl.factor
index 8326da35842d586c979dc179b37ef472be584dc9..e0565c8aa01702d79d58da4dc31b8d49c5bd941e 100644 (file)
@@ -1,11 +1,12 @@
 ! Copyright (C) 2006, 2007, 2008 Alex Chapman
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays combinators kernel math math.vectors
-namespaces opengl opengl.gl sequences tetris.board tetris.game
-tetris.piece ui.render tetris.tetromino ui.gadgets colors ;
+
+USING: accessors arrays colors combinators kernel math opengl
+opengl.gl sequences tetris.game tetris.piece ;
+
 IN: tetris.gl
 
-#! OpenGL rendering for tetris
+! OpenGL rendering for tetris
 
 : draw-block ( block -- )
     { 1 1 } gl-fill-rect ;
@@ -14,34 +15,42 @@ IN: tetris.gl
     piece-blocks [ draw-block ] each ;
 
 : draw-piece ( piece -- )
-    dup tetromino>> colour>> gl-color draw-piece-blocks ;
+    dup tetromino>> color>> gl-color draw-piece-blocks ;
 
 : draw-next-piece ( piece -- )
-    dup tetromino>> colour>>
+    dup tetromino>> color>>
     >rgba-components drop 0.2 <rgba> gl-color draw-piece-blocks ;
 
 ! TODO: move implementation specific stuff into tetris-board
 : (draw-row) ( x y row -- )
-    [ over ] dip nth dup
-    [ gl-color 2array draw-block ] [ 3drop ] if ;
+    overd nth [ gl-color 2array draw-block ] [ 2drop ] if* ;
 
 : draw-row ( y row -- )
-    [ length iota swap ] keep [ (draw-row) ] 2curry each ;
+    [ length <iota> swap ] keep [ (draw-row) ] 2curry each ;
 
 : draw-board ( board -- )
-    rows>> [ length iota ] keep
-    [ dupd nth draw-row ] curry each ;
+    rows>> [ swap draw-row ] each-index ;
 
 : scale-board ( width height board -- )
     [ width>> ] [ height>> ] bi swapd [ / ] dup 2bi* 1 glScalef ;
 
+: set-background-color ( tetris -- )
+    dup running?>> [
+        paused?>> COLOR: light-gray COLOR: white ?
+    ] [ drop COLOR: black ] if gl-color ;
+
+: draw-background ( board -- )
+    [ 0 0 ] dip [ width>> ] [ height>> ] bi glRectf ;
+
 : draw-tetris ( width height tetris -- )
-    #! width and height are in pixels
+    ! width and height are in pixels
     [
         {
             [ board>> scale-board ]
+            [ set-background-color ]
+            [ board>> draw-background ]
             [ board>> draw-board ]
             [ next-piece draw-next-piece ]
             [ current-piece draw-piece ]
         } cleave
-    ] do-matrix ;
\ No newline at end of file
+    ] do-matrix ;