So the other day I started re-creating Breakout, but I've run into some problems with getting the ball to bounce back in different directions.
I'm also having immense trouble with speed...just to try it, I ran the code in DBPro and it ran almost lightning-fast...odd.
But anyway, I'm more concerned with getting the angle stuff worked out.
Here's my code:
`============================================
`== Escape!! | V1.0 | Date Created 8/27/09 ==
`============================================
`Set The Graphics
Set Display Mode 1024,768,32
Hide Mouse
Sync On : Sync Rate 60
Backdrop On : Color Backdrop RGB(0,0,0)
Autocam Off
`---------------------------------
`-- Create The First Level --
`---------------------------------
`Create The Barriers For Level One
Make Object Box 1,102,6,2 : `The side-to-side wall
Make Object Box 2,2,6,125 : `The front-to-back wall
Make Object Box 3,2,6,125 : `The front-to-back end wall
`Position The Barriers
Position Object 1,0,0,50
Position Object 2,50,0,-12
Position Object 3,-50,0,-12
`Create The Paddle
Make Object Box 4,15,6,2
Color Object 4,RGB(255,128,16) : `Colors the paddle Orange-Redish
`Position The Paddle
Position Object 4,0,0,-50
`Create the Ball
Make Object Sphere 5,2.2 : Position Object 5,0,0,0 : Color Object 5,RGB(20,1920,125)
`Create The First Row of Red Blocks (20-29)
Make Object Box 20,8,2,2 : Position Object 20,-45,0,20
Make Object Box 21,8,2,2 : Position Object 21,-35,0,20
Make Object Box 22,8,2,2 : Position Object 22,-25,0,20
Make Object Box 23,8,2,2 : Position Object 23,-15,0,20
Make Object Box 24,8,2,2 : Position Object 24,-5,0,20
Make Object Box 25,8,2,2 : Position Object 25,5,0,20
Make Object Box 26,8,2,2 : Position Object 26,15,0,20
Make Object Box 27,8,2,2 : Position Object 27,25,0,20
Make Object Box 28,8,2,2 : Position Object 28,35,0,20
Make Object Box 29,8,2,2 : Position Object 29,45,0,20
`Create The Second Row of Yellow Blocks (30-39)
Make Object Box 30,8,2,2 : Position Object 30,-45,0,25
Make Object Box 31,8,2,2 : Position Object 31,-35,0,25
Make Object Box 32,8,2,2 : Position Object 32,-25,0,25
Make Object Box 33,8,2,2 : Position Object 33,-15,0,25
Make Object Box 34,8,2,2 : Position Object 34,-5,0,25
Make Object Box 35,8,2,2 : Position Object 35,5,0,25
Make Object Box 36,8,2,2 : Position Object 36,15,0,25
Make Object Box 37,8,2,2 : Position Object 37,25,0,25
Make Object Box 38,8,2,2 : Position Object 38,35,0,25
Make Object Box 39,8,2,2 : Position Object 39,45,0,25
`Create The Third Row of Green Blocks (40-49)
Make Object Box 40,8,2,2 : Position Object 40,-45,0,30
Make Object Box 41,8,2,2 : Position Object 41,-35,0,30
Make Object Box 42,8,2,2 : Position Object 42,-25,0,30
Make Object Box 43,8,2,2 : Position Object 43,-15,0,30
Make Object Box 44,8,2,2 : Position Object 44,-5,0,30
Make Object Box 45,8,2,2 : Position Object 45,5,0,30
Make Object Box 46,8,2,2 : Position Object 46,15,0,30
Make Object Box 47,8,2,2 : Position Object 47,25,0,30
Make Object Box 48,8,2,2 : Position Object 48,35,0,30
Make Object Box 49,8,2,2 : Position Object 49,45,0,30
`Create The Fourth Row of Blue Blocks (50-59)
Make Object Box 50,8,2,2 : Position Object 50,-45,0,35
Make Object Box 51,8,2,2 : Position Object 51,-35,0,35
Make Object Box 52,8,2,2 : Position Object 52,-25,0,35
Make Object Box 53,8,2,2 : Position Object 53,-15,0,35
Make Object Box 54,8,2,2 : Position Object 54,-5,0,35
Make Object Box 55,8,2,2 : Position Object 55,5,0,35
Make Object Box 56,8,2,2 : Position Object 56,15,0,35
Make Object Box 57,8,2,2 : Position Object 57,25,0,35
Make Object Box 58,8,2,2 : Position Object 58,35,0,35
Make Object Box 59,8,2,2 : Position Object 59,45,0,35
`Create The Fifth Row of Purple Blocks (60-69)
Make Object Box 60,8,2,2 : Position Object 60,-45,0,40
Make Object Box 61,8,2,2 : Position Object 61,-35,0,40
Make Object Box 62,8,2,2 : Position Object 62,-25,0,40
Make Object Box 63,8,2,2 : Position Object 63,-15,0,40
Make Object Box 64,8,2,2 : Position Object 64,-5,0,40
Make Object Box 65,8,2,2 : Position Object 65,5,0,40
Make Object Box 66,8,2,2 : Position Object 66,15,0,40
Make Object Box 67,8,2,2 : Position Object 67,25,0,40
Make Object Box 68,8,2,2 : Position Object 68,35,0,40
Make Object Box 69,8,2,2 : Position Object 69,45,0,40
`Make a For-Next Loop to set the collision and to color the blocks
For a=20 To 29
Color Object a,RGB(255,0,0)
Next a
For b=30 To 39
Color Object b,RGB(255,235,0)
Next b
For c=40 To 49
Color Object c,RGB(0,255,0)
Next c
For d=50 To 59
Color Object d,RGB(0,0,255)
Next d
For e=60 To 69
Color Object e,RGB(200,0,255)
Next e
`Position and angle the initial camera view
Position Camera 0,125,-12
XRotate Camera 90
CamFlag=0 : `This will let us change the camera view in-game
`------------------------------------
`-- Main Program Loop --
`------------------------------------
Do
Text 0,0,"FPS: "+Str$(Screen FPS() )
If LeftKey()=1 And PadPos#<55 Then PadPos#=PadPos#-0.8
If RightKey()=1 And PadPos#>-55 Then PadPos#=PadPos#+0.8
Position Object 4,PadPos#,0,-55 : `This Updates the Position of the paddle and also ensures that it will move when the keys are pressed
If PadPos#=<-40
PadPos#=-40
If PadPos#=>40
PadPos#=40
EndIf
EndIf
`Change the Camera View
If KeyState(79)=1 and CamFlag=1 <> CamFlag=2
CamFlag=0
If CamFlag=0
Position Camera 0,125,-12
XRotate Camera 90
EndIf
EndIf
If KeyState(80)=1 and CamFlag=2 <> CamFlag=0
CamFlag=1
If CamFlag=1
Set Cursor 0,12
Print "Alternate View 1"
Position Camera -50,125,0
XRotate Camera 95
ZRotate Camera 20
EndIf
EndIf
If KeyState(81)=1 and CamFlag=1 <> CamFlag=0
CamFlag=2
If CamFlag=2
Set Cursor 0,12
Print "Alternate View 2"
Position Camera 0,125,-135
XRotate Camera 40
ZRotate Camera 0
EndIf
EndIf
`Ball Movement
ballx#=newxvalue(ballx#,balla#,1)
ballz#=newzvalue(ballz#,balla#,1)
`Bouncing
if ballz#<-14 and ballz#>-12.5 and ABS(PadPos#-ballx#)<1.5 then balla#=180-balla#
if ballz#>45 then balla#=180-balla#
if ballx#>40 or ballx#<-40 then balla#=360-balla#
`MAKE SURE balla# IS LESS THAN 360 AND MORE THAN 0
balla#=wrapvalue(balla#)
position object 5,ballx#,0,ballz# : yrotate object 5,balla#
If Object Collision(5,4) Then balla#=wrapvalue(balla#+180)
`Ball to box collision
For z = 20 to 69
If object collision(5,0)=z
balla#=wrapvalue(balla#+180)
Hide object z
Set Object Collision Off z
EndIf
Next z
Sync
Loop
This is the part I'm really focusing on right now:
`Ball Movement
ballx#=newxvalue(ballx#,balla#,1)
ballz#=newzvalue(ballz#,balla#,1)
`Bouncing
if ballz#<-14 and ballz#>-12.5 and ABS(PadPos#-ballx#)<1.5 then balla#=180-balla#
if ballz#>45 then balla#=180-balla#
if ballx#>40 or ballx#<-40 then balla#=360-balla#
`MAKE SURE balla# IS LESS THAN 360 AND MORE THAN 0
balla#=wrapvalue(balla#)
position object 5,ballx#,0,ballz# : yrotate object 5,balla#
If Object Collision(5,4) Then balla#=wrapvalue(balla#+180)
`Ball to box collision
For z = 20 to 69
If object collision(5,0)=z
balla#=wrapvalue(balla#+180)
Hide object z
Set Object Collision Off z
EndIf
Next z
I did not write that code, I copied it from an old thread (which might explain the speed issue). However, I understand most of it, I just don't know how to add angles to the ball bouncing back and forth.
Any help/advice is appreciated!
-Yodaman Jer
Hoping that, one day, I'll finally get around to producing a game for you all to play.