Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:a5f6ba8c378e, 2014-06-05 (annotated)
- Committer:
- Vato
- Date:
- Thu Jun 05 17:37:09 2014 +0000
- Revision:
- 0:a5f6ba8c378e
PAI Pong v1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vato | 0:a5f6ba8c378e | 1 | #include "mbed.h" |
Vato | 0:a5f6ba8c378e | 2 | #include "N5110.h" |
Vato | 0:a5f6ba8c378e | 3 | #include "Reket.h" |
Vato | 0:a5f6ba8c378e | 4 | #include "Loptica.h" |
Vato | 0:a5f6ba8c378e | 5 | |
Vato | 0:a5f6ba8c378e | 6 | Reket rLijevi (2, 3, 21, 28); |
Vato | 0:a5f6ba8c378e | 7 | Reket rDesni (80, 81, 21, 28); |
Vato | 0:a5f6ba8c378e | 8 | Loptica loptica (41, 12, 2, 1); |
Vato | 0:a5f6ba8c378e | 9 | |
Vato | 0:a5f6ba8c378e | 10 | int p1_skor = 0; |
Vato | 0:a5f6ba8c378e | 11 | int p2_skor = 0; |
Vato | 0:a5f6ba8c378e | 12 | |
Vato | 0:a5f6ba8c378e | 13 | int zaustaviX, zaustaviY; |
Vato | 0:a5f6ba8c378e | 14 | |
Vato | 0:a5f6ba8c378e | 15 | N5110 display(dp4,dp24,dp23,dp25,dp2,dp6,dp18); |
Vato | 0:a5f6ba8c378e | 16 | DigitalOut enable (dp14); |
Vato | 0:a5f6ba8c378e | 17 | |
Vato | 0:a5f6ba8c378e | 18 | AnalogIn P1(dp9); |
Vato | 0:a5f6ba8c378e | 19 | AnalogIn P2(dp10); |
Vato | 0:a5f6ba8c378e | 20 | |
Vato | 0:a5f6ba8c378e | 21 | InterruptIn taster(dp1); |
Vato | 0:a5f6ba8c378e | 22 | Ticker t; |
Vato | 0:a5f6ba8c378e | 23 | Timer dbnc; |
Vato | 0:a5f6ba8c378e | 24 | Timer dvostruki; |
Vato | 0:a5f6ba8c378e | 25 | |
Vato | 0:a5f6ba8c378e | 26 | bool pauza = true; |
Vato | 0:a5f6ba8c378e | 27 | bool poen = false; |
Vato | 0:a5f6ba8c378e | 28 | bool reset = false; |
Vato | 0:a5f6ba8c378e | 29 | |
Vato | 0:a5f6ba8c378e | 30 | void Lcifre(int cifra) |
Vato | 0:a5f6ba8c378e | 31 | { |
Vato | 0:a5f6ba8c378e | 32 | if(cifra == 0) |
Vato | 0:a5f6ba8c378e | 33 | { |
Vato | 0:a5f6ba8c378e | 34 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 35 | display.setPixel(31 + i, 1); |
Vato | 0:a5f6ba8c378e | 36 | for(int i = 0; i < 5; i++) |
Vato | 0:a5f6ba8c378e | 37 | display.setPixel(34, 1 + i); |
Vato | 0:a5f6ba8c378e | 38 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 39 | display.setPixel(31 + i, 5); |
Vato | 0:a5f6ba8c378e | 40 | for(int i = 0; i < 5; i++) |
Vato | 0:a5f6ba8c378e | 41 | display.setPixel(31, 1 + i); |
Vato | 0:a5f6ba8c378e | 42 | } |
Vato | 0:a5f6ba8c378e | 43 | else if(cifra == 1) |
Vato | 0:a5f6ba8c378e | 44 | { |
Vato | 0:a5f6ba8c378e | 45 | for(int i = 0; i < 5; i++) |
Vato | 0:a5f6ba8c378e | 46 | display.setPixel(34, 1 + i); |
Vato | 0:a5f6ba8c378e | 47 | } |
Vato | 0:a5f6ba8c378e | 48 | else if(cifra == 2) |
Vato | 0:a5f6ba8c378e | 49 | { |
Vato | 0:a5f6ba8c378e | 50 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 51 | display.setPixel(31 + i, 1); |
Vato | 0:a5f6ba8c378e | 52 | for(int i = 0; i < 3; i++) |
Vato | 0:a5f6ba8c378e | 53 | display.setPixel(34, 1 + i); |
Vato | 0:a5f6ba8c378e | 54 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 55 | display.setPixel(31 + i, 3); |
Vato | 0:a5f6ba8c378e | 56 | for(int i = 0; i < 3; i++) |
Vato | 0:a5f6ba8c378e | 57 | display.setPixel(31, 3 + i); |
Vato | 0:a5f6ba8c378e | 58 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 59 | display.setPixel(31 + i, 5); |
Vato | 0:a5f6ba8c378e | 60 | } |
Vato | 0:a5f6ba8c378e | 61 | else if(cifra == 3) |
Vato | 0:a5f6ba8c378e | 62 | { |
Vato | 0:a5f6ba8c378e | 63 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 64 | display.setPixel(31 + i, 1); |
Vato | 0:a5f6ba8c378e | 65 | for(int i = 0; i < 5; i++) |
Vato | 0:a5f6ba8c378e | 66 | display.setPixel(34, 1 + i); |
Vato | 0:a5f6ba8c378e | 67 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 68 | display.setPixel(31 + i, 3); |
Vato | 0:a5f6ba8c378e | 69 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 70 | display.setPixel(31 + i, 5); |
Vato | 0:a5f6ba8c378e | 71 | } |
Vato | 0:a5f6ba8c378e | 72 | else if(cifra == 4) |
Vato | 0:a5f6ba8c378e | 73 | { |
Vato | 0:a5f6ba8c378e | 74 | for(int i = 0; i < 3; i++) |
Vato | 0:a5f6ba8c378e | 75 | display.setPixel(31, 1 + i); |
Vato | 0:a5f6ba8c378e | 76 | for(int i = 0; i < 5; i++) |
Vato | 0:a5f6ba8c378e | 77 | display.setPixel(34, 1 + i); |
Vato | 0:a5f6ba8c378e | 78 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 79 | display.setPixel(31 + i, 3); |
Vato | 0:a5f6ba8c378e | 80 | } |
Vato | 0:a5f6ba8c378e | 81 | else if(cifra == 5) |
Vato | 0:a5f6ba8c378e | 82 | { |
Vato | 0:a5f6ba8c378e | 83 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 84 | display.setPixel(31 + i, 1); |
Vato | 0:a5f6ba8c378e | 85 | for(int i = 0; i < 3; i++) |
Vato | 0:a5f6ba8c378e | 86 | display.setPixel(31, i + 1); |
Vato | 0:a5f6ba8c378e | 87 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 88 | display.setPixel(31 + i, 3); |
Vato | 0:a5f6ba8c378e | 89 | for(int i = 0; i < 3; i++) |
Vato | 0:a5f6ba8c378e | 90 | display.setPixel(34, i + 3); |
Vato | 0:a5f6ba8c378e | 91 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 92 | display.setPixel(31 + i, 5); |
Vato | 0:a5f6ba8c378e | 93 | } |
Vato | 0:a5f6ba8c378e | 94 | display.refresh(); |
Vato | 0:a5f6ba8c378e | 95 | } |
Vato | 0:a5f6ba8c378e | 96 | |
Vato | 0:a5f6ba8c378e | 97 | void Rcifre(int cifra) |
Vato | 0:a5f6ba8c378e | 98 | { |
Vato | 0:a5f6ba8c378e | 99 | if(cifra == 0) |
Vato | 0:a5f6ba8c378e | 100 | { |
Vato | 0:a5f6ba8c378e | 101 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 102 | display.setPixel(48 + i, 1); |
Vato | 0:a5f6ba8c378e | 103 | for(int i = 0; i < 5; i++) |
Vato | 0:a5f6ba8c378e | 104 | display.setPixel(48, 1 + i); |
Vato | 0:a5f6ba8c378e | 105 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 106 | display.setPixel(48 + i, 5); |
Vato | 0:a5f6ba8c378e | 107 | for(int i = 0; i < 5; i++) |
Vato | 0:a5f6ba8c378e | 108 | display.setPixel(51, 1 + i); |
Vato | 0:a5f6ba8c378e | 109 | } |
Vato | 0:a5f6ba8c378e | 110 | else if(cifra == 1) |
Vato | 0:a5f6ba8c378e | 111 | { |
Vato | 0:a5f6ba8c378e | 112 | for(int i = 0; i < 5; i++) |
Vato | 0:a5f6ba8c378e | 113 | display.setPixel(48, 1 + i); |
Vato | 0:a5f6ba8c378e | 114 | } |
Vato | 0:a5f6ba8c378e | 115 | else if(cifra == 2) |
Vato | 0:a5f6ba8c378e | 116 | { |
Vato | 0:a5f6ba8c378e | 117 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 118 | display.setPixel(48 + i, 1); |
Vato | 0:a5f6ba8c378e | 119 | for(int i = 0; i < 3; i++) |
Vato | 0:a5f6ba8c378e | 120 | display.setPixel(51, 1 + i); |
Vato | 0:a5f6ba8c378e | 121 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 122 | display.setPixel(48 + i, 3); |
Vato | 0:a5f6ba8c378e | 123 | for(int i = 0; i < 3; i++) |
Vato | 0:a5f6ba8c378e | 124 | display.setPixel(48, 3 + i); |
Vato | 0:a5f6ba8c378e | 125 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 126 | display.setPixel(48 + i, 5); |
Vato | 0:a5f6ba8c378e | 127 | } |
Vato | 0:a5f6ba8c378e | 128 | else if(cifra == 3) |
Vato | 0:a5f6ba8c378e | 129 | { |
Vato | 0:a5f6ba8c378e | 130 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 131 | display.setPixel(48 + i, 1); |
Vato | 0:a5f6ba8c378e | 132 | for(int i = 0; i < 5; i++) |
Vato | 0:a5f6ba8c378e | 133 | display.setPixel(51, 1 + i); |
Vato | 0:a5f6ba8c378e | 134 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 135 | display.setPixel(48 + i, 3); |
Vato | 0:a5f6ba8c378e | 136 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 137 | display.setPixel(48 + i, 5); |
Vato | 0:a5f6ba8c378e | 138 | } |
Vato | 0:a5f6ba8c378e | 139 | else if(cifra == 4) |
Vato | 0:a5f6ba8c378e | 140 | { |
Vato | 0:a5f6ba8c378e | 141 | for(int i = 0; i < 3; i++) |
Vato | 0:a5f6ba8c378e | 142 | display.setPixel(48, 1 + i); |
Vato | 0:a5f6ba8c378e | 143 | for(int i = 0; i < 5; i++) |
Vato | 0:a5f6ba8c378e | 144 | display.setPixel(51, 1 + i); |
Vato | 0:a5f6ba8c378e | 145 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 146 | display.setPixel(48 + i, 3); |
Vato | 0:a5f6ba8c378e | 147 | } |
Vato | 0:a5f6ba8c378e | 148 | else if(cifra == 5) |
Vato | 0:a5f6ba8c378e | 149 | { |
Vato | 0:a5f6ba8c378e | 150 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 151 | display.setPixel(48 + i, 1); |
Vato | 0:a5f6ba8c378e | 152 | for(int i = 0; i < 3; i++) |
Vato | 0:a5f6ba8c378e | 153 | display.setPixel(48, i + 1); |
Vato | 0:a5f6ba8c378e | 154 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 155 | display.setPixel(48 + i, 3); |
Vato | 0:a5f6ba8c378e | 156 | for(int i = 0; i < 3; i++) |
Vato | 0:a5f6ba8c378e | 157 | display.setPixel(51, i + 3); |
Vato | 0:a5f6ba8c378e | 158 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 159 | display.setPixel(48 + i, 5); |
Vato | 0:a5f6ba8c378e | 160 | } |
Vato | 0:a5f6ba8c378e | 161 | display.refresh(); |
Vato | 0:a5f6ba8c378e | 162 | } |
Vato | 0:a5f6ba8c378e | 163 | |
Vato | 0:a5f6ba8c378e | 164 | void Lbrisi() |
Vato | 0:a5f6ba8c378e | 165 | { |
Vato | 0:a5f6ba8c378e | 166 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 167 | display.clearPixel(31 + i, 1); |
Vato | 0:a5f6ba8c378e | 168 | for(int i = 0; i < 5; i++) |
Vato | 0:a5f6ba8c378e | 169 | display.clearPixel(34, 1 + i); |
Vato | 0:a5f6ba8c378e | 170 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 171 | display.clearPixel(31 + i, 3); |
Vato | 0:a5f6ba8c378e | 172 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 173 | display.clearPixel(31 + i, 5); |
Vato | 0:a5f6ba8c378e | 174 | for(int i = 0; i < 5; i++) |
Vato | 0:a5f6ba8c378e | 175 | display.clearPixel(31, 1 + i); |
Vato | 0:a5f6ba8c378e | 176 | display.refresh(); |
Vato | 0:a5f6ba8c378e | 177 | } |
Vato | 0:a5f6ba8c378e | 178 | |
Vato | 0:a5f6ba8c378e | 179 | void Rbrisi() |
Vato | 0:a5f6ba8c378e | 180 | { |
Vato | 0:a5f6ba8c378e | 181 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 182 | display.clearPixel(48 + i, 1); |
Vato | 0:a5f6ba8c378e | 183 | for(int i = 0; i < 5; i++) |
Vato | 0:a5f6ba8c378e | 184 | display.clearPixel(51, 1 + i); |
Vato | 0:a5f6ba8c378e | 185 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 186 | display.clearPixel(48 + i, 3); |
Vato | 0:a5f6ba8c378e | 187 | for(int i = 0; i < 4; i++) |
Vato | 0:a5f6ba8c378e | 188 | display.clearPixel(48 + i, 5); |
Vato | 0:a5f6ba8c378e | 189 | for(int i = 0; i < 5; i++) |
Vato | 0:a5f6ba8c378e | 190 | display.clearPixel(48, 1 + i); |
Vato | 0:a5f6ba8c378e | 191 | display.refresh(); |
Vato | 0:a5f6ba8c378e | 192 | } |
Vato | 0:a5f6ba8c378e | 193 | |
Vato | 0:a5f6ba8c378e | 194 | void igraj() |
Vato | 0:a5f6ba8c378e | 195 | { |
Vato | 0:a5f6ba8c378e | 196 | if(poen) return; |
Vato | 0:a5f6ba8c378e | 197 | |
Vato | 0:a5f6ba8c378e | 198 | for(int i = 0; i < 47; i++) |
Vato | 0:a5f6ba8c378e | 199 | display.setPixel(41, i); |
Vato | 0:a5f6ba8c378e | 200 | display.refresh(); |
Vato | 0:a5f6ba8c378e | 201 | |
Vato | 0:a5f6ba8c378e | 202 | rLijevi.brisiReket(display); |
Vato | 0:a5f6ba8c378e | 203 | if(!pauza) |
Vato | 0:a5f6ba8c378e | 204 | rLijevi.osvjeziPoziciju(P1); |
Vato | 0:a5f6ba8c378e | 205 | rLijevi.crtajReket(display); |
Vato | 0:a5f6ba8c378e | 206 | |
Vato | 0:a5f6ba8c378e | 207 | rDesni.brisiReket(display); |
Vato | 0:a5f6ba8c378e | 208 | if(!pauza) |
Vato | 0:a5f6ba8c378e | 209 | rDesni.osvjeziPoziciju(P2); |
Vato | 0:a5f6ba8c378e | 210 | rDesni.crtajReket(display); |
Vato | 0:a5f6ba8c378e | 211 | |
Vato | 0:a5f6ba8c378e | 212 | loptica.brisiLopticu(display); |
Vato | 0:a5f6ba8c378e | 213 | if(!pauza) |
Vato | 0:a5f6ba8c378e | 214 | loptica.osvjeziPoziciju(); |
Vato | 0:a5f6ba8c378e | 215 | loptica.crtajLopticu(display); |
Vato | 0:a5f6ba8c378e | 216 | |
Vato | 0:a5f6ba8c378e | 217 | if(loptica.dajX() <= 5) |
Vato | 0:a5f6ba8c378e | 218 | { |
Vato | 0:a5f6ba8c378e | 219 | if(loptica.dajY() == rLijevi.dajY1() or loptica.dajY() == rLijevi.dajY1() + 1) |
Vato | 0:a5f6ba8c378e | 220 | loptica.postaviKorak(2, -2); |
Vato | 0:a5f6ba8c378e | 221 | else if (loptica.dajY() == rLijevi.dajY1() + 2 or loptica.dajY() == rLijevi.dajY1() + 3) |
Vato | 0:a5f6ba8c378e | 222 | loptica.postaviKorak(2, -1); |
Vato | 0:a5f6ba8c378e | 223 | else if (loptica.dajY() == rLijevi.dajY1() + 4) |
Vato | 0:a5f6ba8c378e | 224 | loptica.postaviKorak(2, 0); |
Vato | 0:a5f6ba8c378e | 225 | else if (loptica.dajY() == rLijevi.dajY1() + 5 or loptica.dajY() == rLijevi.dajY1() + 6) |
Vato | 0:a5f6ba8c378e | 226 | loptica.postaviKorak(2, 1); |
Vato | 0:a5f6ba8c378e | 227 | else if (loptica.dajY() == rLijevi.dajY1() + 7 or loptica.dajY() == rLijevi.dajY1() + 8) |
Vato | 0:a5f6ba8c378e | 228 | loptica.postaviKorak(2, 2); |
Vato | 0:a5f6ba8c378e | 229 | } |
Vato | 0:a5f6ba8c378e | 230 | |
Vato | 0:a5f6ba8c378e | 231 | if(loptica.dajX() >= 0 and loptica.dajX() < 2) |
Vato | 0:a5f6ba8c378e | 232 | { |
Vato | 0:a5f6ba8c378e | 233 | if((loptica.dajY() < rLijevi.dajY1() - 1) or (loptica.dajY() > rLijevi.dajY2() + 1)) |
Vato | 0:a5f6ba8c378e | 234 | { |
Vato | 0:a5f6ba8c378e | 235 | p2_skor++; |
Vato | 0:a5f6ba8c378e | 236 | loptica.brisiLopticu(display); |
Vato | 0:a5f6ba8c378e | 237 | loptica.setX(41); |
Vato | 0:a5f6ba8c378e | 238 | loptica.setY(12); |
Vato | 0:a5f6ba8c378e | 239 | loptica.postaviKorak(2, 1); |
Vato | 0:a5f6ba8c378e | 240 | if(p2_skor == 5) |
Vato | 0:a5f6ba8c378e | 241 | poen = true; |
Vato | 0:a5f6ba8c378e | 242 | else return; |
Vato | 0:a5f6ba8c378e | 243 | } |
Vato | 0:a5f6ba8c378e | 244 | } |
Vato | 0:a5f6ba8c378e | 245 | |
Vato | 0:a5f6ba8c378e | 246 | if(loptica.dajX() >= 78) |
Vato | 0:a5f6ba8c378e | 247 | { |
Vato | 0:a5f6ba8c378e | 248 | if(loptica.dajY() == rDesni.dajY1() or loptica.dajY() == rDesni.dajY1() + 1) |
Vato | 0:a5f6ba8c378e | 249 | loptica.postaviKorak(-2, -2); |
Vato | 0:a5f6ba8c378e | 250 | else if(loptica.dajY() == rDesni.dajY1() + 2 or loptica.dajY() == rDesni.dajY1() + 3) |
Vato | 0:a5f6ba8c378e | 251 | loptica.postaviKorak(-2, -1); |
Vato | 0:a5f6ba8c378e | 252 | else if(loptica.dajY() == rDesni.dajY1() + 4) |
Vato | 0:a5f6ba8c378e | 253 | loptica.postaviKorak(-2, 0); |
Vato | 0:a5f6ba8c378e | 254 | else if(loptica.dajY() == rDesni.dajY1() + 5 or loptica.dajY() == rDesni.dajY1() + 6) |
Vato | 0:a5f6ba8c378e | 255 | loptica.postaviKorak(-2, 1); |
Vato | 0:a5f6ba8c378e | 256 | else if(loptica.dajY() == rDesni.dajY1() + 7 or loptica.dajY() == rDesni.dajY1() + 8) |
Vato | 0:a5f6ba8c378e | 257 | loptica.postaviKorak(-2, 2); |
Vato | 0:a5f6ba8c378e | 258 | } |
Vato | 0:a5f6ba8c378e | 259 | |
Vato | 0:a5f6ba8c378e | 260 | if(loptica.dajX() >= 81 and loptica.dajX() <= 83) |
Vato | 0:a5f6ba8c378e | 261 | { |
Vato | 0:a5f6ba8c378e | 262 | if((loptica.dajY() < rDesni.dajY1() - 1) or (loptica.dajY() > rDesni.dajY2() + 1)) |
Vato | 0:a5f6ba8c378e | 263 | { |
Vato | 0:a5f6ba8c378e | 264 | p1_skor++; |
Vato | 0:a5f6ba8c378e | 265 | loptica.brisiLopticu(display); |
Vato | 0:a5f6ba8c378e | 266 | loptica.setX(41); |
Vato | 0:a5f6ba8c378e | 267 | loptica.setY(12); |
Vato | 0:a5f6ba8c378e | 268 | loptica.postaviKorak(-2, 1); |
Vato | 0:a5f6ba8c378e | 269 | if(p1_skor == 5) |
Vato | 0:a5f6ba8c378e | 270 | poen = true; |
Vato | 0:a5f6ba8c378e | 271 | else return; |
Vato | 0:a5f6ba8c378e | 272 | } |
Vato | 0:a5f6ba8c378e | 273 | } |
Vato | 0:a5f6ba8c378e | 274 | |
Vato | 0:a5f6ba8c378e | 275 | if(loptica.dajY() <= 1 or loptica.dajY() >= 46) |
Vato | 0:a5f6ba8c378e | 276 | loptica.postaviKorak(loptica.dajKorakX(), loptica.dajKorakY() * (-1)); |
Vato | 0:a5f6ba8c378e | 277 | |
Vato | 0:a5f6ba8c378e | 278 | Lbrisi(); |
Vato | 0:a5f6ba8c378e | 279 | Rbrisi(); |
Vato | 0:a5f6ba8c378e | 280 | Lcifre(p1_skor); |
Vato | 0:a5f6ba8c378e | 281 | Rcifre(p2_skor); |
Vato | 0:a5f6ba8c378e | 282 | |
Vato | 0:a5f6ba8c378e | 283 | if(poen) |
Vato | 0:a5f6ba8c378e | 284 | { |
Vato | 0:a5f6ba8c378e | 285 | loptica.setX(41); |
Vato | 0:a5f6ba8c378e | 286 | loptica.setY(12); |
Vato | 0:a5f6ba8c378e | 287 | loptica.postaviKorak(0, 0); |
Vato | 0:a5f6ba8c378e | 288 | if(p1_skor == 5) display.printString("P1WINS", 2, 2); |
Vato | 0:a5f6ba8c378e | 289 | if(p2_skor == 5) display.printString("P2 WINS", 43, 2); |
Vato | 0:a5f6ba8c378e | 290 | } |
Vato | 0:a5f6ba8c378e | 291 | |
Vato | 0:a5f6ba8c378e | 292 | if(reset) |
Vato | 0:a5f6ba8c378e | 293 | { |
Vato | 0:a5f6ba8c378e | 294 | loptica.setX(41); |
Vato | 0:a5f6ba8c378e | 295 | loptica.setY(12); |
Vato | 0:a5f6ba8c378e | 296 | loptica.postaviKorak(-2, 1); |
Vato | 0:a5f6ba8c378e | 297 | display.clear(); |
Vato | 0:a5f6ba8c378e | 298 | reset = false; |
Vato | 0:a5f6ba8c378e | 299 | poen = false; |
Vato | 0:a5f6ba8c378e | 300 | p1_skor = 0; |
Vato | 0:a5f6ba8c378e | 301 | p2_skor = 0; |
Vato | 0:a5f6ba8c378e | 302 | } |
Vato | 0:a5f6ba8c378e | 303 | } |
Vato | 0:a5f6ba8c378e | 304 | |
Vato | 0:a5f6ba8c378e | 305 | void pauzaStartRestart() |
Vato | 0:a5f6ba8c378e | 306 | { |
Vato | 0:a5f6ba8c378e | 307 | if(dbnc.read_ms() > 200 and dvostruki.read_ms() > 800) |
Vato | 0:a5f6ba8c378e | 308 | { |
Vato | 0:a5f6ba8c378e | 309 | dbnc.reset(); |
Vato | 0:a5f6ba8c378e | 310 | dvostruki.reset(); |
Vato | 0:a5f6ba8c378e | 311 | pauza = !pauza; |
Vato | 0:a5f6ba8c378e | 312 | } |
Vato | 0:a5f6ba8c378e | 313 | |
Vato | 0:a5f6ba8c378e | 314 | if(dvostruki.read_ms() < 800 and dbnc.read_ms() > 200) |
Vato | 0:a5f6ba8c378e | 315 | { |
Vato | 0:a5f6ba8c378e | 316 | reset = true; |
Vato | 0:a5f6ba8c378e | 317 | poen = false; |
Vato | 0:a5f6ba8c378e | 318 | dbnc.reset(); |
Vato | 0:a5f6ba8c378e | 319 | dvostruki.reset(); |
Vato | 0:a5f6ba8c378e | 320 | } |
Vato | 0:a5f6ba8c378e | 321 | } |
Vato | 0:a5f6ba8c378e | 322 | |
Vato | 0:a5f6ba8c378e | 323 | int main() { |
Vato | 0:a5f6ba8c378e | 324 | enable = 1; |
Vato | 0:a5f6ba8c378e | 325 | display.init(); |
Vato | 0:a5f6ba8c378e | 326 | display.setXYAddress(0, 0); |
Vato | 0:a5f6ba8c378e | 327 | taster.rise(&pauzaStartRestart); |
Vato | 0:a5f6ba8c378e | 328 | t.attach(&igraj, 0.08); |
Vato | 0:a5f6ba8c378e | 329 | dbnc.start(); |
Vato | 0:a5f6ba8c378e | 330 | dvostruki.start(); |
Vato | 0:a5f6ba8c378e | 331 | while(1) {} |
Vato | 0:a5f6ba8c378e | 332 | } |