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

Username:   Password: 
 RegisterRegister   
 FINALLY DONE PONG!!!!!!!!!!!!!!!!!!
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
WhatDotColourMaster




PostPosted: Mon Dec 05, 2005 4:35 pm   Post subject: FINALLY DONE PONG!!!!!!!!!!!!!!!!!!

Well, This is IT!!!!! I finally finished PONG RPG. I know many of you might have already done this but im excited because it took me a long time(trust me) to figure out this(especially the variables).I recomended many kids in my class to check this site out, so they could learn from this site. Well have fun playing PONG.

Any Comments always appreciated...


code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%PONG RPG Final Version 1.01%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


setscreen ("graphics:vga,nocursor,noecho,title:Pong RPG")
cls


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%VARIABLES%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


var ballx, bally, font, font2, font3, point, point1 : int := 100
var level1, level2, speed, paddle1, paddle, difficult, bdelay : int := 1
var xchange, ychange, hits, txc, tyc, font1 : int := 5
var plength1, plength2 : real := 20
var cooldowns : array 1 .. 9 of int
var first, right, up, freezed, ok, abil, gameon : boolean := true
var key, key1 : string (1)
var font4, font5, font6, choice : int
font4 := Font.New ("Arial:100:bold")
font5 := Font.New ("Arial:80:bold")
font := Font.New ("Arial:20:bold")
font1 := Font.New ("Arial:15:bold")
font6 := Font.New ("Arial:40:bold")
font2 := Font.New ("Arial:10")
font3 := Font.New ("Arial:7")
var name : array 1 .. 9 of string
point1 := 0
point := 0
hits := 0
paddle1 := 250
paddle := 250
speed := 15

var barrier, backbarrier, PU, change, already, able : boolean := false
var error, distance, paddlespeed, errormax, currabil, cooldown : int
var multi : real

name (1) := "Panic"
name (2) := "Super Panic"
name (3) := "Integrated Defence"
name (4) := "Angles"
name (5) := "Weighted Ball"
name (6) := "Freeze"
name (7) := "Slow"
name (8) := "Really Slow"
name (9) := "Public Enemy"
cooldowns (1) := 60000
cooldowns (2) := 60000
cooldowns (3) := 0
cooldowns (4) := 30000
cooldowns (5) := 45000
cooldowns (6) := 90000
cooldowns (7) := 60000
cooldowns (8) := 60000
cooldowns (9) := 60000



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%BACKGROUND%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


procedure gameover
    if point = 10
            then
        cls
        loop
            Font.Draw ("YOU WIN!!", 50, 200, font4, 9)
            Font.Draw ("YOU WIN!!", 53, 203, font4, 12)
            Font.Draw ("YOU WIN!!", 56, 206, font4, 10)
            Font.Draw ("YOU WIN!!", 59, 209, font4, 14)
            delay (200)
            cls
            Font.Draw ("YOU WIN!!", 50, 200, font4, 12)
            Font.Draw ("YOU WIN!!", 53, 203, font4, 10)
            Font.Draw ("YOU WIN!!", 56, 206, font4, 14)
            Font.Draw ("YOU WIN!!", 59, 209, font4, 9)
            delay (200)
            cls
            Font.Draw ("YOU WIN!!", 50, 200, font4, 10)
            Font.Draw ("YOU WIN!!", 53, 203, font4, 14)
            Font.Draw ("YOU WIN!!", 56, 206, font4, 9)
            Font.Draw ("YOU WIN!!", 59, 209, font4, 12)
            delay (200)
            cls
        end loop
    elsif point1 = 10
            then
        cls
        loop
            Font.Draw ("YOU LOSE!!", 50, 200, font4, 9)
            Font.Draw ("YOU LOSE!!", 53, 203, font4, 12)
            Font.Draw ("YOU LOSE!!", 56, 206, font4, 10)
            Font.Draw ("YOU LOSE!!", 59, 209, font4, 14)
            delay (200)
            cls
            Font.Draw ("YOU LOSE!!", 50, 200, font4, 12)
            Font.Draw ("YOU LOSE!!", 53, 203, font4, 10)
            Font.Draw ("YOU LOSE!!", 56, 206, font4, 14)
            Font.Draw ("YOU LOSE!!", 59, 209, font4, 9)
            delay (200)
            cls
            Font.Draw ("YOU LOSE!!", 50, 200, font4, 10)
            Font.Draw ("YOU LOSE!!", 53, 203, font4, 14)
            Font.Draw ("YOU LOSE!!", 56, 206, font4, 9)
            Font.Draw ("YOU LOSE!!", 59, 209, font4, 12)
            delay (200)
            cls
        end loop
    end if
end gameover

procedure background
    drawfillbox (0, 0, 640, 90, 15)
    drawfillbox (2, 2, 638, 88, 7)
    drawfillbox (2, 2, 270, 88, 1)
    drawfilloval (270, 45, 20, 43, 1)
    drawfillbox (370, 2, 638, 88, 2)
    drawfilloval (370, 45, 20, 43, 2)
    drawfilloval (320, 45, 10, 10, 14)
    Font.Draw ("Pong", 297, 60, font, 0)
    Font.Draw ("Pong", 298, 61, font, 15)
    Font.Draw ("RPG", 300, 10, font, 0)
    Font.Draw ("RPG", 301, 11, font, 15)
    Font.Draw ("Current Ability:", 20, 60, font, 15)
    Font.Draw (name (currabil), 90, 30, font, 8)
    Font.Draw (name (currabil), 92, 31, font, 14)
    Font.Draw ("Time Left Until Next Usage:", 10, 10, font2, 15)
    cooldown := cooldowns (currabil)
    Font.Draw (intstr (round (cooldown / 1000)) + " Seconds", 145, 10,
        font2, 12)
end background


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%PROCEDURES/PROCESSES/FUNCTIONS%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

process gameovermusic
    loop
        if gameon = false
                then
            Music.PlayFile ("gameover.wav")
        end if
    end loop
end gameovermusic

process backmusic
    loop
        if gameon = true
                then
            Music.PlayFile ("Back.wav")
            delay (500)
        end if
    end loop
end backmusic

process intromusic
    Music.PlayFile ("intro.wav")
end intromusic

procedure intro
    fork intromusic
    delay (2500)
    for i : 1 .. 500
        Font.Draw ("PONG!!", - 400 + i, 220, font4, 15)
        delay (1)
        drawfillbox ( - 410 + i, 220, i, 500, 0)
        %Font.Draw ("PONG!!", - 400 + i, 220, font4, 0)
    end for

    Font.Draw ("PONG!!", 100, 220, font4, 15)
    delay (1900)
    Font.Draw ("RPG", 290, 130, font5, 1)
    delay (1700)
    Font.Draw ("RPG", 293, 133, font5, 9)
    delay (410)
    Font.Draw ("RPG", 287, 133, font5, 9)
    delay (410)
    Font.Draw ("RPG", 293, 130, font5, 9)
    delay (410)
    Font.Draw ("RPG", 287, 130, font5, 9)
    delay (2000)
    Font.Draw ("Press Any Key To Continue...", 50, 60, font, 15)
    getch (key)
    cls
end intro

procedure afterintro
    Font.Draw ("Choose A Difficulty Setting", 40, 300, font6, 1)
    Font.Draw ("Choose A Difficulty Setting", 43, 303, font6, 9)
    Font.Draw ("1. Easy", 40, 240, font6, 12)
    Font.Draw ("2. Normal", 40, 180, font6, 12)
    Font.Draw ("3. ARE YOU INSANE?!", 40, 120, font6, 12)
    getch (key)
    if key = "1" or key = "2" or key = "3"
            then
        difficult := strint (key)
    else
        difficult := 3
    end if
    cls
    Font.Draw ("Choose An Ability To Master", 0, 400, font6, 1)
    Font.Draw ("Choose An Ability To Master", 3, 403, font6, 9)
    Font.Draw ("1. Defence", 40, 240, font6, 12)
    Font.Draw ("2. Ball Manipulation", 40, 180, font6, 12)
    Font.Draw ("3. Offence", 40, 120, font6, 12)
    getch (key)
    if key = "1" or key = "2" or key = "3"
            then
        choice := strint (key)
    else
        choice := 2
    end if

    if key = "1"
            then
        currabil := 1
    elsif key = "2"
            then
        currabil := 4
    elsif key = "3"
            then
        currabil := 7
    end if
    Music.PlayFile ("stop.wav")
end afterintro

process abilities
    if able = true
            then
        %%%%%PANIC%%%%%
        if currabil = 1
                then
            barrier := true
            Font.Draw ("Barrier Active", 160, 35, font1, 12)
            delay (5000)
            Font.Draw ("Barrier Active", 160, 35, font1, 1)
            barrier := false
            %%%%%ADVANCED PANIC%%%%%
        elsif currabil = 2
                then
            Font.Draw ("Barrier Active", 160, 35, font1, 12)
            barrier := true
            delay (10000)
            Font.Draw ("Barrier Active", 160, 35, font1, 1)
            barrier := false
            %%%%%INTEGRATED DEFENCE%%%%%
        elsif currabil = 3
                then
            backbarrier := true
            %%%%%ANGLES%%%%%
        elsif currabil = 4
                then
            xchange := 5
            ychange := 5
            %%%%%WEIGHTED BALL%%%%%
        elsif currabil = 5
                then
            speed := speed * 2
            delay (5000)
            speed := round (speed / 1.5)
            %%%%%FREEZE%%%%%
        elsif currabil = 6
                then
            txc := xchange
            tyc := ychange
            xchange := 0
            ychange := 0
            delay (2000)
            xchange := txc
            ychange := tyc
            %%%%%SLOW%%%%%
        elsif currabil = 7
                then
            multi := multi * 2
            delay (2000)
            multi := multi / 2
            %%%%%REALLY SLOW%%%%%
        elsif currabil = 8
                then
            multi := multi * 3
            delay (2000)
            multi := round (multi / 3)
            %%%%%PUBLIC ENEMY%%%%%
        elsif currabil = 9
                then
            PU := true
            delay (10000)
            PU := false
        end if
        able := false
        cooldown := cooldowns (currabil)
    end if
end abilities

process playercontrol
    loop
        if gameon = true
                then
            getch (key1)
            if key1 = "q" or key1 = "Q"
                    then
                %Restrictions to stop paddle from going off screen%
                if paddle <= 435
                        then
                    paddle := paddle + 15
                end if
            elsif key1 = "a" or key1 = "A"
                    then
                %Restrictions to stop paddle from going on the lower panel%
                if paddle >= 145
                        then
                    paddle := paddle - 15
                end if
            end if


            if key1 = "z" or key = "Z"
                    then
                fork abilities
            end if


            delay (1)
        end if
    end loop
end playercontrol

procedure ballreset
    ballx := 320
    bally := 300
    paddle1 := 200
    paddle := 300
    speed := 15
    xchange := 5
    ychange := 5
    right := true
    up := true

    getch (key)
end ballreset

process cooldowncount
    loop
        if gameon = true
                then
            Font.Draw ("Time Left Until Next Usage:", 10, 10, font2, 15)
            Font.Draw (intstr (round (cooldown / 1000)) + " Seconds", 145,
                10,
                font2, 12)
            delay (1000)
            if gameon = true
                    then
                if cooldown - 1000 >= 0
                        then
                    cooldown := cooldown - 1000
                end if
                drawfillbox (145, 10, 190, 25, 1)
                Font.Draw ("Time Left Until Next Usage:", 10, 10, font2, 15)
                if currabil not= 3
                        then
                    Font.Draw (intstr (round (cooldown / 1000)) + " Seconds",
                        145,
                        10,
                        font2, 12)
                else
                    Font.Draw ("Passive", 145, 10, font2, 9)
                end if
                if cooldown = 0
                        then
                    able := true
                end if
            end if
        end if
    end loop
end cooldowncount

procedure ball
    loop
        drawfilloval (ballx, bally, 10, 10, 14)
        delay (10)
        drawfillbox (0, 90, 640, 480, 0)
        drawfillbox (610, paddle1 - 40, 620, paddle1 + 40, 2)
        drawfillbox (30, paddle - 40, 20, paddle + 40, 1)
        drawfillbox (640, 88, 0, 90, 15)
        drawfillbox (370, 2, 638, 88, 2)
        drawfillbox (2, 85, 270, 88, 1)
        if change = true
                then
            drawfillbox (2, 2, 270, 88, 1)
            change := false
            cooldown := cooldowns (currabil)
            Font.Draw (name (currabil), 90, 30, font, 8)
            Font.Draw (name (currabil), 92, 31, font, 14)
            Font.Draw ("Current Ability:", 20, 60, font, 15)
            able := false
        elsif change = false
                then
            Font.Draw (name (currabil), 90, 30, font, 8)
            Font.Draw (name (currabil), 92, 31, font, 14)
        end if

        Font.Draw ( (intstr (point)), 10, 450, font, 1)
        Font.Draw ( (intstr (point)), 11, 452, font, 9)
        Font.Draw ( (intstr (point1)), 615, 450, font, 2)
        Font.Draw ( (intstr (point1)), 616, 452, font, 10)

        if point = 10 or point1 = 10
                then
            gameon := false
            Music.PlayFile ("stop.wav")
            fork gameovermusic
            gameover
        end if

    end loop
end ball

if difficult = 1 or difficult = 2
        then
    multi := 1.6
else
    multi := 1.9
end if

process computerai
    %%Stupid computer AI...too much programming
    if difficult = 1
            then
        bdelay := 30
        errormax := 10
    elsif difficult = 2
            then
        bdelay := 25
        errormax := 15
    elsif difficult = 3
            then
        bdelay := 20
        errormax := 20
    end if

    loop
        if gameon = true
                then
            distance := 600 - ballx

            if difficult = 1 or difficult = 2
                    then
                if distance <= 150 and distance > 70
                        then
                    paddlespeed := 5 * round ( (difficult / multi))
                elsif distance <= 70
                        then
                    paddlespeed := 7 * round ( (difficult / multi))
                else
                    paddlespeed := 4 * round ( (difficult / multi))
                end if
            elsif difficult = 3
                    then
                if distance <= 60 and distance > 20
                        then
                    paddlespeed := 5 * round ( (difficult / multi))
                elsif distance <= 20
                        then
                    paddlespeed := 7 * round ( (difficult / multi))
                else
                    paddlespeed := 4 * round ( (difficult / multi))
                end if
            end if

            randint (error, 1, errormax)

            if error not= 1
                    then
                if bally > paddle1
                        then
                    paddle1 := paddle1 + paddlespeed
                elsif bally < paddle1
                        then
                    paddle1 := paddle1 - paddlespeed
                end if
            end if
            drawfillbox (610, paddle1 - 40, 620, paddle1 + 40, 2)
            delay (bdelay)
        end if
    end loop
end computerai


process check
    loop
        if gameon = true
                then
            var yeah : int

            if PU = true
                    then
                yeah := 2
            else
                yeah := 1
            end if

            if right = true
                    then
                ballx := (ballx + xchange) * yeah
                if up = true
                        then
                    bally := (bally + ychange) * yeah
                else
                    bally := (bally - ychange) * yeah
                end if
            else
                ballx := ballx - xchange
                if up = true
                        then
                    bally := bally + ychange
                else
                    bally := bally - ychange
                end if
            end if


            if ballx >= (maxx - 10) %HITS RIGHT SIDE%
                    then
                point := point + 1
                ballreset

            elsif ballx <= 10 %HITS LEFT SIDE%
                    then

                %Checks for Integrated Defence being active
                if backbarrier = true
                        then
                    var joe : int
                    randint (joe, 1, 3)
                    if joe = 1
                            then
                        barrier := true
                    end if
                end if
                if barrier = false
                        then
                    point1 := point1 + 1
                    ballreset
                else
                    right := true
                end if
                if backbarrier = true and barrier = true
                        then
                    barrier := false
                end if
            end if


            if bally >= (maxy - 10)
                    then
                up := false
            elsif bally <= 100
                    then
                up := true
            end if

            %locatexy (5, 470)
            %put hits


            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %%%%%%%%%%%%COLLISION CHECKER-DO NOT MODIFY!!!%%%%%%%%%%%%%%%%%%%%
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

            %collision check for computer paddle
            if ballx >= 600 and ballx <= 610
                    then

                %Lower checker
                if bally >= paddle1 - 40 and bally < paddle1 - 25
                        then
                    if up = true and right = true
                            then
                        ychange := ychange - 1
                    elsif up = false and right = true
                            then
                        ychange := ychange + 1
                    end if
                    right := false
                end if

                %Middle checker
                if bally >= paddle1 - 25 and bally <= paddle1 + 25
                        then
                    right := false
                end if

                %Upper checker
                if bally <= paddle1 + 40 and bally > paddle1 + 25
                        then
                    if up = true and right = true
                            then
                        ychange := ychange + 1
                    elsif up = false and right = true
                            then
                        ychange := ychange - 1
                    end if
                    right := false
                end if
                hits := hits + 1
            end if

            %collision check for PLAYER paddle
            if ballx >= 30 and ballx <= 40
                    then

                %Lower checker
                if bally >= paddle - 40 and bally < paddle - 25
                        then
                    if up = true and right = false
                            then
                        ychange := ychange - 1
                    elsif up = false and right = false
                            then
                        ychange := ychange + 1
                    end if
                    right := true
                end if

                %Middle checker
                if bally >= paddle - 25 and bally <= paddle + 25
                        then
                    right := true
                end if

                %Upper checker
                if bally <= paddle + 40 and bally > paddle + 25
                        then
                    if up = true and right = false
                            then
                        ychange := ychange + 1
                    elsif up = false and right = false
                            then
                        ychange := ychange - 1
                    end if
                    right := true
                end if
                hits := hits + 1
            end if

            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %%%%%%%%%%%%%%%%%%%%%%END COLLISION CHECKER%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


            if hits not= 0
                    then
                if ok = true
                        then
                    if hits mod 5 = 0
                            then
                        if speed not= 1
                                then
                            ok := false
                            speed := speed - 2
                        else
                            ok := true
                        end if
                    end if
                end if
            end if

            if point = 4
                    then
                if already = false
                        then
                    currabil := currabil + 1
                    already := true
                    change := true
                end if
            end if

            if point = 8
                    then
                if already = false
                        then
                    currabil := currabil + 1
                    change := true
                    already := true
                end if
            end if

            delay (speed)
        end if
    end loop
end check


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%CALLING THE PROCEDURES/FUNCTIONS/PROCESSES%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


intro
afterintro

background
fork computerai
fork check
fork playercontrol
fork cooldowncount
fork backmusic
ball
Sponsor
Sponsor
Sponsor
sponsor
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  [ 1 Posts ]
Jump to:   


Style:  
Search: