×

液晶游戏机开源分享

消耗积分:2 | 格式:zip | 大小:0.13 MB | 2022-11-22

分享资料个

描述

您好,它非常简单,因此无需解释,只需获取零件并使用接线图复制代码即可!

怎么玩!

PITF-ARD 点击开始。向右走找到门钥匙以完成关卡。向上移动操纵杆跳跃。

#include 
#include 
#include 
LiquidCrystal_I2C lcd(0x27,16,2);
// VARIABLES DECLARATION
int game = 0;
int gameover = 0;
int le = 0;
float ll = 0;
int key = LOW;
int mov=0;
int cc=1;
int screen1[202];
int screen2[202];
int ind = 0;
int randomNumber=0;
int ax=0;
int ay=0;
int timegame=2000;
int clef = 0;
int jump = 0;
int path = 42;
int ck = 2;
// CHARS DECLARATION
byte man1[] = {0x04, 0x0E, 0x0E, 0x0E, 0x04, 0x04, 0x1F, 0x1F} ;
byte man2[] = {0x04, 0x1E, 0x05, 0x04, 0x0B, 0x10, 0x1F, 0x1F} ;
byte man3[] = {0x04, 0x0F, 0x14, 0x04, 0x1A, 0x01, 0x1F, 0x1F} ;
byte man4[] = {0x15, 0x0E, 0x04, 0x0E, 0x11, 0x00, 0x00, 0x00} ;
byte man5[] = {0x15, 0x0E, 0x04, 0x0E, 0x11, 0x00, 0x1F, 0x1F} ;
byte man6[] = {0x00, 0x00, 0x04, 0x0E, 0x04, 0x04, 0x1F, 0x1F} ;
byte flat[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F};
byte hole[] = {0x0E, 0x1F, 0x15, 0x1B, 0x0E, 0x04, 0x1F, 0x1F} ;
byte m1[] = {0x1F, 0x1F, 0x1F, 0x19, 0x10, 0x00, 0x00, 0x00} ;
byte m2[] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0F, 0x06, 0x00} ;
byte m3[] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0C, 0x00, 0x00} ;
byte m4[] = {0x1F, 0x1F, 0x00, 0x0A, 0x00, 0x0A, 0x00, 0x0A} ;
byte m5[] = {0x1F, 0x1F, 0x1F, 0x00, 0x0A, 0x00, 0x0A, 0x00} ;
byte m6[] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x0A, 0x00} ;
byte keys[8] = {0x00, 0x03, 0x1F, 0x13, 0x00, 0x00, 0x1F, 0x1F} ;
byte dooro[8] = {0x1F, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x1F} ;
byte door[8] = {0x1F, 0x1F, 0x1D, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F} ;
void setup(){
 lcd.init();
 lcd.backlight();
 lcd.home();
 lcd.clear();
// CHARACTER ASSOCIATION
 lcd.createChar(1, man1);
 lcd.createChar(2, flat);
 lcd.createChar(3, hole);
 lcd.createChar(8, keys);
 lcd.createChar(7, door);
}
void loop(){
 if (game == 0)
 {
   if (gameover == 0)
     {
     // TITLE SCREEN SCREEN
       lcd.home();
       lcd.setCursor(0, 0);
       lcd.print("  Key game");
       lcd.setCursor(0, 1);
       lcd.print(" 2020"); 
       key = digitalRead(7);
       if (key == LOW)
           {
           // INIT GAME
           lcd.clear();
           lcd.home();
           le = 0;
           ll = 0;
           gameover = 1;
           cc=2;
           jump = 0;
           path = 16;
           } 
      }
    else
      {
          // NEW SCREEN - START
           randomSeed(analogRead(0));
           game = 1;
           key = LOW;
           le = le + 1;
           ll = ll + 1;
           path = path + 10;
           if (path>202)
           {
           path = 202;
           }
           ind = 0;
           for(int s=0;s<(path + 10);s++)
            {
            screen1[s] = 2;        
            }
           for(int s=11;s<(path -2 );s=s+3)
            {
            randomNumber = int(random(2, 4));
            //randomNumber = 3;
            screen1[s] = randomNumber;        
            }
           screen1[6]=7;
           screen1[path + 1]=8;
           for(int s=0;s<(path+10);s++)
            {
            randomNumber = int(random(4, 7));
            screen2[s] = randomNumber;        
            }
          if ((ll/2) == int(ll/2))
            {
             lcd.createChar(4, m4);
             lcd.createChar(5, m5);
             lcd.createChar(6, m6);
            }
            else
            {
             lcd.createChar(4, m1);
             lcd.createChar(5, m2);
             lcd.createChar(6, m3);
            }
          timegame = 2000;
          clef = 0;
          lcd.createChar(7, door);
          cc = 2;
          ck = 2;
    }
 }
 else
 {
 // GAME LOOP
     if (jump == 3)
     {
     jump = 0;
     }
     lcd.home();
     timegame = timegame - le;
     for(int s=ind;s<(ind+16);s++)
     {
      lcd.setCursor(s-ind, 0);
      lcd.write(byte(screen2[s]));
      lcd.setCursor(s-ind, 1);
      lcd.write(byte(screen1[s]));
     }
     if (timegame < 0)
     {
       timegame = 0;
     }
     lcd.setCursor(16-String(timegame).length(), 0);
     lcd.print(timegame);
if (jump == 0)
{
    lcd.setCursor(7, 1);
    lcd.write(byte(1));
    ck = screen1[ind+7];
    if (mov == 1)
     {
     if (cc==1)
     {
       lcd.createChar(1, man1);
     }
     else
     {
       lcd.createChar(1, man1);
     }
     mov = 0;
     }
     else
     {
     lcd.createChar(1, man1);
     mov = 1;
     }
}
if (jump > 0)
{
      lcd.setCursor(7, 0);
      lcd.write(byte(1));
      lcd.createChar(1, man4);
      if (cc == 2)
      {
      ind = ind + 1;
      }
      else
      {
      ind = ind - 1;
      }
 if (jump == 1)
 {
      jump = 2;
 }
 else
 {
      jump = 3;
 }
}    
     // CHECK LIVE OR DIE - LOOP GAME OR GAME OVER
     if ((ck == 2)&&(timegame>0))  // SET THE VARIABLE TO CHECK
     {
     ay = analogRead(1);   
     ax = analogRead(0);
     if ((ax > 600) && (jump == 0))
       {
           if (ind<(path-7))
           {
           ind = ind + 1;
           cc = 2;
           }
           else
           {
             screen1[path + 1]=2;
             clef = 1;
             lcd.createChar(7, dooro);
           }
       }
     if ((ax < 200) && (jump == 0))
     {
           if (ind>0)
           {
              ind = ind - 1;
              cc = 1;
           }
           else
           {
            if (clef==1)
            {
             // CHECK LEVEL CLEAR - START
           lcd.setCursor(0, 1);
           lcd.print("                ");
           lcd.setCursor((int(10-String(le).length())/2),1);
           lcd.print("LEVEL ");
           lcd.print(le+1);
           delay(4000);
           lcd.clear();    
           game = 0;
           gameover = 1;
//  CHECK LEVEL CLEAR - END
             }
           }
     }
     if ((ay < 200) && (ind >1) && (ind <(path - 8)) && (jump == 0))
     {
     jump = 1;
     }
     delay(200);
// GAME LOOP - END
 }
 else
 {
//  GAME OVER - START
   if (timegame>0)
     {
     lcd.setCursor(0, 0);
     lcd.print("   GAME  OVER :(   ");
     lcd.setCursor(7, 1);
     lcd.write(byte(1));
     lcd.createChar(1, man6);
     }
     else
     {
     lcd.setCursor(0, 1);
     lcd.print("   TIME  OVER   ");  
     }
     delay(4000);
     lcd.clear();    
     game = 0;
     gameover =0;
//  GAME OVER - END
   }
 }
}

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !