Computer Science Canada

help with an exit when statement!

Author:  Randolf Nitler [ Tue Jan 15, 2008 7:46 pm ]
Post subject:  help with an exit when statement!

I have a fairly large problem with placing an exit when statement, or something along the same lines that will allow my missiles to land onto the ground when the y coordinate of the missile (currentYcorrdinate1, currentYcoordinate2) gets bellow y = 15. I want my program to then stop at that very point and draw my crater which i made in a for loop. The thing is, since the whole thing is in a loop, i want it to only draw the crater when the missile's y coordinate gets under y = 15, but it goes on drawing craters bellow 15. The second thing is, let's say i manage to get this fixed, i use an exit when statment to allow me to draw my crater. Then what, that stops my loop from running and i can't draw any more craters!, how would i get my loop to run again and draw another crater with a different power variable, or a different angle variable. I basically want my loop to restart, after the previous crater has been drawn so i can change the variable values and draw even more craters. What kind of a loop can i have to do this? I'd very much appreciate a quick response to my problem, and if you have any suggestions to make my life a lot easier, share your views. Thanks again!

code:

setscreen ("offscreenonly")

drawfillbox (0, 0, maxx, 20, brightgreen)
var player1locationX, player1locationY, player2locationX, player2locationY : int
var radius : int
radius := 15
player1locationX := 150
player1locationY := 20
player2locationX := 450
player2locationY := 20

drawfilloval (player1locationX, player1locationY, radius, radius, brightred)
drawfilloval (player1locationX, player1locationY, 3, 3, black)
drawfilloval (player2locationX, player2locationY, radius, radius, brightblue)
drawfilloval (player2locationX, player2locationY, 3, 3, black)

% variables for player 1's and 2's power
var power1, power2 : int
power1 := 0
power2 := 0

% p1angle and p2angle
var p1angle, p2angle : int
p1angle := 0
p2angle := 180

% small oval coordinates
var oval1X, oval1Y, oval2X, oval2Y : int
oval1X := 25 + player1locationX
oval1Y := player1locationY
oval2X := 25 + player2locationX
oval2Y := player2locationY

loop
    % movement variables
    var chars : array char of boolean
    Input.KeyDown (chars)
    if chars ('w') then
        p1angle := p1angle + 1
        delay (25)
    elsif chars ('s') then
        p1angle := p1angle - 1
        delay (25)
    end if

    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        p2angle := p2angle + 1
        delay (25)
    elsif chars (KEY_DOWN_ARROW) then
        p2angle := p2angle - 1
        delay (25)
    end if

    % set p1angle parameters
    if p1angle > 180 then
        p1angle := 180
    elsif p1angle < 0 then
        p1angle := 0
    end if

    if p2angle > 180 then
        p2angle := 180
    elsif p2angle < 0 then
        p2angle := 0
    end if

    % display the p1angle on the screen
    locate (1, 10)
    put "PLAYER 1's ANGLE:", p1angle, "  PLAYER 1's POWER: ", power1
    % display the p2angle on the screen
    locate (2, 10)
    put "PLAYER 2's ANGLE:", p2angle, "  PLAYER 2's POWER: ", power2

    %Keys for player 1 to change their power
    Input.KeyDown (chars)
    if chars ('d') then
        power1 := power1 + 1
        drawfillbox (50, 450, 50 + power1, 470, brightred)
        delay (25)
    end if

    % keys for player 2 to change their power
    Input.KeyDown (chars)
    if chars (KEY_RIGHT_ARROW) then
        power2 := power2 + 1
        drawfillbox (850, 450, 850 + power2, 470, brightblue)
        delay (25)
    end if

    % for player 1's missile must go up, and then come down at a certain time
    % put time in a for loop
    for t : 1 .. 100
        % name missile variables
        var health1 : int
        health1 := 100
        locate (1, 60)
        put "HP = ", health1
        var currentXlocation1, currentYlocation1, gravity : real
        gravity := -1
        currentXlocation1 := player1locationX + (cosd (p1angle) * power1 * t) % calculate the missiles current x position
        currentYlocation1 := player1locationY + (sind (p1angle) * power1 * t + 0.5 * gravity * (t) ** 2) % calculate the missiles current y position
        % draw player 1's missile missile
        Input.KeyDown (chars)
        if chars ('q') and currentYlocation1 < 15 then
            drawfilloval (round (currentXlocation1), round (currentYlocation1), 3, 3, black)
            for c : 1 .. 15
                drawfilloval (round (currentXlocation1), round (currentYlocation1), c, c, white)
                delay (10)
            end for
        end if
    end for

    % for player 2's missile must go up, and then come down at a certain time
    % put time in a for loop
    for t : 1 .. 100
        % name missile variables
        var health2 : int
        health2 := 100
        locate (2, 60)
        put "HP = ", health2
        var currentXlocation2, currentYlocation2, gravity : real
        gravity := -1
        currentXlocation2 := player2locationX + (cosd (p2angle) * power2 * t) % calculate ht emissiles current x position
        currentYlocation2 := player2locationY + (sind (p2angle) * power2 * t + 0.5 * gravity * (t) ** 2) % calculate the missile current y position
        % draw player 2's missile missile
        Input.KeyDown (chars)
        if chars (KEY_ENTER) and currentYlocation2 < 15 then
            drawfilloval (round (currentXlocation2), round (currentYlocation2), 3, 3, black)
            for c : 1 .. 15
                drawfilloval (round (currentXlocation2), round (currentYlocation2), c, c, white)
                delay (10)
            end for
        end if
    end for
    View.Update
end loop

Author:  syntax_error [ Tue Jan 15, 2008 8:17 pm ]
Post subject:  Re: help with an exit when statement!

life would be soo much easier if you simple used procs
so hey heres a thought use procs and then the whole loop issue will be soo much simpler for you
to get on your own
I know not an answer you wanted *my heart bleeds* BooHoo but its a good choice [!]

Author:  ericfourfour [ Tue Jan 15, 2008 9:15 pm ]
Post subject:  RE:help with an exit when statement!

You are going to have to store each crater you make. Look into arrays and records. There are guides in the Turing Walkthrough.


: