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

Username:   Password: 
 RegisterRegister   
 Exiting a program?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SunsFan13




PostPosted: Fri May 09, 2008 9:40 am   Post subject: Exiting a program?

code:
process ball1
    setscreen ("graphics")

    var key : array char of boolean

    var x, y, r : int

    x := maxx div 2 % Start at center
    y := maxy div 2 % Start at center
    r := 10 % Ball radius


    loop

        % Draw circle
        drawfilloval (x, y, r, r, brightred)

        Input.KeyDown (key)

        % Move Left
        if key (KEY_LEFT_ARROW) and x > 15 then % x>15 = left boundary
            if whatdotcolor (x - 12, y) = black then
                delay (85)
                drawfilloval (x, y, r, r, black)
                x := x - r
            else
                Text.Color (brightred)
                put "You hit him!"
            end if
            % Move Right
        elsif key (KEY_RIGHT_ARROW) and x < maxx - 15 then % x<maxx - 15 = right boundary
            if whatdotcolor (x + 12, y) = black then
                delay (85)
                drawfilloval (x, y, r, r, black)
                x := x + r
            else
                Text.Color (brightred)
                put "You hit him!"
            end if
            % Move Up
        elsif key (KEY_UP_ARROW) and y < maxy - 15 then  % y<maxy-15 = top boundary
            if whatdotcolor (x, y + 12) = black then
                delay (85)
                drawfilloval (x, y, r, r, black)
                y := y + r
            else
                Text.Color (brightred)
                put "You hit him!"
            end if

            % Move Down
        elsif key (KEY_DOWN_ARROW) and y > 15 then       % y>15 = bottom boundary
            if whatdotcolor (x, y - 12) = black then
                delay (85)
                drawfilloval (x, y, r, r, black)
                y := y - r
            else
                Text.Color (brightred)
                put "You hit him!"
            end if



        end if
    end loop
end ball1         %End process ball1


process ball2         %Begin process ball2


    var key : array char of boolean

    var x, y, r : int

    x := maxx div 4
    y := maxy div 4
    r := 10         % Ball radius


    loop
       
        % Draw circle
        drawfilloval (x, y, r, r, brightgreen)

        Input.KeyDown (key)

        % Move Left
        if key ('a') and x > 14 then         % x>15 = left boundary
            if whatdotcolor (x - 12, y) = black then
                delay (85)
                drawfilloval (x, y, r, r, black)
                x := x - r
            else
                Text.Color (brightgreen)
                put "You hit him!"
            end if

            % Move Right
        elsif key ('d') and x < maxx - 15 then             % x<maxx - 15 = right boundary
            if whatdotcolor (x + 12, y) = black then
                delay (85)
                drawfilloval (x, y, r, r, black)
                x := x + r
            else
                Text.Color (brightgreen)
                put "You hit him!"
            end if

            % Move Up
        elsif key ('w') and y < maxy - 15 then                 % y<maxy-15 = top boundary
            if whatdotcolor (x, y + 12) = black then
                delay (85)
                drawfilloval (x, y, r, r, black)
                y := y + r
            else
                Text.Color (brightgreen)
                put "You hit him!"
            end if
            % Move Down
        elsif key ('s') and y > 15 then                     %y>15 = bottom boundary
            if whatdotcolor (x, y - 12) = black then
                delay (85)
                drawfilloval (x, y, r, r, black)
                y := y - r
            else
                Text.Color (brightgreen)
                put "You hit him!"
            end if


        end if
    end loop
end ball2

fork ball1
fork ball2


The teacher explained to me, or tried, how to do this, but I didn't really understand.
Basically, I need it when one ball "hits" the other, for it to exit.
At the moment, when one ball "hits", it just puts "You hit him" and totally glitches out, I need it to exit.

Thanks in advance,
Chris Canada
Sponsor
Sponsor
Sponsor
sponsor
petree08




PostPosted: Fri May 09, 2008 9:42 am   Post subject: RE:Exiting a program?

Don't use processes,

weird things happen with processes


also i wouldn't use whatdotcolor for collision detection

find the length between the two balls and when the length is lesser than the radius then they have hit each other. this way you only have to check for collision once
SunsFan13




PostPosted: Fri May 09, 2008 9:53 am   Post subject: Re: Exiting a program?

Yeah, and I wouldn't, except thats how we've been taught, so thats how he wants it done.

He said something about using true/false statements, but I'm not sure how to do it really.
So, help with what I need .. using the existing code?
SunsFan13




PostPosted: Mon May 12, 2008 10:22 am   Post subject: RE:Exiting a program?

No body can help me? :\
S_Grimm




PostPosted: Mon May 12, 2008 11:24 am   Post subject: RE:Exiting a program?

var hit : boolean := false

code between this

put "You Hit Him"
hit := true
if hit = true then
quit
end if
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  [ 5 Posts ]
Jump to:   


Style:  
Search: