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.

Cool! i got the bounce off the padle to work, but it still fires off the wrong way, i made it fire upwards rather then downwards but it fires off in a 45degree angle

Also gotta try to figure out how to make it bounce off the pillars, i tried to make it bounce off when it collided, but for example if the ball makes it to the top and flys downward to the pillars it keeps going, also screws up if it hits the pillars from the side, works fine if it hits from the bottom though.


Heres my code:

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
Global bal_xdir = 1
Global bal_ydir = 1

;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

bal_xdir = -1
bal_ydir = -1

;@!@!@!@@@!@!@!@!@@@@@@@@@@@@@!@!@!@!@!@!@!@!@!
;@!@!@@@@@@!!!!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
    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
   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
    ;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
   Delete p
   End If
  Next

;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()

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
If ball_x < 0 Then bal_xdir = 1
If ball_x > 1670 Then bal_xdir = -1

If RectsOverlap(ball_x,ball_y,15,15,player_x,player_y,100,20) Then bal_ydir = -1

If move=0 Then
ball_y=player_y+-20
ball_x=player_x+40
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