Sisic Nedim i Yahya Aly

Dependencies:   SPI_TFT_ILI9341 TFT_fonts mbed

Committer:
2018US_NedimSisic
Date:
Sat Jun 30 22:34:56 2018 +0000
Revision:
0:78147151cc2c
Child:
1:257db033a098
Publishovanje projekta Flappy Bird, Yahya Aly i Nedim Sisic

Who changed what in which revision?

UserRevisionLine numberNew contents of line
2018US_NedimSisic 0:78147151cc2c 1
2018US_NedimSisic 0:78147151cc2c 2 #include "mbed.h"
2018US_NedimSisic 0:78147151cc2c 3 #include "stdio.h"
2018US_NedimSisic 0:78147151cc2c 4 #include "SPI_TFT_ILI9341.h"
2018US_NedimSisic 0:78147151cc2c 5 #include "stdlib.h"
2018US_NedimSisic 0:78147151cc2c 6 #include "time.h"
2018US_NedimSisic 0:78147151cc2c 7
2018US_NedimSisic 0:78147151cc2c 8 #include "string"
2018US_NedimSisic 0:78147151cc2c 9
2018US_NedimSisic 0:78147151cc2c 10 //#include "Arial12x12.h"
2018US_NedimSisic 0:78147151cc2c 11 #include "Arial24x23.h"
2018US_NedimSisic 0:78147151cc2c 12 //#include "Arial28x28.h"
2018US_NedimSisic 0:78147151cc2c 13 //#include "Neu42x35.h"
2018US_NedimSisic 0:78147151cc2c 14 //#include "font_big.h"
2018US_NedimSisic 0:78147151cc2c 15 //#include "SDFileSystem.h"
2018US_NedimSisic 0:78147151cc2c 16 #define dp23 P0_0
2018US_NedimSisic 0:78147151cc2c 17
2018US_NedimSisic 0:78147151cc2c 18
2018US_NedimSisic 0:78147151cc2c 19 //SPI_TFT_ILI9341 TFT(PTD2,PTD3,PTD1,PTD0,PTA20,PTA13,"TFT"); // mosi, miso, sclk, cs, reset, dc
2018US_NedimSisic 0:78147151cc2c 20 SPI_TFT_ILI9341 TFT(dp2,dp1,dp6,dp24,dp23,dp25,"TFT");
2018US_NedimSisic 0:78147151cc2c 21
2018US_NedimSisic 0:78147151cc2c 22
2018US_NedimSisic 0:78147151cc2c 23 #define xKraj 319
2018US_NedimSisic 0:78147151cc2c 24 #define yKraj 239
2018US_NedimSisic 0:78147151cc2c 25 #define xPtica 100
2018US_NedimSisic 0:78147151cc2c 26 #define vrhZelenog 195
2018US_NedimSisic 0:78147151cc2c 27 #define dnoZelenog 206
2018US_NedimSisic 0:78147151cc2c 28 #define duzinaZelenog 80
2018US_NedimSisic 0:78147151cc2c 29 #define pomakPticeY 1
2018US_NedimSisic 0:78147151cc2c 30
2018US_NedimSisic 0:78147151cc2c 31 #define ZelenaNaslov 47011
2018US_NedimSisic 0:78147151cc2c 32 #define TamnoZelena 28133
2018US_NedimSisic 0:78147151cc2c 33 #define SvijetloZelena 38698
2018US_NedimSisic 0:78147151cc2c 34 #define NeboPlava 19993
2018US_NedimSisic 0:78147151cc2c 35 #define Zemlja 54961
2018US_NedimSisic 0:78147151cc2c 36 #define Zuto 63364
2018US_NedimSisic 0:78147151cc2c 37
2018US_NedimSisic 0:78147151cc2c 38
2018US_NedimSisic 0:78147151cc2c 39 //InterruptIn t(A2);
2018US_NedimSisic 0:78147151cc2c 40 InterruptIn t(dp9);
2018US_NedimSisic 0:78147151cc2c 41
2018US_NedimSisic 0:78147151cc2c 42
2018US_NedimSisic 0:78147151cc2c 43 int pticaY, prosliPticaY;
2018US_NedimSisic 0:78147151cc2c 44 float brzinaPtice(0), grav(1);
2018US_NedimSisic 0:78147151cc2c 45 float frame(0.033333);
2018US_NedimSisic 0:78147151cc2c 46 int stuboviXevi[3]; // = {320, 320, 320};
2018US_NedimSisic 0:78147151cc2c 47 int stuboviY[3];
2018US_NedimSisic 0:78147151cc2c 48 int prviZelPocetak, drugiZelPocetak;
2018US_NedimSisic 0:78147151cc2c 49 int dijelic = 3; // za koliko se pomjere stubovi i zeleni dijelovi u jednom frameu
2018US_NedimSisic 0:78147151cc2c 50 int maxBrzina (20), skokBrzina(-7);
2018US_NedimSisic 0:78147151cc2c 51 int stanje(0);
2018US_NedimSisic 0:78147151cc2c 52 int skor, bestSkor;
2018US_NedimSisic 0:78147151cc2c 53 bool kolizija(false);
2018US_NedimSisic 0:78147151cc2c 54 bool pocetak(true); // true do prvog pojavljivanja treceg stuba
2018US_NedimSisic 0:78147151cc2c 55
2018US_NedimSisic 0:78147151cc2c 56 void ns();
2018US_NedimSisic 0:78147151cc2c 57
2018US_NedimSisic 0:78147151cc2c 58
2018US_NedimSisic 0:78147151cc2c 59 //++++++++++++++ Ptica
2018US_NedimSisic 0:78147151cc2c 60
2018US_NedimSisic 0:78147151cc2c 61
2018US_NedimSisic 0:78147151cc2c 62 void crtajPticu() { // crtaj pticu
2018US_NedimSisic 0:78147151cc2c 63
2018US_NedimSisic 0:78147151cc2c 64 // brisanje
2018US_NedimSisic 0:78147151cc2c 65 if (prosliPticaY == pticaY) // Nema potrebe za brisanjem
2018US_NedimSisic 0:78147151cc2c 66 return;
2018US_NedimSisic 0:78147151cc2c 67 if (prosliPticaY < pticaY) { // pomjerila se dolje // generalno: da li je brze ili sporije if (){return;} else()...
2018US_NedimSisic 0:78147151cc2c 68 TFT.fillrect(xPtica - 9, prosliPticaY - 6, xPtica + 7, pticaY - 7, NeboPlava); // od proslog pocetka do trenutnog
2018US_NedimSisic 0:78147151cc2c 69 } else { // pomjerila se gore
2018US_NedimSisic 0:78147151cc2c 70 TFT.fillrect(xPtica - 9, pticaY + 6, xPtica + 7, prosliPticaY + 5, NeboPlava); // od trenutnog kraja do proslog
2018US_NedimSisic 0:78147151cc2c 71 }
2018US_NedimSisic 0:78147151cc2c 72
2018US_NedimSisic 0:78147151cc2c 73 // crtanje
2018US_NedimSisic 0:78147151cc2c 74 // za crtanje ptice promjenljiva je pticaY
2018US_NedimSisic 0:78147151cc2c 75 TFT.fillrect(xPtica-6,pticaY-5,xPtica,pticaY+4,63364); // zuto
2018US_NedimSisic 0:78147151cc2c 76 TFT.pixel(xPtica-6,pticaY-5,19993);
2018US_NedimSisic 0:78147151cc2c 77 TFT.fillrect(xPtica,pticaY-5,xPtica+4,pticaY-1,White); // bijelo
2018US_NedimSisic 0:78147151cc2c 78 TFT.pixel(xPtica+4,pticaY-5,19993);
2018US_NedimSisic 0:78147151cc2c 79 TFT.fillrect(xPtica-8,pticaY-2,xPtica-4,pticaY+1,White); // bijelo
2018US_NedimSisic 0:78147151cc2c 80 // horizontalne linije
2018US_NedimSisic 0:78147151cc2c 81 TFT.line(xPtica+1,pticaY,xPtica+6,pticaY,18856);
2018US_NedimSisic 0:78147151cc2c 82 TFT.line(xPtica+1,pticaY+2,xPtica+6,pticaY+2,18856);
2018US_NedimSisic 0:78147151cc2c 83 TFT.line(xPtica+1,pticaY+4,xPtica+5,pticaY+4,18856);
2018US_NedimSisic 0:78147151cc2c 84 TFT.line(xPtica+1,pticaY+1,xPtica+6,pticaY+1,62216);
2018US_NedimSisic 0:78147151cc2c 85 TFT.line(xPtica+1,pticaY+3,xPtica+5,pticaY+3,62216);
2018US_NedimSisic 0:78147151cc2c 86 TFT.line(xPtica-3,pticaY-6,xPtica+2,pticaY-6,18856);
2018US_NedimSisic 0:78147151cc2c 87 TFT.line(xPtica-8,pticaY-3,xPtica-5,pticaY-3,18856);
2018US_NedimSisic 0:78147151cc2c 88 TFT.line(xPtica-6,pticaY+4,xPtica-5,pticaY+4,18856);
2018US_NedimSisic 0:78147151cc2c 89 TFT.line(xPtica-5,pticaY-5,xPtica-4,pticaY-5,18856);
2018US_NedimSisic 0:78147151cc2c 90 // vertikalne linje
2018US_NedimSisic 0:78147151cc2c 91 TFT.line(xPtica+5,pticaY-3,xPtica+5,pticaY-1,18856);
2018US_NedimSisic 0:78147151cc2c 92 TFT.line(xPtica+3,pticaY-3,xPtica+3,pticaY-2,18856);
2018US_NedimSisic 0:78147151cc2c 93 TFT.line(xPtica-1,pticaY-4,xPtica-1,pticaY-2,18856);
2018US_NedimSisic 0:78147151cc2c 94 TFT.line(xPtica-3,pticaY-1,xPtica-3,pticaY,18856);
2018US_NedimSisic 0:78147151cc2c 95 TFT.line(xPtica-9,pticaY-2,xPtica-9,pticaY,18856);
2018US_NedimSisic 0:78147151cc2c 96 // pixeli
2018US_NedimSisic 0:78147151cc2c 97 TFT.pixel(xPtica,pticaY-1,18856);
2018US_NedimSisic 0:78147151cc2c 98 TFT.pixel(xPtica,pticaY+1,18856);
2018US_NedimSisic 0:78147151cc2c 99 TFT.pixel(xPtica,pticaY+3,18856);
2018US_NedimSisic 0:78147151cc2c 100 TFT.pixel(xPtica,pticaY-5,18856);
2018US_NedimSisic 0:78147151cc2c 101 TFT.pixel(xPtica-4,pticaY+1,18856);
2018US_NedimSisic 0:78147151cc2c 102 TFT.pixel(xPtica+7,pticaY+1,18856);
2018US_NedimSisic 0:78147151cc2c 103 TFT.pixel(xPtica-7,pticaY+3,18856);
2018US_NedimSisic 0:78147151cc2c 104 TFT.pixel(xPtica+6,pticaY+3,18856);
2018US_NedimSisic 0:78147151cc2c 105 TFT.pixel(xPtica-1,pticaY+2,18856);
2018US_NedimSisic 0:78147151cc2c 106 TFT.pixel(xPtica-4,pticaY-2,18856);
2018US_NedimSisic 0:78147151cc2c 107 TFT.pixel(xPtica-6,pticaY-4,18856);
2018US_NedimSisic 0:78147151cc2c 108 TFT.pixel(xPtica+3,pticaY-5,18856);
2018US_NedimSisic 0:78147151cc2c 109 TFT.pixel(xPtica+4,pticaY-4,18856);
2018US_NedimSisic 0:78147151cc2c 110
2018US_NedimSisic 0:78147151cc2c 111 TFT.pixel(xPtica,pticaY+2,62216);
2018US_NedimSisic 0:78147151cc2c 112 }
2018US_NedimSisic 0:78147151cc2c 113
2018US_NedimSisic 0:78147151cc2c 114 /*
2018US_NedimSisic 0:78147151cc2c 115 void crtajPticu() {
2018US_NedimSisic 0:78147151cc2c 116 if (prosliPticaY == pticaY) // Nema potrebe za brisanjem
2018US_NedimSisic 0:78147151cc2c 117 return;
2018US_NedimSisic 0:78147151cc2c 118
2018US_NedimSisic 0:78147151cc2c 119 if (prosliPticaY < pticaY) { // pomjerila se dolje // generalno: da li je brze ili sporije if (){return;} else()...
2018US_NedimSisic 0:78147151cc2c 120 TFT.fillrect(xPtica - 9, prosliPticaY - 6, xPtica + 7, pticaY - 7, NeboPlava); // od proslog pocetka do trenutnog
2018US_NedimSisic 0:78147151cc2c 121 } else { // pomjerila se gore
2018US_NedimSisic 0:78147151cc2c 122 TFT.fillrect(xPtica - 9, pticaY + 6, xPtica + 7, prosliPticaY + 5, NeboPlava); // od trenutnog kraja do proslog
2018US_NedimSisic 0:78147151cc2c 123 }
2018US_NedimSisic 0:78147151cc2c 124 // crtanje
2018US_NedimSisic 0:78147151cc2c 125 TFT.fillrect(xPtica - 9, pticaY - 6, xPtica + 7, pticaY + 5, Zuto);
2018US_NedimSisic 0:78147151cc2c 126 TFT.fillrect(xPtica + 3, pticaY - 3, xPtica + 4, pticaY, 18856);
2018US_NedimSisic 0:78147151cc2c 127
2018US_NedimSisic 0:78147151cc2c 128 // alt brisanje: if (prosli != trenutni) TFT.fillrect(xPtica - 9, prosliPticaY - 6, xPtica + 7, prosliPticaY + 5, NeboPlava);
2018US_NedimSisic 0:78147151cc2c 129 }
2018US_NedimSisic 0:78147151cc2c 130 */
2018US_NedimSisic 0:78147151cc2c 131 void skok() { // flap
2018US_NedimSisic 0:78147151cc2c 132 brzinaPtice = skokBrzina;
2018US_NedimSisic 0:78147151cc2c 133 }
2018US_NedimSisic 0:78147151cc2c 134
2018US_NedimSisic 0:78147151cc2c 135 //++++++++++++ Ptica^^^, update je kod tla
2018US_NedimSisic 0:78147151cc2c 136
2018US_NedimSisic 0:78147151cc2c 137
2018US_NedimSisic 0:78147151cc2c 138
2018US_NedimSisic 0:78147151cc2c 139 //********* TLO
2018US_NedimSisic 0:78147151cc2c 140
2018US_NedimSisic 0:78147151cc2c 141 void crtajZeleniDjelic(int pocetak) {
2018US_NedimSisic 0:78147151cc2c 142 TFT.fillrect(pocetak, vrhZelenog, pocetak + dijelic - 1, dnoZelenog, SvijetloZelena);
2018US_NedimSisic 0:78147151cc2c 143 }
2018US_NedimSisic 0:78147151cc2c 144
2018US_NedimSisic 0:78147151cc2c 145 void brisiZeleniDjelic(int izaKraja) {
2018US_NedimSisic 0:78147151cc2c 146 TFT.fillrect(izaKraja, vrhZelenog, izaKraja + dijelic + 1, dnoZelenog, TamnoZelena);
2018US_NedimSisic 0:78147151cc2c 147 }
2018US_NedimSisic 0:78147151cc2c 148
2018US_NedimSisic 0:78147151cc2c 149 void crtajCijeliZeleni(int pocetak) {
2018US_NedimSisic 0:78147151cc2c 150 crtajZeleniDjelic(pocetak);
2018US_NedimSisic 0:78147151cc2c 151 brisiZeleniDjelic(pocetak + duzinaZelenog);
2018US_NedimSisic 0:78147151cc2c 152 // TFT.fillrect(pocetak, vrhZelenog, pocetak + duzinaZel , dnoZelene, SvijetloZelena);
2018US_NedimSisic 0:78147151cc2c 153 }
2018US_NedimSisic 0:78147151cc2c 154
2018US_NedimSisic 0:78147151cc2c 155 void crtajZeleniDijelovi(int pocetak) {
2018US_NedimSisic 0:78147151cc2c 156 brisiZeleniDjelic(duzinaZelenog - xKraj + pocetak - 1); // 0 + duzZ - ((xKraj - poc) + 1)
2018US_NedimSisic 0:78147151cc2c 157 crtajZeleniDjelic(pocetak);
2018US_NedimSisic 0:78147151cc2c 158 // TFT.fillrect(0, vrhZelenog, duzinaZel - xKraj + pocetak , dnoZelenog, SvijetloZelena);
2018US_NedimSisic 0:78147151cc2c 159 // TFT.fillrect(pocetak , vrhZelenog, xKraj, dnoZelenog, SvijetloZelena);
2018US_NedimSisic 0:78147151cc2c 160 }
2018US_NedimSisic 0:78147151cc2c 161
2018US_NedimSisic 0:78147151cc2c 162 void crtajZelene() { // (int prviZelPocetak, int drugiZelPocetak)
2018US_NedimSisic 0:78147151cc2c 163 if (prviZelPocetak > xKraj - duzinaZelenog + 1) { // prvi u dijelovima
2018US_NedimSisic 0:78147151cc2c 164 crtajZeleniDijelovi(prviZelPocetak);
2018US_NedimSisic 0:78147151cc2c 165 crtajCijeliZeleni(drugiZelPocetak);
2018US_NedimSisic 0:78147151cc2c 166 } else if (drugiZelPocetak > xKraj - duzinaZelenog + 1) { // drugi u dijelovima
2018US_NedimSisic 0:78147151cc2c 167 crtajCijeliZeleni(prviZelPocetak);
2018US_NedimSisic 0:78147151cc2c 168 crtajZeleniDijelovi(drugiZelPocetak);
2018US_NedimSisic 0:78147151cc2c 169 } else { // oba su cijeli
2018US_NedimSisic 0:78147151cc2c 170 crtajCijeliZeleni(prviZelPocetak);
2018US_NedimSisic 0:78147151cc2c 171 crtajCijeliZeleni(drugiZelPocetak);
2018US_NedimSisic 0:78147151cc2c 172 }
2018US_NedimSisic 0:78147151cc2c 173 }
2018US_NedimSisic 0:78147151cc2c 174
2018US_NedimSisic 0:78147151cc2c 175 void updatePticaZel() {
2018US_NedimSisic 0:78147151cc2c 176 // update y koordinate ptice, i pratecih varijabli
2018US_NedimSisic 0:78147151cc2c 177 brzinaPtice += grav;
2018US_NedimSisic 0:78147151cc2c 178 if (brzinaPtice > maxBrzina)
2018US_NedimSisic 0:78147151cc2c 179 brzinaPtice = maxBrzina;
2018US_NedimSisic 0:78147151cc2c 180 prosliPticaY = pticaY;
2018US_NedimSisic 0:78147151cc2c 181 pticaY += brzinaPtice * pomakPticeY;
2018US_NedimSisic 0:78147151cc2c 182 if (pticaY + 3 >= vrhZelenog) {
2018US_NedimSisic 0:78147151cc2c 183 kolizija = true;
2018US_NedimSisic 0:78147151cc2c 184 } else if (pticaY < 5) { // pri vrhu ekrana
2018US_NedimSisic 0:78147151cc2c 185 pticaY = 6;
2018US_NedimSisic 0:78147151cc2c 186 }
2018US_NedimSisic 0:78147151cc2c 187
2018US_NedimSisic 0:78147151cc2c 188
2018US_NedimSisic 0:78147151cc2c 189 // Update x koordinata zelenih
2018US_NedimSisic 0:78147151cc2c 190 prviZelPocetak -= dijelic;
2018US_NedimSisic 0:78147151cc2c 191 drugiZelPocetak -= dijelic;
2018US_NedimSisic 0:78147151cc2c 192 if (prviZelPocetak < 0) {
2018US_NedimSisic 0:78147151cc2c 193 prviZelPocetak = xKraj + 1 - dijelic;
2018US_NedimSisic 0:78147151cc2c 194 } else if (drugiZelPocetak < 0) {
2018US_NedimSisic 0:78147151cc2c 195 drugiZelPocetak = xKraj + 1 - dijelic;
2018US_NedimSisic 0:78147151cc2c 196 }
2018US_NedimSisic 0:78147151cc2c 197
2018US_NedimSisic 0:78147151cc2c 198 }
2018US_NedimSisic 0:78147151cc2c 199
2018US_NedimSisic 0:78147151cc2c 200 //************** Tlo^^^
2018US_NedimSisic 0:78147151cc2c 201
2018US_NedimSisic 0:78147151cc2c 202
2018US_NedimSisic 0:78147151cc2c 203
2018US_NedimSisic 0:78147151cc2c 204 //---------------- STUBOVI
2018US_NedimSisic 0:78147151cc2c 205
2018US_NedimSisic 0:78147151cc2c 206 void crtajStubove() {// promjena
2018US_NedimSisic 0:78147151cc2c 207 for (int i = 0; i < 3; i++) {
2018US_NedimSisic 0:78147151cc2c 208 // brisanje
2018US_NedimSisic 0:78147151cc2c 209 if (stuboviXevi[i] + 36 + dijelic < 320) {
2018US_NedimSisic 0:78147151cc2c 210 TFT.fillrect(stuboviXevi[i] + 36, 0, stuboviXevi[i] + 37 + dijelic, stuboviY[i] - 85, NeboPlava);
2018US_NedimSisic 0:78147151cc2c 211 TFT.fillrect(stuboviXevi[i] + 36, stuboviY[i], stuboviXevi[i] + 37 + dijelic, 194, NeboPlava);
2018US_NedimSisic 0:78147151cc2c 212 }
2018US_NedimSisic 0:78147151cc2c 213 // crtanje
2018US_NedimSisic 0:78147151cc2c 214 if (stuboviXevi[i]>= 0) {
2018US_NedimSisic 0:78147151cc2c 215 TFT.fillrect(stuboviXevi[i], 0, stuboviXevi[i] +dijelic, stuboviY[i] - 85, 26571);
2018US_NedimSisic 0:78147151cc2c 216 TFT.fillrect(stuboviXevi[i], stuboviY[i], stuboviXevi[i] + dijelic, 194, 26571);
2018US_NedimSisic 0:78147151cc2c 217 }
2018US_NedimSisic 0:78147151cc2c 218 }
2018US_NedimSisic 0:78147151cc2c 219 }
2018US_NedimSisic 0:78147151cc2c 220
2018US_NedimSisic 0:78147151cc2c 221
2018US_NedimSisic 0:78147151cc2c 222
2018US_NedimSisic 0:78147151cc2c 223 void updateStubovi() {
2018US_NedimSisic 0:78147151cc2c 224 int n(0); // broj aktivnih stubova
2018US_NedimSisic 0:78147151cc2c 225 if (pocetak && stuboviXevi[0] > 200)
2018US_NedimSisic 0:78147151cc2c 226 n = 1;
2018US_NedimSisic 0:78147151cc2c 227 else if (pocetak && stuboviXevi[0] > 81)
2018US_NedimSisic 0:78147151cc2c 228 n = 2;
2018US_NedimSisic 0:78147151cc2c 229 else {
2018US_NedimSisic 0:78147151cc2c 230 n = 3;
2018US_NedimSisic 0:78147151cc2c 231 pocetak = false;
2018US_NedimSisic 0:78147151cc2c 232 }
2018US_NedimSisic 0:78147151cc2c 233
2018US_NedimSisic 0:78147151cc2c 234 for(int i(0); i < n; i++) {
2018US_NedimSisic 0:78147151cc2c 235 if (stuboviXevi[i] - dijelic >= -36) // mozda povecati sa -36 na vise, ili samo vece bez jednako
2018US_NedimSisic 0:78147151cc2c 236 {
2018US_NedimSisic 0:78147151cc2c 237 stuboviXevi[i] -= dijelic; // prva greska: bez (-)
2018US_NedimSisic 0:78147151cc2c 238 if (stuboviXevi[i] <= 100 && stuboviXevi[i] + dijelic > 100) { // dodano manjeJEDNAKO
2018US_NedimSisic 0:78147151cc2c 239 skor++;
2018US_NedimSisic 0:78147151cc2c 240 ns();
2018US_NedimSisic 0:78147151cc2c 241 }
2018US_NedimSisic 0:78147151cc2c 242 if (stuboviXevi[i] < 107 && stuboviXevi[i] + 35 > 91 && // stuboviXevi[i] < 107 && stuboviXevi[i] > 56
2018US_NedimSisic 0:78147151cc2c 243 (pticaY + 3 >= stuboviY[i] || pticaY - 6 <= stuboviY[i] - 86)) {
2018US_NedimSisic 0:78147151cc2c 244 kolizija = true;
2018US_NedimSisic 0:78147151cc2c 245 return;
2018US_NedimSisic 0:78147151cc2c 246 }
2018US_NedimSisic 0:78147151cc2c 247 }
2018US_NedimSisic 0:78147151cc2c 248 else
2018US_NedimSisic 0:78147151cc2c 249 {
2018US_NedimSisic 0:78147151cc2c 250 stuboviXevi[i] = 320;
2018US_NedimSisic 0:78147151cc2c 251 stuboviY[i] = rand()%35 + 115; // opseg mozemo prosiriti ako treba
2018US_NedimSisic 0:78147151cc2c 252 }
2018US_NedimSisic 0:78147151cc2c 253 }
2018US_NedimSisic 0:78147151cc2c 254 }
2018US_NedimSisic 0:78147151cc2c 255
2018US_NedimSisic 0:78147151cc2c 256 //---------------- Stubovi^
2018US_NedimSisic 0:78147151cc2c 257
2018US_NedimSisic 0:78147151cc2c 258
2018US_NedimSisic 0:78147151cc2c 259 void nultoStanje() { // stanje 0: intro ekran
2018US_NedimSisic 0:78147151cc2c 260 TFT.background(Black); // set background to black
2018US_NedimSisic 0:78147151cc2c 261 TFT.foreground(ZelenaNaslov); // set chars to light green
2018US_NedimSisic 0:78147151cc2c 262 TFT.cls();
2018US_NedimSisic 0:78147151cc2c 263 TFT.set_font((unsigned char*) Arial24x23);
2018US_NedimSisic 0:78147151cc2c 264 TFT.locate(75, 98);
2018US_NedimSisic 0:78147151cc2c 265 printf("Flappy bird");
2018US_NedimSisic 0:78147151cc2c 266 wait(2);
2018US_NedimSisic 0:78147151cc2c 267 }
2018US_NedimSisic 0:78147151cc2c 268
2018US_NedimSisic 0:78147151cc2c 269 void prvoStanje() { // stanje 1, ptica se ne pomjera
2018US_NedimSisic 0:78147151cc2c 270 // pocetne vrijednosti
2018US_NedimSisic 0:78147151cc2c 271 pticaY = 120;
2018US_NedimSisic 0:78147151cc2c 272 prviZelPocetak = duzinaZelenog * 2;
2018US_NedimSisic 0:78147151cc2c 273 drugiZelPocetak = duzinaZelenog * 4;
2018US_NedimSisic 0:78147151cc2c 274
2018US_NedimSisic 0:78147151cc2c 275 crtajPticu();
2018US_NedimSisic 0:78147151cc2c 276 while(stanje == 1) { // dok je stanje 1 (mijenja se samo klikom)
2018US_NedimSisic 0:78147151cc2c 277 crtajZelene();
2018US_NedimSisic 0:78147151cc2c 278 updatePticaZel(); // mijenja i pticu, ali se ne prikazuje
2018US_NedimSisic 0:78147151cc2c 279 wait(frame);
2018US_NedimSisic 0:78147151cc2c 280 }
2018US_NedimSisic 0:78147151cc2c 281 }
2018US_NedimSisic 0:78147151cc2c 282
2018US_NedimSisic 0:78147151cc2c 283 void drugoStanje() { // Stanje 2, let ptice bez stubova
2018US_NedimSisic 0:78147151cc2c 284 pticaY = 120;
2018US_NedimSisic 0:78147151cc2c 285 kolizija = false;
2018US_NedimSisic 0:78147151cc2c 286 brzinaPtice = skokBrzina; // samo promijenili brzinu da bude skok
2018US_NedimSisic 0:78147151cc2c 287
2018US_NedimSisic 0:78147151cc2c 288 for (int i = 0; i < 60; i++) { // 60 = 2s/frame, ne mozemo poravnati sa stubovima?
2018US_NedimSisic 0:78147151cc2c 289 crtajPticu();
2018US_NedimSisic 0:78147151cc2c 290 crtajZelene();
2018US_NedimSisic 0:78147151cc2c 291 updatePticaZel();
2018US_NedimSisic 0:78147151cc2c 292 if (i < 30) {
2018US_NedimSisic 0:78147151cc2c 293 TFT.fillrect(70, dnoZelenog + 1, 120, dnoZelenog + 2, 21508);
2018US_NedimSisic 0:78147151cc2c 294 TFT.fillrect(70, dnoZelenog + 3, 120, dnoZelenog + 4, 52552);
2018US_NedimSisic 0:78147151cc2c 295 TFT.fillrect(70, dnoZelenog + 5, 120, yKraj, Zemlja);
2018US_NedimSisic 0:78147151cc2c 296 }
2018US_NedimSisic 0:78147151cc2c 297 if (kolizija)
2018US_NedimSisic 0:78147151cc2c 298 return;
2018US_NedimSisic 0:78147151cc2c 299 wait(frame);
2018US_NedimSisic 0:78147151cc2c 300 }
2018US_NedimSisic 0:78147151cc2c 301 }
2018US_NedimSisic 0:78147151cc2c 302
2018US_NedimSisic 0:78147151cc2c 303 void cetvrtoStanje() { // meni // promjena
2018US_NedimSisic 0:78147151cc2c 304 //TFT.set_font((unsigned char*) Arial24x23);
2018US_NedimSisic 0:78147151cc2c 305 if(skor > bestSkor)
2018US_NedimSisic 0:78147151cc2c 306 bestSkor = skor;
2018US_NedimSisic 0:78147151cc2c 307 TFT.fillrect(55, 80, 264, 191, 54961);
2018US_NedimSisic 0:78147151cc2c 308 TFT.locate(65, 100);
2018US_NedimSisic 0:78147151cc2c 309 printf("GAME OVER");
2018US_NedimSisic 0:78147151cc2c 310 TFT.locate(75, 130);
2018US_NedimSisic 0:78147151cc2c 311 printf("Score: %d", skor);
2018US_NedimSisic 0:78147151cc2c 312 TFT.locate(75, 160);
2018US_NedimSisic 0:78147151cc2c 313 printf("Best: %d", bestSkor);
2018US_NedimSisic 0:78147151cc2c 314 }
2018US_NedimSisic 0:78147151cc2c 315
2018US_NedimSisic 0:78147151cc2c 316 void ns() { // napisi skor // promjena (nova funkcija)
2018US_NedimSisic 0:78147151cc2c 317 int pozx(120);
2018US_NedimSisic 0:78147151cc2c 318 if(skor < 10)
2018US_NedimSisic 0:78147151cc2c 319 pozx = 155;
2018US_NedimSisic 0:78147151cc2c 320 else if(skor < 100)
2018US_NedimSisic 0:78147151cc2c 321 pozx = 148;
2018US_NedimSisic 0:78147151cc2c 322 else if(skor < 1000)
2018US_NedimSisic 0:78147151cc2c 323 pozx = 140;
2018US_NedimSisic 0:78147151cc2c 324 //TFT.fillrect(140,215,180,230,18856); // mozda zatreba
2018US_NedimSisic 0:78147151cc2c 325 TFT.locate(pozx, 215);
2018US_NedimSisic 0:78147151cc2c 326 printf("%d", skor);
2018US_NedimSisic 0:78147151cc2c 327 }
2018US_NedimSisic 0:78147151cc2c 328
2018US_NedimSisic 0:78147151cc2c 329 void klik() {
2018US_NedimSisic 0:78147151cc2c 330 if (stanje == 2 || stanje == 3) { // ako je stanje 2 ili 3; stanje & 2
2018US_NedimSisic 0:78147151cc2c 331 skok();
2018US_NedimSisic 0:78147151cc2c 332 } else if (stanje == 1) { // ako je stanje 1; stanje & 1
2018US_NedimSisic 0:78147151cc2c 333 stanje++;
2018US_NedimSisic 0:78147151cc2c 334 } else if (stanje == 4) { // stanje je 4; stanje & 4
2018US_NedimSisic 0:78147151cc2c 335 stanje = 1;
2018US_NedimSisic 0:78147151cc2c 336 }
2018US_NedimSisic 0:78147151cc2c 337 }
2018US_NedimSisic 0:78147151cc2c 338
2018US_NedimSisic 0:78147151cc2c 339 int main() {
2018US_NedimSisic 0:78147151cc2c 340
2018US_NedimSisic 0:78147151cc2c 341 //Inicijalizacija;
2018US_NedimSisic 0:78147151cc2c 342 TFT.claim(stdout);
2018US_NedimSisic 0:78147151cc2c 343 TFT.set_orientation(1);
2018US_NedimSisic 0:78147151cc2c 344 // enable = 0 ??
2018US_NedimSisic 0:78147151cc2c 345
2018US_NedimSisic 0:78147151cc2c 346 srand(time(NULL));
2018US_NedimSisic 0:78147151cc2c 347 skor = 0;
2018US_NedimSisic 0:78147151cc2c 348 bestSkor = 0;
2018US_NedimSisic 0:78147151cc2c 349
2018US_NedimSisic 0:78147151cc2c 350 stanje = 0;
2018US_NedimSisic 0:78147151cc2c 351 nultoStanje(); // intro ekran
2018US_NedimSisic 0:78147151cc2c 352
2018US_NedimSisic 0:78147151cc2c 353 t.mode(PullUp);
2018US_NedimSisic 0:78147151cc2c 354 t.rise(&klik);
2018US_NedimSisic 0:78147151cc2c 355
2018US_NedimSisic 0:78147151cc2c 356 // Stanja 1 do 4
2018US_NedimSisic 0:78147151cc2c 357 while(1) {
2018US_NedimSisic 0:78147151cc2c 358 // Crtanje pozadine
2018US_NedimSisic 0:78147151cc2c 359 TFT.fillrect(0, 0, xKraj, vrhZelenog - 1, NeboPlava);
2018US_NedimSisic 0:78147151cc2c 360 TFT.fillrect(0, vrhZelenog + 3, xKraj, dnoZelenog, TamnoZelena);
2018US_NedimSisic 0:78147151cc2c 361 TFT.fillrect(0, dnoZelenog + 1, xKraj, dnoZelenog + 2, 21508);
2018US_NedimSisic 0:78147151cc2c 362 TFT.fillrect(0, dnoZelenog + 3, xKraj, dnoZelenog + 4, 52552);
2018US_NedimSisic 0:78147151cc2c 363 // TODO: dodati linije, to su one dolje, modifikovati
2018US_NedimSisic 0:78147151cc2c 364 TFT.fillrect(0, dnoZelenog + 5, xKraj, yKraj, Zemlja);
2018US_NedimSisic 0:78147151cc2c 365
2018US_NedimSisic 0:78147151cc2c 366 TFT.background(54961);
2018US_NedimSisic 0:78147151cc2c 367 TFT.foreground(Black);
2018US_NedimSisic 0:78147151cc2c 368 stanje = 1;
2018US_NedimSisic 0:78147151cc2c 369 prvoStanje();
2018US_NedimSisic 0:78147151cc2c 370
2018US_NedimSisic 0:78147151cc2c 371 // nakon klika
2018US_NedimSisic 0:78147151cc2c 372 stanje = 2;
2018US_NedimSisic 0:78147151cc2c 373 drugoStanje(); // traje 2s ili do sudara sa tlom
2018US_NedimSisic 0:78147151cc2c 374
2018US_NedimSisic 0:78147151cc2c 375
2018US_NedimSisic 0:78147151cc2c 376 stanje = 3; // igranje sa preprekama
2018US_NedimSisic 0:78147151cc2c 377 for (int i = 0; i < 3; i++) {
2018US_NedimSisic 0:78147151cc2c 378 stuboviXevi[i] = 320;
2018US_NedimSisic 0:78147151cc2c 379 stuboviY[i] = rand()%70 + 100;
2018US_NedimSisic 0:78147151cc2c 380 }
2018US_NedimSisic 0:78147151cc2c 381 frame = 0.015;
2018US_NedimSisic 0:78147151cc2c 382
2018US_NedimSisic 0:78147151cc2c 383 while (!kolizija)
2018US_NedimSisic 0:78147151cc2c 384 {
2018US_NedimSisic 0:78147151cc2c 385 crtajPticu();
2018US_NedimSisic 0:78147151cc2c 386 crtajStubove();
2018US_NedimSisic 0:78147151cc2c 387 crtajZelene();
2018US_NedimSisic 0:78147151cc2c 388 updatePticaZel();
2018US_NedimSisic 0:78147151cc2c 389 updateStubovi();
2018US_NedimSisic 0:78147151cc2c 390 wait(0.025);
2018US_NedimSisic 0:78147151cc2c 391 }
2018US_NedimSisic 0:78147151cc2c 392
2018US_NedimSisic 0:78147151cc2c 393 // doslo do kolizije
2018US_NedimSisic 0:78147151cc2c 394 wait(1);
2018US_NedimSisic 0:78147151cc2c 395 stanje = 4;
2018US_NedimSisic 0:78147151cc2c 396 cetvrtoStanje();
2018US_NedimSisic 0:78147151cc2c 397 wait(4);
2018US_NedimSisic 0:78147151cc2c 398 }
2018US_NedimSisic 0:78147151cc2c 399 }