ball dodger: first game

Advice on general approaches or feasibility and discussions about game design

Re: ball dodger: first game

Postby Summoner123 » Thu Aug 13, 2015 3:34 pm

EatMyBlitch wrote: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.



The error occurs because you don't have changed the parameter of function, to draw o circle you need the Xposition, Yposition and the radius of circle

Code: Select all
gb.display.fillCircle(x, y, r);


in the example of my later post I used

Code: Select all
gb.display.fillCircle(player_x, player_y, player_size/2);


If you want a circle and not a fillcircle you can change the fillcircle() to drawCircle().

Change the spawn point is very easy to, just change the position of the player and anemy after all titleScreen when it be call.

Code: Select all

  gb.titleScreen(F("unamed"));
 player_x=0;            //Move the player ball to left of screen
 player_y=0;            //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

User avatar
Summoner123
 
Posts: 26
Joined: Fri Mar 20, 2015 12:35 am

Re: ball dodger: first game

Postby EatMyBlitch » Thu Aug 13, 2015 3:53 pm

thanks again :D .I suck at programming :cry:
now i need to just program that each time you touch the catch ball it gives you a point and i need to make it so that at 3,6,9,11,15 and so on a new killer ball comes.
EatMyBlitch
 
Posts: 76
Joined: Tue Dec 23, 2014 4:29 pm
Location: Netherlands

Re: ball dodger: first game

Postby EatMyBlitch » Thu Aug 13, 2015 5:22 pm

i got a score :)
EDIT : now it resets each time you die.
EatMyBlitch
 
Posts: 76
Joined: Tue Dec 23, 2014 4:29 pm
Location: Netherlands

Re: ball dodger: first game

Postby Skyrunner65 » Thu Aug 13, 2015 5:51 pm

Hey if you want, here's how you could do multiple balls:
1. create variables for each ball.
2. For each ball, do this:
Code: Select all
gb.display.drawBitmap(VARIABLEX, VARIABLEY, ball)

3. Move as needed.
It's pretty simple. :)
User avatar
Skyrunner65
 
Posts: 371
Joined: Thu Mar 20, 2014 5:37 pm
Location: NC,USA

Re: ball dodger: first game

Postby EatMyBlitch » Thu Aug 13, 2015 5:54 pm

Thanks i will try and implement it
i don't have a variable called ball and i don't know what to put in it.
EatMyBlitch
 
Posts: 76
Joined: Tue Dec 23, 2014 4:29 pm
Location: Netherlands

Re: ball dodger: first game

Postby Skyrunner65 » Thu Aug 13, 2015 7:05 pm

No, the "ball variable" is the name of the sprite you are using for the ball... :D
User avatar
Skyrunner65
 
Posts: 371
Joined: Thu Mar 20, 2014 5:37 pm
Location: NC,USA

Re: ball dodger: first game

Postby EatMyBlitch » Thu Aug 13, 2015 7:06 pm

im not using a sprite.
can i make the catch ball bounce of the player?
Because then you can only get 1 point per hit instead of like 4.
BTW: the code i tried to run so that another ball will spawn at 3 points does not work. I tried this if(score/3 == int); so basically it checks if score:3 is an integer. (integer means a whole number like 1,10, 100, 50, 80. But not 1.4, 3.7, 6.3.). It says it expected a primary-expression.
here's my code.
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;
    //Check if person touched a catch ball
    if(gb.collideRectRect(person_x, person_y, person_size, person_size, catch_x, catch_y, catch_r, catch_r))
  { gb.sound.playOK();
    score = score + 1;}
    //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(score/3 == int);
//a new ball gets spawned

    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);
   
    //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

Re: ball dodger: first game

Postby EatMyBlitch » Sat Oct 17, 2015 1:38 pm

Dammit i just lost the game!!! :lol:

BTW:can somebody please provide some lines of code. So that the catch ball bounces of the player and only gives 1 point.

Nevermind did it myself :lol:

Code: Select all
    if(gb.collideRectRect(person_x, person_y, person_size, person_size, catch_x, catch_y, catch_size, catch_size))
  { gb.sound.playOK();
      //change the direction of the horizontal speed
      catch_vx = -catch_vx;
      catch_vy = -catch_vy;
    score = score + 1;}


now the only thing i need to add is that every three times you score another killer ball comes in.
EatMyBlitch
 
Posts: 76
Joined: Tue Dec 23, 2014 4:29 pm
Location: Netherlands

Re: ball dodger: first game

Postby EatMyBlitch » Sat Apr 30, 2016 10:52 am

Will nobody help me with the new kill ball each time you get 3 points thing? :cry:
*CRIES*
EatMyBlitch
 
Posts: 76
Joined: Tue Dec 23, 2014 4:29 pm
Location: Netherlands

Re: ball dodger: first game

Postby superfreaky » Sat Apr 30, 2016 5:59 pm

EatMyBlitch wrote:Will nobody help me with the new kill ball each time you get 3 points thing? :cry:
*CRIES*

Well maybe they want you to try for yourself first. After all, the best way to learn is through figuring out after long thought, and showing through example next. :)
superfreaky
 
Posts: 183
Joined: Wed Oct 28, 2015 1:46 am

PreviousNext

Return to Project Guidance & Game development

Who is online

Users browsing this forum: No registered users and 59 guests

cron