1 ! Copyright (C) 2006, 2007 Alex Chapman
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel sequences arrays math math.vectors namespaces
4 opengl opengl.gl ui.render ui.gadgets tetris.game tetris.board
5 tetris.piece tetris.tetromino ;
8 #! OpenGL rendering for tetris
10 : draw-block ( block -- )
11 dup { 1 1 } v+ 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 clone 0.2 3 pick set-nth gl-color draw-piece-blocks ;
22 ! TODO: move implementation specific stuff into tetris-board
23 : (draw-row) ( x y row -- )
25 [ gl-color 2array draw-block ] [ 3drop ] if ;
27 : draw-row ( y row -- )
28 dup length -rot [ (draw-row) ] 2curry each ;
30 : draw-board ( board -- )
31 board-rows dup length swap
32 [ dupd nth draw-row ] curry each ;
34 : scale-tetris ( width height tetris -- )
35 [ board-width swap ] keep board-height / -rot / swap 1 glScalef ;
37 : (draw-tetris) ( width height tetris -- )
38 #! width and height are in pixels
41 dup tetris-board draw-board
42 dup tetris-next-piece draw-next-piece
43 tetris-current-piece draw-piece
46 : draw-tetris ( width height tetris -- )
47 origin get [ (draw-tetris) ] with-translation ;