hi, i am working on a pong type game (heard its good for beginners) but encountered some problems. I have already got the ball bouncing off the walls and the player/computer, but the game so far is really booring; the ball never changes direction unless someone loses. Does anyone know what i could do to make the ball move forwards and up or forwards and down, accordingly to which side of the paddle it hits?
here is my code so far (dont laugh..):
Graphics3D 1280,800
SetBuffer BackBuffer()
light=CreateLight()
cam=CreateCamera()
SeedRnd MilliSecs()
;collisions
Const type_lefts=1
Const type_ball=2
Const type_rights=3
Const type_top=4
Const type_bottom=5
Const type_player=6
Const type_computer=7
player=CreateCube()
PositionEntity player, -4.5,0,5
ScaleEntity player, 0.2,1.1,0.1
EntityType player, type_player
EntityRadius player, 0.1
computer=CreateCube()
PositionEntity computer, 4,0,5
ScaleEntity computer, 0.2,1.1,0.1
EntityType computer, type_computer
EntityRadius computer, 0.1
;ball
Global sphere_x# = 0
Global sphere_x_speed# = 0.1
Global sphere_y_speed# = 0.2
Global sphere_y# = 0
Global sphere = CreateSphere()
ScaleEntity sphere, 0.2,0.2,0.2
EntityType sphere, type_ball
EntityRadius sphere, 0.1
PositionEntity sphere, 0,0,5
;collisions
Collisions type_ball, type_lefts, 2, 1
Collisions type_ball, type_rights, 2, 1
Collisions type_ball, type_top,2,1
Collisions type_ball, type_bottom, 2, 1
Collisions type_ball, type_player, 2, 1
Collisions type_ball, type_computer, 2, 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
top=CreateCube()
PositionEntity top, 0,4.5,5
ScaleEntity top, 6,0.5,1
EntityType top, type_top
EntityAlpha top, 0
bottom=CreateCube()
PositionEntity bottom, 0,-4.3,5
ScaleEntity bottom, 6,0.5,1
EntityType bottom, type_bottom
EntityAlpha bottom, 0
lefts=CreateCube()
PositionEntity lefts, -6.5,0,5
ScaleEntity lefts, 0.5,4,1
EntityAlpha lefts, 0
EntityType lefts, type_lefts
Rights=CreateCube()
PositionEntity rights, 6.5,0,5
ScaleEntity rights, 0.5,4,1
EntityAlpha rights, 0
EntityType rights, type_rights
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;THE SCORES
score1=0
score2=0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
While Not KeyDown(1)
;moving the player
If KeyDown(200) Then MoveEntity player, 0,0.1,0
If KeyDown(208) Then MoveEntity player, 0,-0.1,0
sphere_y = sphere_x + sphere_y_speed#
sphere_x = sphere_x + sphere_x_speed#
MoveEntity sphere, sphere_x_speed#,sphere_y_speed#,0
;adding the points (1 by 1)
;point for the computer
oldpoint1 = point1
point1 = (EntityCollided (sphere, type_lefts) <> 0)
If point1 And (Not oldpoint1) Then
score2=score2+1
EndIf
;point for the player
oldpoint2 = point2
point2 = (EntityCollided (sphere, type_rights) <> 0)
If point2 And (Not oldpoint2) Then
score1=score1+1
EndIf
UpdateWorld
;bounce off the walls when hit
If EntityCollided(sphere, type_lefts) Then sphere_x_speed# = 0-sphere_x_speed#
If EntityCollided(sphere, type_rights) Then sphere_x_speed# = 0-sphere_x_speed#
If EntityCollided(sphere, type_top) Then sphere_y_speed# = 0-sphere_y_speed#
If EntityCollided(sphere, type_bottom) Then sphere_y_speed# = 0-sphere_y_speed#
If EntityCollided(sphere, type_player) Then sphere_x_speed# = 0-sphere_x_speed#
If EntityCollided(sphere, type_player) Then sphere_y_speed# = 0-sphere_y_speed#
If EntityCollided(sphere, type_computer) Then sphere_x_speed# = 0-sphere_x_speed#
If EntityCollided(sphere, type_computer) Then sphere_y_speed# = 0-sphere_y_speed#
RenderWorld
Text 150,10,"player1: "+score1
Text 150,20,"Computer: "+score2
Text 0,0,"ball x speed: "+sphere_x_speed#
Flip
Wend
End
thanks
|