Anyone can help me please ??? (for a psp pong)

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
dbgtnet
Posts: 10
Joined: Sun Dec 25, 2005 12:11 am

Anyone can help me please ??? (for a psp pong)

Post by dbgtnet »

Hi !!!!

I am a new one in coding in general. My first real project is to do a psp pong. But the last thing I have to do it's the ball and the game is finished. So if anyone of you can do me a little code that only move the ball. I already know how to draw it.

What I need :

1-It bounce on the Y of the psp screen.
2-It give points in the X of the psp screen. (the variable are points and points 2)
3-It bounce on mp and mp2 (the pallets)

Thanks a lot !!!!!
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

1-It bounce on the Y of the psp screen.
Since I don't know anything about your setup of the movement variables, I just suppose you hold the ball position with the variables ballx and bally and the movement vector in movex and movey (which need to be signed ints).
At your movement code for the ball, just do something like that:

Code: Select all

ballx += movex;
bally += movey;
if &#40;bally<=0 || bally>=272&#41; movey = -movey;
2-It give points in the X of the psp screen. (the variable are points and points 2)
Could you specify this more? I hardly understand what you want, but by the game logic I would suppose you want the game to increase points for the appropriate player if the ball reaches the a players table end (goes beyond the vertical screen edge)? Well, for that, just do something like that:

Code: Select all

if &#40;ballx<=0&#41; &#123;
  // player1 on the left let the ball go beyond the screen, so player2 gets 1 point
  points2 += 1;
  // add ball reset here
&#125;
if &#40;ballx>=480&#41; &#123;
  // player2 on the right let the ball go beyond the screen, player1 gets a point
  points1 += 1;
  // add ball reset here
&#125;
3-It bounce on mp and mp2 (the pallets)
I suppose you mean it should bounce off the player sticks, correct? Then however, it would be neccessary to have at least a little insight in how you manage your player sticks, esp their position.
However, it will come down to some simple collision detection, so lets say you have your stick position set by stick1_y, your stick is 5 pixels from the left of the screen and your stick is stick_h pixels long. Then it would be something like that:

Code: Select all

if &#40;ballx==5&#41; &#123;
  if &#40;bally>=stick1_y && bally<=stick1_y+stick_h&#41; &#123;
    movex = -movex;
  &#125;
&#125;
This is the very simple way of getting it to bounce and doesn't use the movement speed of the player stick to speed up the movement of the ball or change the angle of the bounce, but that would be just some playing with the variables and adjusting for playability.
dbgtnet
Posts: 10
Joined: Sun Dec 25, 2005 12:11 am

Post by dbgtnet »

Hi !!!!

Thanks for your fast response.

I put your code and all but the ball dont move :(.

Here's my code

Code: Select all

int drawball&#40;void&#41;
&#123;
		ballx += movex;
		bally += movey;
		if &#40;bally<=0 || bally>=272&#41; movey = -movey; 
		if &#40;ballx<=0&#41; &#123;
		// player1 on the left let the ball go beyond the screen, so player2 gets 1 point
		points2 += 1;
    int	ballx=136;
	int	bally=240;
					  &#125;
		if &#40;ballx>=480&#41; &#123;
		// player2 on the right let the ball go beyond the screen, player1 gets a point
		points += 1;
    int	ballx=136;
	int	bally=240;
						&#125; 
		if &#40;ballx==10&#41; &#123;
		if &#40;bally>=cy && bally<=cy+25&#41; &#123;
		movex = -movex;
														&#125;
					  &#125; 
		if &#40;ballx==10&#41; &#123;
		if &#40;bally>=cy2 && bally<=cy2+25&#41; &#123;
		movex = -movex;
														&#125;
					  &#125;
		DrawImage&#40;ballblack, ballx, bally, 0, 0, ball, ball2, PAINTSRC&#41;;
		return;
&#125;
HaQue
Posts: 91
Joined: Fri Nov 25, 2005 8:52 am
Location: Adelaide, Australia
Contact:

Post by HaQue »

Hi, Im not sure of the rest of your code, but do you have timers setup on the ball?

If you just code it to move it is possible that it is moving so fast that you cant even see it!
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Well, sure it won't move if you define and initialize the ballx and bally variables each time after you did add the movement vector (if that even was initialized before). You have to make ballx and bally global and initalize them at the start of your program to some value, then also initialize the movement vector to something, like movex = 2; movey = 1; These two variables hold how fast and in which direction the ball is moving, so this is essential (and most likely will need some tweaks to get the ball to move at the correct speed).

Code: Select all

static int ballx = 136, bally = 240;
static int movex = 2;
static int movey = 1;

int drawball&#40;void&#41;
&#123;
      ballx += movex;
      bally += movey;
      if &#40;bally<=0 || bally>=272&#41; movey = -movey;
      if &#40;ballx<=0&#41; &#123;
      // player1 on the left let the ball go beyond the screen, so player2 gets 1 point
      points2 += 1;
      ballx=136;
      bally=240;
      movex = 2;  // Also reset the movement vector
      movey = 1;
      &#125;

      if &#40;ballx>=480&#41; &#123;
      // player2 on the right let the ball go beyond the screen, player1 gets a point
      points += 1;
      ballx=136;
      bally=240;
      movex = -2;  // Reset movement vector
      movey = 1;
      &#125;
      if &#40;ballx==10&#41; &#123;
      if &#40;bally>=cy && bally<=cy+25&#41; &#123;
      movex = -movex;
                                          &#125;
                 &#125;
      if &#40;ballx==10&#41; &#123;
      if &#40;bally>=cy2 && bally<=cy2+25&#41; &#123;
      movex = -movex;
                                          &#125;
                 &#125;
      DrawImage&#40;ballblack, ballx, bally, 0, 0, ball, ball2, PAINTSRC&#41;;
      return;
&#125;

Also, this part of the code won't work properly

Code: Select all

      if &#40;ballx==10&#41; &#123;
      if &#40;bally>=cy && bally<=cy+25&#41; &#123;
      movex = -movex;
                                          &#125;
                 &#125;
      if &#40;ballx==10&#41; &#123;
      if &#40;bally>=cy2 && bally<=cy2+25&#41; &#123;
      movex = -movex;
                                          &#125;
                 &#125;
Because it assumes the player2 is at the same x position (ballx==10) as player1, which obviously isn't the case. Change the second ballx==10 to ballx==player2x to fix that.
dbgtnet
Posts: 10
Joined: Sun Dec 25, 2005 12:11 am

Post by dbgtnet »

Thanks a lot it's work ^^
Post Reply