- Code: Select all
float acc = 1;
void loop(){
acc = score / shots;
}
Is anything wrong with this? It displays as -0.00 or just 0.00. Here is my full code:
- Code: Select all
#include <Gamebuino.h>
#include <SPI.h>
Gamebuino gb;
byte PROGMEM doge[] =
{
16,16,
B00000011,B11000000,
B00000111,B11100000,
B00001111,B11110000,
B00011111,B11111000,
B00111111,B11111100,
B01110111,B11101110,
B01110111,B11101110,
B11110001,B10001111,
B11110001,B10001111,
B11111001,B10011111,
B01111000,B00011110,
B00000000,B00000000,
B00000000,B00001100,
B00011000,B00111110,
B00011100,B01111110,
B00001110,B01111100,
};
byte PROGMEM logo[] =
{
24,24,
B11111111,B11111111,B11111111,
B10000000,B00000000,B00000001,
B10000000,B00000000,B00110001,
B10000000,B00001000,B01110001,
B10000000,B00000100,B00100001,
B10000000,B00000000,B10000001,
B10000000,B00001100,B00000001,
B10000000,B00001010,B00000001,
B10000000,B00010001,B00100001,
B10000000,B00100010,B00010001,
B10000000,B01000100,B00000001,
B10000000,B10001000,B00000001,
B10000001,B00010000,B00000001,
B10000010,B00101000,B00000001,
B10001100,B01110000,B00000001,
B10000110,B11100000,B00000001,
B10000001,B11110000,B00000001,
B10000001,B11110000,B00000001,
B10000000,B11110000,B00000001,
B10000000,B11100000,B00000001,
B10000000,B00000000,B00000001,
B10000000,B00000000,B00000001,
B10000000,B00000000,B00000001,
B11111111,B11111111,B11111111,
};
byte PROGMEM bushes[] =
{
88,20,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00111111,B00000000,B00000000,B01111100,B00000000,B00000000,B11111110,B00000000,B00000000,B00000000,B11110000,
B01111111,B11111000,B00000011,B11111111,B00000000,B11111111,B11111111,B00011111,B11000000,B11111111,B11111111,
B11111111,B11111100,B00001111,B11111111,B11000111,B11111111,B11111111,B11111110,B10111111,B11111111,B11111111,
B11111111,B11111110,B00111111,B11111111,B11111111,B11111111,B11111111,B11111111,B01111111,B11111111,B11111111,
B11111111,B11111111,B01111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,
B11110111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,
B11100011,B11111111,B11111111,B11111111,B11111111,B11110111,B11111111,B11111111,B11111111,B11111111,B11111111,
B11110111,B11111111,B11111111,B11111111,B11111111,B11100011,B11111111,B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,B11111111,B11110111,B11111111,B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11110111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11100011,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11110111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,
};
byte PROGMEM player[] =
{
8,3,
B01000000,
B11100000,
B01000000,
};
float thing_x = LCDWIDTH/2;
float thing_y = LCDHEIGHT/2;
float thing_vx = 0;
float thing_vy = 0;
float thing_size = 7;
float acc = 1;
int score = 0;
int highscore = 0;
int scorefin = 0;
int time = 0;
int shots = 0;
void setup(){
gb.begin();
gb.titleScreen(F("Goomba Hunt"),logo);
gb.popup(F("Shotgun those goombas!"), 20);
}
int count = 0;
int dogepos = -10;
int dogey = -10;
void loop(){
if(gb.update()){
acc = score / shots;
gb.display.println(acc);
gb.display.drawBitmap(thing_x, thing_y, player);
gb.display.println(score);
gb.display.println();
gb.display.drawBitmap(0,28,bushes);
if (dogepos >=0) {
gb.display.drawBitmap(dogepos,20,doge);
}
if(thing_x < 0){
thing_vx = -thing_vx;
}
if(thing_x + thing_size > LCDWIDTH){
thing_vx = -thing_vx;
}
if(thing_y < 0){
thing_vy = -thing_vy;
}
if(thing_y + thing_size > LCDHEIGHT){
thing_vy = -thing_vy;
}
if(gb.buttons.repeat(BTN_UP,2)){
thing_vy = thing_vy - 1;
}
if(gb.buttons.repeat(BTN_DOWN,2)){
thing_vy = thing_vy + 1;
}
if(gb.buttons.repeat(BTN_RIGHT,2)){
thing_vx = thing_vx + 1;
}
if(gb.buttons.repeat(BTN_LEFT,2)){
thing_vx = thing_vx - 1;
}
if(gb.buttons.pressed(BTN_A)){
thing_y = thing_y - 10;
thing_vy = 2;
shots = shots + 1;
gb.sound.playTick();
}
if(gb.buttons.pressed(BTN_B)){
thing_vx = 0;
thing_vy = 0;
gb.popup(F("Velocities Reset"),50);
}
thing_x = thing_x + thing_vx;
thing_y = thing_y + thing_vy;
}
if (count++ % 5 == 0) {
thing_vx = thing_vx * 0.999;
thing_vy = thing_vy * 0.999;
}
if ((count % 20000 == 0)){
if ((random(0,1) < 0.05)) {
dogepos = random(0,76);
dogey = random(10,20);
}
else if (random(0,1) < 0.2) {
dogepos = -1;
dogey = -1;
}
}
if((gb.collideBitmapBitmap(thing_x,thing_y,player,dogepos,dogey,doge)&&(gb.buttons.pressed(BTN_A)))){
score = score + 1;
dogepos = -10;
dogey = -10;
gb.sound.playOK();
}
}