Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Deleting the brick when the ball hits its
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Velocity




PostPosted: Wed Dec 14, 2011 7:09 pm   Post subject: Deleting the brick when the ball hits its

What is it you are trying to achieve?
When the ball bounces off the paddle and hits a brick, the brick gets deleted.

What is the problem you are having?
deleting the brick.

Describe what you have tried to solve this problem
I tried putting each brick value into a procedure with a cls and when the ball touches it i execute the procedure, i also tried saying if the x and y value equals the box shell value it will make the box move off the screen.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
I m sure that everyone is already aware of my code as you may have seen it in my previous posts, i just want to know how to make the brick go away after the ball hits it.

Please specify what version of Turing you are using
4.1.1a
Sponsor
Sponsor
Sponsor
sponsor
Velocity




PostPosted: Wed Dec 14, 2011 7:28 pm   Post subject: RE:Deleting the brick when the ball hits its

if ball_x1 = block_x1 then
d1Clear
if ball_x1 = block_x2 then
d1Clear
if ball_x1 = block_y1 then
d1Clear
if ball_x1 = block_y2 then
d1Clear
if ball_y1 = block_x1 then
d1Clear
if ball_y1 = block_x2 then
d1Clear
if ball_y1 = block_y1 then
d1Clear
if ball_y1 = block_y2 then
d1Clear
end if
end if
end if
end if
end if
end if
end if
end if

that is what i thought when d1Clear = drawfillbox .... block_x1, x2, y1, y2, it runs the program but it doesnt do anything.


Here is my code to those who have not seen it :


import GUI
View.Set ("graphics:638;690")
%_______The "Bank"_______%
type DataOfBlock :
record
x, y, width, height, center : int
defeated : boolean
end record
type DataOfShell :
record
right, top, left, bottom, c : int
end record
type BallData :
record
x, y, r, xv, yv, speed, c : int
end record
%_______Global Variables_______%
var PicID : int
var x : int := 700
var y : int := 500
var replay : string
var fontS : int
var xSpacing, ySpacing : int %
var blockH, blockW : int %
var shell : DataOfShell %
var ball : BallData %%%
var blockXDimension : int := 20 %
var blockYDimension : int := 10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var block : array 1 .. blockXDimension, 1 .. blockYDimension of DataOfBlock %
var x1, y1, x2, y2 : int
var ball_x1, ball_x2, ball_y1, ball_y2 : int %
var ball_directionx1 : int := 1 %
var ball_directiony1 : int := 1
var ball_directiony2 : int := 1
var ball_directionx2 : int := 1 %
var ball_speed : int
var continueGame : string %
var lives : int %
var score : int
var timeElapsed1, timeElapsed2 : int
var boundary_x1 : int := ((maxx div maxx) - 1) + 20 %
var boundary_x2 : int := maxx - 20 %
var boundary_y1 : int := maxy - 20 %
var boundary_y2 : int := ((maxy div maxy) - 1) + 20
var block_x1, block_y1, block_x2, block_y2 : int

proc initialValues
% Blocks (overall)
shell.right := 710 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
shell.top := 680 %
shell.left := 60 %
shell.bottom := 50 %
shell.c := 35
% Ball
ball_speed := 10 %
ball_x1 := 512 %
ball_y1 := 200
% Paddle (Player)
x1 := 250 %
y1 := 25 %
x2 := 350 %
y2 := 50
% lives and score
lives := 2
score := 0
% blocks
block_x1 := 25
block_y1 := 200
block_x2 := 75
block_y2 := 250
% font
fontS := Font.New ("Verdana:20")
% splash screen
timeElapsed1 := Time.Elapsed div 1000
Pic.Draw (PicID, maxx div 2 - (638 div 2), maxy div 2 - (690 div 2), picCopy)
end initialValues
procedure d1Clear
drawfillbox (block_x1 + 40, block_y1 + 75, block_x2 + 40, block_y2 + 75, blue)
cls
end d1Clear
%_______Procedures_______%
procedure TheGame
initialValues
setscreen ("graphics:1000;650,title:The AI BrickBreaker Game")
View.Set ("offscreenonly")
var arrowKeys : array char of boolean
lives += 1
timeElapsed1 := Time.Elapsed div 1000
loop
locate (1, 10)
put "Lives: ", lives
locate (1, 30)
put "Score: ", score
locate (1, 50)
timeElapsed2 := Time.Elapsed div 1000 - timeElapsed1
put "Game Time: ", timeElapsed2



%% Player Screen %%________________________________________________

drawfillbox (block_x1 + 40, block_y1 + 75, block_x2 + 40, block_y2 + 75, blue)
drawfillbox (block_x1 + 100 + 20, block_y1 + 75, block_x2 + 100 + 20, block_y2 + 75, blue)
drawfillbox (block_x1 + 180 + 20, block_y1 + 75, block_x2 + 180 + 20, block_y2 + 75, blue)
drawfillbox (block_x1 + 260 + 20, block_y1 + 75, block_x2 + 260 + 20, block_y2 + 75, blue)
drawfillbox (block_x1 + 340 + 20, block_y1 + 75, block_x2 + 340 + 20, block_y2 + 75, blue)

drawfillbox (block_x1 + 40, block_y1 + 150, block_x2 + 40, block_y2 + 150, blue)
drawfillbox (block_x1 + 80 + 20 + 20, block_y1 + 150, block_x2 + 80 + 20 + 20, block_y2 + 150, blue)
drawfillbox (block_x1 + 160 + 20 + 20, block_y1 + 150, block_x2 + 160 + 20 + 20, block_y2 + 150, blue)
drawfillbox (block_x1 + 240 + 20 + 20, block_y1 + 150, block_x2 + 240 + 20 + 20, block_y2 + 150, blue)
drawfillbox (block_x1 + 320 + 20 + 20, block_y1 + 150, block_x2 + 320 + 20 + 20, block_y2 + 150, blue)

drawfillbox (block_x1 + 40, block_y1 + 225, block_x2 + 40, block_y2 + 225, blue)
drawfillbox (block_x1 + 80 + 20 + 20, block_y1 + 225, block_x2 + 80 + 20 + 20, block_y2 + 225, blue)
drawfillbox (block_x1 + 160 + 20 + 20, block_y1 + 225, block_x2 + 160 + 20 + 20, block_y2 + 225, blue)
drawfillbox (block_x1 + 240 + 20 + 20, block_y1 + 225, block_x2 + 240 + 20 + 20, block_y2 + 225, blue)
drawfillbox (block_x1 + 320 + 20 + 20, block_y1 + 225, block_x2 + 320 + 20 + 20, block_y2 + 225, blue)

drawfillbox (block_x1 + 40, block_y1 + 300, block_x2 + 40, block_y2 + 300, blue)
drawfillbox (block_x1 + 120, block_y1 + 300, block_x2 + 120, block_y2 + 300, blue)
drawfillbox (block_x1 + 200, block_y1 + 300, block_x2 + 200, block_y2 + 300, blue)
drawfillbox (block_x1 + 280, block_y1 + 300, block_x2 + 280, block_y2 + 300, blue)
drawfillbox (block_x1 + 360, block_y1 + 300, block_x2 + 360, block_y2 + 300, blue)

%% AI Screen %%________________________________________________

drawfillbox (block_x1 + 540, block_y1 + 75, block_x2 + 540, block_y2 + 75, blue)
drawfillbox (block_x1 + 620, block_y1 + 75, block_x2 + 620, block_y2 + 75, blue)
drawfillbox (block_x1 + 700, block_y1 + 75, block_x2 + 700, block_y2 + 75, blue)
drawfillbox (block_x1 + 780, block_y1 + 75, block_x2 + 780, block_y2 + 75, blue)
drawfillbox (block_x1 + 860, block_y1 + 75, block_x2 + 860, block_y2 + 75, blue)

drawfillbox (block_x1 + 540, block_y1 + 150, block_x2 + 540, block_y2 + 150, blue)
drawfillbox (block_x1 + 620, block_y1 + 150, block_x2 + 620, block_y2 + 150, blue)
drawfillbox (block_x1 + 700, block_y1 + 150, block_x2 + 700, block_y2 + 150, blue)
drawfillbox (block_x1 + 780, block_y1 + 150, block_x2 + 780, block_y2 + 150, blue)
drawfillbox (block_x1 + 860, block_y1 + 150, block_x2 + 860, block_y2 + 150, blue)

drawfillbox (block_x1 + 540, block_y1 + 225, block_x2 + 540, block_y2 + 225, blue)
drawfillbox (block_x1 + 620, block_y1 + 225, block_x2 + 620, block_y2 + 225, blue)
drawfillbox (block_x1 + 700, block_y1 + 225, block_x2 + 700, block_y2 + 225, blue)
drawfillbox (block_x1 + 780, block_y1 + 225, block_x2 + 780, block_y2 + 225, blue)
drawfillbox (block_x1 + 860, block_y1 + 225, block_x2 + 860, block_y2 + 225, blue)

drawfillbox (block_x1 + 540, block_y1 + 300, block_x2 + 540, block_y2 + 300, blue)
drawfillbox (block_x1 + 620, block_y1 + 300, block_x2 + 620, block_y2 + 300, blue)
drawfillbox (block_x1 + 700, block_y1 + 300, block_x2 + 700, block_y2 + 300, blue)
drawfillbox (block_x1 + 780, block_y1 + 300, block_x2 + 780, block_y2 + 300, blue)
drawfillbox (block_x1 + 860, block_y1 + 300, block_x2 + 860, block_y2 + 300, blue)

%%_______________________________________________________________________________%%

% for y : 1 .. blockYDimension
% if y not= 1 then
% if 470 + (y * (block (1, y - 1).height + ySpacing)) >= 650 then
% exit
% end if
% end if
% end for
% for x : 1 .. blockXDimension
% if x not= 1 then
% if 60 + (x * (block (x - 1, y).width + xSpacing)) >= 610 then
% exit
% end if
% end if
% block (x, y).width := blockW
% block (x, y).height := blockH
% block (x, y).center := Rand.Int (2, 14)
% block (x, y).x := 60 + (x * (block (x, y).width + xSpacing))
% block (x, y).y := 470 + (y * (block (x, y).height + ySpacing))
% block (x, y).defeated := false
% if x not= 1 then
% loop
% if block (x, y).center = block (x - 1, y).center then
% block (x, y).center := Rand.Int (4, 12)
% else
% exit
% end if
% end loop
% end if
% if y not= 1 then
% loop
% if block (x, y).center = block (x, y - 1).center then
% block (x, y).center := Rand.Int (4, 12)
% else
% exit
% end if
% end loop
% end if
% end for
% drawbox (shell.left, shell.bottom, shell.right, shell.top, shell.c)
% drawbox (shell.left - 3, shell.bottom - 3, shell.right + 2, shell.top + 2, shell.c)
% Draw.Fill (shell.left - 1, shell.bottom - 1, 35, 35)
% for YP : 1 .. blockYDimension
% for x : 1 .. blockXDimension
% if block (x, y).defeated = false then
% drawfillbox (block (x, y).x, block (x, y).y, block (x, y).x +
% block (x, y).width, block (x, y).y + block (x, y).height, block (x, y).center)
% end if
% end for
% end for
% for YD : 1 .. blockYDimension
% for x : 1 .. blockXDimension
% if block (x, y).defeated = false then
% if ball_x1 + ball_y1 >= block (x, y).x and ball_x1 - ball_y1 <= block (x, y).x + block (x, y).width then
% if ball_y1 + ball_x1 >= block (x, y).y and ball_y1 - ball_x1 <= block (x, y).y + block (x, y).height then
% block (x, y).defeated := true
% score += 5
% ball.yv *= -1
% end if
% end if
% end if
% end for
% end for
% if ball_y1 + ball_y1 >= shell.top then
% ball_y1 := shell.top - ball_y1 - 1 + ball.yv
% elsif ball_x1 - ball_y1 <= shell.left then
% ball_x1 := shell.left + ball_y1 + 1 + ball.xv
% elsif ball_x1 + ball_y1 >= shell.right then
% ball_x1 := shell.right - ball_y1 - 1 + ball.xv
% end if


Input.KeyDown (arrowKeys)
if arrowKeys (KEY_RIGHT_ARROW) then
x1 += 10
x2 += 10
end if
if arrowKeys (KEY_LEFT_ARROW) then
x2 -= 10
x1 -= 10
end if

if x1 > 250 and x2 < 350 then
x1 := 100
elsif x1 < 250 and x2 > 350 then
x2 := 100
elsif y1 > 25 and y2 < 50 then
y1 := 25
elsif y1 < 25 and y2 > 50 then
y2 := 25
end if
if arrowKeys (KEY_ESC) then
cls
break
end if
var colorchanger1 : int
randint (colorchanger1, 1, 101)
delay (1)
drawfillbox (x1, y1, x2, y2, colorchanger1)
delay (5)
drawbox (20, 20, maxx - 20, maxy - 20, 51)
drawbox (5, 5, maxx - 5, maxy - 10, 51)
drawfillbox (250, 900, 350, 925, 101)
drawfillbox (maxx div 2 - 5 + 25, 20, maxx div 2 - 5 + 30, maxy - 20, 51)
drawfilloval (ball_x1, ball_y1, 15, 15, 48)
drawfill (maxx - 15, maxy - 15, 71, 51)
if x1 >= maxx div 2 - 40 or x2 >= maxx div 2 + 15 then
x1 -= 10
x2 -= 10
end if
if x1 <= 25 or x2 <= +25 then
x1 += 10
x2 += 10
end if
if ball_y1 >= maxy - 40 then
ball_directiony1 *= -1
end if
if ball_x1 >= maxx div 2 + 5 then
ball_directionx1 *= -1
end if
if ball_x1 <= 45 then
ball_directionx1 *= -1
end if
var direction : int
ball_x1 += (ball_directionx1 * ball_speed)
ball_y1 += (ball_directiony1 * ball_speed)
if ball_x1 <= x2 and ball_y1 <= y2 + 15 and ball_x1 >= x1 and ball_y1 >= y1 + 15 then
ball_directiony1 *= -1
end if

%% ______________ (AI + Paddle + ball)_______________%%

var x1_1, y1_1, x2_2, y2_2 : int
x1_1 := 1050
y1_1 := 25
x2_2 := 1150
y2_2 := 50
ball_x2 := 900 %
ball_y2 := 200
drawfilloval (ball_x2, ball_y2, 15, 15, 61)
drawfillbox (x1_1, y1_1, x2_2, y2_2, 141)


if ball_y2 >= maxy - 40 then
ball_directiony2 *= -1
end if
if ball_x2 >= maxx div 2 + 5 then
ball_directionx2 *= -1
end if
if ball_x2 <= 45 then
ball_directionx2 *= -1
end if
var direction1 : int
ball_x2 += (ball_directionx2 * ball_speed)
ball_y2 += (ball_directiony2 * ball_speed)
if ball_x2 <= x2_2 and ball_y2 <= y2_2 + 15 and ball_x2 >= x1_1 and ball_y2 >= y1_1 + 15 then
ball_directiony2 *= -1
end if
%%_________________________________________________%%
if ball_y1 < 25 then
lives -= 1
if lives <= 0 then
cls
Font.Draw ("You Have Lost Sad", 50, 50, fontS, green)
put "You have acquired a total score of: ", score
loop
put "Would you like to play again?"
get replay
if replay = "Yes" or replay = "yes" or replay = "y" then
put "Your game will replay shortly..."
put "Get READY!"
Time.Delay (3000)
timeElapsed1 := 0
lives := 4
TheGame
timeElapsed1 := Time.Elapsed div 1000
elsif replay = "No" or replay = "no" or replay = "n" then
put "Good bye, and thanks for playing!"
Time.Delay (2500)
cls
break
else
put "Invalid answer"
cls
end if
end loop
end if
end if
loop
if ball_y1 <= 20 then
cls
put "Would you like to continue? y/n: " ..
get continueGame
else
exit
end if
if continueGame = "y" or continueGame = "yes" then
cls
ball_x1 := 512
ball_y1 := 200
ball_directionx1 := 1
ball_directiony1 := 1
ball_directiony2 := 1
ball_directionx2 := 1
exit
elsif continueGame = "n" or continueGame = "No" then
put "Have A Nice Day!"
delay (2500)
break
else
put "Invalid answer."
delay (2500)
cls
end if
end loop
delay (10)
View.Update
delay (5)
cls
end loop
end TheGame

procedure Instructions
colorback (16)
color (48)
cls
locate (4, 1)
put "The objective of the game is..."
locate (7, 1)
color (58)
put "to destroy all of the blocks on your side of the screen (bottom)"
locate (10, 1)
color (73)
put "Before the computer destroys all of his blocks on his side of the screen (top)"
locate (13, 1)
color (81)
put "You will use the 'Left' and 'Right' Arrow keys to move left and right"
locate (16, 1)
color (67)
put "If you press the 'ESC' key on your keyboard the game will exit."
locate (19, 1)
color (96)
put "Good Luck and go smash some blocks. HINT : You only have 3 Lives!"

end Instructions
procedure TheTitleScreen
var font1 : int
font1 := Font.New ("Arial:13")
assert font1 > 0
PicID := Pic.FileNew ("ball02.jpg")
Pic.Draw (PicID, maxx div 2 - (638 div 2), maxy div 2 - (690 div 2), picCopy)
var game_Button : int := GUI.CreateButton (265, 275, 0, "Click To Play!", TheGame)
var instruction : string
locate (37, 4)
Font.Draw ("Please hold 'Click to Play' while you type your answer below!", 50, 150, font1, yellow)
locate (38, 4)
Font.Draw ("You will be redirected to the instructions so keep holding your mouse.", 50, 125, font1, green)
locate (39, 4)
Font.Draw ("Or drag away from 'Click to Play' then read and Click it afterwards.", 50, 75, font1, yellow)
locate (40, 4)
Font.Draw ("Do you want to see the game Instructions? ", 50, 40, font1, green)
locate (41, 47)
get instruction
if instruction = "yes" then
Instructions
else
Instructions
end if
end TheTitleScreen
procedure returnBack
var go_back : char := "n"
loop
get go_back
if go_back = "y" then
TheTitleScreen
end if
end loop
end returnBack
TheTitleScreen
loop
exit when GUI.ProcessEvent
end loop
Dreadnought




PostPosted: Wed Dec 14, 2011 8:54 pm   Post subject: Re: Deleting the brick when the ball hits its

So your program runs

loop
Draw stuff
View.Update
Delay
Cls
end loop

Your D1clear procedure draw a rectangle, then clear the screen. So what is the point of drawing the rectangle in the first place?

When you want to "delete" the rectangle, what you want is for it to not show up anymore (and for the program to imagine its not there). Remember that your program draw all rectangles on every loop.
So how would you go about making a rectangle not appear? And how does your program know that its should not appear?

If you can answer these questions then you know what to do.
Velocity




PostPosted: Wed Dec 14, 2011 9:05 pm   Post subject: RE:Deleting the brick when the ball hits its

what i meant to say is if the ball_x1 and ball_y1 touches any side of the brick it will disappear. but it doesnt allow me say that because it has to be a boolean type, so i tried to scale it down but i failed.

1. i wanted to say when the ball touches the brick it clears it.

2. No clue

3. well when the ball touches the sides of the brick then it should not appear

question 2 and 3 i have no clue how to go about doing that... could you explain those steps further please.
mirhagk




PostPosted: Wed Dec 14, 2011 9:18 pm   Post subject: RE:Deleting the brick when the ball hits its

Well each brick should keep track of whether it's alive or dead, so you would want an array of booleans. You notice you are getting a lot of arrays, so you might want to just use a type, it will save you time in the future.

So now you store whether it's alive or dead, you just need to check this each time you draw, so if it's dead, don't draw it.

When the ball collides with the brick (I assume you know how to check for this) then just kill the brick. Also make sure the ball only collides with alive bricks.
RandomLetters




PostPosted: Wed Dec 14, 2011 9:24 pm   Post subject: RE:Deleting the brick when the ball hits its

Say we have a box on the screen.

In our game, we can have an integer, box1, which represents the state, or "should-be-drawn-ness" of the box. If it is 0, then the box has been cleared, so we dont draw it, if it is 1, then we need to draw it.

Every frame, we check the value of that variable to determine if we need to draw it or not

if box1 = 1 then
%draw the box

or, if you have multiple styles (for example, crumbling boxes, you could draw a different style with each number using a procedure)

if box1 = 2 then
%draw crumbling box

thus, when you want to clear a box, all you need to do is set that variable to 0.

if collision() then
box1 = 0
end if

In this way, you can have an array of integers representing each box. and loop through each integer to determine if you should draw a box or not.
Velocity




PostPosted: Wed Dec 14, 2011 10:47 pm   Post subject: RE:Deleting the brick when the ball hits its

if i knew how to make it so that if it is 0 the box will not be drawn then i wouldnt be askin- .... wait if i declare a variable for each co-ordinate of each box and say if the ball touches that co-ording then that co-ordinate equals 0 so it wont draw that co-ordinate?
Velocity




PostPosted: Wed Dec 14, 2011 10:51 pm   Post subject: RE:Deleting the brick when the ball hits its

and thank you for identifying the source of the problem for me Smile
Sponsor
Sponsor
Sponsor
sponsor
Velocity




PostPosted: Wed Dec 14, 2011 10:52 pm   Post subject: RE:Deleting the brick when the ball hits its

But could you further explain the meaning of what you referred to and to what i have asked? thanks !
RandomLetters




PostPosted: Wed Dec 14, 2011 11:01 pm   Post subject: RE:Deleting the brick when the ball hits its

Are you looking for how to detect collision between a ball and the brick?

http://compsci.ca/v3/viewtopic.php?t=13661

For each brick, think of it as an "object" with information describing it. One is whether or not it exists on the screen. Another piece of information is the coordinates of each corner (like when you draw the box). These are separate pieces of information! You use those coordinates to detect collision as in the tutorial.
Aange10




PostPosted: Thu Dec 15, 2011 1:33 am   Post subject: RE:Deleting the brick when the ball hits its

Maybe this will help

Turing:

% Firstly, lets create a record. This program will show you how to do that,
% however, if you need further help, a tutorial by AsianSensation can be found
% at http://compsci.ca/v3/viewtopic.php?t=9636

type BrickData :
    record
        xCord, yCord, width, height : int
        alive : boolean
    end record

% Next we will create three bricks, using an array 1 .. 3. IF you need further
% help on arrays, a tutorial by Clayton can be found at
% http://compsci.ca/v3/viewtopic.php?t=14333

var brick : array 1 .. 3 of BrickData

% You may ask yourself 'What is BrickData?'. BrickData is the type we defined
% earlier. ^^^^. 'What is this type?' Well this type is a special, manually
% made type. This type consists of four integer variables. One is named xCord,
% another is named width, another coined as height,and a last named yCord.
% Lastly, there is a flag variable, a boolean, named alive.

% Now, lets initalize this array. That means to give each element (spot in an
% array) a value. We will be using a for loop to quickly access each element
% of the array named brick. If you are unfamiliar with for loops, or need a
% general refresher, visit http://compsci.ca/v3/viewtopic.php?t=3678 . It's
% a wonderful tutorial fabricated by Cervantes.

for i : 1 .. 3
    brick (i).xCord := 10 + ((i - 1) * 100)
    brick (i).yCord := 100
    brick (i).width := 50
    brick (i).height := 50
    brick (i).alive := true
end for

% Now we will give the computer the option to decide (this concept is commonly referred to
% as artificial intelligence, or AI) what to do. Our main tool for doing this
% will be the 'alive' flag, and if structures. If you are unfamiliar with
% boolean type (refered to in this comment as 'flag'), you may get a refresher
% at http://compsci.ca/v3/viewtopic.php?t=9634 . Cervantes's well written basics
% guide. If you need a refresher on if statements, check out another of
% Cervantes's guides; if structures: http://compsci.ca/v3/viewtopic.php?t=14656

for i : 1 .. 3 % Lets go through the array
    if brick (i).alive = true then
        drawfillbox (brick (i).xCord, brick (i).yCord, brick (i).xCord + brick (i).width, brick (i).yCord + brick (i).height, 8 + i)
        % Here we would usually check for collision. However that is not covered
        % in this tutorial. But a tutorial over collison may be found at
        % http://www.compsci.ca/v2/viewtopic.php?t=13661 , written by Richcash
    elsif brick (i).alive = false then
        % Do not draw anything. Do not check for collision.
    end if
end for


% To show functionality in the program, we will make a way to toggle (to switch
% on if off, or off if on, respectively) the alive flag. Here we will use
% basic get and put commands (information on which can be found at
% http://www.compsci.ca/v2/viewtopic.php?t=9634 . Written by Cervantes)
% and simple if statements. Again, information on if statements can be found
% at http://www.compsci.ca/v2/viewtopic.php?t=14656 . [A tutorial written by
% the famous Cervantes] Lastly,  we will be using loops, a tutorial and description
% on which can be found at http://www.compsci.ca/v2/viewtopic.php?t=3678 . Written
% once again by Cervantes. (We'll call him mr.C from now on ;])

var input : string

loop
    cls
    put "Block 1 is on the left. Block 2 is in the middle. Block 3 is on the right. To toggle the life of these blocks, simply type in their numbers." ..
    put "You may also type 5 to exit."
   
    % Now, using what we learned earlier, let's draw the bricks.

    for i : 1 .. 3 % Lets go through the array
        if brick (i).alive = true then
            drawfillbox (brick (i).xCord, brick (i).yCord, brick (i).xCord + brick (i).width, brick (i).yCord + brick (i).height, 8 + i)
            % Here we would usually check for collision. However that is not covered
            % in this tutorial. But a tutorial over collison may be found at
            % http://www.compsci.ca/v2/viewtopic.php?t=13661 , written by Richcash
        elsif brick (i).alive = false then
            % Do not draw anything. Do not check for collision.
        end if
    end for

    % Now let's allow the user to toggle the boxes
   
    locatexy (100, 300)
    get input : 1

    if input = "1" then
        % Toggle the 'life' of block 1.
        brick (1).alive := not brick (1).alive
    elsif input = "2" then
        % Toggle the 'life' of block 2.
        brick (2).alive := not brick (2).alive
    elsif input = "3" then
        % Toggle the 'life' of block 3.
        brick (3).alive := not brick (3).alive
    elsif input = "5" then
        exit
    end if


    % Finally, we will nest this in a loop
end loop


% Many aspects of this tutorial may be improved, reorganized, or other-wise
% more offecient by more complex means of programming. If you'd like to
% learn about these 'more complex means of programming', I would personally
% reccomend you visiting http://compsci.ca/v3/viewtopic.php?t=8808 .

% If you fully understand this tutorial, I'd suggest you learning procedures
% next, as they are the next biggest step.


% ~ Aange10


Velocity




PostPosted: Thu Dec 15, 2011 7:47 am   Post subject: RE:Deleting the brick when the ball hits its

Aange that actually helped sooo much! Thank you so much, i fixed my problem now, and random letters thank you so much for linking me to the tutorial for collision Smile
Aange10




PostPosted: Thu Dec 15, 2011 5:24 pm   Post subject: RE:Deleting the brick when the ball hits its

Umhm.
Velocity




PostPosted: Mon Jan 09, 2012 1:08 am   Post subject: RE:Deleting the brick when the ball hits its

um im sorry to be reviving dead threads but what if i didnt make all the brick seperatedly and i just made one set of a twenty bricks using for statements, then how would i go about clearing them?
Aange10




PostPosted: Mon Jan 09, 2012 7:55 am   Post subject: RE:Deleting the brick when the ball hits its

The trollish code posted above did use a set of bricks, 3. Now just change it from 3 to 20.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 30 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: