 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
dbgtnet
Joined: 25 Dec 2005 Posts: 10
|
Posted: Tue Feb 14, 2006 5:21 am Post subject: Anyone can help me please ??? (for a psp pong) |
|
|
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 !!!!! |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Tue Feb 14, 2006 6:07 am Post subject: |
|
|
| Quote: | | 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: |
ballx += movex;
bally += movey;
if (bally<=0 || bally>=272) movey = -movey;
|
| Quote: |
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: |
if (ballx<=0) {
// player1 on the left let the ball go beyond the screen, so player2 gets 1 point
points2 += 1;
// add ball reset here
}
if (ballx>=480) {
// player2 on the right let the ball go beyond the screen, player1 gets a point
points1 += 1;
// add ball reset here
}
|
| Quote: | | 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: |
if (ballx==5) {
if (bally>=stick1_y && bally<=stick1_y+stick_h) {
movex = -movex;
}
}
|
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. |
|
| Back to top |
|
 |
dbgtnet
Joined: 25 Dec 2005 Posts: 10
|
Posted: Tue Feb 14, 2006 8:32 am Post subject: |
|
|
Hi !!!!
Thanks for your fast response.
I put your code and all but the ball dont move :(.
Here's my code
| Code: | int drawball(void)
{
ballx += movex;
bally += movey;
if (bally<=0 || bally>=272) movey = -movey;
if (ballx<=0) {
// player1 on the left let the ball go beyond the screen, so player2 gets 1 point
points2 += 1;
int ballx=136;
int bally=240;
}
if (ballx>=480) {
// player2 on the right let the ball go beyond the screen, player1 gets a point
points += 1;
int ballx=136;
int bally=240;
}
if (ballx==10) {
if (bally>=cy && bally<=cy+25) {
movex = -movex;
}
}
if (ballx==10) {
if (bally>=cy2 && bally<=cy2+25) {
movex = -movex;
}
}
DrawImage(ballblack, ballx, bally, 0, 0, ball, ball2, PAINTSRC);
return;
} |
|
|
| Back to top |
|
 |
HaQue
Joined: 25 Nov 2005 Posts: 91 Location: Adelaide, Australia
|
Posted: Tue Feb 14, 2006 7:22 pm Post subject: |
|
|
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! _________________ www.smartwave-wireless.com |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Tue Feb 14, 2006 8:19 pm Post subject: |
|
|
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: |
static int ballx = 136, bally = 240;
static int movex = 2;
static int movey = 1;
int drawball(void)
{
ballx += movex;
bally += movey;
if (bally<=0 || bally>=272) movey = -movey;
if (ballx<=0) {
// 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;
}
if (ballx>=480) {
// 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;
}
if (ballx==10) {
if (bally>=cy && bally<=cy+25) {
movex = -movex;
}
}
if (ballx==10) {
if (bally>=cy2 && bally<=cy2+25) {
movex = -movex;
}
}
DrawImage(ballblack, ballx, bally, 0, 0, ball, ball2, PAINTSRC);
return;
}
|
Also, this part of the code won't work properly
| Code: |
if (ballx==10) {
if (bally>=cy && bally<=cy+25) {
movex = -movex;
}
}
if (ballx==10) {
if (bally>=cy2 && bally<=cy2+25) {
movex = -movex;
}
}
|
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. |
|
| Back to top |
|
 |
dbgtnet
Joined: 25 Dec 2005 Posts: 10
|
Posted: Fri Feb 17, 2006 7:17 am Post subject: |
|
|
| Thanks a lot it's work ^^ |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|