ball dodger: first game

Advice on general approaches or feasibility and discussions about game design

Re: ball dodger: first game

Postby EatMyBlitch » Sat Apr 30, 2016 6:43 pm

Yeah i though so...
Anyways i changed a bit of the idea of the game so now the speed of the killer ball slowly increases as you gather points.
I think i know how to do that so bye im gonna try it now!
EatMyBlitch
 
Posts: 76
Joined: Tue Dec 23, 2014 4:29 pm
Location: Netherlands

Re: ball dodger: first game

Postby EatMyBlitch » Sun May 01, 2016 11:15 am

im trying to make the speed and size of the killer ball change depending on how many points you have. But the code does not work and every time i get 10, 30, 50, 70, 90 the ball flies across the screen and then dissapears. I know whats wrong but i dont know how to fix it. I think that at the scores mentioned above i change the speed and then the ball comes back in the screen but the vx and vy things of the ball cant be changed so it just flies through the wall because it cant stop and change its path because the vx an vy things are fixed and wont change. Somebody please help :(

Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;











  //declare all the variables needed for the game :
int score = 0;
int catch_x = LCDWIDTH/2;
int catch_y = LCDHEIGHT/2;
int catch_vx = 3;
int catch_vy = 3;
int catch_size = 1;
int catch_r = 1;
int person_x = LCDWIDTH/3; //set the horizontal position to the middle of the screen
int person_y = LCDHEIGHT/6; //vertical position
int person_vx = 5; //horizontal velocity
int person_vy = 5; //vertical velocity
int person_size = 6; //the size of the ball in number of pixels
int ball_x = LCDWIDTH/5;
int ball_y = LCDHEIGHT/2;
int ball_vx = 2;
int ball_vy = 2;
int ball_size = 2;
int ball_r = 2;
void setup()
{
  // put your setup code here, to run once:
  gb.begin();
  gb.titleScreen(F("Ball dodger"));
   person_x=40;            //Move the player ball to middle of screen
 person_y=24;            //Move the player ball to middle of screen

 ball_x=80;             //Move the enemy ball to Right of screen
 ball_y=0;               //Move the enemy ball to top of screen
 
 catch_x=0;             //Move the catch ball to left of screen
 catch_y=40;             //Move the catch ball to top of screen



}

void loop()
{
  // put your main code here, to run repeatedly:
  if(gb.update()){
    gb.battery.show = false;
    //makes the catch ball bounce of of the killer ball
    if(gb.collideRectRect(ball_x, ball_y, ball_size, ball_size, catch_x, catch_y, catch_size, catch_size))
    {gb.sound.playCancel();
    catch_vx = -catch_vx;
    catch_vy = -catch_vy;
    }
    //Check if person touched a catch ball
    if(gb.collideRectRect(person_x, person_y, person_size, person_size, catch_x, catch_y, catch_size, catch_size))
  { gb.sound.playOK();
    score = score + 1;
    catch_vx = -catch_vx;
    catch_vy = -catch_vy;
    }
    //Check if person touched a enemy ball
    if(gb.collideRectRect(person_x, person_y, person_size, person_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 died!"),20);
// make a sound play
gb.sound.playCancel();
//Go to the title Screen
    gb.titleScreen(F("Ball dodger"));
 score = 0;              //Resets score
 person_x=40;            //Move the player ball to left of screen
 person_y=24;            //Move the player ball to top of screen

 ball_x=80;              //Move the enemy ball to Right of screen
 ball_y=0;               //Move the enemy ball to top of screen
 
 
 catch_x=0;              //Move the catch ball to left of screen
 catch_y=40;             //Move the catch ball to top of screen
 } 
   
    if(gb.buttons.repeat(BTN_RIGHT,2)){ //every 2 frames when the right button is held down
      person_x = person_x + person_vx; //increase the horizontal position by the ball's velocity
    }
    if(gb.buttons.repeat(BTN_LEFT,2)){
      person_x = person_x - person_vx;
     
    }
    if(gb.buttons.repeat(BTN_DOWN,2)){
      person_y = person_y + person_vy;
    }
    if(gb.buttons.repeat(BTN_UP,2)){
      person_y = person_y - person_vy;
    }
    if(gb.buttons.pressed(BTN_C)){
      gb.titleScreen(F("Ball dodger"));
    }
    if(person_x < 0){
      //bring it back in the screen
      person_x = 0;
    }
    //if the person is touching the right side
    if((person_x + person_size) > LCDWIDTH){
      person_x = LCDWIDTH - person_size;
    }
    //if the person is touching the top side
    if(person_y < 0){
      person_y = 0;
    }
    //if the person is touching the down side
    if((person_y + person_size) > LCDHEIGHT){
      person_y = LCDHEIGHT - person_size;
    }
      //draw the person on the screen
    gb.display.drawRect(person_x, person_y, person_size, person_size);
   
   
    //the catch ball starts here
   
   
   
    //add the speed of the catch ball to its position
    catch_x = catch_x + catch_vx;
    catch_y = catch_y + catch_vy;
   
    //check that the catch ball is not going out of the screen
    //if the catch ball is touching the left side of the screen
    if(catch_x < 0){
      //change the direction of the horizontal speed
      catch_vx = -catch_vx;
      //play a preset "tick" sound when the catch ball hits the border
      gb.sound.playTick();
    }
    //if the ball is touching the right side
    if((catch_x + catch_size) > LCDWIDTH){
      catch_vx = -catch_vx;
      gb.sound.playTick();
    }
    //if the ball is touching the top side
    if(catch_y < 0){
      catch_vy = -catch_vy;
      gb.sound.playTick();
    }
    //if the ball is touching the down side
    if((catch_y + catch_size) > LCDHEIGHT){
      catch_vy = -catch_vy;
      gb.sound.playTick();
    }
   
    //draw the ball on the screen
    gb.display.fillCircle(catch_x, catch_y, catch_r);
   
   
   
    //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
    }
    //if the ball is touching the right side
    if((ball_x + ball_size) > LCDWIDTH){
      ball_vx = -ball_vx;
    }
    //if the ball is touching the top side
    if(ball_y < 0){
      ball_vy = -ball_vy;
    }
    //if the ball is touching the down side
    if((ball_y + ball_size) > LCDHEIGHT){
      ball_vy = -ball_vy;
    }
   
    //draw the ball on the screen
    gb.display.fillCircle(ball_x, ball_y, ball_r);
   
        if(score == 10){
    gb.popup(F("10 points nice!"),5);
    ball_vx = 3;
    ball_vy = 3;
    }
            if(score == 20){
    gb.popup(F("20 points good!"),5);
    ball_size = 3;
    ball_vx = 1;
    ball_vy = 1;
    }
            if(score == 30){
    gb.popup(F("30 points WOW!"),5);
    ball_vx = 3;
    ball_vy = 4;
    ball_size = 2;
    }
            if(score == 40){
    gb.popup(F("40 points YAY!"),5);
    ball_size = 4;
    ball_vx = 2;
    ball_vy = 1;
    }
            if(score == 50){
    gb.popup(F("50 points *claps*!"),5);
    ball_size = 2;
    ball_vx = 4;
    ball_vy = 4;
    }
            if(score == 60){
    gb.popup(F("60 points *claspsss*!"),5);
    ball_size = 4;
    ball_vx = 1;
    ball_vy = 2;
    }
    //sorry.... i just had to
            if(score == 69){
    gb.popup(F("69 poin..t...ssss uhm"),15);
    }
            if(score == 70){
    gb.popup(F("70 points great!"),5);
    ball_size = 2;
    ball_vx = 4;
    ball_vy = 5;
    }
            if(score == 80){
    gb.popup(F("80 points gooooodd!"),5);
    ball_size = 4;
    ball_vx = 2;
    ball_vy = 2;
    }
            if(score == 90){
    gb.popup(F("90 points almost there!"),5);
    ball_size = 2;
    ball_vx = 5;
    ball_vy = 5;
    }
            if(score == 100){
    gb.popup(F("100 points whoeeheoee!!!"),5);
    ball_size = 5;
    ball_vx = 2;
    ball_vy = 2;
    gb.popup(F("YOU WON!!!"),20);
    gb.sound.playOK();
    gb.sound.playTick();
    gb.sound.playCancel();
    gb.titleScreen(F("Ball dodger"));
 score = 0;              //Resets score
 person_x=40;            //Move the player ball to left of screen
 person_y=24;            //Move the player ball to top of screen

 ball_x=80;              //Move the enemy ball to Right of screen
 ball_y=0;               //Move the enemy ball to top of screen
 
 
 catch_x=0;              //Move the catch ball to left of screen
 catch_y=40;             //Move the catch ball to top of screen
 }
    //the score starts here
         
  gb.display.fontSize = 1;
  gb.display.cursorX = 0;
  gb.display.cursorY = 0;
  gb.display.print(score);
 }}
EatMyBlitch
 
Posts: 76
Joined: Tue Dec 23, 2014 4:29 pm
Location: Netherlands

Previous

Return to Project Guidance & Game development

Who is online

Users browsing this forum: No registered users and 56 guests

cron