Computer Science Canada

Target Shooter

Author:  petree08 [ Thu Nov 02, 2006 12:00 pm ]
Post subject:  Target Shooter

This is a game in witch you have 2 shoot has many targets as you can with the mouse.

I kinda jazzed it up a bit by adding my logo and a tittle screen (that looks kinda old shool)

Have Fun!

code:


const TIME_T := 60
const TARGET_NUM := 10
const C_C := 0
var TimeLeft : int := TIME_T
var IntToString : string
var Font1 : int := Font.New ("Arial:20")
var Font2 : int := Font.New ("System:50")
var Font3 : int := Font.New ("System:140")
var Score : int := 0
var Hitter : boolean
var Pauser : char
var Index2 : nat := 1
var Xm, Ym, Click : int
var Clicker : boolean := false
var X, Y, Dx, Dy : array 1 .. TARGET_NUM of int
var Length : array 1 .. TARGET_NUM of real4
var Hit, Miss : nat1 := 0
var YesNo : string (2)

process Bang
    sound (200, 100)
end Bang

procedure Crosshairs

    drawline (Xm - 30, Ym, Xm - 5, Ym, C_C)
    drawline (Xm + 30, Ym, Xm + 5, Ym, C_C)
    drawline (Xm, Ym - 30, Xm, Ym - 5, C_C)
    drawline (Xm, Ym + 30, Xm, Ym + 5, C_C)

    Draw.ThickLine (Xm - 100, Ym, Xm - 30, Ym, 5, C_C)
    Draw.ThickLine (Xm + 100, Ym, Xm + 30, Ym, 5, C_C)
    Draw.ThickLine (Xm, Ym - 100, Xm, Ym - 30, 5, C_C)
    Draw.ThickLine (Xm, Ym + 100, Xm, Ym + 30, 5, C_C)


    drawoval (Xm, Ym, 100, 100, C_C)
    drawoval (Xm, Ym, 30, 30, C_C)

    drawfilloval (Xm, Ym, 3, 3, 12)


end Crosshairs


procedure Random

    for Index : 1 .. TARGET_NUM
        randint (X (Index), 1, maxx)
        randint (Y (Index), 1, maxy)

        loop
            randint (Dx (Index), -1, 1)
            exit when Dx (Index) not= 0
        end loop
        loop
            randint (Dy (Index), -1, 1)
            exit when Dy (Index) not= 0
        end loop
    end for
end Random
process Timer
    loop
        delay (1000)
        TimeLeft := TimeLeft - 1
        exit when TimeLeft <= 0
    end loop
end Timer

procedure Pause
    Pauser := getchar
end Pause

procedure Logo
    colorback (0)

    cls
    Font.Draw ("W", 300, 300, Font3, 7)
    View.Update
    delay (100)
    Font.Draw ("W", 305, 305, Font3, 4)
    View.Update
    delay (100)
    Font.Draw ("PEE-TORE", 200, 300, Font2, 7)
    View.Update
    delay (100)
    Font.Draw ("PEE-TORE", 205, 305, Font2, 12)
    View.Update
    delay (1000)

    Font.Draw ("**PEE-TORE GAMES**", 200, 100, Font1, 12)
    View.Update
    delay (2000)
end Logo



setscreen ("graphics:max,max,nobuttonbar,offscreenonly")

Logo

colorback (7)
loop
    Random
    cls

    Font.Draw ("DISC SHOOTER", maxx div 2 - 200, maxy - 200, Font2, 12)
    Font.Draw ("**PEE-TORE GAMES** presents: ", 200, maxy - 100, Font1, 12)
    Font.Draw ("(press any key to continue) ", 200, maxy - 300, Font1, 12)
    View.Update
    Pause

    cls
    Font.Draw ("The object of this game is to shoot has many targets as you can"
        , 1, maxy - 50, Font1, 12)
    Font.Draw ("with in the time limit."
        , 1, maxy - 100, Font1, 12)

    Font.Draw ("(press any key to continue)", 1, maxy - 150, Font1, 12)
    View.Update
    Pause

    for decreasing CountDown : 3 .. 0
        cls
        IntToString := intstr (CountDown)

        Font.Draw (IntToString, maxx div 2, maxy div 2, Font1, 12)
        View.Update
        delay (1000)
    end for


    TimeLeft := TIME_T
    Score := 0
    Hit := 0
    Miss := 0
    fork Timer
    loop

        cls




        mousewhere (Xm, Ym, Click)

        for Index : 1 .. TARGET_NUM
            if X (Index) >= maxx or X (Index) <= 1 then
                Dx (Index) := -Dx (Index)
            end if

            if Y (Index) >= maxy or Y (Index) <= 1 then
                Dy (Index) := -Dy (Index)
            end if
            Y (Index) := Y (Index) + Dy (Index)
            X (Index) := X (Index) + Dx (Index)
            drawfilloval (X (Index), Y (Index), 15, 15, 12)
            drawfilloval (X (Index), Y (Index), 10, 10, 0)
            drawfilloval (X (Index), Y (Index), 5, 5, 12)
        end for


        % Shooting and checking if a target was hit

        if Click = 1 and Clicker = false then
            fork Bang
            Index2 := 1
            Clicker := true
            Hitter := false
            loop
                % find length between mouse and targets
                Length (Index2) := sqrt ((X (Index2) - Xm) ** 2 + (Y (Index2) - Ym) ** 2)
                % check if the length is within the range of the radius of the disc
                if Length (Index2) < 15 then

                    Hitter := true % used for to flag if a target was hit
                    Hit := Hit + 1
                    Score := Score + 50
                    randint (X (Index2), 1, maxx)
                    randint (Y (Index2), 1, maxy)
                else
                    Hitter := false
                end if
                exit when Hitter = true or Index2 >= TARGET_NUM %
                Index2 := Index2 + 1  % bumps the target being checked


            end loop
            if Hitter = false then
                Miss := Miss + 1
                Score := Score - 100
            end if
        elsif Click = 0 then
            Clicker := false
        end if
        Crosshairs

        IntToString := intstr (Hit)

        Font.Draw ("Hit :" + IntToString, 10, 10, Font1, C_C)


        IntToString := intstr (Miss)

        Font.Draw ("Miss :" + IntToString, 100, 10, Font1, C_C)
        IntToString := intstr (Score)

        Font.Draw ("Score :" + IntToString, 250, 10, Font1, C_C)

        IntToString := intstr (TimeLeft)

        Font.Draw ("Time left :" + IntToString, 10, maxy - 20, Font1, C_C)



        % put "Hit: ", Hit
        % put "Missed: ", Miss
        % put "Score ", Score

        exit when TimeLeft <= 0
        View.Update
    end loop
    cls

    Font.Draw ("Times Up!", maxx div 2, maxy - 100, Font2, 12)
    IntToString := intstr (Score)

    Font.Draw ("Your score was " + IntToString, maxx div 2, maxy - 200, Font1, 12)


    Font.Draw ("Would you like to play again? (y/n)", maxx div 2 - 100, maxy - 300, Font1, 12)
    View.Update
    get YesNo
    exit when YesNo = "n"
end loop



: