So far in my code it worked fine, until I added the collision with the paddles. Now it won't bounce off the ceiling and floor.

Code:

.PONG
28->A
28->B
44->X
28->Y
rand^4->D
[COCOCOCOCOCOCOCO]->Pic0
[0303030303030303]->Pic1
[3C7EFFFFFFFF7E3C]->Pic2
Repeat getKey(15)
DispGraphClrDraw
Pt-On(94,A,Pic0)
Pt-On(65530,B,Pic1)
Pt-On(X,Y,Pic2)
Line(0,0,95,0)
Line(0,63,95,63)
[Movement code]
[AI Movement Code]
.Ball Movement
If D=0
X--
Y--
End
If D=1
X--
Y++
End
If D=2
X++
Y--
End
If D=3
X++
Y++
End
If pxl-Test(X,Y+8)=1
If D=1
0->D
Else
2->D
End
End
If pxl-Test(X,Y-1)=1
If D=0
1->D
Else
3->D
End
End
If pxl-Test(X+8,Y+3)=1
If D=3
1->D
Else
0->D
End
End
If pxl-Test(X-1,Y+3)=1
If D=0
2->D
Else
3->D
End
End
[Ball reset code]
Pause 50
End
Can you use the code tag please?
I solved it Very Happy
Instead of using pxl-Test( I changed it all to location basis (What Kerm told me to do in the first place >.>)
So far it just seems like an enjoyable Ping Pong.
I'm going to see if I can put something extra in...
hellninjas wrote:
I solved it Very Happy
Instead of using pxl-Test( I changed it all to location basis (What Kerm told me to do in the first place >.>)
So far it just seems like an enjoyable Ping Pong.
I'm going to see if I can put something extra in...
Great, glad you took my advice. Does it have an "AI" like the one I suggested? Is it a perfect AI, or does it make mistakes? Does it have scoring and winning/losing?
There is scoring, but the AI is really dumb, I made it where if the paddles location is less than or greater than the ball, it would try to align itself, one pixel at a time. But I added a 1 in 10 chance for it not to move, because the ball moves one pixel at a time, otherwise allowing the player to actually beat the AI. But I found that sitting in the lower part of your side of the screen will allow the ball to just bounce off you paddle no matter what, (yes it is making contact, it just keeps going back there thanks to the dumb AI). Right now my score is 0 - 221 cause I haven't moved xD.
Any suggestions on how I could make the collision work better and the AI a bit smarter?
It doesn't sound like there's anything wrong with collision, but there's a problem with the size of your field (or the angle of the ball). Either change the ball's angle to not be 45 degrees all the time, or change the width or height of the playing field. Alternatively, you could make this an even better game by making the outgoing angle of the ball depend on the incoming angle and where it strikes each paddle. Most Breakout clones use that sort of method.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
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

 

Advertisement