3D Breakout question

Blitz3D Forums/Blitz3D Beginners Area/3D Breakout question

Ash_UK(Posted 2006) [#1]
Hi guys :o) I would like to have the ball bouncing around the board (left,right,up,down etc) as I am trying to make a 3D breakout game, but I'm not quite sure how to do it. I have included my code below for you to test and maybe modify? Also could you tell me if I have done the mouse control/collision detection the right way please?

Thanks guys, here's the code:

Breakout 3D.zip


FreetimeCoder(Posted 2006) [#2]
Here is a code to move the Player and make the ball bouncing:

Graphics3D 1024,768
SetBuffer BackBuffer()

Const BALL_COL = 1
Const BOARD_COL = 2


Global CAMERA = CreateCamera()
PositionEntity CAMERA,0,70,-60
RotateEntity CAMERA,45,0,0

Global OMNI = CreateLight()
AmbientLight 190,190,190

Global BOARD = LoadAnimMesh("models/game_board.3ds")
Global BASE = FindChild(BOARD,"base")
EntityType board,BOARD_COL,True

Global ball_x# = 0
Global ball_z# = 0
Global ball_x_speed = 1
Global ball_z_speed = 1
Global ball = CreateSphere()
EntityType ball,BALL_COL
EntityRadius ball,2

Global user_x# = 0
Global user_z# = -40
Global user = CreateCube()
ScaleEntity USER,5,3,1

	
	
EntityType USER,BALL_COL
EntityRadius user,7

MoveEntity ball,0,2,0

Collisions BALL_COL,BOARD_COL,2,2
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2


While Not KeyHit(1)
Cls
	MXS#=MouseXSpeed()
	user_x = user_x+MXS/5
	MYS#=-MouseYSpeed()
	user_z = user_z+MYS/5
	
	PositionEntity USER,user_x,0,user_z
	
	If KeyDown(200) Then TurnEntity CAMERA,0.5,0,0
	If KeyDown(208) Then TurnEntity CAMERA,-0.5,0,0
	
	;AmbientLight 150,50,Rand(0,255)
	
	ball_x = ball_x+ball_x_speed
	ball_z= ball_z+ball_z_speed
	PositionEntity ball,ball_x,2,ball_z
	
	UpdateWorld
	If EntityCollided(ball,BOARD_COL)
		If EntityX(ball)>30 Or EntityX(ball)<-30
			ball_x_speed = -ball_x_speed
		EndIf
		If EntityZ(ball)>40 Or EntityZ(ball)<-40
			ball_z_speed = -ball_z_speed
		EndIf
	EndIf
	RenderWorld
	
	Text 0,0,EntityZ(ball)
	Flip
	
Wend
End



Ash_UK(Posted 2006) [#3]
Thank you so P.K, very much appriciated :o)

Thanks again!


Ash_UK(Posted 2006) [#4]
I seem to be having another problem. I would like to draw the rows of bricks, but it isn't drawing properly, any idea why? :o) Thanks

Here's my code: (By the way I have started the code from scratch again :o)


Graphics3D 800,600
SetBuffer BackBuffer()


Global Cam_pivot = CreatePivot()
Global Camera = CreateCamera(Cam_pivot)
  MoveEntity Cam_pivot,0,100,-65
  RotateEntity Camera,45,0,0

Global Omni = CreateLight()

Global Area_x = 0
Global Area_z = 0
Global Area_width = 5
Global Area_height = 3

Global Brick_width = 10
Global Brick_height = 2
Global Brick_depth = 3

Global Brick = CreateCube()
FitMesh Brick,0,0,0,Brick_width,Brick_height,Brick_depth


;Global Board = LoadMesh("models/game_board.3ds")

Dim Bricks(Area_width-1,Area_height-1)

draw_level()




While Not KeyHit(1)
Cls
	
  If KeyDown(200) Then MoveEntity Cam_pivot,0,0,1
  If KeyDown(208) Then MoveEntity Cam_pivot,0,0,-1
	
  UpdateWorld
  RenderWorld
	
  Flip
	
Wend
End






Function draw_level()

  For z=0 To Area_height-1
    For x=0 To Area_width-1
      Bricks(x,z)=0
    Next
  Next

  Restore level1

  
  For z=0 To Area_height-1
    For x=0 To Area_width-1
      Read count
      If count=1 Then Bricks(x,z) = CopyEntity(Brick)
    Next
  Next


  For z=0 To Area_height-1
    For x=0 To Area_width-1
      PositionEntity Bricks(x,z),(Brick_width*Area_width),0,Area_z+(Brick_depth*Area_height)
    Next
  Next

End Function




.level1
Data 1,1,1,1,1
Data 1,1,1,1,1
Data 1,1,1,1,1





Ash_UK(Posted 2006) [#5]
Ahh, fixed it :o) I wasn't using the "x" co-ordinate in the positionentity code. Sorry about that :p

Thanks again!


Ash_UK(Posted 2006) [#6]
Hello again :o) Here is my latest code in a zip file. I was wondering how could I go about getting bricks in there with collisions when the balls hits them? Also I can't quite figure out how to get the bat colliding properly with the board (So it doesn't move any further than the boundaries on the right). I would be so grateful if someone could take a look at my code and maybe show me what I need to do to fix these issues. Thank you :o)

Code:
Breakout3D Latest Code.zip