2 Replies - 325 Views - Last Post: 21 March 2012 - 02:02 AM Rate Topic: -----

#1 blacksakura  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 12-March 12

would this work?

Posted 20 March 2012 - 12:54 AM

would this piece of collision code work?


	if ((bally + ball_width) && (ballx + ball_height) >= (leftpaddley + paddle_width && leftpaddlex + paddle_height))
		ball = 0;



Is This A Good Question/Topic? 0
  • +

Replies To: would this work?

#2 Mylo  Icon User is offline

  • Knows all, except most.

Reputation: 265
  • View blog
  • Posts: 747
  • Joined: 11-October 11

Re: would this work?

Posted 20 March 2012 - 03:01 AM

I'm sure that is not compilable. You are using logical operators between numbers. They should be evaluating booleans.

Edit: Not java forum, sorry.

However, it shouldn't work. I believe in C++ a non-zero number equates to true. True/False is above or equal to True/False. Also, you place ballY with width, and x with height which makes no sense.

What you need to do is:

if (ballX + ball_width >= paddleX)
 // this would be if the ball is going right and hits the paddle. If you are going left, you will need to account for the paddles width, but not the balls width. This is the same for up and down.


This post has been edited by Mylo: 20 March 2012 - 03:12 AM

Was This Post Helpful? 0
  • +
  • -

#3 blacksakura  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 12-March 12

Re: would this work?

Posted 21 March 2012 - 02:00 AM

thanks heaps that helped alot =D

just got back from uni after finishing my pong clone = D i am pretty happy with the results

if anyone wants it i can upload it =D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1