Merge branch 'master' of https://github.com/thammi/r0ket into thammi-tron

This commit is contained in:
schneider 2012-01-19 01:17:15 +01:00
commit abca3eeb7e
1 changed files with 106 additions and 0 deletions

106
firmware/l0dable/tron.c Normal file
View File

@ -0,0 +1,106 @@
/*
* coded by Thammi from Pentagon Village
*/
#include <sysinit.h>
#include <stdio.h>
#include "basic/basic.h"
#include "basic/random.h"
#include "lcd/display.h"
#include "usetable.h"
void randomizeCoin(int* x, int* y);
void ram() {
int key;
int d = 0;
int x = RESX / 2;
int y = RESY / 2;
int p = 0;
int q, r;
randomizeCoin(&q, &r);
lcdClear();
while (1) {
// display
lcdSetPixel(q, r, p % 3);
lcdSetPixel(x, y, 1);
lcdDisplay();
// wait
delayms(20);
// input
key=getInputRaw();
switch(key) {
case BTN_RIGHT:
d = 3;
break;
case BTN_LEFT:
d = 2;
break;
case BTN_UP:
d = 0;
break;
case BTN_DOWN:
d = 1;
break;
case BTN_ENTER:
return;
}
// step
if(d > 1) {
x = (RESX + x + (d & 1) * 2 - 1) % RESX;
} else {
y = (RESY + y + d * 2 - 1) % RESY;
}
p += 1;
// collision
if(x == q && y == r) {
p += 99;
randomizeCoin(&q, &r);
} else if(lcdGetPixel(x, y)) {
lcdClear();
lcdPrint("You failed,");
lcdNl();
lcdPrint(nickname);
lcdPrint("!");
lcdNl();
lcdNl();
lcdPrintInt(p);
lcdPrintln(" points");
lcdDisplay();
while(getInputRaw() != BTN_ENTER);
return;
}
}
return;
}
void randomizeCoin(int* x, int* y) {
// WARNING: if you are really got at this the game freezes :D
for(;;) {
*x = getRandom() % RESX;
*y = getRandom() % RESY;
if(!lcdGetPixel(*x, *y)) {
return;
}
}
}