1010
Check-in [0098826de3]
Not logged in
Public Repositories
mwm's Repositories

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Switch to Arduboy2, add shape placing code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:0098826de3d0cac83f0749af7618908cfac0f3e8
User & Date: mwm 2016-10-30 12:48:15
Context
2016-10-30
16:44
Ok, it now scores. Still some bugs, though. check-in: a6dd099b63 user: mwm tags: trunk
12:48
Switch to Arduboy2, add shape placing code. check-in: 0098826de3 user: mwm tags: trunk
12:07
Now has all shapes and colors check-in: 65129846b2 user: mwm tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Makefile.

1
2
3
4
BOARD_TAG = leonardo
ARDUINO_LIBS = Arduboy SPI EEPROM

include ../Makefile

|


1
2
3
4
BOARD_TAG = leonardo
ARDUINO_LIBS = Arduboy2 SPI EEPROM

include ../Makefile

Changes to Tiny-1010.ino.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
..
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
...
141
142
143
144
145
146
147
























148
149
150
151
152
153
154
...
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
...
198
199
200
201
202
203
204

205
206



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
 * point.
 *
 * Shapes are presented in groups of three. After all three have been placed,
 * another set of three is presented. If it isn't possible to place any existing
 * block, the game ends.
 */

#include <Arduboy.h>
Arduboy arduboy;


/* The  board */
const byte BOARD_SIZE = 10;	// a board_size by board_size game
const byte BLOCK_SIZE = 6;	// Each tile is tile_size pixels on a side.
const byte BOARD_X = 62;	// Left edge of board
const byte BOARD_Y = 2;		// Top edge of the board.
................................................................................
void
color_tile(const byte x, const byte y, const byte color) {
     arduboy.drawBitmap(BOARD_X + x * BLOCK_SIZE, BOARD_Y + y * BLOCK_SIZE,
                        colors[color % (sizeof(colors) / TILE_SIZE)],
                        TILE_SIZE, TILE_SIZE, WHITE);
}

/* The shapes
 * Shapes: 2x2 corners in all 4 orientations
 *         3x3 corner in all 4 orientations
 *         L's in 8 orientations (4 long, 4 wide)
 *         blocks: size 1, 2, and 3
 *         straights: size 2, 3, 4 and 5
 */
const byte ss = 3;	// 1x1 square

const byte threes[][3] = {
     { 6,  6,  6},	// vertical 3 in a row
     { 7,  7,  0},	// vertical 2 in a row
     {10, 10, 10},	// horizontal 3 in a row
     {11, 11, 0},	// horizontal 2 in a row
................................................................................
     unsigned score;
     byte delay;
     int8_t shape;		// Currently selected shape
     byte shape_x, shape_y;	// And it's location on the board.
     byte board[BOARD_SIZE * BOARD_SIZE];
} game;


























void
reset_game(void) {
     game.score = 0;
     for (byte i = 0; i < BOARD_SIZE * BOARD_SIZE; i += 1) {
          game.board[i] = EMPTY;
     }
................................................................................
     } else {
          draw_score(score / 10);
          arduboy.write(score % 10 + '0');
     }
}

void

draw_game(void) {
     arduboy.clear();
     arduboy.setCursor(0, 0);
     draw_score(game.score);

     for (byte y = 0; y < BOARD_SIZE; y += 1)
          for (byte x = 0; x < BOARD_SIZE; x += 1)
               color_tile(x, y, game.board[x + y * BOARD_SIZE]);

     if (game.shape >= 0) {
          const shape * const s = &shapes[game.shape];
          for (byte y = 0; y < s->height; y += 1)
               for (byte x = 0; x < s->width; x += 1) {
                    color_tile(game.shape_x + x, game.shape_y + y,
                               s->tiles[x + s->width * y]);
               }
     }

     arduboy.display();
}


................................................................................
     reset_game();
     draw_game();
}

void
loop(void) {
     const shape *s = &shapes[game.shape];


     while (!arduboy.nextFrame())



          ;
     
     if (arduboy.pressed(UP_BUTTON) && (game.shape_y > 0))
          game.shape_y -= 1;
     else if (arduboy.pressed(DOWN_BUTTON)
          && (game.shape_y < BOARD_SIZE - s->height))
          game.shape_y += 1;
     else if (arduboy.pressed(LEFT_BUTTON) && (game.shape_x > 0))
          game.shape_x -= 1;
     else if (arduboy.pressed(RIGHT_BUTTON)
          && (game.shape_x < BOARD_SIZE - s->width))
          game.shape_x += 1;
     else if (arduboy.pressed(A_BUTTON)) {
          game.shape = (game.shape + 1) % (sizeof(shapes) / sizeof(shape));
          game.shape_x = game.shape_y = 0;
     } else if (arduboy.pressed(B_BUTTON)) {
          game.shape -= 1;
          if (game.shape < 0) game.shape = sizeof(shapes) / sizeof(shape) - 1;
          game.shape_x = game.shape_y = 0;
     }
     game.score = game.shape_x * 10 + game.shape_y;
     draw_game();
     delay(game.delay);
}







|
|







 







|
<
<
<
<
<
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>


<











|







 







>

<
>
>
>
|
<











|
|

<
|






10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
..
48
49
50
51
52
53
54
55






56
57
58
59
60
61
62
...
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
...
183
184
185
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
...
216
217
218
219
220
221
222
223
224

225
226
227
228

229
230
231
232
233
234
235
236
237
238
239
240
241
242

243
244
245
246
247
248
249
 * point.
 *
 * Shapes are presented in groups of three. After all three have been placed,
 * another set of three is presented. If it isn't possible to place any existing
 * block, the game ends.
 */

#include <Arduboy2.h>
Arduboy2 arduboy;


/* The  board */
const byte BOARD_SIZE = 10;	// a board_size by board_size game
const byte BLOCK_SIZE = 6;	// Each tile is tile_size pixels on a side.
const byte BOARD_X = 62;	// Left edge of board
const byte BOARD_Y = 2;		// Top edge of the board.
................................................................................
void
color_tile(const byte x, const byte y, const byte color) {
     arduboy.drawBitmap(BOARD_X + x * BLOCK_SIZE, BOARD_Y + y * BLOCK_SIZE,
                        colors[color % (sizeof(colors) / TILE_SIZE)],
                        TILE_SIZE, TILE_SIZE, WHITE);
}

/* The shapes */






const byte ss = 3;	// 1x1 square

const byte threes[][3] = {
     { 6,  6,  6},	// vertical 3 in a row
     { 7,  7,  0},	// vertical 2 in a row
     {10, 10, 10},	// horizontal 3 in a row
     {11, 11, 0},	// horizontal 2 in a row
................................................................................
     unsigned score;
     byte delay;
     int8_t shape;		// Currently selected shape
     byte shape_x, shape_y;	// And it's location on the board.
     byte board[BOARD_SIZE * BOARD_SIZE];
} game;


byte
shape_clear(void) {
     const shape * const s = &shapes[game.shape];

     for (byte y = 0; y < s->height; y += 1)
          for (byte x = 0; x < s->width; x += 1)
               if (s->tiles[x + y * s->width]
               && game.board[game.shape_x + x + (game.shape_y + y) * BOARD_SIZE])
                    return 0;
     return 1;
}
     

void
place_shape(void)  {
     const shape * const s = &shapes[game.shape];

     for (byte y = 0; y < s->height; y += 1)
          for (byte x = 0; x < s->width; x += 1)
               if (s->tiles[x + y * s->width])
                    game.board[game.shape_x + x + (game.shape_y + y) * BOARD_SIZE]
                         = s->tiles[x + y * s->width];
}

void
reset_game(void) {
     game.score = 0;
     for (byte i = 0; i < BOARD_SIZE * BOARD_SIZE; i += 1) {
          game.board[i] = EMPTY;
     }
................................................................................
     } else {
          draw_score(score / 10);
          arduboy.write(score % 10 + '0');
     }
}

void

draw_game(void) {
     arduboy.clear();

     draw_score(game.score);

     for (byte y = 0; y < BOARD_SIZE; y += 1)
          for (byte x = 0; x < BOARD_SIZE; x += 1)
               color_tile(x, y, game.board[x + y * BOARD_SIZE]);

     if (game.shape >= 0) {
          const shape * const s = &shapes[game.shape];
          for (byte y = 0; y < s->height; y += 1)
               for (byte x = 0; x < s->width; x += 1) {
                    color_tile(game.shape_x + x, game.shape_y + y,
                               s->tiles[x + y * s->width]);
               }
     }

     arduboy.display();
}


................................................................................
     reset_game();
     draw_game();
}

void
loop(void) {
     const shape *s = &shapes[game.shape];
     byte can_place = shape_clear();


     arduboy.digitalWriteRGB(can_place ? RGB_OFF : RGB_ON,
                             can_place ? RGB_ON : RGB_OFF, RGB_OFF);
     arduboy.pollButtons();


     if (arduboy.pressed(UP_BUTTON) && (game.shape_y > 0))
          game.shape_y -= 1;
     else if (arduboy.pressed(DOWN_BUTTON)
          && (game.shape_y < BOARD_SIZE - s->height))
          game.shape_y += 1;
     else if (arduboy.pressed(LEFT_BUTTON) && (game.shape_x > 0))
          game.shape_x -= 1;
     else if (arduboy.pressed(RIGHT_BUTTON)
          && (game.shape_x < BOARD_SIZE - s->width))
          game.shape_x += 1;
     else if (arduboy.pressed(A_BUTTON)) {
          if (can_place)
               place_shape();
     } else if (arduboy.pressed(B_BUTTON)) {

          game.shape = (game.shape + 1) % (sizeof(shapes) / sizeof(shape));
          game.shape_x = game.shape_y = 0;
     }
     game.score = game.shape_x * 10 + game.shape_y;
     draw_game();
     delay(game.delay);
}