INHOUDSOPGAWE:

Space Race Game Weergawe 2: 5 stappe
Space Race Game Weergawe 2: 5 stappe

Video: Space Race Game Weergawe 2: 5 stappe

Video: Space Race Game Weergawe 2: 5 stappe
Video: БОЛЬШОЙ ФИЛЬМ ПРО ДАГЕСТАН: Махачкала. Жизнь в горных аулах. Сулакский каньон. Шамильский район 2024, Julie
Anonim
Image
Image

Hey almal. Voor die spelweergawe het ek die eerste weergawe van die spel gepubliseer. Vandag wys ek u Space Race Game weergawe 2. Kom ons kyk na stappe …

Stap 1: ONDERDELE

SKEMA
SKEMA

Hier is 'n lys van dele waarmee ek hierdie projek gemaak het:

  • Arduino UNO
  • Joystick -module
  • Jumper Wires (manlik tot manlik en manlik tot vroulik)
  • Broodbord

Stap 2: SKEMA

VCC -> Arduino 5V

BL -> Arduino -pen 3

GND -> Arduino GND

CLK (SCLK) -> Arduino -pen 8

DIN (MOSI) -> Arduino -pen 9

DC -> Arduino -pen 10

CE of CS -> Arduino -pen 12

RST (RESET) -> Arduino -pen 11

Stap 3: KODE

KODE
KODE

Die kode bevat verduidelikings van kodefunksies. U sal dit maklik verstaan. As u 'n probleem het, kan u my kontak.

#insluit

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

boolean control = true;

boolean dusmanoldu = true;

eksterne uint8_t SmallFont ; // beskryf die lettertipes

eksterne uint8_t MediumNumbers ; ekstern uint8_t arac ; // beskryf ons vorm ekstern uint8_t dusmanAraci ; // beskryf die vorm van die vyand const int xpin = A0; // joystick x pin char pozisyon = 3; // beskryf die ligging, ons vorm begin plek 3 int BL = 3; int skor = 0; int hiz = 0; int dusmankonum1; // beskryf vyand1 x ligging int dusmankonum2; // beskryf vyand2 x ligging int dusmankonum3; // beskryf vyand3 x ligging int dusmankonum4; // beskryf vyand4 x ligging int dusmankonum5; // beskryf vyand5 x ligging int dusmaninYdekonumu;

void oyunEkrani () {// stel spelskerm in

lcd.clrScr (); lcd.drawRect (0, 0, 47, 47); // ons teken reghoek lcd.setFont (SmallFont); // stel lettertipe lcd.print ("skor", 57, 1); // druk telling lcd.print ("hiz", 60, 24); // druksnelheid lcd.setFont (MediumNumbers); // stel lettertipe lcd.printNumI (skor, 55, 8); // kry telling lcd.printNumI (hiz, 63, 32); // kry spoed lcd.update (); }

void dusmanAracidurum (int yer, int asama) {// stel plekke vir vyandelike vorms in

if (yer == 1) {lcd.drawBitmap (2, asama, dusmanAraci, 7, 7); lcd.update ();} // if location = 1 teken vyand hierdie plek as (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 ();}}

ongeldig oyunbitti () {// as ons misluk, is die spel verby

terwyl (1) {vertraging (100); // wag 1 milisekonde lcd.clrScr (); lcd.setFont (SmallFont); lcd.print ("OYUN BITTI", CENTRE, 8); // druk spel oor lcd.print ("skorunuz =", 3, 30); // druk u telling lcd.setFont (MediumNumbers) af; lcd.printNumI (skor, 60, 25); // kry laaste telling lcd.update (); }}

ongeldige opstelling () {

pinMode (BL, UITGANG); // terugsit lig Output pinMode (xpin, INPUT); // stel x -pen in as 'n invoer lcd. InitLCD (); // begin die lcd -skerm lcd.setContrast (55); // stel kontras (tussen 0 en 127) Serial.begin (9600); // begin met reekskommunikasie}

leemte -lus () {

analogWrite (BL, 350); oyunEkrani ();

// joyistic durumu … // stel die joyistick -ligging 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 beheer is waar pozisyon ++; // verhoog die ligging wat dit beteken, skuif die vorm na die regte kontrol = false; } anders as (durumx> 300 && durumx <600) {kontrol = true; } // pozisyon durumu … // posisie staat … if (pozisyon == 1) {// if location = 1; lcd.drawBitmap (2, 41, arac, 7, 7); lcd.update ();} // teken ons skip as (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 ();}

as (dusmanoldu) {// as die vyand se vorm dood is, kyk of dit dood is

dusmankonum1 = pozisyon; // teken eerste vyandelike vorm dusmankonum2 = random (0, 6); // teken êrens 'n ander vyandelike vorm dusmankonum3 = random (0, 6); dusmankonum4 = ewekansig (0, 6); dusmankonum5 = ewekansig (0, 6); dusmaninYdekonumu = 0; // bring vyand van bo af dusmanoldu = vals;} // vyand word herskep sodat hulle nie dood is nie

dusmanAracidurum (dusmankonum1, dusmaninYdekonumu); dusmaninYdekonumu ++; // teken die eerste vyandelike vorm en kry dit van bo na onder

dusmanAracidurum (dusmankonum2, dusmaninYdekonumu); dusmaninYdekonumu ++; // teken die tweede vyandelike vorm en haal dit van bo na onder dusmanAracidurum (dusmankonum3, dusmaninYdekonumu); dusmaninYdekonumu ++; dusmanAracidurum (dusmankonum4, dusmaninYdekonumu); dusmaninYdekonumu ++; as (dusmaninYdekonumu> 35 && ((dusmankonum1 == pozisyon) || (dusmankonum2 == pozisyon) || (dusmankonum3 == pozisyon) || (dusmankonum4 == pozisyon))) {// as ons vorm vyandelike vorms raak oyunbitti (); //die spel is verby }

as (dusmaninYdekonumu> 42) {// as ons vorm van vyande ontsnap

dusmanoldu = waar; // vermoor vyandelike vorms skor ++; // verhoog die telling een vir een}

// skora gore hizi artiriyoruz // verhoog spoed volgens telling

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

}

Stap 4: KODE BITMAP

Verder moet u 'n bitmap -grafika vir vorms insluit, dit moet 'n.c -lêer wees.

#include // include for progmem function

const unsigned char arac PROGMEM = {// ons vorm -bitmap

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

const unsigned char dusmanAraci PROGMEM = {// vyandskip se bitmap

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

Stap 5: Dankie dat u gekyk het

Betekenis van 'n paar woorde:

Oyun => Spel

Arac => Vorm

Dusman => Vyand

kontrol => beheer

Konum, Yer => Ligging

Oyun Bitti => Game Over

Skor => telling

Hiz => Spoed

Aanbeveel: