Ball moving like arkanoid or brick game

Blitz3D Forums/Blitz3D Beginners Area/Ball moving like arkanoid or brick game

Hello Fellow coders

id like to make a ball deflect and move around a 800,600 screen.

im using sprite candy how can i do a 2d version but for blitz3d +sprite candy , or just blitz3d if you dont have sprite candy



thanks

What is sprite candy?

EDIT: Ah, I see now: http://www.x-pressive.com/SpriteCandy/

I'm not sure if you mean like this or not. But, I did this a while ago trying stuff out.

Graphics 800,600,16,2 
SetBuffer BackBuffer() 
AppTitle "Bouncey Ball Thing" 
boxsize=2
box_x = 20 ; negative so it will start OFF screen 
box_y = 100 
randomx=Rnd(0,8)
randomy=Rnd(0,5)
While Not KeyHit(1) 
	Cls 
	Color (255,255,255)
	Rect box_x,box_y,boxsize,boxsize,1
	Flip 
	If box_x>=800 Then boxright=True 
	If box_x<=0 Then boxright=False 
	If box_y>=600 Then boxdown=True 
	If box_y<=0 Then boxdown=False 
	If boxright=False Then
		box_x=box_x+randomx
	Else 
		box_x=box_x-randomx
	EndIf
	If boxdown=False Then
		box_y=box_y+randomx
	Else 
		box_y=box_y-randomx
	EndIf
Wend 
End


I imagine there's probably an better way to do this though.

Make your ball have a X- and Y-Speed, adding this values to the ball's position each frame

If it hits a wall, just flip the corresponding axis like so:

If ball_x_pos < 0 then ball_x_speed= -ball_x_speed

Use HUD_SetObjectOrigin (ball,0,0) to center the handle after loading/creating your ball.