arduino ide编写的esp32和st773580*160的一个接球小游戏

#include<TFT_eSPI.h>

#define led 2

int bx,by=5,x=65,y=57,mark,level=1;

const int r=5,sjs=23,pin=13;

TFT_eSPI tft=TFT_eSPI();

uint16_t color=tft.color565(128,0,128); //RGB颜色转GBR565,紫色

void setup()

{

// put your setup code here, to run once:

Serial.begin(921600);

pinMode(led,OUTPUT);

pinMode(pin,INPUT);

digitalWrite(led,LOW);

tft.init();

tft.fillScreen(TFT_WHITE);

tft.setRotation(3);

tft.setTextSize(2);

tft.setTextColor(TFT_BLACK);

randomSeed(analogRead(sjs)); //使用一个引脚来作为随机数种子

bx=random(5,155);

}

void loop()

{

// put your main code here, to run repeatedly:

if(bx>=x&&bx<=x+15&&by+5>=y&&by+5<=y+3)

{

mark++;

if(mark%5==0)

{

level++;

}

tft.fillScreen(TFT_WHITE);

tft.setCursor(0,0);

tft.println("you win!");

tft.print("your mark:");

tft.println(mark);

tft.print("your level:");

tft.print(level);

delay(1000);

tft.fillScreen(TFT_WHITE);

randomSeed(analogRead(sjs));

bx=random(5,155);

by=5;

x=65;

y=57;

}

if(bx<=155&&bx>=5&&by>=5&&by<=75)

{

tft.fillRect(x,y,15,3,TFT_BLACK);

tft.fillCircle(bx,by,r,color);

tft.drawPixel(bx,by,TFT_WHITE);

delay(100);

tft.fillCircle(bx,by,r,TFT_WHITE);

tft.fillRect(x,y,15,3,TFT_WHITE);

x=double(analogRead(13))/4095.00*145;

Serial.println(bx>=x&&bx<=x+15&&by+5<=y&&by+5>=y+3);

Serial.print(x);

Serial.print(" ");

Serial.print(bx);

Serial.print(" ");

Serial.println(by);

by+=2*level+1;

}

else

{

tft.fillScreen(TFT_WHITE);

tft.setCursor(0,0);

tft.println("Game ovor!");

tft.print("your mark:");

tft.println(mark);

tft.print("your level:");

tft.print(level);

digitalWrite(led,HIGH);

delay(100);

digitalWrite(led,LOW);

delay(100);

digitalWrite(led,HIGH);

delay(100);

digitalWrite(led,LOW);

delay(100);

digitalWrite(led,HIGH);

delay(3000);

exit(0);

}

}

cpp 复制代码
#include<TFT_eSPI.h>
#define led 2
int bx,by=5,x=65,y=57,mark,level=1;
const int r=5,sjs=23,pin=13;
TFT_eSPI tft=TFT_eSPI();
uint16_t color=tft.color565(128,0,128); //RGB颜色转GBR565,紫色
void setup()
{
  // put your setup code here, to run once:
  Serial.begin(921600);
  pinMode(led,OUTPUT);
  pinMode(pin,INPUT);
  digitalWrite(led,LOW);
  tft.init();
  tft.fillScreen(TFT_WHITE);
  tft.setRotation(3);
  tft.setTextSize(2);
  tft.setTextColor(TFT_BLACK);
  randomSeed(analogRead(sjs)); //使用一个引脚来作为随机数种子
  bx=random(5,155);
}
void loop()
{
  // put your main code here, to run repeatedly:
  if(bx>=x&&bx<=x+15&&by+5>=y&&by+5<=y+3)
  {
    mark++;
    if(mark%5==0)
    {
      level++;
    }
    tft.fillScreen(TFT_WHITE);
    tft.setCursor(0,0);
    tft.println("you win!");
    tft.print("your mark:");
    tft.println(mark);
    tft.print("your level:");
    tft.print(level);
    delay(1000);
    tft.fillScreen(TFT_WHITE);
    randomSeed(analogRead(sjs));
    bx=random(5,155);
    by=5;
    x=65;
    y=57;
  }
  if(bx<=155&&bx>=5&&by>=5&&by<=75)
  {
    tft.fillRect(x,y,15,3,TFT_BLACK);
    tft.fillCircle(bx,by,r,color);
    tft.drawPixel(bx,by,TFT_WHITE);
    delay(100);
    tft.fillCircle(bx,by,r,TFT_WHITE);
    tft.fillRect(x,y,15,3,TFT_WHITE);
    x=double(analogRead(13))/4095.00*145;
    Serial.println(bx>=x&&bx<=x+15&&by+5<=y&&by+5>=y+3);
    Serial.print(x);
    Serial.print(" ");
    Serial.print(bx);
    Serial.print(" ");
    Serial.println(by);
    by+=2*level+1;
  }
  else
  {
    tft.fillScreen(TFT_WHITE);
    tft.setCursor(0,0);
    tft.println("Game ovor!");
    tft.print("your mark:");
    tft.println(mark);
    tft.print("your level:");
    tft.print(level);
    digitalWrite(led,HIGH);
    delay(100);
    digitalWrite(led,LOW);
    delay(100);
    digitalWrite(led,HIGH);
    delay(100);
    digitalWrite(led,LOW);
    delay(100);
    digitalWrite(led,HIGH);
    delay(3000);
    exit(0);
  }
}
相关推荐
leoufung11 分钟前
vim 多个关键字高亮插件介绍
linux·编辑器·vim
Karoku0661 小时前
【CI/CD】CI/CD环境搭建流程和持续集成环境配置
运维·ci/cd·docker·容器·kubernetes·prometheus
Nerd Nirvana3 小时前
软考—系统架构设计(案例 | 论文)
linux·系统架构·软件工程·软考·计算机基础
勤奋的凯尔森同学4 小时前
webmin配置终端显示样式,模仿UbuntuDesktop终端
linux·运维·服务器·ubuntu·webmin
Hylan_J5 小时前
【VSCode】MicroPython环境配置
ide·vscode·python·编辑器
技术小齐8 小时前
网络运维学习笔记 016网工初级(HCIA-Datacom与CCNA-EI)PPP点对点协议和PPPoE以太网上的点对点协议(此处只讲华为)
运维·网络·学习
ITPUB-微风8 小时前
Service Mesh在爱奇艺的落地实践:架构、运维与扩展
运维·架构·service_mesh
打不了嗝 ᥬ᭄9 小时前
Linux的权限
linux
落幕9 小时前
C语言-进程
linux·运维·服务器
深度Linux9 小时前
C++程序员内功修炼——Linux C/C++编程技术汇总
linux·项目实战·c/c++