Inhoudsopgave:

Space Race Game versie 2: 5 stappen
Space Race Game versie 2: 5 stappen

Video: Space Race Game versie 2: 5 stappen

Video: Space Race Game versie 2: 5 stappen
Video: Taylor Swift - You Need To Calm Down 2024, Juli-
Anonim
Image
Image

Hallo iedereen. Vóór deze spelversie publiceerde ı de eerste versie van het spel. Vandaag laat ı je Space Race Game-versie 2 zien. Laten we eens kijken naar de stappen …

Stap 1: ONDERDELEN

SCHEMA
SCHEMA

Hier is een lijst met onderdelen die ik heb gebruikt om dit project te maken:

  • Arduino UNO
  • Joystick-module
  • Jumperdraden (man naar man en man naar vrouw)
  • Breadboard

Stap 2: SCHEMA

VCC -> Arduino 5V

BL -> Arduino-pin 3

GND -> Arduino GND

CLK (SCLK) -> Arduino-pin 8

DIN (MOSI) -> Arduino pin 9

DC -> Arduino-pin 10

CE of CS -> Arduino pin 12

RST (RESET) -> Arduino-pin 11

Stap 3: CODE

CODE
CODE

De code heeft uitleg over codefuncties. Je zult het snel begrijpen. Als u een probleem heeft, kunt u contact met mij opnemen.

#erbij betrekken

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

booleaanse kontrol=waar;

booleaanse dusmanoldu=waar;

extern uint8_t SmallFont; // beschrijf de lettertypen

extern uint8_t MediumNumbers; extern uint8_t arac; //beschrijf onze vorm extern uint8_t dusmanAraci; // beschrijf vijandelijke vorm const int xpin = A0; //joystick x pin char pozisyon=3; // beschrijf de locatie, onze vorm startlocatie 3 int BL=3; int skor=0; int hiz=0; int dusmankonum1; // beschrijf vijand1 x locatie int dusmankonum2; // beschrijf vijand 2 x locatie int dusmankonum3; // beschrijf vijand3 x locatie int dusmankonum4; // beschrijf vijand4 x locatie int dusmankonum5; // beschrijf vijand 5 x locatie int dusmaninYdekonumu;

void oyunEkrani () { // spelscherm instellen

lcd.clrScr(); lcd.drawRect(0, 0, 47, 47); // we tekenen rechthoek lcd.setFont (SmallFont); //set lettertype lcd.print ("skor", 57, 1); //printscore lcd.print("hiz", 60, 24); // afdruksnelheid lcd.setFont (gemiddelde nummers); //set lettertype lcd.printNumI (skor, 55, 8); //score krijgen lcd.printNumI(hiz, 63, 32); // haal snelheid lcd.update(); }

void dusmanAracidurum (int yer, int asama) { // stel locaties in voor vijandige vormen

if(yer==1){ lcd.drawBitmap(2, asama, dusmanAraci, 7, 7);lcd.update();}//if location=1 teken vijand vorm deze locatie if(yer==2){ lcd.drawBitmap(10, asama, dusmanAraci, 7, 7);lcd.update();} if(yer==3){ lcd.drawBitmap(18, asama, dusmanAraci, 7, 7);lcd.update(); } if(yer==4){ lcd.drawBitmap(26, asama, dusmanAraci, 7, 7);lcd.update();} if(yer==5){ lcd.drawBitmap(34, asama, dusmanAraci, 7, 7);lcd.update();} if(yer==6){ lcd.drawBitmap(42, asama, dusmanAraci, 7, 7);lcd.update();} }

void oyunbitti(){ // als we falen, is het spel voorbij

while(1){ vertraging(100); // wacht 1 milliseconde lcd.clrScr (); lcd.setFont (SmallFont); lcd.print("OYUN BITTI", CENTER, 8); //print game over lcd.print("skorunuz=", 3, 30); // druk je score af lcd.setFont (MediumNumbers); lcd.printNumI(skor, 60, 25); //haal laatste score lcd.update(); } }

ongeldige setup() {

pinMode (BL, UITGANG); // stel achtergrondverlichting in Uitgang pinMode (xpin, INPUT); // stel x pin in als invoer lcd. InitLCD(); //initialiseer het lcd-scherm lcd.setContrast(55); // stel contrast in (ongeveer 0 tot 127) Serial.begin (9600); //start seriële communicatie}

lege lus() {

analoogWrite(BL, 350); oyunEkrani();

// joyistic durumu … // stel de joyistick-locatie in …

int durumx=analogRead(xpin); if(durumx <300 && pozisyon!=1 && kontrol==true){ //if location!=1, x state600 && pozisyon!=6 && kontrol==true){ //if location!=3, x state> 600 en controle is waar pozisyon++; // verhoog de locatie die het betekent verplaats de vorm naar rechts kontrol=false; } else if(durumx >300 && durumx <600){ kontrol=true; } //pozisyon durumu… //position staat… if(pozisyon==1){ //if location=1; lcd.drawBitmap(2, 41, arac, 7, 7);lcd.update();}//teken ons schip if(pozisyon==2){ lcd.drawBitmap(10, 41, arac, 7, 7); lcd.update();} if(pozisyon==3){ lcd.drawBitmap(18, 41, arac, 7, 7);lcd.update();} if(pozisyon==4){ lcd.drawBitmap(26, 41, arac, 7, 7);lcd.update();} if(pozisyon==5){ lcd.drawBitmap(34, 41, arac, 7, 7);lcd.update();} if(pozisyon ==6){ lcd.drawBitmap(42, 41, arac, 7, 7);lcd.update();}

if (dusmanoldu) { // als de vijandelijke vorm dood is, controleer of ze dood zijn

dusmankonum1=pozisyon; //teken eerste vijandelijke vorm dusmankonum2=willekeurig (0, 6);//teken ergens een andere vijandelijke vorm dusmankonum3=willekeurig (0, 6); dusmankonum4=willekeurig(0, 6); dusmankonum5=willekeurig (0, 6); dusmaninYdekonumu=0; //breng vijand van boven dusmanoldu=false;} // vijand wordt opnieuw gemaakt zodat ze niet dood zijn

dusmanAracidurum(dusmankonum1, dusmaninYdekonumu);dusmaninYdekonumu++; // teken de eerste vijandelijke vorm en haal deze van boven naar beneden

dusmanAracidurum(dusmankonum2, dusmaninYdekonumu);dusmaninYdekonumu++; // teken de tweede vijandelijke vorm en haal deze van boven naar beneden dusmanAracidurum(dusmankonum3, dusmaninYdekonumu);dusmaninYdekonumu++; dusmanAracidurum(dusmankonum4, dusmaninYdekonumu);dusmaninYdekonumu++; if(dusmaninYdekonumu>35 && ((dusmankonum1 == pozisyon)||(dusmankonum2 == pozisyon)||(dusmankonum3 == pozisyon)||(dusmankonum4 == pozisyon)))){ // als onze vorm vijandige vormen raakt oyunbitti(); //het spel is voorbij }

if(dusmaninYdekonumu >42){//if onze vorm ontsnappen aan vijanden

dusmanoldu = waar; // dood vijandige vormen skor++; // verhoog de score één voor één}

//skora gore hizi artiriyoruz //snelheid verhogen volgens score

if (skor>=0 && skor=10 && skor=20 && skor=30 && skor=40 && skor=50){ hiz=6; vertraging (5); }

}

Stap 4: CODE BITMAP

Verder moet u een bitmapafbeelding voor vormen opnemen. Het moet een.c-bestand zijn.

#include //include voor programmafunctie

const unsigned char arac PROGMEM = { //our shape bitmap

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

const unsigned char dusmanAraci PROGMEM = { // vijandelijk schip bitmap

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

Stap 5: Bedankt voor het bekijken

Betekenis van enkele woorden:

Oyun => Spel

Arac = > Vorm

Dusman => Vijand

controle = >controle

Konum, Yer => Locatie

Oyun Bitti => Spel voorbij

Skor => Score

Hiz => Snelheid

Aanbevolen: