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

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

Overview
Comment:Tweak that keys page some more. Move the init polling into the loop().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:ad5306ec1636bb8c16e19096a75b3fbc09c08429
User & Date: mwm 2016-11-07 13:22:30
Context
2016-11-07
14:46
Move help pages to PROGMEM to save RAM. check-in: 0719801f3f user: mwm tags: trunk
13:22
Tweak that keys page some more. Move the init polling into the loop(). check-in: ad5306ec16 user: mwm tags: trunk
12:30
Clean up help pages a bit. check-in: 7eb0d14ba6 user: mwm tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Tiny-1010.ino.

136
137
138
139
140
141
142
143
144




145

146
147
148
149
150
151
152
153
154
155
156
157
158
159
...
381
382
383
384
385
386
387





388
389
390
391
392
393
394
...
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465

466
467
468
469
470
471
472
...
475
476
477
478
479
480
481



























482
483
484
485
486
487
488
...
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561

     "      Game play\n\nSelect shapes to\nplace on empty\nsquares on the 10x10\n"
     "game board. Filling a\nrow or column clears\nit.",

     "       Scoring\n\nPlacing a shape\nscores one point for\neach block in the\n"
     "shape, and ten points\nfor each line\ncleared.",

     "  Buttons: B pauses!\n Selecting\336  Moving\n\30 & \31     \336 Move with\n"
     "changes   \336 \33\31\30\32. \33\n\33 starts  \336 at left\n"




     "moving.   \336 deselects\nA autofits\336 A places\nthen moves\336",


     "        About\n\n1010 c Mike Meyer\nmike@mired.org\n\nhttps://goo.gl/9EeMnN",
     NULL
};

// The game
typedef enum {MENU, DONE, SELECTING, MOVING, PAGING} game_state;
const byte WAIT_LEN = 3;

struct game_data {
     unsigned long high, score;
     byte delay;
     int8_t waiting[WAIT_LEN];	// Shapes ready to be played.
     byte x, y;	// And it's location on the board.
................................................................................
     arduboy.print("Score\n");
     arduboy.print(game.score);
     arduboy.setCursor(0, 44); 
     arduboy.print("High\n");
     arduboy.print(game.high);

     switch (state) {





     case DONE:
          blue = RGB_ON;
          // Fall through
     case MENU:
          draw_menu();
          break;
     case PAGING:
................................................................................
          game.high = 0;
          selected = HELP;
          EEPROM.put(saved_game, game);
          EEPROM.write(store, flagbyte);
          EEPROM.write(store + 1, flagbyte);
     } else {
          EEPROM.get(saved_game, game);
          state = DONE;
          selected = NEW;
          prompt = GAMEOVER;
          for (byte i = 0; i < WAIT_LEN; i += 1) {
               if (game.waiting[i] >= 0) {
                    state = MENU;
                    selected = RESUME;
                    prompt = PAUSED;
                    break;
               }
          }
     }

     draw_board();
     arduboy.print("\n\n1010 v1.0\n by mwm\n\nPress A");
     arduboy.display();
     do arduboy.pollButtons();
     while (!arduboy.justPressed(A_BUTTON));
     arduboy.initRandomSeed();

}

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

................................................................................
          prompt = PAUSED;
          state = MENU;
          selected = RESUME;
          return;
     }

     switch (state) {



























     case SELECTING:
          if (arduboy.justPressed(UP_BUTTON))
               do {
                    if (selected)
                         selected -= 1;
                    else
                         selected = WAIT_LEN - 1;
................................................................................
               game.waiting[i] = -1;
          if (arduboy.justPressed(A_BUTTON))
               do_menu();
          else if (arduboy.justPressed(LEFT_BUTTON)
                   || arduboy.justPressed(RIGHT_BUTTON))
               selected = selected == NEW ? HELP : NEW;
          break;
     case MENU:
          if (arduboy.justPressed(A_BUTTON)) {
               do_menu();
          } else if (arduboy.justPressed(LEFT_BUTTON)) {
               if (selected)
                    selected -= 1;
               else
                    selected = MENU_LAST - 1;
          } else if (arduboy.justPressed(RIGHT_BUTTON)) {
               selected = (selected + 1) % MENU_LAST;
          }
          break;
     case PAGING:
          if (arduboy.justPressed(LEFT_BUTTON) && selected)
              selected -= 1;
          else if (arduboy.justPressed(RIGHT_BUTTON) & help[selected + 1] != NULL)
               selected += 1;
          else if (arduboy.justPressed(UP_BUTTON)) {
               state = MENU;
               selected = HELP;
          }
     }

     EEPROM.put(saved_game, game);
     if (state == MOVING) {
          unsigned long end = millis() + game.delay;
          // Used pressed as the button just exists the loop.
          while (millis() < end)
               if (arduboy.pressed(A_BUTTON) || arduboy.pressed(B_BUTTON))
                    break;
     }
}







|
|
>
>
>
>
|
>

|




|







 







>
>
>
>
>







 







<




<






<
<
<
<
<
<
<
>







 







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







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<











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
...
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
...
450
451
452
453
454
455
456

457
458
459
460

461
462
463
464
465
466







467
468
469
470
471
472
473
474
...
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
...
552
553
554
555
556
557
558





















559
560
561
562
563
564
565
566
567
568
569

     "      Game play\n\nSelect shapes to\nplace on empty\nsquares on the 10x10\n"
     "game board. Filling a\nrow or column clears\nit.",

     "       Scoring\n\nPlacing a shape\nscores one point for\neach block in the\n"
     "shape, and ten points\nfor each line\ncleared.",

     "  Buttons: B pauses!\n"
     " Selecting\336  Moving\n"
     "\30\31 changes\336 \33\31\30\32\n"
     "shape     \336 moves\n"
     "\32 selects \336 \33 at left\n"
     "to corner \336 deselects\n"
     "A autofits\336 A places\n"
     "then moves\336 shape",

     "        About\n\n1010 c Mike Meyer\nmwm@mired.org\n\nhttps://goo.gl/9EeMnN",
     NULL
};

// The game
typedef enum {INIT, MENU, DONE, SELECTING, MOVING, PAGING} game_state;
const byte WAIT_LEN = 3;

struct game_data {
     unsigned long high, score;
     byte delay;
     int8_t waiting[WAIT_LEN];	// Shapes ready to be played.
     byte x, y;	// And it's location on the board.
................................................................................
     arduboy.print("Score\n");
     arduboy.print(game.score);
     arduboy.setCursor(0, 44); 
     arduboy.print("High\n");
     arduboy.print(game.high);

     switch (state) {
     case INIT:
          arduboy.fillRect(0, 0, BOARD_X - 1, 64, 0);
          arduboy.setCursor(0, 16);
          draw_msg("1010 v0.95\n  by mwm\n\nPress A");
          break;
     case DONE:
          blue = RGB_ON;
          // Fall through
     case MENU:
          draw_menu();
          break;
     case PAGING:
................................................................................
          game.high = 0;
          selected = HELP;
          EEPROM.put(saved_game, game);
          EEPROM.write(store, flagbyte);
          EEPROM.write(store + 1, flagbyte);
     } else {
          EEPROM.get(saved_game, game);

          selected = NEW;
          prompt = GAMEOVER;
          for (byte i = 0; i < WAIT_LEN; i += 1) {
               if (game.waiting[i] >= 0) {

                    selected = RESUME;
                    prompt = PAUSED;
                    break;
               }
          }
     }







     state = INIT;
}

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

................................................................................
          prompt = PAUSED;
          state = MENU;
          selected = RESUME;
          return;
     }

     switch (state) {
     case INIT:
          if (arduboy.justPressed(A_BUTTON)) {
               arduboy.initRandomSeed();
               state = MENU;
          }
          break;
     case MENU:
          if (arduboy.justPressed(A_BUTTON)) {
               do_menu();
          } else if (arduboy.justPressed(LEFT_BUTTON)) {
               if (selected)
                    selected -= 1;
               else
                    selected = MENU_LAST - 1;
          } else if (arduboy.justPressed(RIGHT_BUTTON)) {
               selected = (selected + 1) % MENU_LAST;
          }
          break;
     case PAGING:
          if (arduboy.justPressed(LEFT_BUTTON) && selected)
              selected -= 1;
          else if (arduboy.justPressed(RIGHT_BUTTON) & help[selected + 1] != NULL)
               selected += 1;
          else if (arduboy.justPressed(UP_BUTTON)) {
               state = MENU;
               selected = HELP;
          }
     case SELECTING:
          if (arduboy.justPressed(UP_BUTTON))
               do {
                    if (selected)
                         selected -= 1;
                    else
                         selected = WAIT_LEN - 1;
................................................................................
               game.waiting[i] = -1;
          if (arduboy.justPressed(A_BUTTON))
               do_menu();
          else if (arduboy.justPressed(LEFT_BUTTON)
                   || arduboy.justPressed(RIGHT_BUTTON))
               selected = selected == NEW ? HELP : NEW;
          break;





















     }

     EEPROM.put(saved_game, game);
     if (state == MOVING) {
          unsigned long end = millis() + game.delay;
          // Used pressed as the button just exists the loop.
          while (millis() < end)
               if (arduboy.pressed(A_BUTTON) || arduboy.pressed(B_BUTTON))
                    break;
     }
}