
-----------------------------------
bigmac586
Mon Jan 05, 2009 10:15 am

Need help on brick like game
-----------------------------------
ok i need help with the collision detection in my program, its for a gr 10 ISU, i need some boundaries, and i need the ball to bounce of the bricks, any help would be very appreciated thanks. This is my code

drawfillbox(0,390,50,400,brightred)
drawfillbox(75,390,125,400,brightred)
drawfillbox(150,390,200,400,brightred)
drawfillbox(225,390,275,400,brightred)
drawfillbox(300,390,350,400,brightred)
drawfillbox(375,390,425,400,brightred)
drawfillbox(450,390,500,400,brightred)
drawfillbox(525,390,575,400,brightred)
drawfillbox(600,390,650,400,brightred)
drawfillbox(0,370,50,380,brightred)
drawfillbox(75,370,125,380,brightred)
drawfillbox(150,370,200,380,brightred)
drawfillbox(225,370,275,380,brightred)
drawfillbox(300,370,350,380,brightred)
drawfillbox(375,370,425,380,brightred)
drawfillbox(450,370,500,380,brightred)
drawfillbox(525,370,575,380,brightred)
drawfillbox(600,370,650,380,brightred)
drawfillbox(0,350,50,360,brightred)
drawfillbox(75,350,125,360,brightred)
drawfillbox(150,350,200,360,brightred)
drawfillbox(225,350,275,360,brightred)
drawfillbox(300,350,350,360,brightred)
drawfillbox(375,350,425,360,brightred)
drawfillbox(450,350,500,360,brightred)
drawfillbox(525,350,575,360,brightred)
drawfillbox(600,350,650,360,brightred)
var stickSpeed := 3
var dir:= 100
var dir2:= 180
var getKey : array char of boolean
var ballSpeed := 2
var x, y : int
var dx, dy := 1
setscreen("offscreenonly")
x := 70
y := 313
drawfillbox (dir2, 20, dir, 30, black)
procedure moveleft 
 drawfillbox (dir2, 20, dir, 30, white)
   dir -= 1
   dir2 -= 1
   drawfillbox (dir2, 20, dir, 30, black)
   drawbox (dir2, 20, dir, 30, black)
   delay (stickSpeed)
   %View.Update
end moveleft
procedure moveright
 drawfillbox (dir2, 20, dir, 30, white)
   dir += 1
   dir2 += 1
   drawfillbox (dir2, 20, dir, 30, black)
   drawbox (dir2, 20, dir, 30, black)
   delay (stickSpeed)
   %View.Update
end moveright
process BouncyBall
   loop
       locate (1, 1)
       colorback (green)
       %put " x ", x, "   y ", y, "   dir ", dir, "   dir2 ", dir2, "          dir3 ", dir3, "   dir4 ", dir4
       %Draw.Text ("1P Score = ", 0, maxy - 18, scoreFont, red)
      
       locate (1, 43)
     
       x += dx
       y += dy
       delay (ballSpeed)     % Balls speed
       drawfilloval (x, y, 5, 5, brightcyan)
       drawoval (x, y, 5, 5, brightcyan)
     
   
       View.Update
       drawfilloval (x, y, 5, 5, white)
       % BOUNDARIES
        
     
       
           
   end loop
end BouncyBall
fork BouncyBall
  
       
loop
Input.KeyDown (getKey)
if getKey (KEY_LEFT_ARROW) then
       moveleft
   end if
if getKey (KEY_RIGHT_ARROW) then
       moveright
 if (dir = maxx - 80) then
       dir2 := maxx
       dir := maxx - 80
   end if
       end if
end loop

-----------------------------------
Tony
Mon Jan 05, 2009 11:08 am

RE:Need help on brick like game
-----------------------------------
do you know how to set up collision against just one brick?

Then, to keep the code from turning into a horrible pile of redundant if-statements, use arrays and a for-loop to generalize it.

Also, don't use fork, it's not necessary. Your BouncyBall and Input.KeyDown can happily live inside a single loop.

-----------------------------------
bigmac586
Mon Jan 05, 2009 11:16 am

Re: Need help on brick like game
-----------------------------------
umm no i dont know how to set up collision against just one brick

umm i dont know how to use arrays 

if i put the input.keydown inside one loop, then my paddle won't move and if i take away the fork no ball shows up at all

i should know more about arrays and collision detection but my teacher is dumb.

-----------------------------------
Nova
Mon Jan 05, 2009 11:50 am

RE:Need help on brick like game
-----------------------------------
Showing some code would make things much easier to help
Also, there are plenty of tutorials on collisions and arrays
Just search it

-----------------------------------
Tony
Mon Jan 05, 2009 12:38 pm

Re: Need help on brick like game
-----------------------------------
my teacher is dumb.
Turing Walkthrough -- there, I've fixed it for you.
