gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Help needed with a pong clone [Renamed]

#80643 - biubid_boy - Mon Apr 24, 2006 1:27 pm

Hello everybody.
I'm working on a game, a bit like pog, but with four paddles (bars) instead of one. The idea is that if a ball colides with the green paddle, it changes to green, but if it colides with the green wall, it stays the same colour, namely yellow. I'm only working with two paddles as of now. For yellow it already works but I cant seem to do it for green. Heres my code:

Code:

void MoveBall(void) {
   if (ballDirection == 0 && xball < xMax && yball < yMax) {
      xball++;xball++;
      yball++;
   }
   if (ballDirection == 0 && ((xball >= xMax || yball >= yMax) || (xball >= xpaddlegreen - 6 && yball >= ypaddlegreen && yball <= ypaddlegreen + 16))) {
      memcpy( (u16 *)0x06014000, &ballgreenData, sizeof(ballgreenData) );
          if (xball >= xMax || xball >= xpaddlegreen - 6) {     
         ballDirection = 3;
      } else {
         ballDirection = 1;
      }
   }

   if (ballDirection == 1 && xball < xMax && yball > yMin) {
      xball++;xball++;
      yball--;
   }
   if (ballDirection == 1 && ((xball >= xMax || yball <= yMin) || (xball >= xpaddlegreen - 6 && yball >= ypaddlegreen && yball <= ypaddlegreen + 16))) {
          if (xball >= xMax || xball >= xpaddlegreen - 6) {         
         ballDirection = 2;
      } else {
         ballDirection = 0;
      }
   }

   if (ballDirection == 2 && xball > xMin && yball > yMin) {
      xball--;xball--;
      yball--;
   }
   if (ballDirection == 2 && ((xball <= xMin || yball <= yMin) || (xball == xpaddleyellow + 8 && yball >= ypaddleyellow && yball <= ypaddleyellow + 32))) {
      if (xball == xpaddleyellow + 8) {
            memcpy( (u16 *)0x06014000, &ballyellowData, sizeof(ballyellowData) );     
         ballDirection = 1;
      } else if (xball <= xMin) {
         ballDirection = 1;
      } else {
         ballDirection = 3;
      }
   }

   if (ballDirection == 3 && xball > xMin && yball < yMax) {
      xball--;xball--;
      yball++;
   }
   if (ballDirection == 3 && ((xball <= xMin  || yball >= yMax) || (xball == xpaddleyellow + 8 && yball >= ypaddleyellow && yball <= ypaddleyellow + 32))) {
      if (xball == xpaddleyellow + 8) {
            memcpy( (u16 *)0x06014000, &ballyellowData, sizeof(ballyellowData) );
         ballDirection = 0;
      } else if (xball <= xMin) {
         ballDirection = 0;
      } else {
     ballDirection = 2;
      }
   }

}


Can anyone help me get this sorted?
Thanks,
Biubid_boy.

#80644 - tepples - Mon Apr 24, 2006 1:33 pm

First thing you need to do is abstract that memcpy out into a loadSpriteCel function.

In addition, is there a reason why you're using a bitmapped background instead of a simple tiled background?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#80653 - gauauu - Mon Apr 24, 2006 3:59 pm

Looks like you're missing your mempy for green when ballDirection == 1