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

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

Overview
Comment:Integrate the DONE & MENU menu handling
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:0f10991731b3d7383341d75130a0353729e6bf1f
User & Date: mwm 2016-11-09 11:42:15
Context
2016-11-17
02:28
Fix it so you can only pause a game when SELECTING or MOVING, and so that you always restart to MENU, not DONE. check-in: 41ae9899c2 user: mwm tags: trunk
2016-11-09
11:42
Integrate the DONE & MENU menu handling check-in: 0f10991731 user: mwm tags: trunk
2016-11-08
13:20
Fix a couple of places that you could use the menu/paging system to resume a done game with new pieces. check-in: 36b8d8890e user: mwm tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Tiny-1010.ino.

370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
...
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
...
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
void
draw_menu(void) {
     draw_msg(prompt);
     arduboy.print(F("\n\n\33 "));
     arduboy.print(selected == HELP ? F(" Help ") :
                   selected == RESUME ? F("Resume") :
                   selected == KEYS ? F(" Keys ") :
                   selected == NEW ? F("New") :
                   F("BUG!"));
     arduboy.print(F(" \32"));
}

byte
draw_game(void) {
     byte can_place = 0;
................................................................................
     switch (state) {
     case INIT:
          if (arduboy.justPressed(A_BUTTON)) {
               arduboy.initRandomSeed();
               state = prompt == PAUSED ? MENU : DONE;
          }
          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)
                   && selected < sizeof(help) / sizeof(char *) - 1)
               selected += 1;
................................................................................
          else if (arduboy.pressed(LEFT_BUTTON)) {
               if (game.x > 0)
                    game.x -= 1;
               else
                    state = SELECTING;
          }
          break;
     case DONE:
          for (byte i = 0; i < WAIT_LEN; i += 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;
     }
}







|







 







>
>
>
>



>
>
|
|
|
|
|
|
|
|
>







 







<
<
<
<
<
<
<
<
<











370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
...
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
518
519
...
557
558
559
560
561
562
563









564
565
566
567
568
569
570
571
572
573
574
void
draw_menu(void) {
     draw_msg(prompt);
     arduboy.print(F("\n\n\33 "));
     arduboy.print(selected == HELP ? F(" Help ") :
                   selected == RESUME ? F("Resume") :
                   selected == KEYS ? F(" Keys ") :
                   selected == NEW ? F(" New  ") :
                   F("BUG!"));
     arduboy.print(F(" \32"));
}

byte
draw_game(void) {
     byte can_place = 0;
................................................................................
     switch (state) {
     case INIT:
          if (arduboy.justPressed(A_BUTTON)) {
               arduboy.initRandomSeed();
               state = prompt == PAUSED ? MENU : DONE;
          }
          break;
     case DONE:
          for (byte i = 0; i < WAIT_LEN; i += 1)
               game.waiting[i] = -1;
          // And fall through...
     case MENU:
          if (arduboy.justPressed(A_BUTTON)) {
               do_menu();
          }
          do {
               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;
               }
          } while (prompt == GAMEOVER && selected == RESUME);
          break;
     case PAGING:
          if (arduboy.justPressed(LEFT_BUTTON) && selected)
              selected -= 1;
          else if (arduboy.justPressed(RIGHT_BUTTON)
                   && selected < sizeof(help) / sizeof(char *) - 1)
               selected += 1;
................................................................................
          else if (arduboy.pressed(LEFT_BUTTON)) {
               if (game.x > 0)
                    game.x -= 1;
               else
                    state = SELECTING;
          }
          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;
     }
}