ball dodger: first game

Advice on general approaches or feasibility and discussions about game design

Re: ball dodger: first game

Postby Sorunome » Sat Aug 08, 2015 12:39 pm

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.
User avatar
Sorunome
 
Posts: 629
Joined: Sun Mar 01, 2015 1:58 pm

Re: ball dodger: first game

Postby EatMyBlitch » Sat Aug 08, 2015 12:45 pm

thnxs :D
EatMyBlitch
 
Posts: 76
Joined: Tue Dec 23, 2014 4:29 pm
Location: Netherlands

Re: ball dodger: first game

Postby EatMyBlitch » Sat Aug 08, 2015 12:52 pm

:cry: i still dont understand it.
EatMyBlitch
 
Posts: 76
Joined: Tue Dec 23, 2014 4:29 pm
Location: Netherlands

Re: ball dodger: first game

Postby Skyrunner65 » Sat Aug 08, 2015 4:31 pm

I think I could help:
Code: Select all
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.
}


That's for borders.
User avatar
Skyrunner65
 
Posts: 371
Joined: Thu Mar 20, 2014 5:37 pm
Location: NC,USA

Re: ball dodger: first game

Postby EatMyBlitch » Sat Aug 08, 2015 6:03 pm

Thnxs :)
Skyrunner65 does the code go in void loop or void setup?
And do i just paste it in or do i have to adapt it to my code?
EatMyBlitch
 
Posts: 76
Joined: Tue Dec 23, 2014 4:29 pm
Location: Netherlands

Re: ball dodger: first game

Postby Skyrunner65 » Sat Aug 08, 2015 6:29 pm

You should make sure that the variables are how you want it.
Also, it needs to go into the Loop().
User avatar
Skyrunner65
 
Posts: 371
Joined: Thu Mar 20, 2014 5:37 pm
Location: NC,USA

Re: ball dodger: first game

Postby EatMyBlitch » Sat Aug 08, 2015 6:33 pm

Thanks again I will now try it out.
did you mean this:
Code: Select all
#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);
   
 
 }}
 

Please help!!!
EatMyBlitch
 
Posts: 76
Joined: Tue Dec 23, 2014 4:29 pm
Location: Netherlands

Re: ball dodger: first game

Postby EatMyBlitch » Sun Aug 09, 2015 6:38 pm

please give me help because im stuck :cry: :cry: :cry:
EatMyBlitch
 
Posts: 76
Joined: Tue Dec 23, 2014 4:29 pm
Location: Netherlands

Re: ball dodger: first game

Postby Summoner123 » Thu Aug 13, 2015 4:24 am

EatMyBlitch wrote:Please help!!!



I tried to compile you code, but in the collision test you still using a nonexistent bitmaps, look to this line:

Code: Select all
if(gb.collideBitmapBitmap(player_x, player_y, player, 0, 0, top) == true){ //if they try to go through the border...


"player" and "top" don't exist, if you want know if the ball touch the border, compare the position of the ball with the size of screen like the example.

Just excluding the lines 32 to 43 and changing the drawfillrect to drawfillcircle (it's not necessary, but ball's are not squared, write??..... :lol: ) you code work's very well...
I have add a simple collision example to your code (I spect you do not mind) and We have it:

Image

The code than I have added (just 3 lines comented):

Code: Select all
//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"));}
   
   



I hope this help you...
User avatar
Summoner123
 
Posts: 26
Joined: Fri Mar 20, 2015 12:35 am

Re: ball dodger: first game

Postby EatMyBlitch » Thu Aug 13, 2015 8:58 am

i knew the problem and i thought i understood it. But i had no idea how to fix it.
Thank you so much. :lol:
BTW: it shows an error when i replace gb.display.fillRect with gb.display.fillCircle. even though it changes colour.
and 1 more question how do i make a ball hollow?
and how do i make the spawn points reset.
EatMyBlitch
 
Posts: 76
Joined: Tue Dec 23, 2014 4:29 pm
Location: Netherlands

PreviousNext

Return to Project Guidance & Game development

Who is online

Users browsing this forum: No registered users and 23 guests