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
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mr. T




PostPosted: Mon Sep 19, 2005 5:55 pm   Post subject: JezzBall

This section of code doesn't seem to work properly.
code:

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

What this section of code is supposed to do is cancel the creation of a bar if it intersects with a previously created wall. For some reason this only works in certain instances. Any ideas why?

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
beard0




PostPosted: Mon Sep 19, 2005 6:53 pm   Post subject: (No subject)

I was wondering when this would show up again :P
I think I need some info at this point on what you want the overall program to do. Also, with this much code, please post it as an attachment.
Mr. T




PostPosted: Mon Sep 19, 2005 7:09 pm   Post subject: Alex's Opinion

This segment of code
code:

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

should interrupt the creation of a new bar if it detects that it has hit a previously existing bar. For some reason this only happens in certain instances. Test it out and see for yourself.
beard0




PostPosted: Mon Sep 19, 2005 7:12 pm   Post subject: (No subject)

Yep, I got that. I want to know what the overal program does, or rather, will do eventually.
Mr. T




PostPosted: Mon Sep 19, 2005 7:13 pm   Post subject: Alex's Opinion

well have u ever played the real jezzball before?
beard0




PostPosted: Mon Sep 19, 2005 7:18 pm   Post subject: (No subject)

well, obviously, no, or I wouldn't be asking.
Mr. T




PostPosted: Mon Sep 19, 2005 7:38 pm   Post subject: Alex's Opinion

You could have just said that from the get-go. I'm to tired to infer what you are implying. Here's an online version. It's in spanish but wont hinder ur game play. It shouldnt take too long to figure out either.
http://www.bolaloca.com/way/cool/bl/s_play.html
wtd




PostPosted: Mon Sep 19, 2005 7:44 pm   Post subject: Re: Alex's Opinion

Pwned wrote:
code:

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


Bad, bad programmer! Smile

You should know where on the screen any bars are, and at any given time where balls are. Then it's a reasonably simple matter to determine if they're colliding.
Sponsor
Sponsor
Sponsor
sponsor
beard0




PostPosted: Mon Sep 19, 2005 7:57 pm   Post subject: (No subject)

Okay, I got you now ;)

So, the problem is that your not resseting your barInterrupt variable to true everywhere you should be. On top of which, you really shouldn't need to use that variable anyway, just put the code that you have in the if barInterrupt blah blah blah... later in this area, under the appopriate section of your if construct.

wtd is one of the people I was talking about earlier who scoffs at the whatdotcolor collision detection, and, right as he is, it can be quite uesful, especially when you are a less experienced programmer.
Mr. T




PostPosted: Mon Sep 19, 2005 8:00 pm   Post subject: Re: Alex's Opinion

wtd wrote:
Pwned wrote:
code:

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


Bad, bad programmer! Smile

Not very supportive. Sad
Mr. T




PostPosted: Mon Sep 19, 2005 8:01 pm   Post subject: Alex's Opinion

beard0 wrote:
So, the problem is that your not resseting your barInterrupt variable to true everywhere you should be.

where should it be?
beard0




PostPosted: Mon Sep 19, 2005 8:08 pm   Post subject: (No subject)

well, your code is pretty messy. Rather than asking that, I was hoping that you would go with the later part of what I was saying, and not use the boolean variable at all.
Mr. T




PostPosted: Mon Sep 19, 2005 8:15 pm   Post subject: Alex's Opinion

Ok i took it out like u said, but im still getting the same result Crying or Very sad


JezzBall.zip
 Description:

Download
 Filename:  JezzBall.zip
 Filesize:  1.77 KB
 Downloaded:  95 Time(s)

[Gandalf]




PostPosted: Mon Sep 19, 2005 8:19 pm   Post subject: Re: Alex's Opinion

wtd wrote:
You should know where on the screen any bars are, and at any given time where balls are. Then it's a reasonably simple matter to determine if they're colliding.

I agree, but if you are looking for more speed (Turing-wise) then whatdotcolour would be better (if it is sufficient for the program), since instead of checking each bar against each bar it would only check for a colour once in the whole 'frame'.

Pwned, you took out the variable, now do the next step... beard0 said it already (although slightly 'blahish').
Mr. T




PostPosted: Mon Sep 19, 2005 8:24 pm   Post subject: (No subject)

The second part of what beard0 said was...
beard0 wrote:
just put the code that you have in the if barInterrupt blah blah blah... later in this area, under the appopriate section of your if construct.

but if i already took out the barInterrupt variable, how can i do this?
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  [ 25 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: