Computer Science Canada

counter

Author:  TrAnCeIn4LiFe [ Sun Jun 13, 2004 11:55 am ]
Post subject:  counter

anybody know what is wrong with my life counter Sad it wont take lfie away when it touches the enmy.. then when it reaches zero on x axis

code:



    var exr, eyt, xre, xle, yte, ybe : int := 0     % local variable for enemy

    %/%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %  Randomize Enemy's and Location    %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\%

    randint (eyt, 0, maxx)
    for decreasing x : maxy .. 1
        exr += +xre + xle     % x postion of enemy
        eyt += +yte + ybe     % y postion of enemy
        randomize
        randint (num, 1, 4)     % randomizes 4 enemys to be displayed on the screen
        Pic.Draw (sprite3 (num), eyt, exr + x, picMerge)     % draws the random enemy on the screen
    end for

    %/%%%%%%%%%%%%%%%%%%
    %  Life Counter    %
    %%%%%%%%%%%%%%%%%%\%

    % bxr += +xl + xr
    % byt += +yb + yt
    % exr += +xre + xle
    % eyt += +yte + ybe

    if (xl = xle) and (xr = xre) and (yb = ybe) and (yt = yte) then
        planelife := planelife - 1     % subtracts 1 life if the enemy touches you
    end if

                bxr += +xl + xr     % x position of plane
                byt += +yb + yt     % y position of plane

        %/%%%%%%%%%%%%%%%%%
        %  Clear Modes    %
        %%%%%%%%%%%%%%%%%\%

        xl := 0
        xr := 0
        yt := 0
        yb := 0

Author:  Bizarro [ Sun Jun 13, 2004 12:04 pm ]
Post subject: 

Try this

if (xl>xbe) and (xr >= yte) then
planelife := planelife - 1

Instead of this

if (xl = xle) and (xr = xre) and (yb = ybe) and (yt = yte) then
planelife := planelife - 1

if not, then your going to have to ask the gomezian.

Author:  Tony [ Sun Jun 13, 2004 12:19 pm ]
Post subject: 

you seem to be checking for the collision outside of your loop Confused

Author:  TrAnCeIn4LiFe [ Sun Jun 13, 2004 1:25 pm ]
Post subject: 

hum i cant move them inside the loop with other stuf....
this is what i got

code:
process enemy

    var exr, eyt, xre, xle, yte, ybe : int := 0     % local variable for enemy

    %/%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %  Randomize Enemy's and Location    %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\%

    randint (eyt, 0, maxx)
    for decreasing x : maxy .. 1
        exr += +xre + xle     % x postion of enemy
        eyt += +yte + ybe     % y postion of enemy
        randomize
        randint (num, 1, 4)     % randomizes 4 enemys to be displayed on the screen
        Pic.Draw (sprite3 (num), eyt, exr + x, picMerge)     % draws the random enemy on the screen
    end for

    %/%%%%%%%%%%%%%%%%%%
    %  Score Counter   %
    %%%%%%%%%%%%%%%%%%\%

    if (xre = 0 and xle = 0) then
        plane_count := plane_count + 50     % for every plane to reach 0 adds 50 points to final score
    end if

    %/%%%%%%%%%%%%%%%%%%
    %  Life Counter    %
    %%%%%%%%%%%%%%%%%%\%

    % bxr += +xl + xr
    % byt += +yb + yt
    % exr += +xre + xle
    % eyt += +yte + ybe

    if (xl = xle) and (xr = xre) and (yb = ybe) and (yt = yte) then
        planelife := planelife - 1     % subtracts 1 life if the enemy touches you
    end if

    %/%%%%%%%%%%%%%%%%%%%%
    %  Draw Life Bars    %
    %%%%%%%%%%%%%%%%%%%%\% for different amount of life you have
    loop
        if planelife = 5 then
            Pic.Draw (sprite1 (1), 0, 160, picMerge)
        elsif planelife = 4 then
            Pic.Draw (sprite1 (2), 0, 160, picMerge)
        elsif planelife = 3 then
            Pic.Draw (sprite1 (3), 0, 160, picMerge)
        elsif planelife = 2 then
            Pic.Draw (sprite1 (4), 0, 160, picMerge)
        elsif planelife = 1 then
            Pic.Draw (sprite1 (5), 0, 160, picMerge)
        else
            endin
        end if
    end loop
end enemy

procedure fly

    View.Set ("offscreenonly,nobuttonbar")
    setscreen ("graphics:maxx;maxy,noecho,nocursor")

    %/%%%%%%%%%%%%%%%%%%%%%%%%%%
    %  Input Keys For Plane    %
    %%%%%%%%%%%%%%%%%%%%%%%%%%\%

    loop
        Input.KeyDown (chars)
        if chars (KEY_UP_ARROW) then
            for x : 1 .. 1
                xx (x) := x
                yt := 8
            end for
        elsif chars (KEY_RIGHT_ARROW) then
            for x : 1 .. 1
                xx (x) := 2
                xr := 8
            end for
        elsif chars (KEY_DOWN_ARROW) then
            for x : 1 .. 1
                xx (x) := x
                yb := yb - 8
            end for
        elsif chars (KEY_LEFT_ARROW) then
            for x : 1 .. 1
                xx (x) := x + 2
                xl := xl - 8
            end for
        end if

        %/%%%%%%%%%%%%%%%%%%%
        %  Move Airplane    %
        %%%%%%%%%%%%%%%%%%%\%

        if xx (1) > 0 then
            for x : 1 .. 1
                bxr += +xl + xr     % x position of plane
                byt += +yb + yt     % y position of plane
                Pic.Draw (background, 0, 0, picCopy)
                Pic.Draw (sprite1 (1), 0, 160, picMerge)
                Pic.Draw (sprite (xx (x)), bxr, byt, picMerge)
                Draw.Text ("S C O R E :", 5, 370, font, black)     % draws score bar
                Font.Draw (intstr (plane_count), 70, 370, font, black)     % converts score to string so it can aplly font
            end for
            View.Update
        end if

        %/%%%%%%%%%%%%%%%%%
        %  Boundries      %
        %%%%%%%%%%%%%%%%%\%

        for x : 1 .. 1
            if byt >= maxy then
                byt := maxy - 15
                Pic.Draw (sprite (x), xr, xl, picMerge)
            elsif byt = -40 then
                byt := 40
                Pic.Draw (sprite (x), xr, xl, picMerge)
            elsif bxr >= maxx then
                bxr := maxx - 80
                Pic.Draw (sprite (x), yb, yt, picMerge)
            elsif bxr = -40 then
                bxr := 40
                Pic.Draw (sprite (x), yb, yt, picMerge)
            end if
        end for

        %/%%%%%%%%%%%%%%%%%
        %  Clear Modes    %
        %%%%%%%%%%%%%%%%%\%

        xl := 0
        xr := 0
        yt := 0
        yb := 0

        fork enemy

    end loop

end fly


: