- Code: Select all
while(1){
if(gb.update()){
//your game here
}
}
See Reference : gb.update.
while(1){
if(gb.update()){
//your game here
}
}
void loop(){
while(gb.update()){
//code code code blah blah blah
}
gb.update();{
//title screen to be able to get back to the game list
gb.titleScreen(F("Work in progress"), logo);
}
}
gb.update();{
//title screen to be able to get back to the game list
gb.titleScreen(F("Work in progress"), logo);
}
void loop(){
while(1){
if (gb.update()) {
// Your game's first screen
// Code code code blah blah blah
if(gb.buttons.pressed(BTN_C)){
break; //break out of the while loop when C is pressed
}
}
}
// Back to title screen
gb.titleScreen(F("Work in progress"), logo);
}
//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;
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;
int score = 0; //$ value
int timer = 0;
int item1_quantity = 0; //the number of item1s collected
int item2_quantity = 0; //the number of item2s collected
static unsigned char PROGMEM logo[]=
{
46,10,
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,
B01111110, B01111000, B11111001, B11100110, B01100001, B10011000,
B01111110, B11111101, B11111011, B11110110, B01100001, B10011000,
B00011000, B11001101, B10000011, B00110111, B01100001, B10011000,
B00011000, B11111101, B11110011, B00110111, B11100001, B10011000,
B00011000, B11111100, B11111011, B00110111, B11100001, B11111000,
B11011000, B11001100, B00011011, B00110110, B11100001, B11111000,
B11111000, B11001101, B11111011, B11110110, B01101101, B10011000,
B11111000, B11001101, B11110001, B11100110, B01101101, B10011000,
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,
};
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,
};
// 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(){
while(1){
while(1){
if(gb.update()){
gb.battery.show = false;
//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();
}
gb.display.drawBitmap(item1_x,item1_y,item1);
gb.display.drawBitmap(item2_x,item2_y,item2);
//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.print("$ = "); gb.display.print(score); //problems with layers and "draw order"!! :P
// timer system
timer += 10;
if(timer >= 200);
break;
}
if(gb.buttons.pressed(BTN_C)){
break; //break out of the while loop when C is pressed
break; //2x for loop nesting
}
}
}
while(1){
if(gb.update());{
gb.display.println("Cherrys : "); gb.display.print(item1_quantity);
gb.display.println("Bombs : "); gb.display.println(item2_quantity);
gb.display.println("$ : "); gb.display.print(score);
if(gb.buttons.pressed(BTN_A)){
break;
break;
}
}
}
}
while(1){
gb.update();{
//title screen to be able to get back to the game list
gb.titleScreen(F("Work in progress"), logo);
if(gb.buttons.pressed(BTN_A)){
break;
}
}
}
}
if(gb.buttons.pressed(BTN_C)){
break; //break out of the while loop when C is pressed
break; //2x for loop nesting
}
if(timer >= 200);
break;
//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(){
while(1){
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 :(
}
}
while(1){
if(gb.update());{
//title screen to be able to get back to the game list
gb.titleScreen(F("Work in progress"), logo);
if(gb.buttons.pressed(BTN_A)){
break;
}
}
}
}
if(gb.update());{
if(gb.update()){
Return to Programming Questions
Users browsing this forum: No registered users and 3 guests