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.

Hey, i have a question and may have more as i go on so i made this thread. For my breakout clone i'm working on.

First of all i'm really new at programming my only other language is HTML, so bare with me :).


Anyways, i'm working on a breakout clone to teach me basics of game programming, I'm trying to figure out at the moment how to make a pillar go buh bye when the ball hits i'v tried to make a veriable that has to be true to draw a block, and if the pillar hits then the veriable is false for that block. but i also made it when it hits the pillars it gives me points, so even after it hits if the ball pass's through that area it gives me a point.

heres my code, also i'm trying to figure out how to make the ball bounce back ect:

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

Graphics 1680,1050,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=840,ball_y=880,power_x=0,power_y=0
Global move=0, pldelay=MilliSecs()
Global player, power, ball, mouse, score=0

;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

;@!@!@!@@@!@!@!@!@@@@@@@@@@@@@!@!@!@!@!@!@!@!@!
;@!@!@@@@@@!!!!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()
    If move=2 Then ballmovement2()

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

    ;Draws the ball
    Oval ball_x,ball_y,20,20
   
    ;Draws the player controled object
    Rect player_x,player_y,100,20

    ;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
   pillars.pillar=First 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
    For temp=1 To 109
    pillars=After pillars 
    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
    ;Power block -> player
    If RectsOverlap(PL,power_y,60,38,player_x,player_y,100,20) And ball_x=player_x+40 And move=0 Then
    move=2
   End If

  ;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
   End If
  Next

;Flip all the actions into the front buffer
 Flip
    ;tmrscreen=MilliSecs()
Wend

;This function is activated from the "Move=" code if the = value is 1 this is activated
Function ballmovement()
    If move=2 Then ball_y = ball_y + -20
    ball_y = ball_y + -10
    If ball_y=0 Then ball_y=880 ball_x=player_x+40 move=0
End Function

;This function is activated from the "Move=" code if the = value is 2 this is activated
Function ballmovement2()
    ball_y = ball_y + -20
    If ball_y=0 Then ball_y=880 ball_x=player_x+40 move=0
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