]> gitweb.factorcode.org Git - factor.git/blob - extra/tetris/tetromino/tetromino.factor
colors: merge colors.constants and colors.hex.
[factor.git] / extra / tetris / tetromino / tetromino.factor
1 ! Copyright (C) 2006, 2007, 2008 Alex Chapman
2 ! See http://factorcode.org/license.txt for BSD license.
3
4 USING: kernel arrays namespaces sequences math math.order
5 math.vectors colors random ;
6
7 IN: tetris.tetromino
8
9 TUPLE: tetromino states colour ;
10
11 C: <tetromino> tetromino
12
13 SYMBOL: tetrominoes
14
15 {
16   [
17     { {
18         { 0 0 } { 1 0 } { 2 0 } { 3 0 }
19       }
20       { { 0 0 }
21         { 0 1 }
22         { 0 2 }
23         { 0 3 }
24       }
25     } COLOR: cyan
26   ] [
27     {
28       {         { 1 0 }
29         { 0 1 } { 1 1 } { 2 1 }
30       } {
31         { 0 0 }
32         { 0 1 } { 1 1 }
33         { 0 2 }
34       } {
35         { 0 0 } { 1 0 } { 2 0 }
36                 { 1 1 }
37       } {
38                 { 1 0 }
39         { 0 1 } { 1 1 }
40                 { 1 2 }
41       }
42     } COLOR: purple
43   ] [
44     { { { 0 0 } { 1 0 }
45         { 0 1 } { 1 1 } }
46     } COLOR: yellow
47   ] [
48     {
49       { { 0 0 } { 1 0 } { 2 0 }
50         { 0 1 }
51       } {
52         { 0 0 } { 1 0 }
53                 { 1 1 }
54                 { 1 2 }
55       } {
56                         { 2 0 }
57         { 0 1 } { 1 1 } { 2 1 }
58       } {
59         { 0 0 }
60         { 0 1 }
61         { 0 2 } { 1 2 }
62       }
63     } COLOR: orange
64   ] [
65     {
66       { { 0 0 } { 1 0 } { 2 0 }
67                         { 2 1 }
68       } {
69                 { 1 0 }
70                 { 1 1 }
71         { 0 2 } { 1 2 }
72       } {
73         { 0 0 }
74         { 0 1 } { 1 1 } { 2 1 }
75       } {
76         { 0 0 } { 1 0 }
77         { 0 1 }
78         { 0 2 }
79       }
80     } COLOR: blue
81   ] [
82     {
83       {          { 1 0 } { 2 0 }
84         { 0 1 } { 1 1 }
85       } {
86         { 0 0 }
87         { 0 1 } { 1 1 }
88                 { 1 2 }
89       }
90     } COLOR: green
91   ] [
92     {
93       {
94         { 0 0 } { 1 0 }
95                 { 1 1 } { 2 1 }
96       } {
97                 { 1 0 }
98         { 0 1 } { 1 1 }
99         { 0 2 }
100       }
101     } COLOR: red
102   ]
103 } [ first2 <tetromino> ] map tetrominoes set-global
104
105 : random-tetromino ( -- tetromino )
106     tetrominoes get random ;
107
108 : blocks-max ( blocks quot -- max )
109     map supremum 1 + ; inline
110
111 : blocks-width ( blocks -- width )
112     [ first ] blocks-max ;
113
114 : blocks-height ( blocks -- height )
115     [ second ] blocks-max ;