Cov txheej txheem:

Floppy Bird: 3 Kauj Ruam
Floppy Bird: 3 Kauj Ruam

Video: Floppy Bird: 3 Kauj Ruam

Video: Floppy Bird: 3 Kauj Ruam
Video: Scratch 3.0 Tutorial: How to Make a Flappy Bird Game in Scratch (Part 3) 2024, Kaum ib hlis
Anonim
Noog noog
Noog noog
Noog noog
Noog noog

Hnub no peb yuav ua game siv TFT LCD. Qhov no yuav zoo li kev ua si uas yog nrov tiag tiag thiab ntau tus neeg tseem ua qhov kev ua si no. Qhov kev ua si hu ua Flappy Bird tab sis qhov kev ua si no txawv me ntsis vim tias UI sib txawv raws li qhov kev ua si ua haujlwm li cas. Kuv hu qhov kev ua si Floppy Bird vim qhov no tuaj yeem ua rau muaj teeb meem kev cai lij choj. Txawm li cas los xij nws yog kev ua si lom zem tiag tiag thiab nws yooj yim los ua. Kuv tau ua cov lus qhia no uas yuav tso cai rau koj ua qhov kev ua si kom tiav thiab ua kom nws ua haujlwm zoo li kuv tau ua. Yog tias koj muaj lus nug ces thov tawm hauv qab no thiab kuv yuav sim teb cov lus nug no kom sai li sai tau.

Khoom siv

- Arduino Mega 2560 thiab cable

- Arduino Mega Shield

- Arduino TFT LCD Tau tshaj nrog Arduino Mega 2560

- SD daim npav

Kauj Ruam 1: Sib dhos TFT LCD

Sib sau ua ke ntawm TFT LCD
Sib sau ua ke ntawm TFT LCD

Tam sim no, peb tuaj yeem pib sau cov TFT LCD. Peb yuav txuas TFT LCD mus rau daim ntaub thaiv, yog li ua ntej coj TFT LCD thiab pib kho nws nrog cov pins ntawm daim ntaub thaiv. Thaum koj tau ua raws cov pins, thawb TFT LCD qis kom nws haum rau hauv qhov chaw. Thaum txhua tus pin taub hau nyob hauv daim thaiv thiab koj tsis tuaj yeem pom tus pin taub hau, yog thaum koj paub tias TFT LCD txuas nrog kom raug. Tom ntej no, peb tuaj yeem ntsaws rau hauv daim thaiv rau Arduino Mega 2560. Kho tus pin ntawm daim ntaub thaiv ntawm Arduino Mega thiab ntsaws rau hauv. Thaum txhua tus pin taub hau nyob hauv Arduino Mega thiab koj tsis tuaj yeem pom tus pin taub hau, uas yog thaum koj paub tias TFT LCD tau txuas nrog kom raug thiab nws tau npaj los ua haujlwm. Txuas rau hauv Arduino kom pom tias koj tau txuas nrog LCD kom raug, yog tias lub LCD tig rau thiab lub vijtsam yog dawb ces zoo siab, koj tau ua tiav txuas nrog TFT LCD thiab tam sim no nws tau npaj los ua haujlwm. Thaum kawg, peb muaj ib yam ua, uas yog txuas SD daim npav hauv LCD. Nyob tom qab ntawm TFT LCD muaj daim npav SD qhov uas koj tuaj yeem ntsaws daim npav SD. Yog li ntawd, tsuas yog ntsaws nws thiab nws ua tiav.

Kauj ruam 2: Programming TFT LCD

Kev ua haujlwm ntawm TFT LCD
Kev ua haujlwm ntawm TFT LCD

Tam sim no, peb yuav teeb tsa lub LCD yog li nws tau ua si thiab peb tuaj yeem ua nws. Hauv qab no yog cov cai uas koj yuav tsum tau suav sau thiab xa tawm siv Arduino IDE.

Teeb meem koj yuav muaj:

Hloov qhov ntsuas ntawm TFT LCD raws li tus qauv koj muaj.

TUAJ CODE:

#include #include #include

// ==== Tsim Cov Hom Phiaj

UTFT myGLCD (ILI9341_16, 38, 39, 40, 41); // Cov ntsuas yuav tsum tau hloov kho rau koj Cov Zaub/Shield qauv URTouch myTouch (6, 5, 4, 3, 2);

// ==== Txhais Fonts

sab nrauv uint8_t SmallFont ; sab nrauv uint8_t BigFont ; sab nrauv uint8_t SevenSegNumFont ;

sab nrauv tsis tau kos npe rau noog 01 [0x41A]; // Noog Bitmap

koj x, y. // Variables rau kev tswj hwm qhov twg cov zaub tau raug nias

// Noog noog

pem x = 319; int yP = 100; int yB = 50; int txavRate = 3; int fallRateInt = 0; ntab fallRate = 0; int tau = 0; int lastSpeedUpScore = 0; int siab tshaj plaws; boolean screenPressed = tsis tseeb; boolean gameStarted = tsis tseeb;

void teeb tsa () {

// Pib tso saib myGLCD. InitLCD (); myGLCD.clrScr (); myTouchInitTouch (); myTouch.setPrecision (PREC_MEDIUM); qhab nia siab tshaj = EEPROM.read (0); // Nyeem cov qhab nia siab tshaj los ntawm EEPROM pib game (); // Pib qhov kev ua si}

void voj () {

xP = xP-movingRate; // xP - x kev koom tes ntawm cov pilars; range: 319 - (-51) drawPilars (xP, yP); // Kos tus ncej // yB - y sib koom ntawm cov noog uas nyob ntawm tus nqi ntawm qhov poob qis nce yB+= fallRateInt; fallRate = fallRate+0.4; // Txhua qhov inetration qhov poob qis nce ntxiv kom peb tuaj yeem cuam tshuam qhov nrawm/ nqus lub ntiaj teb fallRateInt = int (fallRate); // Txheeb xyuas kev sib tsoo yog tias (yB> = 180 || yB <= 0) {// gameOver saum thiab hauv qab (); } yog ((xP = 5) && (yB <= yP-2)) {// sab saud gameOver (); } yog ((xP = 5) && (yB> = yP+60)) {// qis dua gameOver (); } // Kos tus noog drawBird (yB);

// Tom qab tus ncej tau dhau los ntawm qhov screen

yog (xPRESET = 250) && (x = 0) && (y = 0) && (x = 30) && (y = 270) {myGLCD.setColor (0, 200, 20); myGLCD.fillRect (318, 0, x, y-1); myGLCD.setColor (0, 0, 0); myGLCD.drawRect (319, 0, x-1, y);

myGLCD.setColor (0, 200, 20);

myGLCD.fillRect (318, y+81, x, 203); myGLCD.setColor (0, 0, 0); myGLCD.drawRect (319, y+80, x-1, 204); } lwm tus yog (x <= 268) {// Kos lub duab plaub xiav txoj cai ntawm tus ncej myGLCD.setColor (114, 198, 206); myGLCD.fillRect (x+51, 0, x+60, y); // Kos tus ncej myGLCD.setColor (0, 200, 20); myGLCD.fillRect (x+49, 1, x+1, y-1); // Kos cov kab dub ntawm tus ncej myGLCD.setColor (0, 0, 0); myGLCD.drawRect (x+50, 0, x, y); // Kos lub duab plaub xiav sab laug ntawm tus ncej myGLCD.setColor (114, 198, 206); myGLCD.fillRect (x-1, 0, x-3, y);

// Tus ncej qab

myGLCD.setColor (114, 198, 206); myGLCD.fillRect (x+51, y+80, x+60, 204); myGLCD.setColor (0, 200, 20); myGLCD.fillRect (x+49, y+81, x+1, 203); myGLCD.setColor (0, 0, 0); myGLCD.drawRect (x+50, y+80, x, 204); myGLCD.setColor (114, 198, 206); myGLCD.fillRect (x-1, y+80, x-3, 204); } // Kos tus qhab nia myGLCD.setColor (0, 0, 0); myGLCD.setBackColor (221, 216, 148); myGLCD.setFont (BigFont); myGLCD.printNumI (qhab nia, 100, 220); }

// ====== drawBird () - Kev ua haujlwm tshwj xeeb

void drawBird (int y) {// Kos tus noog - bitmap myGLCD.drawBitmap (50, y, 35, 30, bird01); // Kos cov duab plaub xiav saum toj thiab hauv qab tus noog txhawm rau txhawm rau tshem nws lub xeev previus myGLCD.setColor (114, 198, 206); myGLCD.fillRoundRect (50, y, 85, y-6); myGLCD.fillRoundRect (50, y+30, 85, y+36); } // ======== gameOver () - Kev ua haujlwm tsis muaj nuj nqis gameOver () {ncua sijhawm (3000); // 1 thib ob // Tshem qhov screen thiab luam tawm cov ntawv myGLCD.clrScr (); myGLCD.setColor (255, 255, 255); myGLCD.setBackColor (0, 0, 0); myGLCD.setFont (BigFont); myGLCD.print ("GAME OVER", CENTER, 40); myGLCD.print ("Score:", 100, 80); myGLCD.printNumI (qhab nia, 200, 80); myGLCD.print ("Rov pib dua …", CENTER, 120); myGLCD.setFont (SevenSegNumFont); myGLCD.printNumI (2, CENTER, 150); ncua (1000); myGLCD.printNumI (1, CENTER, 150); ncua (1000); // Sau tus qhab nia siab tshaj hauv EEPROM yog (qhab nias> siab tshaj plaws) {siab tshaj qhov qhab nias = qhab nia; EEPROM.write (0, qhov qhab nia siab tshaj); } // Pib dua qhov hloov pauv los pib txoj haujlwm qhov tseem ceeb xP = 319; yB = 50; fallRate = 0; tau = 0; lastSpeedUpScore = 0; txavRate = 3; gameStarted = tsis tseeb; // Rov pib ua si pib gameGame (); }

Kauj ruam 3: Ua tiav

Ua tiav!
Ua tiav!

Peb tau ua qhov Circuit Court thiab suav sau cov cai. Tam sim no, peb tsuas yog yuav tsum ntsaws rau hauv Arduino mega thiab ua si game.

Ntawm no, Kuv muaj qhov txuas rau daim vis dis aus uas qhia tias qhov kev ua si no ua haujlwm li cas thiab yuav ua dab tsi thiaj li teeb tsa nws:

drive.google.com/file/d/18hKQ8v2w2OkM_std-…

Qhia rau kuv paub yog tias koj muaj teeb meem hauv qab no.

Pom zoo: