Lot's of little things changed, but have a look...
Gosub Data_Setup
Gosub Environment
Plyr.lives = 4
AI.lives = 4
AI.trigger = 0
MakeObjects()
SetReset()
Do
Ball()
PlyrControl()
AIControl()
ScreenText()
Sync
Loop
`Environment
Data_Setup:
Type ObjData
ID as Integer
x as Float
y as Float
z as Float
xspeed as Float
yspeed as Float
lives as Integer
trigger as integer
flagx as integer
flagy as integer
flag as integer
EndType
Global Ball as ObjData
Global AI as ObjData
Global Plyr as ObjData
Global TB as ObjData
Global BB as ObjData
Global AIB as ObjData
Global PlyrB as ObjData
Return
Environment:
Sync On
Sync Rate 60
BackDrop On
Color BackDrop 0
Autocam Off
Randomize Timer()
Move Camera 0, -550
Set Global Collision on
Return
`Functions
Function MakeObjects()
Set Spot Light 0, 2, 3
Position Light 0, 0, -200, -250
Point Light 0, 0, 0, 0
Make Object Plain 1, 801, 603, 1
Color Object 1, rgb(0, 255, 0)
Set shadow shading on 1
Make Object Box 2, 805, 603, 75
Make Object Box 3, 790, 593, 100
Perform CSG Difference 2, 3
Delete Object 3
TB.ID = 3
Make Object Box TB.ID, 805, 10, 25
Position Object TB.Id, 0, 290, -25
Hide Object TB.ID
BB.ID = 4
Make Object Box BB.ID, 805, 10, 25
Position Object BB.ID, 0, -290, -25
Hide Object BB.ID
AIB.ID = 5
Make Object Box AIB.ID, 25, 603, 25
Position Object AIB.ID, -400, 0, -25
Hide Object AIB.ID
PlyrB.ID = 6
Make Object Box PlyrB.ID, 25, 603, 25
Position Object PlyrB.ID, 400, 0, -25
Hide Object PlyrB.ID
Make Object Plain 7, 5, 580, 1
Ball.ID = 8
Make Object Sphere Ball.ID, 20
Position Object Ball.ID, 0, 0, -30
Ball.x = Object Position x(Ball.ID)
Ball.y = Object Position y(Ball.ID)
Ball.z = Object Position z(Ball.ID)
Set Object Collision to Spheres Ball.ID
Set Shadow Shading on Ball.ID
AI.ID = 9
Make Object Box AI.ID, 10, 60, 12.5
Position Object AI.ID, -350, 0, -30
AI.x = Object Position x(AI.ID)
AI.y = Object Position y(AI.ID)
AI.z = Object Position z(AI.ID)
Set Shadow Shading On AI.ID
Plyr.ID = 10
Make Object Box Plyr.ID, 10, 60, 12.5
Position Object Plyr.ID, 350, 0, -30
Plyr.x = Object Position x(PlyrB.ID)
Plyr.y = Object Position y(PlyrB.ID)
Plyr.z = Object Position z(PlyrB.ID)
Set Shadow Shading On Plyr.ID
ENDFUNCTION
Function SetReset()
Ball.flagx = RND(1)
Ball.flagy = RND(1)
ang=rnd(90)+45
if rnd(1)=0 then inc ang,180.0
Ball.xspeed = sin(ang)*3.0
Ball.yspeed = cos(ang)*3.0
Ball.x = 0
Ball.y = 0
Ball.z = -30
Plyr.x = 350
Plyr.y = 0
Plyr.z = -30
AI.x = -330
AI.y = 0
AI.z = -30
ENDFUNCTION
Function Ball()
`Do 5 checks to ensure ball doesn't pass through bats
for chk=0 to 4
`Moving ball regardless of collision
Inc Ball.x, Ball.xspeed/5.0
Inc Ball.y, Ball.yspeed/5.0
`Resetting flagx
Ball.flagx = 0
If Object collision(Ball.ID, AI.ID) = 1
Ball.flagx = 1
ENDIF
If Object collision(Ball.ID, Plyr.ID) = 1
Ball.flagx = 2
ENDIF
If Object collision(Ball.ID, PlyrB.ID) = 1
Ball.flagx = 3
ENDIF
If Object Collision(Ball.ID, AIB.ID) = 1
Ball.flagx = 4
ENDIF
Select Ball.flagx
Case 1
`Increase speed
Ball.xspeed=abs(Ball.xspeed*1.01)
Ball.yspeed=Ball.yspeed*1.01
`Increase Y speed depending on bat position
inc Ball.yspeed,(Ball.y-AI.y)/50.0
If Ball.flag = 1
Ball.Flag = 0
ENDIF
EndCase
Case 2
`Increase speed
Ball.xspeed=-abs(Ball.xspeed*1.01)
Ball.yspeed=Ball.yspeed*1.01
`Increase Y speed depending on bat position
inc Ball.yspeed,(Ball.y-Plyr.y)/50.0
If Ball.flag = 0
Ball.flag = 1
ENDIF
EndCase
Case 3
Dec Plyr.lives
If Plyr.lives < 0
Center Text Screen Width()/2, Screen Height()/2, "good off! You lovely"
Sync
Wait Key
FullReset()
Else
Center Text Screen Width()/2, Screen Height()/2, "You lose a life"
Sync
Wait 2000
Center Text Screen Width()/2, Screen Height()/2, "Get Ready!"
Sync
Wait 1000
Center Text Screen Width()/2, Screen Height()/2, "GOOO!"
Sync
Wait 500
SetReset()
ENDIF
`Dec Ball.x, Ball.xspeed
Ball.flagx = 1
EndCase
Case 4
Dec AI.lives
If AI.lives < 0
Center Text Screen Width()/2, Screen Height()/2, "You Won you lucky person!"
Sync
Wait Key
FullReset()
Else
Center Text Screen Width()/2, Screen Height()/2, "AI took a hit!"
Sync
Wait 2000
Center Text Screen Width()/2, Screen Height()/2, "Get Ready"
Sync
Wait 1000
Center Text Screen Width()/2, Screen Height()/2, "GOOO!"
Sync
Wait 500
SetReset()
ENDIF
EndCase
`*** No need for default
`Case Default
` Center Text Screen Width()/2, Screen Height()/2, "ERROR:Ball.flagx is lost"
` Sync
` Wait Key
` End
`EndCase
EndSelect
If Object Collision(Ball.ID, TB.ID) = 1
Ball.yspeed = -ABS(Ball.yspeed)
EndIf
If Object Collision(Ball.ID, BB.ID) = 1
Ball.yspeed = ABS(Ball.yspeed)
EndIf
Position Object Ball.ID, Ball.x, Ball.y, Ball.z
next chk
ENDFUNCTION
Function FullReset()
Ball.flagx = RND(1)
Ball.flagy = RND(1)
ang=rnd(90)+45
if rnd(1)=0 then inc ang,180.0
Ball.xspeed = sin(ang)*3.0
Ball.yspeed = cos(ang)*3.0
Ball.x = 0
Ball.y = 0
Ball.z = -30
Plyr.x = 350
Plyr.y = 0
Plyr.z = -30
AI.x = -350
AI.y = 0
AI.z = -30
AI.lives = 3
Plyr.lives = 3
EndFunction
Function PlyrControl()
If Upkey() = 1
Inc Plyr.y,5.0
`If Object Collision (Plyr.ID,Ball.ID) = 1
` Inc Ball.yspeed, 0.25
`Endif
Endif
If Downkey() = 1
Dec Plyr.y,5.0
`If Object Collision(Plyr.ID,Ball.ID) = 1
` Dec ball.yspeed, 0.25
`Endif
Endif
Position Object Plyr.ID,Plyr.x,Plyr.y,Plyr.z
If Object Collision(plyr.ID,BB.ID) = 1 Then Inc Plyr.y,5
If Object Collision (Plyr.ID,TB.ID) = 1 Then dec Plyr.y, 5
Position Object Plyr.ID,Plyr.x,Plyr.y,Plyr.z
EndFunction
Function AIControl()
remstart
If ball.x < AI.trigger
For x = 1 to 5
If AI.y > Ball.y
Dec AI.y
If Object Collision(AI.ID,BB.ID) = 1 Then Inc AI.y
Endif
If AI.y < Ball.y
Inc AI.y
If Object Collision(AI.ID,TB.ID) = 1 Then Dec AI.y
Endif
Next x
Endif
remend
`Move AI bat
if Ball.y<AI.y then dec AI.y,3.0
if Ball.y>AI.y then inc AI.y,3.0
Position Object AI.ID,AI.x,AI.y,AI.z
If Object Collision(AI.ID,TB.ID) = 1 Then dec AI.y,3.0
If Object Collision(AI.ID,BB.ID) = 1 Then inc AI.y,3.0
`Good idea to position the object before collision detection, then position it at it's adjusted location
Position Object AI.ID,AI.x,AI.y,AI.z
EndFunction
Function ScreenText()
Center Text (Screen Width() / 100) *15, (Screen Height() / 100) * 90, "AI Lives: " + Str$(AI.lives)
Center Text (Screen Width() / 100) *85, (Screen Height() / 100) * 90, "Player Lives: " + Str$(Plyr.lives)
EndFunction

Health, Ammo, and bacon and eggs!
