-
Notifications
You must be signed in to change notification settings - Fork 0
/
rmkebab.ino
325 lines (294 loc) · 10.7 KB
/
rmkebab.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#include <SPI.h>
#include <Gamebuino.h>
#include <EEPROM.h>
#define POS_X_BON 2
#define POS_Y_BON_0 2
#define POS_Y_BON_1 18
#define POS_Y_BON_2 34
#define POS_X_AMEL 70
#define POS_Y_AMEL 2
#define POS_X_ART 48
#define POS_Y_ART 16
#define LARG_BOITE 12
#define LARG_CURS LARG_BOITE + 2
#define PRIX_N0_BON_0 50
#define PRIX_N0_BON_1 200
#define PRIX_N0_BON_2 1000
#define PRIX_N0_AMEL 100000
#define PRIX_N1_BON_0 200
#define PRIX_N1_BON_1 700
#define PRIX_N1_BON_2 2000
#define PRIX_N1_AMEL 1000000
#define PRIX_N2_BON_0 2500
#define PRIX_N2_BON_1 4000
#define PRIX_N2_BON_2 10000
#define PRIX_N2_AMEL 50000000
#define PRIX_N3_BON_0 50000
#define PRIX_N3_BON_1 100000
#define PRIX_N3_BON_2 500000
#define PRIX_N3_AMEL 200000000
Gamebuino gb;
struct t_partie {
int bon_0 = 0, bon_1 = 0,
bon_2 = 0, niveau = 0, victoires = 0;
long argent = 100;
int premiere_partie = 0;
} partie;
int curs = 0;
const byte kebaberie[] PROGMEM = {32,32,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7F,0xFC,0x0,0x1,0x80,0x3,0x0,0x6,0x0,0x0,0xC0,0x8,0x56,0x9D,0x20,0x10,0x66,0x95,0x10,0x20,0x54,0xDD,0x88,0x40,0x56,0xD5,0x84,0x40,0x0,0x0,0x6,0x4F,0xFF,0xFF,0xE7,0x49,0x0,0x38,0x25,0x49,0x0,0x7C,0x25,0x4B,0x86,0x6C,0x25,0x4B,0x86,0x44,0x25,0x4B,0x9E,0x54,0x25,0x4B,0x9B,0x38,0x25,0x49,0x1B,0x12,0x25,0x4F,0xFF,0xFF,0xE5,0x40,0x0,0x0,0x5,0x40,0x0,0x0,0x5,0x40,0x0,0x0,0x5,0x50,0x0,0x80,0xE5,0x50,0x0,0x80,0x45,0x51,0xF0,0x80,0x45,0x50,0x40,0x80,0x45,0x5C,0x47,0x80,0x45,0x54,0x44,0x80,0x45,0x54,0x44,0x80,0xA5,};
const byte ambulant[] PROGMEM = {32,32,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xF,0xFF,0x80,0x0,0x1F,0xFF,0xC0,0xE0,0x3F,0xFF,0xE0,0xE0,0x1F,0xFF,0xC0,0xE0,0x8,0x3,0x81,0xF0,0x8,0x1,0x81,0xB0,0x1C,0x1,0x81,0x10,0x8,0x1,0x81,0x50,0x8,0x1,0x81,0xF0,0x8,0x0,0x80,0xB0,0x1C,0x0,0x80,0x90,0x1C,0x0,0x80,0x90,0x1C,0x6,0x80,0xB0,0x1C,0x6,0x80,0xB0,0x9,0xF,0x81,0xB0,0xB,0x4F,0x83,0xF0,0x1F,0xFF,0xFF,0xF0,0x10,0x0,0x4,0x90,0x15,0x69,0xD4,0xD0,0x16,0x69,0x54,0x50,0x15,0x4D,0xDC,0x50,0x15,0x6D,0x5C,0x50,0x30,0x0,0x6,0x70,0x4F,0xFF,0xFE,0x30,0x48,0x0,0x2,0xF0,0x30,0x0,0x2,0xF0,};
const byte broche[] PROGMEM = {16,12,0x40,0x40,0x64,0xC0,0x2E,0x0,0x1B,0x0,0x19,0x0,0x13,0x0,0x55,0x0,0x11,0x40,0x4E,0x0,0x14,0xC0,0x75,0xE0,0xFF,0xF0,};
const byte friteuse[] PROGMEM = {16,12,0x2,0x0,0x20,0x80,0x0,0x0,0xA6,0x0,0x34,0x0,0x3F,0xE0,0xBD,0x0,0xFF,0x0,0xBD,0x40,0x81,0x0,0x81,0x0,0x81,0x0,};
const byte kebabier[] PROGMEM = {16,12,0x1F,0x80,0x3F,0xC0,0x30,0xC0,0x29,0x40,0x20,0x40,0x22,0x40,0x27,0x40,0x10,0x80,0x3F,0xC0,0x41,0x20,0x44,0x20,0x40,0x20,};
const byte amelioration[] PROGMEM = {16,12,0x6,0x0,0xF,0x0,0x19,0x80,0x30,0xC0,0x60,0x60,0x70,0xE0,0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,0x1F,0x80,};
const byte kebabdo[] PROGMEM = {32,32,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3F,0xFF,0x80,0x0,0x20,0x0,0x8E,0x0,0x20,0x0,0x8E,0x70,0x27,0xFC,0x8A,0xD0,0x24,0x44,0x8B,0xB0,0x24,0x44,0x8B,0x60,0x24,0x44,0x88,0xC0,0x27,0xFC,0x89,0x80,0x24,0x44,0x8A,0xC0,0x24,0x44,0x8B,0x60,0x24,0x44,0x8B,0xB0,0x27,0xFC,0x8A,0xD0,0x20,0x0,0x8E,0x70,0x20,0x0,0xFF,0xFE,0x2A,0xD3,0xA2,0xA2,0x2C,0xD2,0xA2,0xA2,0x2A,0x9B,0xB0,0x2,0x2A,0xDA,0xB2,0xA2,0x20,0x0,0x0,0x2,0x23,0xFC,0x7F,0xF2,0x22,0x4,0x40,0x12,0x22,0x4,0x40,0x12,0x22,0x64,0x63,0x72,0x22,0x64,0x63,0x72,0x22,0x24,0x41,0x32,0x22,0xE4,0x4F,0x32,0x22,0x24,0x5D,0xB2,0x22,0x24,0x4B,0xB2,0x22,0x34,0x4B,0xB2,0x22,0x74,0x4B,0xB2,};
const byte masterofkebab[] PROGMEM = {32,32,0x6B,0xA0,0x0,0x0,0x1C,0x0,0x0,0x0,0x14,0x0,0x1,0xE0,0x14,0x7E,0x3,0xF8,0x14,0x42,0x2,0x18,0x14,0x56,0x2,0xB8,0x14,0x5A,0x2,0xD8,0x17,0xD7,0x82,0xB8,0x10,0x56,0x42,0xB8,0x16,0x42,0x22,0x18,0x16,0x7E,0x12,0x18,0x11,0xFF,0x8A,0x18,0x16,0x42,0x7,0xFC,0x16,0x56,0x0,0x4,0x10,0x42,0x1,0xC4,0x10,0x5A,0x8,0x4,0x10,0x42,0xF,0xC4,0x10,0x7E,0xF,0xE4,0x10,0x18,0x8A,0xB4,0x11,0xFF,0x88,0x1C,0x11,0x18,0xF,0xFC,0x10,0x18,0xC,0x1C,0x17,0xFF,0xFF,0xFC,0x3C,0x18,0x0,0x1E,0x1,0x3C,0x0,0x0,0x0,0x24,0x0,0x0,0x13,0xA4,0x3,0xE0,0x2,0xA4,0x4,0x10,0x5F,0xA4,0x27,0xF4,0x11,0xA4,0x3E,0x3E,0x1F,0xA4,0x41,0x41,0x3F,0xB6,0xFF,0x7F,};
const byte camion[] PROGMEM = {16,12,0x0,0x0,0x0,0x0,0x0,0x0,0x7F,0x80,0x54,0xF0,0x58,0xB0,0x54,0x90,0xFF,0xF0,0x30,0xC0,0x0,0x0,0x6D,0xB0,0x0,0x0,};
const byte pays[] PROGMEM = {16,12,0x2F,0xC0,0x2B,0x50,0x2B,0x50,0xAF,0xD0,0x68,0x20,0x3F,0xF0,0x19,0x80,0x28,0xC0,0x48,0x20,0x40,0xA0,0x31,0xE0,0x2F,0x80,};
const byte usine[] PROGMEM = {16,12,0xB5,0x0,0x20,0x0,0x60,0x0,0x60,0x0,0x7E,0x0,0xFF,0x80,0xE0,0xC0,0xEA,0xE0,0xE0,0xB0,0xEA,0x90,0xE0,0xD0,0xEA,0xD0,};
const unsigned int musique[] PROGMEM = {0x438,0x238,0x234,0x838,0x238,0x240,0x248,0x240,0x838,0x424,0x224,0x22C,0x234,0x22C,0x424,0x438,0x434,0x838,0x000};
void afficher();
void afficher_niveau();
void afficher_curseur();
void afficher_textes();
void jeu();
void gerer_actions();
bool acheter(int *bon, long prix);
void acheter_amel();
void gagner_argent();
long prix_bon_0();
long prix_bon_1();
long prix_bon_2();
long prix_amel();
void sauvegarder();
void restaurer();
void setup(){
restaurer();
if (!partie.premiere_partie)
{
partie.premiere_partie = 1111;
partie.argent = 100;
partie.victoires = 0;
partie.niveau = 0;
}
gb.begin();
gb.titleScreen(F("Master Kebab"));
}
void loop(){
if(gb.update()){
jeu();
}
}
void jeu(){
afficher();
gerer_actions();
gagner_argent();
}
void gagner_argent(){
if (gb.frameCount % 20 == 0)
{
partie.argent += (1 + partie.bon_2) *
(partie.bon_0 * prix_bon_0() / 5 +
partie.bon_1 * prix_bon_1() / 7) / 10;
}
}
void gerer_actions(){
if (gb.buttons.repeat(BTN_A,5))
{
if (curs == 0)
acheter(&(partie.bon_0),prix_bon_0());;
if (curs == 1)
acheter(&(partie.bon_1),prix_bon_1());
if (curs == 2)
acheter(&(partie.bon_2),prix_bon_2());
if (curs == 3)
acheter_amel();
}
if (gb.buttons.pressed(BTN_DOWN))
curs = min(3,curs + 1);
if (gb.buttons.pressed(BTN_UP))
curs = max(0,curs - 1);
if (gb.buttons.pressed(BTN_LEFT))
curs = max(0, curs - 3);
if (gb.buttons.pressed(BTN_RIGHT))
curs = min(3, curs + 3);
if (gb.buttons.pressed(BTN_C))
{
sauvegarder();
gb.titleScreen(F("Master Kebab"));
}
}
bool acheter(int *bon, long prix)
{
if (partie.argent >= prix)
{
partie.argent -= prix;
(*bon)++;
return true;
}
return false;
}
void acheter_amel()
{
if (acheter (&(partie.niveau), prix_amel()))
{
gb.sound.playPattern(musique, 1);
partie.bon_0 = 0;
partie.bon_1 = 0;
partie.bon_2 = 0;
partie.argent = prix_amel() / 1000;
}
//TODO pour eviter les bugs
if (partie.niveau > 3)
{
partie.argent = 100;
partie.victoires++;
partie.niveau = 0;
}
}
long prix_bon_0(){
long prix = 0;
if (partie.niveau == 0)
{ prix = PRIX_N0_BON_0; }
if (partie.niveau == 1)
{ prix = PRIX_N1_BON_0; }
if (partie.niveau == 2)
{ prix = PRIX_N2_BON_0; }
if (partie.niveau == 3)
{ prix = PRIX_N3_BON_0; }
prix = prix + partie.bon_0 * prix / 8;
return prix;
}
long prix_bon_1(){
long prix = 0;
if (partie.niveau == 0)
{ prix = PRIX_N0_BON_1; }
if (partie.niveau == 1)
{ prix = PRIX_N1_BON_1; }
if (partie.niveau == 2)
{ prix = PRIX_N2_BON_1; }
if (partie.niveau == 3)
{ prix = PRIX_N3_BON_1; }
prix = prix + partie.bon_1 * prix / 4;
return prix;
}
long prix_bon_2(){
long prix = 0;
if (partie.niveau == 0)
{ prix = PRIX_N0_BON_2; }
if (partie.niveau == 1)
{ prix = PRIX_N1_BON_2; }
if (partie.niveau == 2)
{ prix = PRIX_N2_BON_2; }
if (partie.niveau == 3)
{ prix = PRIX_N3_BON_2; }
prix = prix + partie.bon_2 * prix / 4;
return prix;
}
long prix_amel(){
long prix = 0;
if (partie.niveau == 0)
prix = PRIX_N0_AMEL;
if (partie.niveau == 1)
prix = PRIX_N1_AMEL;
if (partie.niveau == 2)
prix = PRIX_N2_AMEL;
if (partie.niveau == 3)
prix = PRIX_N3_AMEL;
prix = prix + ((prix / 10) * partie.victoires * partie.victoires);
return prix;
}
void afficher(){
afficher_niveau();
afficher_curseur();
afficher_textes();
}
void afficher_textes(){
// BONUS
gb.display.cursorX = POS_X_BON + LARG_CURS;
gb.display.cursorY = POS_Y_BON_0;
gb.display.print(prix_bon_0());
gb.display.println("$");
gb.display.println(partie.bon_0);
gb.display.cursorX = POS_X_BON + LARG_CURS;
gb.display.cursorY = POS_Y_BON_1;
gb.display.print(prix_bon_1());
gb.display.println("$");
gb.display.println(partie.bon_1);
gb.display.cursorX = POS_X_BON + LARG_CURS;
gb.display.cursorY = POS_Y_BON_2;
gb.display.print(prix_bon_2());
gb.display.println("$");
gb.display.println(partie.bon_2);
//AMEL
gb.display.cursorY = POS_Y_AMEL + LARG_CURS;
gb.display.cursorX = POS_X_AMEL - 32;
gb.display.print(prix_amel());
gb.display.println("$");
// SOUSOUS
gb.display.cursorX = POS_X_AMEL - 32;
gb.display.cursorY = 0;
gb.display.print("$:");
gb.display.println(partie.argent);
// Victoires
gb.display.cursorX = POS_X_AMEL - 32;
gb.display.cursorY = 8;
gb.display.print(":^) ");
gb.display.println(partie.victoires);
}
void afficher_curseur(){
int pos_x = 2, pos_y = 2;
if (curs <= 2)
pos_x = POS_X_BON;
else
pos_x = POS_X_AMEL;
switch (curs){
case 0: case 3:
pos_y = POS_Y_BON_0;
break;
case 1:
pos_y = POS_Y_BON_1;
break;
case 2:
pos_y = POS_Y_BON_2;
break;
}
gb.display.drawRect(pos_x, pos_y, LARG_CURS , LARG_CURS);
}
void afficher_niveau(){
if (partie.niveau == 0) {
gb.display.drawBitmap(POS_X_BON, POS_Y_BON_0, friteuse);
gb.display.drawBitmap(POS_X_BON, POS_Y_BON_1, broche);
gb.display.drawBitmap(POS_X_BON, POS_Y_BON_2, kebabier);
gb.display.drawBitmap(POS_X_ART, POS_Y_ART, ambulant);
}
if (partie.niveau == 1) {
gb.display.drawBitmap(POS_X_BON, POS_Y_BON_0, friteuse);
gb.display.drawBitmap(POS_X_BON, POS_Y_BON_1, broche);
gb.display.drawBitmap(POS_X_BON, POS_Y_BON_2, kebabier);
gb.display.drawBitmap(POS_X_ART, POS_Y_ART, kebaberie);
}
if (partie.niveau == 2) {
gb.display.drawBitmap(POS_X_BON, POS_Y_BON_0, friteuse);
gb.display.drawBitmap(POS_X_BON, POS_Y_BON_1, broche);
gb.display.drawBitmap(POS_X_BON, POS_Y_BON_2, kebabier);
gb.display.drawBitmap(POS_X_ART, POS_Y_ART, kebabdo);
}
if (partie.niveau == 3) {
gb.display.drawBitmap(POS_X_BON, POS_Y_BON_0, camion);
gb.display.drawBitmap(POS_X_BON, POS_Y_BON_1, usine);
gb.display.drawBitmap(POS_X_BON, POS_Y_BON_2, pays);
gb.display.drawBitmap(POS_X_ART, POS_Y_ART, masterofkebab);
}
gb.display.drawBitmap(POS_X_AMEL, POS_Y_AMEL, amelioration);
}
void sauvegarder(void)
{
for (unsigned i = 0; i<sizeof(partie); ++i)
EEPROM.write(i,((uint8_t*)&partie)[i]);
}
void restaurer(void)
{
for (unsigned i=0; i<sizeof(partie); ++i)
((uint8_t*)&partie)[i] = EEPROM.read(i);
}