×

液晶游戏机开源分享

消耗积分: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条评论

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

'+ '

'+ '

'+ ''+ '
'+ ''+ ''+ '
'+ ''+ '' ); $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code ==5){ $(pop_this).attr('href',"/login/index.html"); return false } if(data.code == 2){ //跳转到VIP升级页面 window.location.href="//m.obk20.com/vip/index?aid=" + webid return false } //是会员 if (data.code > 0) { $('body').append(htmlSetNormalDownload); var getWidth=$("#poplayer").width(); $("#poplayer").css("margin-left","-"+getWidth/2+"px"); $('#tips').html(data.msg) $('.download_confirm').click(function(){ $('#dialog').remove(); }) } else { var down_url = $('#vipdownload').attr('data-url'); isBindAnalysisForm(pop_this, down_url, 1) } }); }); //是否开通VIP $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code == 2 || data.code ==5){ //跳转到VIP升级页面 $('#vipdownload>span').text("开通VIP 免费下载") return false }else{ // 待续费 if(data.code == 3) { vipExpiredInfo.ifVipExpired = true vipExpiredInfo.vipExpiredDate = data.data.endoftime } $('#vipdownload .icon-vip-tips').remove() $('#vipdownload>span').text("VIP免积分下载") } }); }).on("click",".download_cancel",function(){ $('#dialog').remove(); }) var setWeixinShare={};//定义默认的微信分享信息,页面如果要自定义分享,直接更改此变量即可 if(window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'){ var d={ title:'液晶游戏机开源分享',//标题 desc:$('[name=description]').attr("content"), //描述 imgUrl:'https://'+location.host+'/static/images/ele-logo.png',// 分享图标,默认是logo link:'',//链接 type:'',// 分享类型,music、video或link,不填默认为link dataUrl:'',//如果type是music或video,则要提供数据链接,默认为空 success:'', // 用户确认分享后执行的回调函数 cancel:''// 用户取消分享后执行的回调函数 } setWeixinShare=$.extend(d,setWeixinShare); $.ajax({ url:"//www.obk20.com/app/wechat/index.php?s=Home/ShareConfig/index", data:"share_url="+encodeURIComponent(location.href)+"&format=jsonp&domain=m", type:'get', dataType:'jsonp', success:function(res){ if(res.status!="successed"){ return false; } $.getScript('https://res.wx.qq.com/open/js/jweixin-1.0.0.js',function(result,status){ if(status!="success"){ return false; } var getWxCfg=res.data; wx.config({ //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId:getWxCfg.appId, // 必填,公众号的唯一标识 timestamp:getWxCfg.timestamp, // 必填,生成签名的时间戳 nonceStr:getWxCfg.nonceStr, // 必填,生成签名的随机串 signature:getWxCfg.signature,// 必填,签名,见附录1 jsApiList:['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function(){ //获取“分享到朋友圈”按钮点击状态及自定义分享内容接口 wx.onMenuShareTimeline({ title: setWeixinShare.title, // 分享标题 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享给朋友”按钮点击状态及自定义分享内容接口 wx.onMenuShareAppMessage({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 type: setWeixinShare.type, // 分享类型,music、video或link,不填默认为link dataUrl: setWeixinShare.dataUrl, // 如果type是music或video,则要提供数据链接,默认为空 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ”按钮点击状态及自定义分享内容接口 wx.onMenuShareQQ({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口 wx.onMenuShareWeibo({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口 wx.onMenuShareQZone({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); }); }); } }); } function openX_ad(posterid, htmlid, width, height) { if ($(htmlid).length > 0) { var randomnumber = Math.random(); var now_url = encodeURIComponent(window.location.href); var ga = document.createElement('iframe'); ga.src = 'https://www1.elecfans.com/www/delivery/myafr.php?target=_blank&cb=' + randomnumber + '&zoneid=' + posterid+'&prefer='+now_url; ga.width = width; ga.height = height; ga.frameBorder = 0; ga.scrolling = 'no'; var s = $(htmlid).append(ga); } } openX_ad(828, '#berry-300', 300, 250);