1 ! Copyright (C) 2006, 2007, 2008 Alex Chapman
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays combinators kernel math math.vectors
4 namespaces opengl opengl.gl sequences tetris.board tetris.game
5 tetris.piece ui.render tetris.tetromino ui.gadgets colors ;
8 #! OpenGL rendering for tetris
10 : draw-block ( block -- )
11 { 1 1 } gl-fill-rect ;
13 : draw-piece-blocks ( piece -- )
14 piece-blocks [ draw-block ] each ;
16 : draw-piece ( piece -- )
17 dup tetromino>> colour>> gl-color draw-piece-blocks ;
19 : draw-next-piece ( piece -- )
20 dup tetromino>> colour>>
21 >rgba-components drop 0.2 <rgba> gl-color draw-piece-blocks ;
23 ! TODO: move implementation specific stuff into tetris-board
24 : (draw-row) ( x y row -- )
26 [ gl-color 2array draw-block ] [ 3drop ] if ;
28 : draw-row ( y row -- )
29 [ length iota swap ] keep [ (draw-row) ] 2curry each ;
31 : draw-board ( board -- )
32 rows>> [ length iota ] keep
33 [ dupd nth draw-row ] curry each ;
35 : scale-board ( width height board -- )
36 [ width>> ] [ height>> ] bi swapd [ / ] dup 2bi* 1 glScalef ;
38 : draw-tetris ( width height tetris -- )
39 #! width and height are in pixels
42 [ board>> scale-board ]
43 [ board>> draw-board ]
44 [ next-piece draw-next-piece ]
45 [ current-piece draw-piece ]