You could take a look at this example from the gamebuino library: https://github.com/Rodot/Gamebuino/blob ... player.ino
Basically you have to check if your balls entered the area of the player, one ball at a time.
if(gb.collideBitmapBitmap(playerx, playery, player, 0, 0, top) == true){ //if they try to go through the border...
playery = 2; // Collides, replace with thickness of border.
}
else if(gb.collideBitmapBitmap(playerx, playery, player, 0, 0, left) == true){
playerx = 2;
}
else if(gb.collideBitmapBitmap(playerx, playery, player, 82, 0, right) == true){
playerx = 2; //A bit tricky, basically, this should be 83 - thickness of border - thickness of player.
}
else if(gb.collideBitmapBitmap(playerx, playery, player, 0, 46, down) == true){
playerx = 2; //this should be 47 - height of border - height of player.
}
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
//declare all the variables needed for the game :
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 = 5; //horizontal velocity
int player_vy = 5; //vertical velocity
int player_size = 6; //the size of the ball in number of pixels
int ball_x = LCDWIDTH/5;
int ball_y = LCDHEIGHT/2;
int ball_vx = 4;
int ball_vy = 4;
int ball_size = 4;
void setup()
{
// put your setup code here, to run once:
gb.begin();
gb.titleScreen(F("unnamed"));
}
void loop()
{
// put your main code here, to run repeatedly:
if(gb.update()){
if(gb.collideBitmapBitmap(player_x, player_y, player, 0, 0, top) == true){ //if they try to go through the border...
player_y = 2; // Collides, replace with thickness of border.
}
else if(gb.collideBitmapBitmap(player_x, player_y, player, 0, 0, left) == true){
player_x = 2;
}
else if(gb.collideBitmapBitmap(player_x, player_y, player, 82, 0, right) == true){
player_x = 2; //A bit tricky, basically, this should be 83 - thickness of border - thickness of player.
}
else if(gb.collideBitmapBitmap(player_x, player_y, player, 0, 46, down) == true){
player_x = 2; //this should be 47 - height of border - height of player.
}
//move the ball 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 ball's velocity
gb.sound.playTick(); //play a preset "tick" sound every time the button is pressed
}
if(gb.buttons.repeat(BTN_LEFT,2)){
player_x = player_x - player_vx;
gb.sound.playTick();
}
if(gb.buttons.repeat(BTN_DOWN,2)){
player_y = player_y + player_vy;
gb.sound.playTick();
}
if(gb.buttons.repeat(BTN_UP,2)){
player_y = player_y - player_vy;
gb.sound.playTick();
}
//bonus : play a preset sound when A and B are pressed
if(gb.buttons.pressed(BTN_A)){
gb.sound.playOK();
}
if(gb.buttons.pressed(BTN_B)){
gb.sound.playCancel();
}
if(gb.buttons.pressed(BTN_C)){
gb.titleScreen(F("unnnamed"));
}
if(player_x < 0){
//bring it back in the screen
player_x = 0;
}
//if the ball is touching the right side
if((player_x + player_size) > LCDWIDTH){
player_x = LCDWIDTH - player_size;
}
//if the ball is touching the top side
if(player_y < 0){
player_y = 0;
}
//if the ball is touching the down side
if((player_y + player_size) > LCDHEIGHT){
player_y = LCDHEIGHT - player_size;
}
//draw the ball on the screen
gb.display.fillRect(player_x, player_y, player_size, player_size);
//the enemy ball starts here
//add the speed of the ball to its position
ball_x = ball_x + ball_vx;
ball_y = ball_y + ball_vy;
//check that the ball is not going out of the screen
//if the ball is touching the left side of the screen
if(ball_x < 0){
//change the direction of the horizontal speed
ball_vx = -ball_vx;
//play a preset "tick" sound when the ball hits the border
gb.sound.playTick();
}
//if the ball is touching the right side
if((ball_x + ball_size) > LCDWIDTH){
ball_vx = -ball_vx;
gb.sound.playTick();
}
//if the ball is touching the top side
if(ball_y < 0){
ball_vy = -ball_vy;
gb.sound.playTick();
}
//if the ball is touching the down side
if((ball_y + ball_size) > LCDHEIGHT){
ball_vy = -ball_vy;
gb.sound.playTick();
}
//draw the ball on the screen
gb.display.fillRect(ball_x, ball_y, ball_size, ball_size);
}}
EatMyBlitch wrote:Please help!!!
if(gb.collideBitmapBitmap(player_x, player_y, player, 0, 0, top) == true){ //if they try to go through the border...
//Check if one ball touched the other
if(gb.collideRectRect(player_x, player_y, player_size, player_size, ball_x, ball_y, ball_size, ball_size))
//If touched, send a message with 40 frames of duration (20 frames = 1 Second so 40 frames = 2 second)
{ gb.popup(F("you Lose!"),40);
//Go to the title Screen
gb.titleScreen(F("unnamed"));}
Return to Project Guidance & Game development
Users browsing this forum: No registered users and 7 guests