Graphics 800,600,32,2 SetBuffer BackBuffer() HidePointer SeedRnd MilliSecs() Global rc1 = 255 Global rc2 = 255 Global rc3 = 0 Global bc1 = 255 Global bc2 = 0 Global bc3 = 0 Global lc1 = 0 Global lc2 = 255 Global lc3 = 0 Global tc1 = 0 Global tc2 = 0 Global tc3 = 255 Global x=400 Global y=300 Global xspeed = 1 Global yspeed = 1 Global xx=xspeed Global yy=yspeed Global balltimer = MilliSecs() Global gametimer = MilliSecs() Global ball1 = 255 Global ball2 = 255 Global ball3 = 255 Global score = 0 startgame() While Not KeyHit(1) Cls topborder() leftborder() bottomborder() rightborder() If KeyHit(205) Then changeright() If KeyHit(203) Then changeleft() If KeyHit(208) Then changebottom() If KeyHit(200) Then changetop() Color 255,255,255 Text 0,0,"Time: "+score If MilliSecs()>gametimer+1000 Then score=score+1 gametimer=MilliSecs() End If If score = 20 Then xspeed=xspeed+1 yspeed=yspeed+1 score=score+1 End If If score = 40 Then xspeed=xspeed+1 yspeed=yspeed+1 score=score+1 End If If score = 60 Then wingame() balltime() Color ball1,ball2,ball3 Rect x,y,20,20 x=x+xx y=y+yy checkball() Flip Wend End ; end game Function endgame() For f=0 To 50 Color ball1,ball2,ball3 Rect Rnd(40)+x-10,Rnd(40)+y-10,4,4 Flip Next Delay 500 For f=0 To 600 Step 20 Color 0,0,0 Rect 0,f,800,10 Flip Next For f=10 To 600 Step 20 Color 0,0,0 Rect 0,f,800,10 Flip Next FlushKeys Cls Color 255,255,255 Text 310,300,"Game Over" Text 310,320,"Your time was "+score+" seconds." Flip WaitKey End End Function ;top Function topborder() Color tc1,tc2,tc3 Rect 0,0,800,30 End Function ;left Function leftborder() Color lc1,lc2,lc3 Rect 0,30,30,540 End Function ;bottom Function bottomborder() Color bc1,bc2,bc3 Rect 0,570,800,30 End Function ;right Function rightborder() Color rc1,rc2,rc3 Rect 770,30,30,540 End Function ;change right Function changeright() If rc1=255 And rc2=0 And rc3=0 Then ;if red rc1=0:rc2=255:rc3=0 ;make green Else If rc1=0 And rc2=255 And rc3=0 Then ;if green rc1=0:rc2=0:rc3=255 ;make blue Else If rc1=0 And rc2=0 And rc3=255 Then ;if blue rc1=255:rc2=255:rc3=0 ;make yellow Else If rc1=255 And rc2=255 And rc3=0 Then ;if yellow rc1=255:rc2=0:rc3=0 ;make red End If End Function ;change left Function changeleft() If lc1=255 And lc2=0 And lc3=0 Then ;if red lc1=0:lc2=255:lc3=0 ;make green Else If lc1=0 And lc2=255 And lc3=0 Then ;if green lc1=0:lc2=0:lc3=255 ;make blue Else If lc1=0 And lc2=0 And lc3=255 Then ;if blue lc1=255:lc2=255:lc3=0 ;make yellow Else If lc1=255 And lc2=255 And lc3=0 Then ;if yellow lc1=255:lc2=0:lc3=0 ;make red End If End Function ;change bottom Function changebottom() If bc1=255 And bc2=0 And bc3=0 Then ;if red bc1=0:bc2=255:bc3=0 ;make green Else If bc1=0 And bc2=255 And bc3=0 Then ;if green bc1=0:bc2=0:bc3=255 ;make blue Else If bc1=0 And bc2=0 And bc3=255 Then ;if blue bc1=255:bc2=255:bc3=0 ;make yellow Else If bc1=255 And bc2=255 And bc3=0 Then ;if yellow bc1=255:bc2=0:bc3=0 ;make red End If End Function ;change top Function changetop() If tc1=255 And tc2=0 And tc3=0 Then ;if red tc1=0:tc2=255:tc3=0 ;make green Else If tc1=0 And tc2=255 And tc3=0 Then ;if green tc1=0:tc2=0:tc3=255 ;make blue Else If tc1=0 And tc2=0 And tc3=255 Then ;if blue tc1=255:tc2=255:tc3=0 ;make yellow Else If tc1=255 And tc2=255 And tc3=0 Then ;if yellow tc1=255:tc2=0:tc3=0 ;make red End If End Function ;ball timer Function balltime() If MilliSecs()>balltimer+1000 And x>200 And x<700 And y>200 And y<400 Then col=Int(Rnd(3)+1) Select col Case 1 ball1 = 255 ball2 = 0 ball3 = 0 Case 2 ball1 = 0 ball2 = 255 ball3 = 0 Case 3 ball1 = 0 ball2 = 0 ball3 = 255 Case 4 ball1 = 255 ball2 = 255 ball3 = 0 End Select balltimer=MilliSecs() End If End Function ; check ball collision Function checkball() ;check top bounce If y<30 And tc1=ball1 And tc2=ball2 And tc3=ball3 Then yy=yspeed Else If y<30 Then endgame() End If ;check right bounce If x>750 And rc1=ball1 And rc2=ball2 And rc3=ball3 Then xx=-xspeed Else If x>750 Then endgame() End If ;check bottom bounce If y>550 And bc1=ball1 And bc2=ball2 And bc3=ball3 Then yy=-yspeed Else If y>550 Then endgame() End If ;check left bounce If x<30 And lc1=ball1 And lc2=ball2 And lc3=ball3 Then xx=xspeed Else If x<30 Then endgame() End If End Function ;start game Function startgame() FlushKeys Cls Color 255,255,255 Text 100,85,"S.T.I.N.K" Text 100,115,"A variation on the Pong theme for the Wednesday Workshop #29." Text 100,145,"As usual, a ball will bounce around the screen. As it does, it will change colour." Text 100,160,"It will randomly pick from 4 colours, red, green, blue and yellow." Text 100,190,"The walls are coloured in the same way. In order for the ball to bounce off of the" Text 100,205,"walls, they need to be the same colour. the wall's colour can be changed using the" Text 100,220,"relevant arrow key. They follow the above order of red, green, blue and yellow." Text 100,250,"Try to last as long as is possible. Every 20 seconds, the game speed will increase" Text 100,265,"and a second added to your time. Can you last a minute? ...I couldn't!" Text 100,295,"Press H for a hint, or any other key to start the game." Flip WaitKey If KeyHit(35) Then Text 100,325,"Personally I found it easier to have all the walls coloured the same, and change" Text 100,340,"them all as required." Text 100,370,"Press any key to start." Flip FlushKeys WaitKey End If End Function ;win game Function wingame() For f=0 To 50 Color 255,255,255 Rect Rnd(40)+x-10,Rnd(40)+y-10,4,4 Flip Next Delay 500 For f=0 To 600 Step 20 Color 0,0,0 Rect 0,f,800,10 Flip Next For f=10 To 600 Step 20 Color 0,0,0 Rect 0,f,800,10 Flip Next FlushKeys Cls Color 255,255,255 Text 310,300,"YOU LASTED A MINUTE !" Text 310,320,"Your time was "+score+" seconds." Flip WaitKey End End Function