Breakout clone help

Blitz3D Forums/Blitz3D Beginners Area/Breakout clone help

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

That wasnt it. Still screwed up heres the whole code:

AppTitle "Breakout by Yahfree","Sure you want to quit?"

Graphics GraphicsWidth,GraphicsHeight,16,1
SetBuffer BackBuffer()

;Tunes for the background
chnbackground=PlayMusic("Music&SFX\Scorpions - Rock You Like A Hurricane.mp3") 

;Global stuff can be accessed anywhere if put here
Global ESC_KEY=1, UP_ARR=200, LEFT_ARR=203, RIGHT_ARR=205, DOWN_ARR=208, SPAC_BAR=57, Q=24, CTR=157
Global ms
Global player_x=800,player_y=900,ball_x=player_x,ball_y=880,power_x=0,power_y=0
Global move=0, pldelay=MilliSecs()
Global player, power, ball, mouse, score=0
Global bal_xdir = 0
Global bal_ydir = -1
Global lifes=4

;Pillars
;SeedRnd MilliSecs()
Type pillar
Field X
Field Y
Field r
Field b
Field g
Field hp
Field pillamount=109
End Type

For tempy=200 To 500 Step 30
For tempx=325 To 1350 Step 100
  pillars.pillar=New pillar
  pillars\X=tempx
  pillars\Y=tempy
  pillars\r=Rand(100,200)
  pillars\g=Rand(100,200)
  pillars\b=Rand(100,200)
  pillars\hp=1
Next
 Next

;creates the empty containers to draw on using the buffer
AutoMidHandle True
player=CreateImage(100,20)
ball=CreateImage(20,20)
life1=CreateImage(20,20)
life2=CreateImage(20,20)
life3=CreateImage(20,20)

SetBuffer ImageBuffer(player)
Rect 0,0,100,20

SetBuffer ImageBuffer(ball)
Oval 0,0,20,20


SetBuffer BackBuffer()


;@!@!@!@@@!@!@!@!@@@@@@@@@@@@@!@!@!@!@!@!@!@!@!
;@!@!@@@@@@!!!!MAIN GAMELOOP CODE!!!!!@!@!@!@!@
;@!@!@!@!@!@!@!@!@!@!@!@!@@@@@@@@@@!!!!@@@!!!@!
While Not KeyHit(ESC_KEY)

;Whipes the memory storage clean every 1 millisec keeps it running nice and smooth
    tmrscreen=MilliSecs()
    If MilliSecs() > ms+1 Then
    Cls
   End If


;Says that this = this... in this case the word "mouse_y" = mouseY() the code for the mouse
     mouse_y=MouseY()
     mouse_x=MouseX()
     pr=Rand(0,255)
     pb=Rand(0,255)
     pg=Rand(0,255)


    ;Player controls 2 of each left and right to move the ball if move=0
    Keycontrols()


    ;Tells that if move=1\2 is activated somehow then that function is also activated
    If move=1 Then ballmovement()


    ;Draws the MouseDot
    Oval mouse_x,mouse_y,1,1

    ;Draws the ball
    DrawImage ball,ball_x,ball_y
    
    ;Draws the life's depending on the lifes veriable
    If lifes>1 Then
    Oval 1411,1005,20,20
  End If
    If lifes>2 Then
    Oval 1433,1005,20,20
  End If
    If lifes>3 Then
    Oval 1455,1005,20,20
  End If
  
    ;Draws the player controled object
    DrawImage player,player_x,player_y

    ;Draws the "Power" block and some of its functions E.G if reachs a point it resets
    Color pr,pb,pg
    Rect PL,power_y,60,38
    power_y = power_y+ 10
    If power_y = 1050 Then power_y = 0
    If power_y =0 Then PL=Rand(0,1580)
    
    ;Color switched back to white
    Color 255,255,255
  
    ;Draws the pillars using types
   For pillars.pillar=Each pillar
   If pillars\hp=1 Then Color pillars\r,pillars\b,pillars\g:Rect pillars\X,pillars\Y,100,30,1:Color 0,0,0:Rect pillars\X,pillars\Y,100,30,0
Next


    ;Switch the color back to white for the text
    Color 255,255,255

    If score=15000 Then
    Text 800,500,"YOU WIN!!"
    score=0
   End If



    ;Text and some maths
    Text 50,50,"Players X: "+player_x+" Players Y: "+player_y
    Text 50,65,"Ball X: "+ball_x+" Ball Y: "+ball_y
    Text 50,80,"Powerblock X:"+PL+" Powerblock Y: "+power_y
    Text 50,95,"MouseDot X: "+mouse_x+" MouseDot Y: "+mouse_y
    Text PL+7,power_y,"Power"
    Text 800,0,"Score: "+score

    ;Collision codes

  ;Ball -> Pillars
  For p.pillar=Each pillar
   If RectsOverlap(p\X,p\Y,100,30,ball_x,ball_y,15,15) Then
   score=score+1
   Delete p
   bal_ydir=1
   End If
  Next


;If the lifes go down to 0 then give 3 more lifes
If lifes=0 lifes=4


Color 255,255,255
Text 0, 0,(ball_x - player_x)*.01


;Flip all the actions into the front buffer
 Flip


Wend

;This function is activated from the "Move=" code if the = value is 1 this is activated
Function ballmovement()

newspeedx = (ball_x - player_x)*.01

ball_x = ball_x + bal_xdir*5
ball_y = ball_y + bal_ydir*5

If ball_y < 0 Then bal_ydir = 1
If ball_y > 1040 Then move=0 lifes=lifes-1
If ball_x < 0 Then bal_xdir = 1
If ball_x > 1670 Then bal_xdir = -1

If ImagesCollide (ball,ball_x,ball_y,0,player,player_x,player_y,0) Then bal_ydir = -1: bal_xdir = newspeedx 

If move=0 Then
ball_y=player_y+-20
ball_x=player_x
End If

End Function




Function Keycontrols()
    If KeyDown(LEFT_ARR) And player_x>0 Then
    player_x = player_x -10
   End If
    If KeyDown(LEFT_ARR) And move=0 And ball_x>40 Then
    ball_x = ball_x + -10
   End If
    If KeyDown(RIGHT_ARR) And player_x<1580 Then
    player_x = player_x + 10
   End If
    If KeyDown(RIGHT_ARR) And move=0 And ball_x<1620 Then
    ball_x = ball_x + 10
   End If
    If KeyDown(SPAC_BAR) Then
    move=1   
   End If
End Function