
-----------------------------------
Velocity
Wed Dec 14, 2011 7:09 pm

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

-----------------------------------
Velocity
Wed Dec 14, 2011 7:28 pm

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).y and ball_y1 - ball_x1 = shell.top then
        %         ball_y1 := shell.top - ball_y1 - 1 + ball.yv
        %     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 = maxx div 2 + 5 then
            ball_directionx1 *= -1
        end if
        if ball_x1 = maxy - 40 then
            ball_directiony2 *= -1
        end if
        if ball_x2 >= maxx div 2 + 5 then
            ball_directionx2 *= -1
        end if
        if ball_x2 