Arduino-Remote

From Digipool-Wiki
Revision as of 12:05, 14 April 2011 by WikiSysop (Talk | contribs) (Created page with "<pre> #include <gamekit_2_1.h> #include <avr/pgmspace.h> #include <EEPROM.h> uint8_t gkTestImage[5][7] PROGMEM = { 0,19,19,19,19,19, 0, 19, 0,15, 0,15, 0,19, 19,15, 0,15,...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
#include <gamekit_2_1.h>
#include <avr/pgmspace.h>
#include <EEPROM.h>


uint8_t gkTestImage[5][7] PROGMEM = {
  0,19,19,19,19,19, 0,
  19, 0,15, 0,15, 0,19,
  19,15, 0,15, 0,15,19,
  19, 0,15, 0, 0, 0,19,
  0,19,19,19,19,19, 0

};

int intro = 0;
int i;

uint8_t title[5][37] PROGMEM = {
  0,0,0,0,0,0,0,9,0,0,0,9,0,0,9,9,0,0,9,9,9,9,9,0,0,9,9,9,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,9,9,0,9,9,0,9,0,0,9,0,0,0,0,9,0,0,9,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,9,0,9,0,9,0,9,9,9,9,0,0,0,9,0,0,0,9,9,9,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,9,0,0,0,9,0,9,0,0,9,0,0,9,0,0,0,0,9,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,9,0,0,0,9,0,9,0,0,9,0,9,9,9,9,9,0,0,9,9,9,0,0,0,0,0,0,0,0,0
};

//here the labyrinths are defined
//15 is a wall
//0 is a way
//20 is the goal

uint8_t start[5][7] PROGMEM = {
  0, 0,15, 0,15, 0, 0,
  0, 0,15, 0, 0, 0, 0,
  0, 0,15, 0,15, 0,20,
  0, 0, 0, 0,15, 0, 0,
  0, 0,15, 0,15, 0, 0

};

uint8_t trick[7][9] PROGMEM = {
  15,15,15,15,15,15,15,15,15,
  15, 0, 0, 0, 0, 0, 0, 0,15,
  0, 0, 0, 0, 0,15,15, 0,15,
  0, 0, 0, 0, 0,15,20, 0,15,
  0, 0, 0, 0, 0,15,15, 0,15,
  15, 0, 0, 0, 0, 0, 0, 0,15,
  15,15,15,15,15,15,15,15,15 

};

uint8_t leicht[13][15] PROGMEM = {
  15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  0 ,0 ,0 ,15,0 ,0 ,0 ,15,0 ,0 ,0 ,0 ,0 ,0 ,15,
  15,15,0 ,15,0 ,15,0 ,15,0 ,15,15,15,0 ,0 ,15,
  15,0 ,0 ,15,0 ,15,0 ,15,0 ,15,0 ,15,0 ,15,15,
  15,0 ,15,15,0 ,15,0 ,15,0 ,15,0 ,0 ,0 ,0 ,15,
  15,0 ,15,0 ,0 ,15,0 ,0 ,0 ,15,0 ,0 ,15,0 ,15,
  15,0 ,15,0 ,15,15,15,15,0 ,15,0 ,15,15,15,15,
  15,0 ,15,0 ,0 ,0 ,0 ,15,0 ,15,0 ,0 ,0 ,0 ,15,
  15,0 ,15,15,15,0 ,15,15,15,15,15,15,15,0 ,15,
  15,0 ,0 ,15,0 ,0 ,0 ,15,0 ,0 ,0 ,0 ,15,0 ,15,
  15,15,0 ,0 ,0 ,15,15,15,15,0 ,15,0 ,15,0 ,15,
  15,0 ,0 ,15,0 ,15,0 ,0 ,0 ,0 ,15,0 ,0 ,0 ,15,
  15,15,15,15,15,15,20,15,15,15,15,15,15,15,15
};

uint8_t mittel[27][27] PROGMEM = {
  15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  0 ,0 ,0 ,0 ,15,0 ,0 ,0 ,15,0 ,0 ,0 ,0 ,0 ,15,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,15,0 ,15,
  15,0 ,15,0 ,15,0 ,15,15,15,0 ,15,15,15,0 ,15,15,15,0 ,15,0 ,15,15,15,0 ,15,0 ,15,
  15,0 ,15,0 ,15,0 ,0 ,0 ,15,0 ,15,0 ,15,0 ,0 ,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,15,
  15,15,15,15,15,0 ,15,0 ,15,15,15,15,15,15,15,0 ,15,0 ,15,15,15,15,15,0 ,15,0 ,15,
  15,0 ,15,0 ,0 ,0 ,15,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,15,0 ,0 ,0 ,0 ,0 ,0 ,0 ,15,0 ,15,
  15,0 ,15,0 ,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,0 ,15,
  15,0 ,0 ,0 ,15,0 ,0 ,0 ,0 ,0 ,15,0 ,0 ,0 ,15,0 ,0 ,0 ,15,0 ,0 ,0 ,15,0 ,0 ,0 ,15,
  15,15,15,15,15,0 ,15,15,15,15,15,0 ,15,0 ,15,0 ,15,0 ,15,0 ,15,0 ,15,0 ,15,15,15,
  15,0 ,0 ,0 ,0 ,0 ,15,0 ,0 ,0 ,0 ,0 ,15,0 ,15,0 ,15,0 ,0 ,0 ,15,0 ,0 ,0 ,15,0 ,15,
  15,0 ,15,15,15,15,15,0 ,15,15,15,15,15,0 ,15,0 ,15,15,15,15,15,15,15,0 ,15,0 ,15,
  15,0 ,0 ,0 ,0 ,0 ,15,0 ,0 ,0 ,0 ,0 ,15,0 ,15,0 ,0 ,0 ,15,0 ,0 ,0 ,15,0 ,0 ,0 ,15,
  15,15,15,15,15,0 ,15,15,15,15,15,0 ,15,0 ,15,0 ,15,0 ,15,15,15,0 ,15,15,15,15,15,
  15,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,15,0 ,0 ,0 ,15,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,20,
  15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15
};

uint8_t mittelschwer[8][50] PROGMEM = {
  15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  0 ,0 ,0 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15,15,15,15,15,15,15
};


void setup(){
  gamekit.Begin();
  gamekit.set_button_timing(20, 20);

  Serial.begin(115200);
  Serial.println("begin");
}




void loop(){

  //Intro
  if(intro==0){
    intro=1;
    gkTest();
  }
  if(intro==1){
    intro=2;  
    introAni();
  }

  //Now use the play_labyrinth function to play the layrinths
  //play_labyrinth( (uint8_t *) name, size_r, size_c, start_r, start_c);
  //
  //where "name" ist the name of the labyrinth
  //size_r and size_c are the rows and columns of the labyrinth map
  //start_r and start_c is the start point in the labyrinth

  play_labyrinth( (uint8_t *) start, 5, 7, 2, 0);
  winning_sound(); 
  delay(1000); //wait some time before startting next level

  play_labyrinth( (uint8_t *) trick, 7, 9, 3, 0);
  winning_sound(); 
  delay(1000); //wait some time before startting next level

  play_labyrinth( (uint8_t *) leicht, 13, 15, 1, 0);
  winning_sound(); 
  delay(1000); //wait some time before startting next level

  play_labyrinth( (uint8_t *) mittelschwer, 8, 50, 1, 0);
  winning_sound();
  delay(1000);

  play_labyrinth( (uint8_t *) mittel, 27, 27, 1, 0);
  winning_sound();
  delay(1000);

  play_labyrinth( (uint8_t *) schwer, 37, 37, 35, 0);
  winning_sound();
  delay(1000);  

}




void play_labyrinth(uint8_t* map_ptr, uint8_t map_r_size, uint8_t map_c_size, uint8_t r_start, uint8_t c_start)
{
  uint8_t cursor_r_pos = r_start;
  uint8_t cursor_c_pos = c_start;

  uint8_t map_r_pos = r_start;
  uint8_t map_c_pos = c_start;

  uint8_t old_cursor_r_pos;
  uint8_t old_cursor_c_pos;

  // run some cycles to shift the frame to a "valid" position
  for (uint8_t i = 0; i <= 7; i++)
  {
    if( ( (cursor_r_pos < (map_r_pos + 1)) || (map_r_pos >= map_r_size - 4) ) && map_r_pos != 0)
      map_r_pos--;

    if( cursor_r_pos > (map_r_pos + 3) && map_r_pos  < map_r_size - 5)
      map_r_pos++;

    if( ( (cursor_c_pos < (map_c_pos + 1)) || (map_c_pos >= map_c_size - 6) ) && map_c_pos != 0)
      map_c_pos--;

    if( cursor_c_pos > (map_c_pos + 5) && map_c_pos < map_c_size - 7)
      map_c_pos++;
  };

  // force a redraw for first display !
  uint8_t old_map_r_pos = map_r_pos + 1;
  uint8_t old_map_c_pos = map_c_pos + 1;

  // play game until the cursor reches the goal 
  while ( gamekit.get_pixel(cursor_r_pos - map_r_pos, cursor_c_pos - map_c_pos) != 20 )
  {

    // check buttons and wall collision (if the pixel has a value of 15 it is a wall!)
    // moreover the cursor has'nt to be outside the map
    if(gamekit.button_pressed(butt_UP))
      if ((gamekit.get_pixel(cursor_r_pos - map_r_pos - 1, cursor_c_pos - map_c_pos) != 15) )
        if (cursor_r_pos != 0)
          cursor_r_pos--;

    if(gamekit.button_pressed(butt_DOWN))
      if (gamekit.get_pixel(cursor_r_pos - map_r_pos + 1, cursor_c_pos - map_c_pos) != 15)
        if (cursor_r_pos < map_r_size )
          cursor_r_pos++;

    if(gamekit.button_pressed(butt_LEFT))
      if (gamekit.get_pixel(cursor_r_pos - map_r_pos, cursor_c_pos - map_c_pos - 1) != 15)
        if (cursor_c_pos != 0)
          cursor_c_pos--;

    if(gamekit.button_pressed(butt_RIGHT))
      if (gamekit.get_pixel(cursor_r_pos - map_r_pos, cursor_c_pos - map_c_pos + 1) != 15)
        if (cursor_c_pos < map_c_size )
          cursor_c_pos++;


    // move frame to ensure that the cursor is in the display
    if( (cursor_r_pos < (map_r_pos + 1)) && map_r_pos != 0)
      map_r_pos--;

    if( cursor_r_pos > (map_r_pos + 3) && map_r_pos  < map_r_size - 5)
      map_r_pos++;

    if( cursor_c_pos < (map_c_pos + 1) && map_c_pos != 0)
      map_c_pos--;

    if( cursor_c_pos > (map_c_pos + 5) && map_c_pos < map_c_size - 7)
      map_c_pos++;


    // redraw display if necessary
    if( (map_r_pos != old_map_r_pos) || (map_c_pos != old_map_c_pos)  )
    {
      gamekit.load_map( (uint8_t *) map_ptr, map_r_size, map_c_size, map_r_pos, map_c_pos);
      // if the cursor reaches the goal let it go into it (thus not redraw it)
      if(gamekit.get_pixel(cursor_r_pos - map_r_pos, cursor_c_pos - map_c_pos) != 20)
        gamekit.set_pixel(cursor_r_pos - map_r_pos, cursor_c_pos - map_c_pos, 18);
      old_cursor_r_pos = cursor_r_pos;
      old_cursor_c_pos = cursor_c_pos;
      old_map_r_pos = map_r_pos;
      old_map_c_pos = map_c_pos;
    }
    else
      if( (cursor_r_pos != old_cursor_r_pos) || (cursor_c_pos != old_cursor_c_pos)  )
      {
        gamekit.set_pixel(old_cursor_r_pos - map_r_pos, old_cursor_c_pos - map_c_pos, 0);
        // if the cursor reaches the goal let it go into it (thus not redraw it)
        if(gamekit.get_pixel(cursor_r_pos - map_r_pos, cursor_c_pos - map_c_pos) != 20)
          gamekit.set_pixel(cursor_r_pos - map_r_pos, cursor_c_pos - map_c_pos, 18);
        old_cursor_r_pos = cursor_r_pos;
        old_cursor_c_pos = cursor_c_pos;
      };
  }

}

void winning_sound(){
  gamekit.play_tone(100,500,LOUD);
  gamekit.play_tone(300,100,LOUD);
  delay(100);
  gamekit.play_tone(100,100,LOUD);
  gamekit.play_tone(300,900,LOUD); 
}

void introAni(){
  for(i=0; i<37; i++){
    gamekit.load_map((uint8_t*) title,5,37,0,i);
    //delay(100);
    gamekit.play_tone(500,100,SILENT);
  }
  gamekit.play_tone(100,500,LOUD);
  gamekit.play_tone(300,100,LOUD);


}

void gkTest(){
  int testNr=0;
  testNr = EEPROM.read(0);
  
  if(testNr >= 2){
    //gamekit.set_pixel(2,3,20);
    delay(200);
    if(gamekit.button_pressed(butt_UP)){
      EEPROM.write(0,0);
      testNr = 0;
    }
  }
  
  if(testNr < 2){

    for(int testX = 0; testX < 25; testX++){
      gamekit.set_pixel(2, 3, random(16));
      gamekit.play_tone(random(1000), 10, LOUD);
    }
    for(int testX = 0; testX < 25; testX++){
      gamekit.set_pixel(1, 1, random(16));
      gamekit.set_pixel(1, 2, random(16));
      gamekit.set_pixel(1, 3, random(16));
      gamekit.set_pixel(1, 4, random(16));
      gamekit.set_pixel(1, 5, random(16));
      gamekit.set_pixel(2, 1, random(16));
      gamekit.set_pixel(2, 2, random(16));
      gamekit.set_pixel(2, 4, random(16));
      gamekit.set_pixel(2, 5, random(16));
      gamekit.set_pixel(3, 1, random(16));
      gamekit.set_pixel(3, 2, random(16));
      gamekit.set_pixel(3, 3, random(16));
      gamekit.set_pixel(3, 4, random(16));
      gamekit.set_pixel(3, 5, random(16));

      gamekit.play_tone(random(1000), 10, LOUD);

    }

    gamekit.load_image(gkTestImage);
    int waitButtons = 0;
    while(waitButtons < 6){
      if(gamekit.button_pressed(butt_FUNCA)){
        if(gamekit.get_pixel(1, 4) == 15){
          gamekit.set_pixel(1, 4, 0);
          waitButtons++;
          gamekit.play_tone(random(1000), 100, LOUD);
        }
      }
      if(gamekit.button_pressed(butt_FUNCB)){
        if(gamekit.get_pixel(2, 5) == 15){
          gamekit.set_pixel(2, 5, 0);
          waitButtons++;
          gamekit.play_tone(random(1000), 100, LOUD);
        }
      }
      if(gamekit.button_pressed(butt_UP)){
        if(gamekit.get_pixel(1, 2) == 15){
          gamekit.set_pixel(1, 2, 0);
          waitButtons++;
          gamekit.play_tone(random(1000), 100, SILENT);
        }
      }
      if(gamekit.button_pressed(butt_DOWN)){
        if(gamekit.get_pixel(3, 2) == 15){
          gamekit.set_pixel(3, 2, 0);
          waitButtons++;
          gamekit.play_tone(random(1000), 100, SILENT);
        }
      }   
      if(gamekit.button_pressed(butt_LEFT)){
        if(gamekit.get_pixel(2, 1) == 15){
          gamekit.set_pixel(2, 1, 0);
          waitButtons++;
          gamekit.play_tone(random(1000), 100, SILENT);
        }
      }    
      if(gamekit.button_pressed(butt_RIGHT)){
        if(gamekit.get_pixel(2, 3) == 15){
          gamekit.set_pixel(2, 3, 0);
          waitButtons++;
          gamekit.play_tone(random(1000), 100, SILENT);
        }
      }    
    }
    testNr++;
    EEPROM.write(0, testNr);
    delay(1000);
  }
}