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

Username:   Password: 
 RegisterRegister   
 sweet tank game
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
petree08




PostPosted: Fri Sep 22, 2006 11:11 am   Post subject: sweet tank game

code:
setscreen ("graphics:max,max,nobuttonbar,offscreenonly")
cls
var YesNo : string (2)
var Font1 : int := Font.New ("Arial:50")
var Font2 : int := Font.New ("Arial:20")
var Count1, Count2 : nat := 0
var X1, Y1, X2, Y2 : int
var Health1, Health2 : int := 0
var XS1, XS2, YS1, YS2 : int
var Hit1, Hit2, Bang, Bang2 : boolean := false
var Right2, Left2, Up2, Down2 : boolean := false
var Right1, Left1, Up1, Down1 : boolean := false
var Key : array char of boolean
var Ch : char
procedure Pause

    Ch := getchar
end Pause





% shooting procedures
process Shot2
    Hit2 := true
    XS2 := X2
    YS2 := Y2
    if Up2 = true then
        loop
            Count2 += 1
            YS2 := YS2 + 1
            delay (0)
            exit when Count2 >= 1000
        end loop

    elsif Down2 = true then
        loop
            Count2 += 1
            YS2 := YS2 - 1
            delay (0)
            exit when Count2 >= 1000
        end loop

    elsif Right2 = true then
        loop
            Count2 += 1
            XS2 := XS2 + 1
            delay (0)
            exit when Count2 >= 1000
        end loop

    elsif Left2 = true then
        loop
            Count2 += 1
            XS2 := XS2 - 1
            delay (0)
            exit when Count2 >= 1000
        end loop

    end if
    Count2 := 0
    Hit2 := false
end Shot2

process Shot1
    Hit1 := true
    XS1 := X1
    YS1 := Y1
    if Up1 = true then
        loop
            Count1 += 1
             delay (0)
            YS1 := YS1 + 1
            exit when Count1 >= 1000
        end loop

    elsif Down1 = true then
        loop
            Count1 += 1
            YS1 := YS1 - 1
            delay (0)
            exit when Count1 >= 1000
        end loop

    elsif Right1 = true then
        loop
            Count1 += 1
            delay (0)
            XS1 := XS1 + 1
            exit when Count1 >= 1000
        end loop

    elsif Left1 = true then
        loop
            Count1 += 1
            XS1 := XS1 - 1
            exit when Count1 >= 1000
        end loop

    end if
    Count1 := 0
    Hit1 := false
end Shot1



const Midx := maxx div 2
const Midy := maxy div 2
colorback (7)
loop



    cls
    Font.Draw ("TANK-FIGHTERZ", 50, Midy, Font1, 10)
    Font.Draw ("press any key to continue", 50, Midy - 100, Font2, 12)
    Font.Draw ("made by Peter Watt", 50, Midy - 200, Font2, 0)
    View.Update
    Pause


    Health1 := 0
    Health2 := 0
    X1 := 10
    Y1 := Midy - 100

    X2 := maxx - 10
    Y2 := Midy + 100

    Left1 := true
    Right2 := true
    cls
    color (0)

    put " the object of this game is to destroy your apponent "
    put ""
    put ""
    color (12)
    put "Player1 controls "
    put ""
    put "Up    : Up arrow "
    put "Down  : Down arrow"
    put "Left  : Left Arrow"
    put "Right : Right Arrow"
    put "Shoot : Enter Key"
    put ""
    put ""
    color (10)
    put "Player 2 controls"
    put "Up    : w key "
    put "Down  : s key"
    put "Left  : a key"
    put "Right :  d key"
    put "Shoot : Space bar"
    color (0)
    put "press any key to continue"
    View.Update
    Pause


    loop
        cls
        %player boundries
        if X1 >= maxx then
            X1 := X1 - 2
        elsif X1 <= 1 then
            X1 := X1 + 2
        elsif Y1 >= maxy then
            Y1 := Y1 - 2
        elsif Y1 <= 1 then
            Y1 := Y1 + 2

        end if

        if X2 >= maxx then
            X2 := X2 - 2
        elsif X2 <= 1 then
            X2 := X2 + 2
        elsif Y2 >= maxy then
            Y2 := Y2 - 2
        elsif Y2 <= 1 then
            Y2 := Y2 + 2

        end if
        drawline (Midx, 1, Midx, maxy, 0)
        Input.KeyDown (Key)
        if Key (KEY_DOWN_ARROW) then
            Down1 := true
            Up1 := false
            Right1 := false
            Left1 := false
            Y1 := Y1 - 2

        elsif Key (KEY_UP_ARROW) then
            Up1 := true
            Down1 := false
            Right1 := false
            Left1 := false
            Y1 := Y1 + 2


        elsif Key (KEY_LEFT_ARROW) then
            Up1 := false
            Down1 := false
            Right1 := false
            Left1 := true
            X1 := X1 - 2


        elsif Key (KEY_RIGHT_ARROW) then
            Up1 := false
            Down1 := false
            Right1 := true
            Left1 := false
            X1 := X1 + 2

        end if




        % player 2 controls
        if Key ('s') then
            Down2 := true
            Up2 := false
            Right2 := false
            Left2 := false
            Y2 := Y2 - 2

        elsif Key ('w') then
            Up2 := true
            Down2 := false
            Right2 := false
            Left2 := false
            Y2 := Y2 + 2


        elsif Key ('a') then
            Up2 := false
            Down2 := false
            Right2 := false
            Left2 := true
            X2 := X2 - 2


        elsif Key ('d') then
            Up2 := false
            Down2 := false
            Right2 := true
            Left2 := false
            X2 := X2 + 2

        end if

        if Key (' ') and Hit2 = false and Bang = false then
            fork Shot2
        end if
        if Hit2 = true then
            drawfilloval (XS2, YS2, 3, 3, 10)
        end if

        if Key (KEY_ENTER) and Hit1 = false and Bang2 = false then
            fork Shot1
        end if
        if Hit1 = true then
            drawfilloval (XS1, YS1, 3, 3, 12)
        end if



        % draw player 1
        if Up1 = true then
            % lefty WIng
            drawfillbox (X1 - 5, Y1 - 20, X1 - 10, Y1 + 7, 15)
            %righty
            drawfillbox (X1 + 5, Y1 - 20, X1 + 10, Y1 + 7, 15)
            % BODY
            drawfillbox (X1 - 5, Y1 - 14, X1 + 5, Y1 + 5, red)
            %COCKPIT
            drawfillbox (X1 - 2, Y1 - 5, X1 + 2, Y1 + 10, 15)
            drawfilloval (X1, Y1 - 3, 4, 4, 15)
        elsif Down1 = true then

            % lefty WIng
            drawfillbox (X1 - 5, Y1 - 17, X1 - 10, Y1 + 10, 15)
            %righty
            drawfillbox (X1 + 5, Y1 - 17, X1 + 10, Y1 + 10, 15)
            % BODY
            drawfillbox (X1 - 5, Y1 - 14, X1 + 5, Y1 + 5, red)
            %COCKPIT
            drawfillbox (X1 - 2, Y1 - 2, X1 + 2, Y1 - 19, 15)
            drawfilloval (X1, Y1 - 5, 4, 4, 15)

        elsif Left1 = true then

            % lefty WIng
            drawfillbox (X1 - 17, Y1 + 5, X1 + 10, Y1 + 10, 15)
            %righty
            drawfillbox (X1 - 17, Y1 - 5, X1 + 10, Y1 - 10, 15)
            % BODY
            drawfillbox (X1 - 14, Y1 - 5, X1 + 5, Y1 + 5, red)
            %COCKPIT
            drawfillbox (X1 - 2, Y1 - 2, X1 - 19, Y1 + 2, 15)
            drawfilloval (X1 - 5, Y1, 4, 4, 15)

        elsif Right1 = true then

            % lefty WIng
            drawfillbox (X1 - 20, Y1 + 5, X1 + 8, Y1 + 10, 15)
            %righty
            drawfillbox (X1 - 20, Y1 - 5, X1 + 8, Y1 - 10, 15)
            % BODY
            drawfillbox (X1 - 14, Y1 - 5, X1 + 5, Y1 + 5, red)
            %COCKPIT
            drawfillbox (X1 - 2, Y1 - 2, X1 + 12, Y1 + 2, 15)
            drawfilloval (X1 - 5, Y1, 4, 4, 15)

        end if
        %drawplayer 2
        if Up2 = true then
            % lefty WIng
            drawfillbox (X2 - 5, Y2 - 20, X2 - 10, Y2 + 7, 15)
            %righty
            drawfillbox (X2 + 5, Y2 - 20, X2 + 10, Y2 + 7, 15)
            % BODY
            drawfillbox (X2 - 5, Y2 - 14, X2 + 5, Y2 + 5, 2)
            %COCKPIT
            drawfillbox (X2 - 2, Y2 - 5, X2 + 2, Y2 + 10, 15)
            drawfilloval (X2, Y2 - 3, 4, 4, 15)
        elsif Down2 = true then

            % lefty WIng
            drawfillbox (X2 - 5, Y2 - 17, X2 - 10, Y2 + 10, 15)
            %righty
            drawfillbox (X2 + 5, Y2 - 17, X2 + 10, Y2 + 10, 15)
            % BODY
            drawfillbox (X2 - 5, Y2 - 14, X2 + 5, Y2 + 5, 2)
            %COCKPIT
            drawfillbox (X2 - 2, Y2 - 2, X2 + 2, Y2 - 19, 15)
            drawfilloval (X2, Y2 - 5, 4, 4, 15)

        elsif Left2 = true then

            % lefty WIng
            drawfillbox (X2 - 17, Y2 + 5, X2 + 10, Y2 + 10, 15)
            %righty
            drawfillbox (X2 - 17, Y2 - 5, X2 + 10, Y2 - 10, 15)
            % BODY
            drawfillbox (X2 - 14, Y2 - 5, X2 + 5, Y2 + 5, 2)
            %COCKPIT
            drawfillbox (X2 - 2, Y2 - 2, X2 - 19, Y2 + 2, 15)
            drawfilloval (X2 - 5, Y2, 4, 4, 15)

        elsif Right2 = true then

            % lefty WIng
            drawfillbox (X2 - 20, Y2 + 5, X2 + 8, Y2 + 10, 15)
            %righty
            drawfillbox (X2 - 20, Y2 - 5, X2 + 8, Y2 - 10, 15)
            % BODY
            drawfillbox (X2 - 14, Y2 - 5, X2 + 5, Y2 + 5, 2)
            %COCKPIT
            drawfillbox (X2 - 2, Y2 - 2, X2 + 12, Y2 + 2, 15)
            drawfilloval (X2 - 5, Y2, 4, 4, 15)

        end if

        if Hit1 = true and Bang = false and YS1 > Y2 - 20 and YS1 < Y2 + 20 and XS1 > X2 - 20 and XS1 < X2 + 20 then
            Health1 += 5

        end if
        if Hit2 = true and Bang2 = false and YS2 > Y1 - 20 and YS2 < Y1 + 20 and XS2 > X1 - 20 and XS2 < X1 + 20 then
            Health2 += 5

        end if


        color (10)
        put "Green tanks damage: ", Health1, " %" : 10 ..
        color (12)
        put "Red tanks damage: ", Health2, " %"
        exit when Health1 >= 100 or Health2 >= 100
        View.Update
    end loop
    cls

    if Health2 >= 100 then
        Font.Draw ("The green tank wins!", 1, Midy, Font1, 10)
    else
        Font.Draw ("The red tank wins!", 1, Midy, Font1, 12)
    end if
    put " Would you like to play again? (y/n?"
    View.Update
    get YesNo
    exit when YesNo = "n"
end loop


mod edit: added tags
Sponsor
Sponsor
Sponsor
sponsor
viperfan7




PostPosted: Wed Nov 08, 2006 7:39 pm   Post subject: (No subject)

ok heres a tip, put the source code in the middle of 2 code tags by first pressing the Code button next to the Quotes and type in the code, then press the Code button again, makes it easeir to understand, and sorry for necroposting[/code]
DemonZ




PostPosted: Thu Nov 09, 2006 3:31 pm   Post subject: (No subject)

the tank game is alright, but there is a bug with not being able to exit the program, and you could have made a menu for user friendlyness, overall, the game is ok, but there is a problem with some of the controls are locking up. but other than that, a good game.
BenLi




PostPosted: Thu Nov 09, 2006 6:28 pm   Post subject: (No subject)

well someone necro posted... so what the heck...

code:

        Input.KeyDown (Key)
        if Key (KEY_DOWN_ARROW) then
            Down1 := true
            Up1 := false
            Right1 := false
            Left1 := false
            Y1 := Y1 - 2

        elsif Key (KEY_UP_ARROW) then
            Up1 := true
            Down1 := false
            Right1 := false
            Left1 := false
            Y1 := Y1 + 2


        elsif Key (KEY_LEFT_ARROW) then
            Up1 := false
            Down1 := false
            Right1 := false
            Left1 := true
            X1 := X1 - 2


        elsif Key (KEY_RIGHT_ARROW) then
            Up1 := false
            Down1 := false
            Right1 := true
            Left1 := false
            X1 := X1 + 2

        end if


a very small change of seperating the if structures would allow for diagonal movement

code:

        Input.KeyDown (Key)
        if Key (KEY_DOWN_ARROW) then
            Down1 := true
            Up1 := false
            Right1 := false
            Left1 := false
            Y1 := Y1 - 2

        elsif Key (KEY_UP_ARROW) then
            Up1 := true
            Down1 := false
            Right1 := false
            Left1 := false
            Y1 := Y1 + 2
        end if

        if Key (KEY_LEFT_ARROW) then
            Up1 := false
            Down1 := false
            Right1 := false
            Left1 := true
            X1 := X1 - 2


        elsif Key (KEY_RIGHT_ARROW) then
            Up1 := false
            Down1 := false
            Right1 := true
            Left1 := false
            X1 := X1 + 2

        end if
[/quote]
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: