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

Username:   Password: 
 RegisterRegister   
 Jezzball
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mr. T




PostPosted: Mon Sep 19, 2005 5:27 pm   Post subject: Jezzball

For those of you who have played jezzball before know that if wall being created, runs into a previously created wall, the new wall should stop growing. For some reason, this only occurs occasionally and under certain circumstances. I don't know why. The relevant code is
code:

            if whatdotcolour (barX + a, barY) = blue
                    then
                barInterrupt := false
            end if

I attempted to hault the growth of the bar using a boolean. Any idea why this is not working properly? Here's the entire code.
code:

var wallCreator : boolean := true
var ballTrapperBoolean : boolean := true
var barInterrupt : boolean := true
const RADIUS : int := 5
var NUM_BALLS : int := 1
var x, y, dx, dy : array 1 .. NUM_BALLS of int
var xLeadingEdge, yLeadingEdge : int
var clr1 : int := green
var clr2 : int := red
var barX, barY, button, left, middle, right : int
var lives : int := 3
var fontGameOver : int := Font.New ("Arial:80")
var barXStore1, barXStore2, barYStore1, barYStore2 : int


View.Set ("nocursor,nobuttonbar, title:JezzBall                  Lives: " + intstr (lives))



process ballTrapper



    %Mouse Declaration
    barInterrupt := true
    ballTrapperBoolean := false %cant create new wall while previous one is being created
    Mouse.ButtonChoose ("multibutton")
    Mouse.Where (barX, barY, button)
    left := button mod 10           % left = 0 or 1
    middle := (button - left) mod 100       % middle = 0 or 10
    right := button - middle - left         % right = 0 or 100

    %Left Click = Horizontal Bar
    if left = 1 and barX >= maxx div 2 and whatdotcolour (barX, barY) not= blue then
        for a : 1 .. barX


            if whatdotcolour (barX + a, barY) = blue
                    then
                barInterrupt := false
            end if

            if barInterrupt = true then
                Draw.FillBox (barX + a, barY, barX, barY + 10, clr1)
                Draw.FillBox (barX - a, barY, barX, barY + 10, clr2)
                barXStore1 := barX + a
                delay (1)

            else
                clr1 := blue
                Draw.FillBox (barXStore1, barY, barX, barY + 10, clr1)
                Draw.FillBox (barX - a, barY, barX, barY + 10, clr2)
                delay (1)
            end if

            if barX + a = maxx  %first end to reach the wall turns blue
                    then
                clr1 := blue
            end if

            if barX - a = 1 and wallCreator = true %right before for loop ends
                    then
                clr1 := blue
                clr2 := blue %when the wall is complete, it will turn blue,
                %indicating that the ball can collide with it
                %without losing a life.
                Draw.FillBox (barX + a, 0, barX, barY, clr1)  %fills in the space below the ball
                Draw.FillBox (barX - a - 1, 0, barX, barY, clr2) %fills in the space below the ball
            end if

            if wallCreator = false then %ball collided with green wall
                Draw.FillBox (barX + a, barY, barX, barY + 10, white)
                Draw.FillBox (barX - a, barY, barX, barY + 10, white)
                lives := lives - 1 %lost life
                View.Set ("nocursor,nobuttonbar, title:JezzBall                  Lives: " + intstr (lives))
                exit
            end if




        end for
       

        clr1 := green
        clr2 := red %colour reset, next time a wall is created, it will be
        %green, indicating that if the ball collides with it
        %you will lose a life.

    elsif left = 1 and barX < maxx div 2 and whatdotcolour (barX, barY) not= blue then
       
        for a : 1 .. maxx - barX

            if whatdotcolour (barX - a, barY) = blue
                    then
                barInterrupt := false
            end if

            if barInterrupt = true then
                Draw.FillBox (barX + a, barY, barX, barY + 10, clr1) %fills in the space below the ball
                Draw.FillBox (barX - a, barY, barX, barY + 10, clr2) %fills in the space below the ball
                barXStore2 := barX - a
                delay (1)

            else
                clr2 := blue
                Draw.FillBox (barX + a, barY, barX, barY + 10, clr1) %fills in the space below the ball
                Draw.FillBox (barXStore2, barY, barX, barY + 10, clr2) %fills in the space below the ball
                delay (1)
            end if

            if barX - a = 0 %first end to reach the wall turns blue
                    then
                clr2 := blue
            end if

            if barX + a = maxx - 1 and wallCreator = true %right before for loop ends
                    then
                clr1 := blue
                clr2 := blue
                %when the wall is complete, it will turn blue,
                %indicating that the ball can collide with it
                %without losing a life.
                Draw.FillBox (barX + a + 1, 0, barX, barY, clr1)  %fills in the space below the ball
                Draw.FillBox (barX - a, 0, barX, barY, clr2)  %fills in the space below the ball
            end if

            if wallCreator = false then %ball collided with green wall
                Draw.FillBox (barX + a, barY, barX, barY + 10, white) %fills in the space below the ball
                Draw.FillBox (barX - a, barY, barX, barY + 10, white) %fills in the space below the ball
                lives := lives - 1 %lost life
                View.Set ("nocursor,nobuttonbar, title:JezzBall                  Lives: " + intstr (lives))
                exit
            end if




        end for
       

        clr1 := green
        clr2 := red %colour reset, next time a wall is created, it will be
        %green, indicating that if the ball collides with it
        %you will lose a life.

    end if

    %Right Click = Vertical Bar
    if right = 100 and barY >= maxy div 2 and whatdotcolour (barX, barY) not= blue then
        for a : 1 .. barY


            if whatdotcolour (barX, barY + a) = blue
                    then
                barInterrupt := false
            end if

            if barInterrupt = true then
                Draw.FillBox (barX, barY + a, barX + 10, barY, clr1)
                Draw.FillBox (barX, barY - a, barX + 10, barY, clr2)
                barYStore1 := barY + a
                delay (1)

            else
                clr1 := blue
                Draw.FillBox (barX, barYStore1, barX + 10, barY, clr1)
                Draw.FillBox (barX, barY - a, barX + 10, barY, clr2)
                delay (1)
            end if

            if barY + a = maxy %first end to reach the wall turns blue
                    then
                clr1 := blue
            end if

            if barY - a = 1 and wallCreator = true %right before for loop ends
                    then
                clr1 := blue
                clr2 := blue %when the wall is complete, it will turn blue,
                %indicating that the ball can collide with it
                %without losing a life.
                Draw.FillBox (0, barY + a, barX, barY, clr1)   %fills in the space to the side the ball
                Draw.FillBox (0, barY - a - 1, barX, barY, clr2) %fills in the space to the side the ball
            end if

            if wallCreator = false then %ball collided with green wall
                Draw.FillBox (barX, barY + a, barX + 10, barY, white)
                Draw.FillBox (barX, barY - a, barX + 10, barY, white)
                lives := lives - 1 %lost life
                View.Set ("nocursor,nobuttonbar, title:JezzBall                  Lives: " + intstr (lives))
                exit
            end if
           
           
             
       
           
           
        end for
       
 
        clr1 := green
        clr2 := red %colour reset, next time a wall is created, it will be
        %green, indicating that if the ball collides with it
        %you will lose a life.

    elsif right = 100 and barY < maxy div 2 and whatdotcolour (barX, barY) not= blue then
        for a : 1 .. maxy - barY


            if whatdotcolour (barX, barY - a) = blue
                    then
                barInterrupt := false
            end if

            if barInterrupt = true then
                Draw.FillBox (barX, barY + a, barX + 10, barY, clr1)
                Draw.FillBox (barX, barY - a, barX + 10, barY, clr2)
                barYStore2 := barY - a
                delay (1)

            else
                clr2 := blue
                  Draw.FillBox (barX, barY + a, barX + 10, barY, clr1)
                Draw.FillBox (barX, barYStore2, barX + 10, barY, clr2)
                delay (1)
            end if

            if barY - a = 0 %first end to reach the wall turns blue
                    then
                clr2 := blue
            end if

            if barY + a = maxy - 1 and wallCreator = true %right before for loop ends
                    then
                clr1 := blue
                clr2 := blue %when the wall is complete, it will turn blue,
                %indicating that the ball can collide with it
                %without losing a life.
                Draw.FillBox (0, barY + a + 1, barX, barY, clr1) %fills in the space to the side the ball
                Draw.FillBox (0, barY - a, barX, barY, clr2) %fills in the space to the side the ball
            end if

            if wallCreator = false then %ball collided with green wall

                Draw.FillBox (barX, barY + a, barX + 10, barY, white)
                Draw.FillBox (barX, barY - a, barX + 10, barY, white)
                lives := lives - 1 %lost life
                View.Set ("nocursor,nobuttonbar, title:JezzBall                  Lives: " + intstr (lives))
                exit
            end if
 
           
        end for
       

        clr1 := green
        clr2 := red %colour reset, next time a wall is created, it will be
        %green, indicating that if the ball collides with it
        %you will lose a life.
    end if

    %Boolean reset
    wallCreator := true
    ballTrapperBoolean := true

end ballTrapper






for i : 1 .. NUM_BALLS
    x (i) := Rand.Int (RADIUS, maxx - RADIUS)
    y (i) := Rand.Int (RADIUS, maxy - RADIUS)
    dx (i) := Rand.Int (-6, 6)
    dy (i) := Rand.Int (-6, 6)
end for

loop

    %Boundary Wall Collision
    for i : 1 .. NUM_BALLS
        if x (i) + dx (i) < RADIUS or
                x (i) + dx (i) > maxx - RADIUS then

            %Music.Sound (440, 30)
            dx (i) := -dx (i)
        end if
        if y (i) + dy (i) < RADIUS or
                y (i) + dy (i) > maxy - RADIUS then
            %Music.Sound (440, 30)
            dy (i) := -dy (i)
        end if
        x (i) := x (i) + dx (i)
        y (i) := y (i) + dy (i)
        Draw.FillOval (x (i), y (i), RADIUS, RADIUS, red)
        delay (5)
        View.Update
        Draw.FillOval (x (i), y (i), RADIUS, RADIUS, white)

        %Completed Wall Collision


    end for


    %Uncompleted Wall Collision
    if whatdotcolour (x (1) + RADIUS, y (1) + RADIUS) = green or whatdotcolour (x (1) + RADIUS, y (1) + RADIUS) = red then
        wallCreator := false     %if ball collides with green wall, cancel wall creation
    end if


    % Ball Trapper
    if ballTrapperBoolean = true
            then
        fork ballTrapper
    else
    end if


    %Game Over
    if lives = 0 then
        wallCreator := false
        exit
    end if

end loop

cls
View.Set ("nocursor,nobuttonbar, title:JezzBall                  Lives: " + intstr (lives) + "                  You Lose!")
for i : 1 .. 10
    delay (100)
    Font.Draw ("Game Over!", 30, (maxy div 2) - 20, fontGameOver, i)
end for
Sponsor
Sponsor
Sponsor
sponsor
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 1  [ 1 Posts ]
Jump to:   


Style:  
Search: