//imports the SPI library (needed to communicate with Gamebuino's screen)
#include <SPI.h>
//imports the Gamebuino library
#include <Gamebuino.h>
//creates a Gamebuino object named gb
Gamebuino gb;
static unsigned char PROGMEM logo[]=
{
38,12,
B00111100, B00110000, B11000011, B11000000, B111100,
B00111100, B00110000, B11000011, B11000000, B111100,
B11000011, B00110000, B11001100, B00110011, B000011,
B11000011, B00110000, B11001100, B00110011, B000011,
B11000011, B00110000, B11001100, B00000011, B000000,
B11000011, B00110000, B11001100, B00000011, B000000,
B11111100, B00110000, B11001100, B11000011, B001100,
B11111100, B00110000, B11001100, B11000011, B001100,
B11000011, B00110000, B11001100, B00110011, B000011,
B11000011, B00110000, B11001100, B00110011, B000011,
B00111100, B00001111, B00000011, B11000000, B111100,
B00111100, B00001111, B00000011, B11000000, B111100,
};
static unsigned char PROGMEM player[]=
{
8,8,
B00111100,
B01000010,
B10100101,
B10000001,
B10100101,
B10011001,
B01000010,
B00111100,
};
static unsigned char PROGMEM item2[]=
{
8,8,
B01111110,
B11000011,
B10100101,
B10011001,
B10011001,
B10100101,
B11000011,
B01111110,
};
static unsigned char PROGMEM item1[]=
{
6,6,
B011110,
B100001,
B101101,
B101101,
B100001,
B011110,
};
int score = 0; // score
int item1_quantity = 0;
int item2_quantity = 0;
int player_x = LCDWIDTH/2; //set the horizontal position to the middle of the screen
int player_y = LCDHEIGHT/2; //vertical position
int player_vx = 1; //horizontal velocity
int player_vy = 1; //vertical velocity
int player_size = 8; //the size of the player in number of pixels
int item1_size = 6; //the size of the ball in number of pixels
int item1_x = 30; //initial X position of item1
int item1_y = 10; //initial Y position of item1
int item2_size = 8;
int item2_x = 40;
int item2_y = 2;
// the setup routine runs once when Gamebuino starts up
void setup(){
// initialize the Gamebuino object
gb.begin();
//display the main menu:
gb.titleScreen(F("Work In Progress"), logo);
}
// the loop routine runs over and over again forever
void loop(){
if(gb.update()){
//item1 system
if(gb.collideBitmapBitmap( player_x, player_y, player, item1_x, item1_y, item1)){
item1_x = random(0, LCDWIDTH - item1_size);
item1_y = random(0, LCDHEIGHT - item1_size);
score += 1;
item1_quantity += 1;
gb.sound.playOK();
}
//item2 system
if(gb.collideBitmapBitmap( player_x, player_y, player, item2_x, item2_y, item2)){
item2_x = random(0, LCDWIDTH - item2_size);
item2_y = random(0, LCDHEIGHT - item2_size);
score -= 3;
item2_quantity += 1;
gb.sound.playCancel();
}
//move the player using the buttons
if(gb.buttons.repeat(BTN_RIGHT,2)){ //every 2 frames when the right button is held down
player_x = player_x + player_vx; //increase the horizontal position by the player's velocity
}
if(gb.buttons.repeat(BTN_LEFT,2)){
player_x = player_x - player_vx;
}
if(gb.buttons.repeat(BTN_DOWN,2)){
player_y = player_y + player_vy;
}
if(gb.buttons.repeat(BTN_UP,2)){
player_y = player_y - player_vy;
}
//bonus : play a preset sound when A and B are pressed
if(gb.buttons.pressed(BTN_A)){
gb.sound.playTick();
player_vx = 5;
player_vy = 5;
}
if(gb.buttons.pressed(BTN_B)){
gb.sound.playTick();
player_vx = 2;
player_vy = 2;
}
//check that the player is not going out of the screen
//if the player is touching the left side of the screen
if( player_x < 0){
//bring it back in the screen
player_x = 0;
}
//if the player is touching the right side
if(( player_x + player_size) > LCDWIDTH){
player_x = LCDWIDTH - player_size;
}
//if the player is touching the top side
if( player_y < 0){
player_y = 0;
}
//if the player is touching the down side
if(( player_y + player_size) > LCDHEIGHT){
player_y = LCDHEIGHT - player_size;
}
//draw the player on the screen
gb.display.drawBitmap(player_x, player_y, player);
gb.display.drawBitmap(item1_x,item1_y,item1);
gb.display.drawBitmap(item2_x,item2_y,item2);
gb.display.print("$"); gb.display.print(score);
// timer and endgame system removed for bug testing :(
}
}
Return to Programming Questions
Users browsing this forum: No registered users and 6 guests