Cov txheej txheem:

Arduino Space Race Game Version _1: 5 Cov Kauj Ruam
Arduino Space Race Game Version _1: 5 Cov Kauj Ruam

Video: Arduino Space Race Game Version _1: 5 Cov Kauj Ruam

Video: Arduino Space Race Game Version _1: 5 Cov Kauj Ruam
Video: How to make a STEEL MARBLE TRACK with basic tools! step by step guide 2024, Hlis ntuj nqeg
Anonim
Image
Image

Nyob zoo phooj ywg. Hnub no kuv xav qhia koj yuav ua li cas koj tuaj yeem ua Space Space Game Game los ntawm LCD5110 npo thiab zoo siab.

Kauj ruam 1: YUAV TSUM

SCHEMA
SCHEMA

Nov yog cov npe ntawm ntu uas kuv tau siv los ua txoj haujlwm no:

  • Arduino UAS
  • Joystick Module
  • Jumper Wires (txiv neej rau txiv neej thiab txiv neej rau poj niam)
  • Cov qhob cij

Kauj ruam 2: SCHEMA

VCC -> Arduino 5V

BL -> Arduino tus pin 3

GND -> Arduino GND

CLK (SCLK) -> Arduino tus pin 8

DIN (MOSI) -> Arduino tus pin 9

DC -> Arduino tus pin 10

CE lossis CS -> Arduino tus pin 12

RST (RESET) -> Arduino tus pin 11

Kauj ruam 3: CODE

CODE
CODE

Txoj cai tau piav qhia txog kev ua haujlwm. Koj yuav nkag siab nws yooj yim. Yog tias koj muaj teeb meem, koj tuaj yeem tiv tauj kuv.

#suav nrog

LCD5110 lcd (8, 9, 10, 11, 12); // (clk, din, dc, rst, ce)

int BL = 3;

sab nrauv uint8_t SmallFont ; // piav qhia cov fonts sab nrauv uint8_t MediumNumbers ; sab nrauv uint8_t arac ; // piav qhia peb cov duab sab nrauv uint8_t dusman_araci ; // desribe yeeb ncuab zoo const int xpin = A0; // joystick x pin char pozisyon = 2; // piav qhia qhov chaw nyob, peb cov duab pib qhov chaw 2 boolean kontrol = tseeb; boolean dusmanOldu = muaj tseeb; int skor = 0; int hais = 0; koj dusmanKonumu1; // piav qhia tus yeeb ncuab1 x qhov chaw int dusmanKonumu2; // piav qhia tus yeeb ncuab2 x qhov chaw int dusmaninYdeKonumu; // piav qhia cov yeeb ncuab y qhov chaw nyob

void dusmanAraci (int yer, int asama) {// teeb tsa qhov chaw rau cov yeeb ncuab duab

yog (yer == 1) {// yog qhov chaw = 1; lcd.drawBitmap (2, asama, dusman_araci, 12, 8); // kos tus yeeb ncuab lub cev} yog (yer == 2) {lcd.drawBitmap (18, asama, dusman_araci, 12, 8); } yog (yer == 3) {lcd.drawBitmap (34, asama, dusman_araci, 12, 8); }}

tsis muaj dab tsi oyunBitti () {// yog tias peb ua tsis tiav, qhov kev ua si dhau

thaum (1) {ncua (100); // tos 1 lub hlis lcd.clrScr (); // tshem qhov screen lcd.setFont (SmallFont); // teeb tsa lcd.print ("GAME OVER", CENTER, 20); // luam tawm lcd.update (); // hloov kho qhov screen}}

teeb tsa tsis muaj dab tsi () {pinMode (BL, OUTPUT); // teeb rov qab teeb tso zis lcdInitLCD (); // pib lub lcd screen lcd.setContrast (55); // teeb qhov sib txawv (amound 0 txog 127) Serial.begin (9600); // pib serial comunation}

void voj () {

analogWrite (BL, 200);

// teeb tsa game lcd.drawRect (0, 0, 47, 47); // peb kos duab plaub lcd.setFont (SmallFont); // teeb tsa lcd.print ("skor", 53, 0); // printf qhab nia lcd.setFont (MediumNumbers); // teeb tsa lcd.printNumI (skor, 59, 7); // tau qhab nia lcd.setFont (SmallFont); lcd.print ("hiz", 56, 25); // luam ceev lcd.setFont (MediumNumbers); lcd.printNumI (hiz, 59, 32); // tau ceev lcd.update (); // hloov tshiab

// teeb tsa qhov chaw joyistick int x = analogRead (xpin); if (x <300 && pozisyon! = 1 && kontrol == true) {// yog qhov chaw! = 1, x state600 && pozisyon! = 3 && kontrol == true) {// yog qhov chaw! = 3, x xeev> 600 thiab tswj yog qhov tseeb pozisyon ++; // nce qhov chaw nws txhais tau tias txav cov duab mus rau txoj cai kontrol = cuav; } lwm yog (x> 300 && x <600) {kontrol = tseeb; } Serial.println (x); // rau kev kawm x lub xeev // teeb tsa peb qhov chaw zoo lcd.clrScr (); // tshem qhov screen yog (pozisyon == 1) {// yog qhov chaw = 1; lcd.drawBitmap (2, 37, arac, 12, 8);} // kos peb lub nkoj yog (pozisyon == 2) {lcd.drawBitmap (18, 37, arac, 12, 8);}

yog (pozisyon == 3) {

lcd.drawBitmap (34, 37, arac, 12, 8);}

yog (dusmanOldu) {// yog tias cov yeeb ncuab zoo li tuag lawm, xyuas seb lawv puas tuag

dusmanKonumu1 = pozisyon; // kos thawj tus yeeb ncuab zoo dusmanKonumu2 = random (0, 4); // kos lwm tus yeeb ncuab zoo ib yam dusmaninYdeKonumu = 0; // coj tus yeeb ncuab los saum dusmanOldu = cuav;} // yeeb ncuab rov tsim dua kom lawv tsis tuag dusmanAraci (dusmanKonumu1, dusmaninYdeKonumu); dusmaninYdeKonumu ++; // kos thawj tus yeeb ncuab zoo thiab tau txais nws los ntawm sab saum toj mus rau hauv qab dusmanAraci (dusmanKonumu2, dusmaninYdeKonumu); dusmaninYdeKonumu ++; // kos tus yeeb ncuab thib ob zoo thiab tau txais nws los ntawm sab saum toj mus rau hauv qab yog (dusmaninYdeKonumu> 22 && ((dusmanKonumu1 == pozisyon) || (dusmanKonumu2 == pozisyon)))) {// yog tias peb lub cev kov cov yeeb ncuab lub cev oyunBitti ();} // qhov kev ua si dhau yog (dusmaninYdeKonumu> 40) {// yog tias peb lub cev khiav tawm ntawm cov yeeb ncuab dusmanOldu = muaj tseeb; // tua cov yeeb ncuab lub cev skor ++;} // nce ib los ntawm ib tus qhab nia // nce nrawm raws li tus qhab nia yog (skor> = 0 && skor10 && skor20 && skor30 && skor <= 40) {hiz = 3; ncua (40); }}

Kauj ruam 4: CODE BITMAP

Ib qho ntxiv, koj yuav tsum suav nrog cov duab bitmap rau cov duab.

// ----------------------------------------------------------------------- ------------------------------ // Cov ntaub ntawv tsim los ntawm LCD Assistant // https://en.radzio.dxp.pl /bitmap_converter/// ------------------------------------------------------- --------------------------------- #suav nrog // suav nrog rau txoj haujlwm ua haujlwm

const unsigned char arac PROGMEM = {// peb cov duab bitmap

0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,};

const unsigned char dusman_araci PROGMEM = {// yeeb ncuab nkoj bitmap

0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,};

Kauj Ruam 5: Ua Tsaug rau Kev Pom

UA TSAUG NTAU
UA TSAUG NTAU

Ua ntej ı pib qhia kuv cov haujlwm, ı coded ua lus Turkish yog li kuv tsis tuaj yeem muaj txhua lo lus rau lus Askiv. Ntawm no cov lus txhais lus uas siv qhov haujlwm no, Yog = Game

Arac = Cov duab

Dusman = Yeeb ncuab

kontrol = tswj

Konum, Yer = Qhov chaw

Oyun Bitti = Game Over

Skor = Cov qhab nia

Hiz = Ceev

Pom zoo: