angle and speed

Blitz3D Forums/Blitz3D Beginners Area/angle and speed

Could anyone please tell me how to calculate the angle and speed of a ball when it collides with a bat, like in a breakout game. Also would it be possible to show me some code to see it working.
Thankyou for any reply.

DeViL

Easiest way quite frankly is not worry about speed and angle.

Use Xspeed and Yspeed

When the ball hits the bat may yspeed = -yspeed, and adjust the xspeed depending on where on the bat the ball hits.

Graphics 400,300,0,2

x#=200
y#=150
xd#=Rnd(-2,2)
yd#=Rnd(-2,2)

SetBuffer BackBuffer()

Repeat

	; draw screen
	Cls
	Text x,y,"O",True,True
	
	; update location
	x=x+xd
	y=y+yd
	
	; bounce of sides
	If x<0 Then xd=-xd
	If x>400 Then xd=-xd
	If y<0 Then yd=-yd
	If y>300 Then yd=-yd
	Flip

Until KeyHit(1)


Thankyou so much much Rob, it works now ^-^. And also thankyou very much for the speedily reply, i really appriciate it.

DeViL