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);
  }
}
相关推荐
运维老司机14 分钟前
Jenkins修改LOGO
运维·自动化·jenkins
VernonJsn22 分钟前
visual studio 2005的MFC各种线程函数之间的调用关系
ide·mfc·visual studio
戎梓漩23 分钟前
windows下安装curl,并集成到visual studio
ide·windows·visual studio
D-海漠30 分钟前
基础自动化系统的特点
运维·自动化
我言秋日胜春朝★38 分钟前
【Linux】进程地址空间
linux·运维·服务器
C-cat.1 小时前
Linux|环境变量
linux·运维·服务器
yunfanleo1 小时前
docker run m3e 配置网络,自动重启,GPU等 配置渠道要点
linux·运维·docker
糖豆豆今天也要努力鸭2 小时前
torch.__version__的torch版本和conda list的torch版本不一致
linux·pytorch·python·深度学习·conda·torch
烦躁的大鼻嘎2 小时前
【Linux】深入理解GCC/G++编译流程及库文件管理
linux·运维·服务器
乐大师2 小时前
Deepin登录后提示“解锁登陆密钥环里的密码不匹配”
运维·服务器