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

Username:   Password: 
 RegisterRegister   
 paying for answer
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: Tue Jan 17, 2012 7:18 pm   Post subject: paying for answer

What is it you are trying to achieve?
deleting the brick when the ball hits it, with the ball coming back to the user (brickbreaker)

What is the problem you are having?
cant seem to delete the brick it keeps coming back

Describe what you have tried to solve this problem
i would die before naming all that i tried


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


import GUI
View.Set ("graphics:638;690")
%_______Global Variables_______%

var wholescreen : array 1 .. sizepic (0, 0, maxx, maxy) of int
var arrowKeys : array char of boolean
var colorchanger1 : int
var PicID, PicID1 : int
var replay : string
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 fontS : int
var x, y : int
var ball_speed, ball_speed1 : int
var continueGame : string
var lives : int
var score : int
var timeElapsed1, timeElapsed2 : int
var block_x1, block_y1, block_x2, block_y2 : int
var x1_1, y1_1, x2_2, y2_2 : int
var debugger : boolean := false
var ball_Radius : int := 15
var xb1, yb1, xb2, yb2 : int
var alive : array 1 .. 16 of boolean
var rc1, rc2, rc3, rc4 : int
type BrickData :
    record
        xCord, yCord, width, height : int
        alive : boolean
    end record

var brick : array 1 .. 6 of BrickData
xb1 := 50
yb1 := maxy div 2
x := 50
y := maxy div 2 + 50
randint (rc1, 2, 6)
randint (rc2, 2, 6)
randint (rc3, 2, 6)
randint (rc4, 2, 6)

proc initialValues
    % Ball
    ball_speed := 10
    ball_speed1 := 8
    ball_x1 := 512
    ball_y1 := 200
    ball_x2 := 900
    ball_y2 := 200
    % Paddle (Player)
    x1 := 250
    y1 := 25
    x2 := 350
    y2 := 50
    % lives and score
    lives := 2
    score := 0
    % blocks
    x1_1 := 850
    y1_1 := 25
    x2_2 := 950
    y2_2 := 50
    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

%_______Procedures_______%


procedure TheGame2
    initialValues
    setscreen ("graphics:1000;650,title:The   BrickBreaker   Game")
    View.Set ("offscreenonly")
    colorback (16)
    const SnowFlakesFalling := 600
    var SnowFlakeX : array 1 .. SnowFlakesFalling of int
    var SnowFlakeY : array 1 .. SnowFlakesFalling of int
    for SnowFlake : 1 .. SnowFlakesFalling
        SnowFlakeX (SnowFlake) := Rand.Int (0, maxx)
        SnowFlakeY (SnowFlake) := Rand.Int (0, maxy)
    end for
    lives += 1
    timeElapsed1 := Time.Elapsed div 1000

    loop

        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 + 20, 20, maxx div 2 + 25, maxy - 20, 51)
        drawfilloval (ball_x1, ball_y1, ball_Radius, ball_Radius, 48)
        drawfill (maxx - 15, maxy - 15, 71, 51)
        drawfilloval (ball_x2, ball_y2, 15, 15, 61)
        drawfillbox (x1_1, y1_1, x2_2, y2_2, 31)

        for SnowFlake : 1 .. SnowFlakesFalling
            SnowFlakeY (SnowFlake) -= Rand.Int (1, 5)
            if SnowFlakeY (SnowFlake) < 0 then
                SnowFlakeY (SnowFlake) := maxy
                SnowFlakeY (SnowFlake) := Rand.Int (0, maxx)
            end if
            Draw.FillOval (SnowFlakeX (SnowFlake), SnowFlakeY (SnowFlake), 1, 1, white)
        end for

        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 <= 25 and x2 <= 125 then
            x1 := 30
            x2 := 130
        end if

        if x1 >= maxx div 2 - 85 and x2 >= maxx div 2 + 10 then
            x1 := maxx div 2 - 90
            x2 := maxx div 2 + 10
        end if

        if arrowKeys (KEY_ESC) then
            cls
            break
        end if

        if ball_y1 >= maxy - 50 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 and ball_x1 >= x1 and ball_y1 >= y1 then
            ball_directiony1 *= -1
            ball_directionx1 *= -1
        end if

        for i : 1 .. 6
            brick (i).xCord := 50 + ((i - 1) * 75)
            brick (i).yCord := maxy div 2
            brick (i).width := 50
            brick (i).height := 25
            brick (i).alive := true
        end for

        for i : 1 .. 6
            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)
            elsif brick (i).alive = false then

            end if
            if ball_x1 >= 50 and ball_x1 <= 100 and ball_y1 <= maxy div 2 + 25 and ball_y1 >= maxy div 2 then
                drawfillbox (50, maxy div 2, 100, maxy div 2 + 25, black)
                ball_directiony1 *= -1
            end if
        end for


        for k : 1 .. 6
            brick (k).xCord := 50 + ((k - 1) * 75)
            brick (k).yCord := maxy div 2 + 50
            brick (k).width := 50
            brick (k).height := 25
            brick (k).alive := true
        end for

        for k : 1 .. 6
            if brick (k).alive = true then
                drawfillbox (brick (k).xCord, brick (k).yCord, brick (k).xCord + brick (k).width, brick (k).yCord + brick (k).height, 8 + k)
            elsif brick (k).alive = false then

            end if
            if ball_x1 >= brick (k).xCord and ball_y1 >= brick (k).yCord and ball_x1 >= brick (k).width and ball_y1 >= brick (k).height then
                drawfillbox (brick (k).xCord, brick (k).yCord, brick (k).xCord + brick (k).width, brick (k).yCord + brick (k).height, black)
                ball_directiony1 *= -1
                exit when brick (k).alive = false
            end if
        end for

        for s : 1 .. 6
            brick (s).xCord := 50 + ((s - 1) * 75)
            brick (s).yCord := maxy div 2 + 100
            brick (s).width := 50
            brick (s).height := 25
            brick (s).alive := true
        end for

        for s : 1 .. 6
            if brick (s).alive = true then
                drawfillbox (brick (s).xCord, brick (s).yCord, brick (s).xCord + brick (s).width, brick (s).yCord + brick (s).height, 8 + s)
            elsif brick (s).alive = false then

            end if
            if ball_x1 >= brick (s).xCord and ball_y1 >= brick (s).yCord and ball_x1 >= brick (s).width and ball_y1 >= brick (s).height then
                drawfillbox (brick (s).xCord, brick (s).yCord, brick (s).xCord + brick (s).width, brick (s).yCord + brick (s).height, black)
                ball_directiony1 *= -1
                exit when brick (s).alive = false
            end if
        end for

        for p : 1 .. 6
            brick (p).xCord := 50 + ((p - 1) * 75)
            brick (p).yCord := maxy div 2 + 150
            brick (p).width := 50
            brick (p).height := 25
            brick (p).alive := true
        end for

        for p : 1 .. 6
            if brick (p).alive = true then
                drawfillbox (brick (p).xCord, brick (p).yCord, brick (p).xCord + brick (p).width, brick (p).yCord + brick (p).height, 8 + p)
            elsif brick (p).alive = false then

            end if
            if ball_x1 >= brick (p).xCord and ball_y1 >= brick (p).yCord and ball_x1 >= brick (p).width and ball_y1 >= brick (p).height then
                drawfillbox (brick (p).xCord, brick (p).yCord, brick (p).xCord + brick (p).width, brick (p).yCord + brick (p).height, black)
                ball_directiony1 *= -1
                exit when brick (p).alive = false
            end if
        end for

        for o : 1 .. 6
            brick (o).xCord := 50 + ((o - 1) * 75)
            brick (o).yCord := maxy div 2 + 200
            brick (o).width := 50
            brick (o).height := 25
            brick (o).alive := true
        end for

        for o : 1 .. 6
            if brick (o).alive = true then
                drawfillbox (brick (o).xCord, brick (o).yCord, brick (o).xCord + brick (o).width, brick (o).yCord + brick (o).height, 8 + o)
            elsif brick (o).alive = false then

            end if
            if ball_x1 >= brick (o).xCord and ball_y1 >= brick (o).yCord and ball_x1 >= brick (o).width and ball_y1 >= brick (o).height then
                drawfillbox (brick (o).xCord, brick (o).yCord, brick (o).xCord + brick (o).width, brick (o).yCord + brick (o).height, black)
                ball_directiony1 *= -1
                exit when brick (o).alive = false
            end if
        end for

        for m : 1 .. 6
            brick (m).xCord := 50 + ((m - 1) * 75)
            brick (m).yCord := maxy div 2 + 250
            brick (m).width := 50
            brick (m).height := 25
            brick (m).alive := true
        end for

        for m : 1 .. 6
            if brick (m).alive = true then
                drawfillbox (brick (m).xCord, brick (m).yCord, brick (m).xCord + brick (m).width, brick (m).yCord + brick (m).height, 8 + m)
            elsif brick (m).alive = false then

            end if
            if ball_x1 >= brick (m).xCord and ball_y1 >= brick (m).yCord and ball_x1 >= brick (m).width and ball_y1 >= brick (m).height then
                drawfillbox (brick (m).xCord, brick (m).yCord, brick (m).xCord + brick (m).width, brick (m).yCord + brick (m).height, black)
                ball_directiony1 *= -1
                exit when brick (m).alive = false
            end if
        end for
        %% ______________ (AI + Paddle + ball)_______________%%


        if ball_y2 >= maxy - 30 then
            ball_directiony2 *= -1
        end if
        if ball_x2 >= maxx div 2 + 40 then
            ball_directionx2 *= -1
        end if
        if ball_x2 <= maxx - 40 then
            ball_directionx2 *= -1
        end if
        var direction1 : int
        ball_x2 += (ball_directionx2 * ball_speed1)
        ball_y2 += (ball_directiony2 * ball_speed1)
        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_x2 > x1_1 + 35 then
            x2_2 += 10
            x1_1 += 10
        elsif ball_x2 < x1_1 + 35 then
            x2_2 -= 10
            x1_1 -= 10
        end if

        if x2_2 >= maxx - 30 and x1_1 >= maxx - 130 then
            x1_1 := maxx - 130
            x2_2 := maxx - 30
        end if
        if x1_1 <= maxx div 2 + 30 and x2_2 <= maxx div 2 + 130 then
            x1_1 := maxx div 2 + 30
            x2_2 := maxx div 2 + 130
        end if

        %%_________________________________________________%%

        color (91)
        put "Lives: ", lives
        locate (1, 20)
        put "Score: ", score
        locate (1, 40)
        timeElapsed2 := Time.Elapsed div 1000 - timeElapsed1
        put "Game Time: ", timeElapsed2
        if ball_y1 < 35 then
            cls
            lives -= 1
            ball_x1 := 512
            ball_y1 := 200
            ball_x2 := 650
            ball_y2 := 200
            ball_directionx1 := 1
            ball_directiony1 := 1
            ball_directiony2 := 1
            ball_directionx2 := 1
            if lives = -1 then
                cls
                Font.Draw ("You Have Lost :(", 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
                        TheGame2
                        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
        delay (10)
        View.Update
        delay (1)
        cls
    end loop
end TheGame2

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 (left)"
    locate (10, 1)
    color (73)
    put "Before the computer destroys all of his blocks on his side of the screen (right)"
    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!"
    var game_Button : int := GUI.CreateButton (265, 275, 0, "Click To Play!", TheGame2)
end Instructions

procedure returnBack
    var go_back : char := " "
    loop
        put "Please enter 'y' to go back"
        get go_back
        if go_back = "y" then
            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!", TheGame2)
            var instructions : int := GUI.CreateButton (265, 225, 0, "Instructions", Instructions)
            exit
        end if
    end loop
end returnBack

PicID := Pic.FileNew ("ball02.jpg")
Pic.Draw (PicID, maxx div 2 - (638 div 2), maxy div 2 - (690 div 2), picCopy)
var fontS1 : int := Font.New ("Verdana:12")
Font.Draw ("Please click 'instructions' to view the instructions then 'Click To Play'.", 35, 500, fontS1, red)
assert fontS1 > 0
Font.Free (fontS1)
var instructions : int := GUI.CreateButton (265, 225, 0, "Instructions", Instructions)
loop
    loop
        exit when GUI.ProcessEvent
    end loop
end loop

proc Debugger (debugger_ : boolean)
    if debugger_ = true then
        var mx, my, mb : int
        Mouse.Where (mx, my, mb)
        if mb = 1 then
            loop
                cls
                Mouse.Where (mx, my, mb)
                put "X: ", mx, " Y:", my
                exit when mb not= 1
                View.Update
                Time.DelaySinceLast (25)
            end loop
        end if
    end if
end Debugger






Please specify what version of Turing you are using
4.1.1a

run the program to see where it goes wrong and help me fix it
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Tue Jan 17, 2012 8:48 pm   Post subject: Re: paying for answer

Don't make posts with titles like this....

Velocity wrote:
cant seem to delete the brick it keeps coming back

i would die before naming all that i tried

Turing:
% Multiple in the middle of the game loop
for i : 1 .. 6
            brick (i).xCord := 50 + ((i - 1) * 75)
            brick (i).yCord := maxy div 2
            brick (i).width := 50
            brick (i).height := 25
            brick (i).alive := true
        end for

I assume you pasted code someone wrote for you (probably as an answer to another question). Try to understand why the code someone else has written works. If you can do that, you won't need to paste it into your code.

Please, don't pay me.
rdrake




PostPosted: Tue Jan 17, 2012 9:15 pm   Post subject: RE:paying for answer

Please try to avoid not only double posting, but triple posting the exact same topic. You have until somebody else posts under you to edit your own post.

I've removed your other two topics and am tempted to lock or remove this one as well.
Velocity




PostPosted: Tue Jan 17, 2012 9:21 pm   Post subject: RE:paying for answer

@dreadnought even with it how would i get the brick to just go away, even if i were to just make 2 for loops with rows and columns?
crossley7




PostPosted: Tue Jan 17, 2012 9:37 pm   Post subject: RE:paying for answer

generally a 'show' boolean variable is used like in the code seen here. That should be enough to get you on the right track. Think about how to properly use that variable and why it even exists
Velocity




PostPosted: Wed Jan 18, 2012 9:13 pm   Post subject: RE:paying for answer

ok it exists to store movement patterns inside and to determine if the object is there or not. but how would i use that in effect with my code, example please?
Velocity




PostPosted: Wed Jan 18, 2012 9:16 pm   Post subject: RE:paying for answer

can someon just write a simple example code to show how to clear the objectt when a ball or another object hits it. just so i can see it feed off it and work further into it, because right now i have no clue of where to go with it. +10 bits if you can.
Aange10




PostPosted: Wed Jan 18, 2012 9:21 pm   Post subject: Re: RE:paying for answer

Velocity @ 18/1/2012, 8:16 pm wrote:
can someon just write a simple example code to show how to clear the objectt when a ball or another object hits it. just so i can see it feed off it and work further into it, because right now i have no clue of where to go with it. +10 bits if you can.


Go look in the submissions. Or the help forum.


OR, you could look at your other forum that "helped so much!" and maybe tell us where you are confused. Instead of requesting us to code it for you (which is was in that thread!)


Your thread: http://compsci.ca/v3/viewtopic.php?t=30151
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Thu Jan 19, 2012 10:54 am   Post subject: RE:paying for answer

Turing:

setscreen ("offscreenonly")
var blockLive : boolean := true
var ballx, bally : int := 0
var ballvx, ballvy : int := 1
var ballsize : int := 5
var blockx, blocky : int := 200


loop
    Draw.FillOval (ballx, bally, ballsize, ballsize, 7)
   
    if blockLive = true then
        Draw.FillBox (blockx, blocky, blockx + 10, blocky + 5, 12)
    end if

    if ballx + ballsize > blockx and ballx - ballsize < blockx + 10 and
            bally + ballsize > blocky and bally - ballsize < blocky + 5 then
        blockLive := false
        ballvy *= -1
    end if
   
    ballx += ballvx
    bally += ballvy
   
    View.Update
    delay (5)
    cls
   
end loop


Very badly done, but thats the basic idea
Beastinonyou




PostPosted: Thu Jan 19, 2012 1:19 pm   Post subject: Re: RE:paying for answer

Raknarg @ Thu Jan 19, 2012 10:54 am wrote:
Turing:

setscreen ("offscreenonly")
var blockLive : boolean := true
var ballx, bally : int := 0
var ballvx, ballvy : int := 1
var ballsize : int := 5
var blockx, blocky : int := 200


loop
    Draw.FillOval (ballx, bally, ballsize, ballsize, 7)
   
    if blockLive = true then
        Draw.FillBox (blockx, blocky, blockx + 10, blocky + 5, 12)
    end if

    if ballx + ballsize > blockx and ballx - ballsize < blockx + 10 and
            bally + ballsize > blocky and bally - ballsize < blocky + 5 then
        blockLive := false
        ballvy *= -1
    end if
   
    ballx += ballvx
    bally += ballvy
   
    View.Update
    delay (5)
    cls
   
end loop


Very badly done, but thats the basic idea


Where's your payment? Lol...........
Raknarg




PostPosted: Thu Jan 19, 2012 2:35 pm   Post subject: RE:paying for answer

Well, i didn't give him the answer yet, he has to figure outhow to use it
Velocity




PostPosted: Thu Jan 19, 2012 3:33 pm   Post subject: RE:paying for answer

i understand that if the ball collides with the brick it will draw another brick of the background color over it, but how come when i run my program... wwoooooow obvs because ... omg i get it.
Raknarg




PostPosted: Thu Jan 19, 2012 6:36 pm   Post subject: RE:paying for answer

Thanks for that incredibly informative post (Y) Razz
Alex C.




PostPosted: Thu Jan 19, 2012 8:27 pm   Post subject: RE:paying for answer

so... Raknarg did you got paid yet? Very Happy
in bits or karma?
or better yet... $v$
Velocity




PostPosted: Thu Jan 19, 2012 8:28 pm   Post subject: RE:paying for answer

just paid him in karma
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  [ 19 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: