This shows you the differences between two versions of the page.
|
pm:prj2022:arosca:snakegamewithgyroscope [2022/05/27 17:10] gabriel.saru [Software Design] |
pm:prj2022:arosca:snakegamewithgyroscope [2022/05/27 19:29] (current) gabriel.saru [Download] |
||
|---|---|---|---|
| Line 64: | Line 64: | ||
| În codul meu am setat lungimea maximă a șarpelui la 64, care este întreaga matrice LED. Am făcut asta pentru că am vrut ca jocul să se termine doar dacă șarpele a murit și nu dacă a ajuns la o anumită lungime. | În codul meu am setat lungimea maximă a șarpelui la 64, care este întreaga matrice LED. Am făcut asta pentru că am vrut ca jocul să se termine doar dacă șarpele a murit și nu dacă a ajuns la o anumită lungime. | ||
| + | Un mic rezumat in ceea ce fac functiile: | ||
| + | * void playGame() --> această funcție va porni jocul | ||
| + | * void draw() --> aceasta functie va apela funcțiile pentru a desena șarpele și ținta | ||
| + | * void drawSnake() --> aceasta functie va desena sarpele | ||
| + | * void drawTarget() --> aceasta functie va atrage ținta | ||
| + | * boolean inPlayField(int x, int y) --> va stabili terenul de joc pentru țintă și șarpe pentru a se spawna pe harta | ||
| + | * void makeTarget() --> aceasta functie va alege o valoare aleatorie și va stabili ținta | ||
| + | * boolean isPartOfSnake(int x, int y) --> aceasta functie se va citi dacă valoarea face parte sau nu din șarpe. | ||
| + | * void makeSnake() --> aceasta functie va stabili valorile șarpelui | ||
| + | * void moveSnake() --> această funcție va muta șarpele în funcție de accelerometru | ||
| + | * void gameOver() --> aceasta functie va afișa spectacolul de lumini și va nota după terminarea jocului | ||
| ==== Cod Sursa ==== | ==== Cod Sursa ==== | ||
| - | <code> //First we need to set up some libraries so that we can use all the parts we want | + | <code> |
| + | |||
| + | #include <SparkFun_MMA8452Q.h> | ||
| + | |||
| + | |||
| + | //First we need to set up some libraries so that we can use all the parts we want | ||
| #include <Wire.h> // we need this to use I2C which is a requirement of the | #include <Wire.h> // we need this to use I2C which is a requirement of the | ||
| // acceleromter and LED matrix | // acceleromter and LED matrix | ||
| - | #include <SFE_MMA8452Q.h> // this will include the library so we can use the accelerometer | + | //#include <SFE_MMA8452Q.h> // this will include the library so we can use the accelerometer |
| //these two libraries are so we can use the LED matrix | //these two libraries are so we can use the LED matrix | ||
| Line 80: | Line 96: | ||
| #include <SPI.h> // needed in Arduino 0019 or later | #include <SPI.h> // needed in Arduino 0019 or later | ||
| #include <Ethernet.h> | #include <Ethernet.h> | ||
| - | #include <Twitter.h> | ||
| - | |||
| #include <EEPROM.h> // this will allow us to store memory on the Arduino. | #include <EEPROM.h> // this will allow us to store memory on the Arduino. | ||
| - | |||
| //Now we need to set up some features for our accelerometer | //Now we need to set up some features for our accelerometer | ||
| Line 104: | Line 117: | ||
| //You can get your token from (http://arduino-tweet.appspot.com/) | //You can get your token from (http://arduino-tweet.appspot.com/) | ||
| //this is my token, make sure to use your own for it to show up on your Twitter news feed | //this is my token, make sure to use your own for it to show up on your Twitter news feed | ||
| - | Twitter twitter("3196797122-2jESNtWDAvddc1zYJkhaQqUjokUpVwraJ1pAbiS"); | ||
| //this will set up a message which we will use later when we want to post to Twitter | //this will set up a message which we will use later when we want to post to Twitter | ||
| Line 165: | Line 177: | ||
| } | } | ||
| prevPowerState = powerButtonState; | prevPowerState = powerButtonState; | ||
| - | |||
| - | //Serial.println(mode); //debug to make sure the modes were working porperly | ||
| switch (mode) { | switch (mode) { | ||
| Line 183: | Line 193: | ||
| int sendButtonState = digitalRead(sendButton); //this will send a Tweet of the score by pushing the red button | int sendButtonState = digitalRead(sendButton); //this will send a Tweet of the score by pushing the red button | ||
| if (sendButtonState == HIGH) { | if (sendButtonState == HIGH) { | ||
| - | sendTweet(); | ||
| } | } | ||
| } | } | ||
| Line 289: | Line 298: | ||
| void makeSnake() { //this will set up the values of the snake | void makeSnake() { //this will set up the values of the snake | ||
| + | | ||
| snakeX[0] = 3; | snakeX[0] = 3; | ||
| snakeY[0] = 4; | snakeY[0] = 4; | ||
| + | | ||
| for (int i = 1; i < maxSnake; i++) { | for (int i = 1; i < maxSnake; i++) { | ||
| snakeX[i] = snakeY[i] = -1; | snakeX[i] = snakeY[i] = -1; | ||
| Line 436: | Line 447: | ||
| matrix.setTextColor(LED_YELLOW); | matrix.setTextColor(LED_YELLOW); | ||
| matrix.setRotation(3); | matrix.setRotation(3); | ||
| + | | ||
| for (int8_t x = 7; x >= -36; x--) { | for (int8_t x = 7; x >= -36; x--) { | ||
| matrix.clear(); | matrix.clear(); | ||
| Line 443: | Line 455: | ||
| delay (100); | delay (100); | ||
| } | } | ||
| - | }</code> | + | } |
| + | |||
| + | |||
| + | </code> | ||
| ==== Rezultate Obţinute ==== | ==== Rezultate Obţinute ==== | ||
| - | TBA | + | Implementarea proiectului este urmatoarea: |
| + | {{:pm/prj2022/arosca/rezultat_sgabriel_1_resized.jpg}} | ||
| + | {{:pm/prj2022/arosca/rezultat_sgabriel_2_resized.jpg}} | ||
| ===== Concluzii ===== | ===== Concluzii ===== | ||
| Line 455: | Line 472: | ||
| ===== Download ===== | ===== Download ===== | ||
| - | * {{ :pm:prj2022:arosca:codsursasnakeaccelerometru.zip | Arhiva cod sursa + comentarii }} | + | * {{ :pm:prj2022:arosca:arhivaplusreadme_sarugabriel333cb.zip | Arhiva cod sursa + comentarii + README }} |
| + | |||
| + | In aceasta sectiune de DOWNLOAD putem gasi arhiva care contine urmatoarele: | ||
| + | |||
| + | * Codul sursa al proiectului; | ||
| + | * README, pentru o explicare mai succinta a functiilor din proiect; | ||
| + | * Libraria accelerometrului; | ||
| Line 461: | Line 484: | ||
| - | Puteți avea și o secțiune de jurnal în care să poată urmări asistentul de proiect progresul proiectului. | + | Ca o secțiune de jurnal, in care laborantul să poată urmări progresul proiectului. |
| - **Alegere Tema Proiect** - **12.04.2022** | - **Alegere Tema Proiect** - **12.04.2022** | ||