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

Username:   Password: 
 RegisterRegister   
 Help get my menu to work better... (more details inside)
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
uberwalla




PostPosted: Tue Aug 22, 2006 5:56 pm   Post subject: Help get my menu to work better... (more details inside)

ok so i have the pong games im working on and i have a menu i created to go through the game.

in the controls sections i have a back type thing that i can't get to work.

if possible could someone try to configure it so it works and tell me so i can imput it into my source code.

o and also after the credits i want it to be able to just go back to the menu if thats at all possible.

thx in advance.
Sponsor
Sponsor
Sponsor
sponsor
NikG




PostPosted: Wed Aug 23, 2006 3:00 pm   Post subject: (No subject)

why did you create another topic?
you could have just added to your old one.
uberwalla




PostPosted: Wed Aug 23, 2006 10:01 pm   Post subject: reply

because this is a newer version... And its a totally different problem.
Cervantes




PostPosted: Wed Aug 23, 2006 10:45 pm   Post subject: (No subject)

Okay, enough of these threads. I feel it necessary to say that I have no desire to offer help, and I'm one who usually offers help in threads that haven't received it yet.

Why have I no desire to help? Because you make it too difficult. You post your entire code and give a vague description of what you want done. Instead, you should post only the relevant portion of your code and give a detailed and, preferrably, easy to read description of the problem and why you think it is occuring or what you think you can do to fix it.
NikG




PostPosted: Thu Aug 24, 2006 2:09 am   Post subject: Re: reply

uberwalla wrote:
because this is a newer version... And its a totally different problem.
You know... it IS possible to post 2 files (such as your newer version) in that first post.

And it's not a different problem, you mentioned the same thing in that first post too!
uberwalla




PostPosted: Thu Aug 24, 2006 10:17 am   Post subject: reply

Cervantes: im sorry but im not very good when it comes to explaining it.
and i posted the whole code because i dont know if i did something wrong somewhere else that caused the problem.

nikg : it isnt the same problem...
from the last post i had trouble because the menu was going into and f****** up the game itself.

what i would like some help on now... is that in the menu i have the section entitled "controls" when i go in i have it that there is a back button sort of thing. I would like it so i can get the back button to work when i hit enter.

Eg.) I start pong and dont know controls... i go to the controls menu and i look at them then hit enter to get back to the main menu. Instead of having to close the whole app. and restarting it Confused .

So plz cervantes, nikg or anyone plz help me with this.

Im sorry for my bad start coming to this forum. I promise to slow down on my threads, and to explain more.
Clayton




PostPosted: Thu Aug 24, 2006 7:30 pm   Post subject: (No subject)

look into forwarding procedures, this allows you to call a procedure from another, even if the called procedure follows the procedure your in (by line number), this way you can have a "controls" proc to display your contol menu, then if enter is pressed go back to the "menu" proc beneath it

have you tried searching before? your question has been asked before, try searching keywords and see what you can come up with before rushing to hit the new topic button
uberwalla




PostPosted: Thu Aug 24, 2006 10:02 pm   Post subject: reply

Ok TY.

and sorry again for not searching.
Sponsor
Sponsor
Sponsor
sponsor
uberwalla




PostPosted: Thu Aug 24, 2006 10:33 pm   Post subject: not working.

ok so i tried forwarding my procedures but it says exactly like it always says, "procedures can only be declared at the program, module, or monitor level"

i dont understand.
uberwalla




PostPosted: Thu Aug 24, 2006 10:47 pm   Post subject: reply

ok this is what i have. i can't seem to understand the forwarding. the code is kinda long sorry, but its as short as i could make it where i can pinpoint the problem.

code:

var font := Font.New ("Comicsans:14:bold")
var winID, winID1, winID2, winID3, winID4, maxnumber, minnumber, changeso, select, answer : int
var font4 := Font.New ("Comicsans:12:bold,underline")
var font5 := Font.New ("Comicsans:12:bold")
var font6 := Font.New ("Comicsans:12")
var keys : array char of boolean
var altered : int := 1
winID := Window.Open ("graphics:500;400;nobuttonbar;position:middle;center;title:Pong!")
procedure selectoptions
    if keys (KEY_UP_ARROW) then
        if altered = minnumber then
            altered := maxnumber
        else
            altered -= changeso
        end if
        delay (150)
    end if
    if keys (KEY_DOWN_ARROW) then
        if altered = maxnumber then
            altered := minnumber
        else
            altered += changeso
        end if
        delay (150)
    end if
end selectoptions

procedure drawoptions
    Font.Draw ("Start", 220, 200, font, black)
    Font.Draw ("Controls", 220, 150, font, black)
    Font.Draw ("Credits", 220, 100, font, black)
    Font.Draw ("Quit", 220, 50, font, black)
end drawoptions

process controls
    loop
        Font.Draw ("Player 1", 145, 182, font4, black)
        Font.Draw ("Player 2", 295, 182, font4, black)
        Font.Draw ("Up:", 145, 145, font5, black)
        Font.Draw ("Down:", 145, 90, font5, black)
        Font.Draw ("Up:", 295, 145, font5, black)
        Font.Draw ("Down:", 295, 90, font5, black)
        Font.Draw ("W", 145, 125, font6, black)
        Font.Draw ("S", 145, 70, font6, black)
        Font.Draw ("Up Arrow", 295, 125, font6, black)
        Font.Draw ("Down Arrow", 295, 70, font6, black)
        drawline (100, 50, 400, 50, black)
        drawline (100, 200, 400, 200, black)
        drawline (100, 50, 100, 200, black)
        drawline (400, 50, 400, 200, black)
        drawline (100, 175, 400, 175, black)
        drawline (250, 200, 250, 50, black)
        locate (maxrow - 1, maxcol div 2 - 2)
        Font.Draw ("Back", 230, 19, font, black)
        drawfilloval (210, 25, 6, 6, black)
        Input.KeyDown (keys)
        if keys (KEY_ENTER) then
            delay (150)
            exit
        end if
        View.Update
    end loop
end controls

procedure pong
    loop
        drawoptions
        Input.KeyDown (keys)
        maxnumber := 4
        minnumber := 1
        changeso := 1
        selectoptions
        select := altered
        if select = 1 then
            drawfilloval (200, 205, 6, 6, black)
            drawfilloval (200, 155, 6, 6, white)
            drawfilloval (200, 105, 6, 6, white)
            drawfilloval (200, 55, 6, 6, white)
        elsif select = 2 then
            drawfilloval (200, 205, 6, 6, white)
            drawfilloval (200, 155, 6, 6, black)
            drawfilloval (200, 105, 6, 6, white)
            drawfilloval (200, 55, 6, 6, white)
        elsif select = 3 then
            drawfilloval (200, 205, 6, 6, white)
            drawfilloval (200, 155, 6, 6, white)
            drawfilloval (200, 105, 6, 6, black)
            drawfilloval (200, 55, 6, 6, white)
        elsif select = 4 then
            drawfilloval (200, 205, 6, 6, white)
            drawfilloval (200, 155, 6, 6, white)
            drawfilloval (200, 105, 6, 6, white)
            drawfilloval (200, 55, 6, 6, black)
        end if
        if keys (KEY_ENTER) then
            if select = 2 then
                %fork click
                cls
                Window.Close (winID)
                winID3 := Window.Open ("graphics:500;400;nobuttonbar;position:middle;center;title:Pong Controls")
                drawfillbox (0, 0, maxx, maxy, 0)
                %Pic.Draw (pic2, 100, 200, 0)
                fork controls
                exit
            end if
        end if
    end loop
end pong

pong
richcash




PostPosted: Thu Aug 24, 2006 11:11 pm   Post subject: (No subject)

1. Don't use a process for your controls (processes are better to be avoided!). Turn your controls process into a procedure (and don't fork it, just call it normally, obviously!)

2. Take the exit statement out of your pong procedure (right under where you previously forked controls).

3. Add a cls after your delay (150) in your controls procedure (line 58).

That should work!
uberwalla




PostPosted: Thu Aug 24, 2006 11:39 pm   Post subject: reply

WOW! it works Very Happy

thx man.

sorry everyone for my annoyance Confused
uberwalla




PostPosted: Thu Aug 24, 2006 11:51 pm   Post subject: reply

nvm sorry guys im back again.
richcash ur idea worked very well, ty.

But when i added it to the rest of my program when i hit enter for the back button it goes back to the menu and its a white screen with dots that move Confused

its really long but ill post it so u can possibly help me out with anything else i may have done wrong so i can learn more Very Happy

code:


var winID, winID1, winID2, winID3, winID4, maxnumber, minnumber, changeso, select, answer : int
var altered : int := 1
var keys : array char of boolean
var chars : array char of boolean
var font := Font.New ("Comicsans:14:bold")
var font1 := Font.New ("Fixedsys:30")
var font2 := Font.New ("Fixedsys:12")
var font3 := Font.New ("Fixedsys:16")
var font4 := Font.New ("Comicsans:12:bold,underline")
var font5 := Font.New ("Comicsans:12:bold")
var font6 := Font.New ("Comicsans:12")
var font7 := Font.New ("Continuum Light:14:bold")
var font8 := Font.New ("Continuum Light:14:italic")
var pic1 : int := Pic.FileNew ("Pong/PONG.bmp")
var pic2 : int := Pic.FileNew ("Pong/PONGcontrols.bmp")
var spd : int := 3
var x : int := 320
var y : int := 200
var a : int := +1
var b : int := -1
var y2, y1 : int := 230
var rx : real
var ry : real
var move : int := 1
var ply : int := 1
var p1, p2 : int := 0
var s : int := 5
var cp : int := 2
var cs : int := 4
var fscredits : int
var fontclr : int
var change : int
var heading, temp : string := " "
var credited : flexible array 1 .. 0 of string
var starx, stary, starspeed : array 1 .. 120 of int
var endtime : int

winID := Window.Open ("graphics:500;400;nobuttonbar;position:middle;center;title:Pong!")
drawfillbox (0, 0, maxx, maxy, 7)
%Pic.Draw (pic1, 100, 200, 0)

process scoreboard
    locate (2, 13)
    put p2
    locate (2, maxcol - 3)
    put p1
    Draw.Box (3, maxy - 40, maxx - 3, maxy - 3, black)
    Font.Draw ("Pong!", 308, maxy - 25, font2, black)
    Font.Draw ("Player 1:", 15, maxy - 27, font2, black)
    Font.Draw ("Player 2:", maxx - 115, maxy - 27, font2, black)
end scoreboard

%process click
   % Music.PlayFile ("Pong/click.wav")
%end click

procedure drawoptions
    Font.Draw ("Start", 220, 200, font, white)
    Font.Draw ("Controls", 220, 150, font, white)
    Font.Draw ("Credits", 220, 100, font, white)
    Font.Draw ("Quit", 220, 50, font, white)
end drawoptions

procedure selectoptions
    if keys (KEY_UP_ARROW) then
        if altered = minnumber then
            altered := maxnumber
        else
            altered -= changeso
        end if
        delay (150)
    end if
    if keys (KEY_DOWN_ARROW) then
        if altered = maxnumber then
            altered := minnumber
        else
            altered += changeso
        end if
        delay (150)
    end if
end selectoptions

process ball
    loop
        fork scoreboard
        Draw.FillBox (0, 0, 640, 400, black)
        Draw.FillOval (320, 200, 10, 10, white)
        ply := 1
        delay (1000)
        fork scoreboard
        y := 200
        x := 320
        rand (rx)
        if rx >= 0.5 then
            a := +1
        else
            a := -1
        end if

        rand (ry)
        if ry >= 0.5 then
            b := +1
        else
            b := -1
        end if

        move := 1

        loop
            Draw.FillOval (x, y, 10, 10, white)
            delay (spd)
            Draw.FillOval (x, y, 10, 10, black)
            y := y - b
            x := x - a
            if y >= 390 then
                b := +1
            elsif y <= 10 then
                b := -1
            end if
            if x >= 612 then
                if y <= y1 + 7 and y >= y1 - 67 then
                    a := +1
                end if
            end if
            if x >= 629 then
                Draw.FillOval (x, y, 10, 10, white)
                ply := 0
                move := 0
                p2 := p2 + 1
                exit
            end if
            if x <= 28 then
                if y <= y2 + 7 and y >= y2 - 67 then
                    a := -1
                end if
            end if
            if x <= 10 then
                Draw.FillOval (x, y, 10, 10, white)
                ply := 0
                move := 0
                p1 := p1 + 1
                exit
            end if
        end loop
        delay (450)
        cls
        locate (25, 1)
        if p1 = s then
            cls
            put "Press Any Key To Continue Game"
            locate (12, 28)
            if cp = 2 then
                winID1 := Window.Open ("graphics:200;100")
                put "Player 2 Wins!"
                delay (1000)
                Window.Close (winID1)
                exit
            elsif cp = 1 then
                drawfillbox (0, 0, maxx, maxy, 7)
                for : 1 .. 25
                    Font.Draw ("YOU WIN!!!", 200, 250, font1, 39)
                    delay (50)
                    Font.Draw ("YOU WIN!!!", 200, 250, font1, 72)
                    delay (50)
                    Font.Draw ("YOU WIN!!!", 200, 250, font1, 19)
                    delay (50)
                end for
                exit
            end if
        elsif p2 = s then
            cls
            put "Press Any Key To Continue Game"
            locate (12, 28)
            if cp = 2 then
                winID1 := Window.Open ("graphics:200;100")
                put "Player 1 Wins!"
                delay (1000)
                Window.Close (winID1)
                exit
            elsif cp = 1 then
                winID1 := Window.Open ("graphics:200;100")
                put "Computer Wins!"
                Window.Close (winID1)
                delay (1000)
                exit
            end if
        end if
        delay (750)
        Input.Pause
    end loop
end ball

process pdl1
    loop
        if ply = 1 then
            Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) and move = 1 then
                y1 := y1 + 1
            elsif chars (KEY_DOWN_ARROW) and move = 1 then
                y1 := y1 - 1
            end if
            if y1 <= 65 then
                y1 := y1 + 1
            elsif y1 >= 395 then
                y1 := y1 - 1
            end if
            Draw.FillBox (622, y1, 627, y1 - 60, white)
            delay (3)
            Draw.FillBox (622, y1, 627, y1 - 60, black)
        end if
    end loop
end pdl1

process pdl2
    loop
        if ply = 1 then
            Input.KeyDown (chars)
            if chars ('w') and move = 1 then
                y2 := y2 + 1
            elsif chars ('s') and move = 1 then
                y2 := y2 - 1
            end if
            if y2 <= 65 then
                y2 := y2 + 1
            elsif y2 >= 395 then
                y2 := y2 - 1
            end if
            Draw.FillBox (18, y2, 13, y2 - 60, white)
            delay (3)
            Draw.FillBox (18, y2, 13, y2 - 60, black)
        end if
    end loop
end pdl2

process comp
    loop
        if ply = 1 then
            if x < 320 then
                if y <= y2 - 30 then
                    y2 := y2 - 1
                elsif y >= y2 - 30 then
                    y2 := y2 + 1
                end if
                if y2 <= 65 then
                    y2 := y2 + 1
                elsif y2 >= 395 then
                    y2 := y2 - 1
                end if
            end if
            Draw.FillBox (18, y2, 13, y2 - 60, white)
            delay (cs)
            Draw.FillBox (18, y2, 13, y2 - 60, black)
        end if
    end loop
end comp

process game
    if cp = 1 then
        fork comp
    elsif cp = 2 then
        fork pdl2
    end if
    fork ball
    fork pdl1
end game

procedure creditswatch
    View.Set ("offscreenonly")
    colourback (18)
    cls

    for i : 1 .. 120
        starx (i) := Rand.Int (0, maxx)
        stary (i) := Rand.Int (65, maxy - 65)
        starspeed (i) := Rand.Int (5, 10)
    end for

   % open : fscredits, "Pong/credits.dat", get

    fontclr := -20
    change := 1

    loop
        for i : 1 .. 120
            drawdot (starx (i), stary (i), 16 + starspeed (i))
            starx (i) -= starspeed (i)
            if starx (i) < 0 then
                starspeed (i) := Rand.Int (5, 15)
                starx (i) := maxx
            end if
        end for

        if fontclr = -20 and temp not= "---" then
            new credited, 0

            get : fscredits, heading : *

            loop
                if eof (fscredits) then
                    temp := "---"
                    endtime := Time.Elapsed
                    exit
                end if

                get : fscredits, temp : *

                if temp = "" then
                    exit
                else
                    new credited, upper (credited) + 1
                    credited (upper (credited)) := temp
                end if
            end loop
        end if

        if temp not= "---" then
            if fontclr div 3 < 16 then
            elsif fontclr div 3 > 31 then
                Font.Draw (heading, maxx div 2 - Font.Width (heading, font7) div 2, maxy div 2 + 25 * (upper (credited) - 1) div 2, font7, 31)
                for i : 1 .. upper (credited)
                    Font.Draw (credited (i), maxx div 2 - Font.Width (credited (i), font8) div 2, maxy div 2 + (upper (credited) - 1 - i - upper (credited) div 2) * 25, font8, 31)
                end for
            else
                Font.Draw (heading, maxx div 2 - Font.Width (heading, font7) div 2, maxy div 2 + 25 * (upper (credited) - 1) div 2, font7, fontclr div 3)
                for i : 1 .. upper (credited)
                    Font.Draw (credited (i), maxx div 2 - Font.Width (credited (i), font8) div 2, maxy div 2 + (upper (credited) - 1 - i - upper (credited) div 2) * 25, font8, fontclr div 3)
                end for
            end if
        end if

        fontclr += change
        if fontclr = 200 then
            change := -2
        elsif fontclr = -20 then
            change := 2
        end if

        View.Update
        delay (30)

        drawfillbox (0, 60, 600, 340, 7)
        exit when hasch

        if temp = "---" then
            exit when (Time.Elapsed - endtime) > 0000
        end if
    end loop

    Font.Free (font7)
    Font.Free (font8)
    close : fscredits
end creditswatch

procedure controls
    loop
        Font.Draw ("Player 1", 145, 182, font4, white)
        Font.Draw ("Player 2", 295, 182, font4, white)
        Font.Draw ("Up:", 145, 145, font5, white)
        Font.Draw ("Down:", 145, 90, font5, white)
        Font.Draw ("Up:", 295, 145, font5, white)
        Font.Draw ("Down:", 295, 90, font5, white)
        Font.Draw ("W", 145, 125, font6, white)
        Font.Draw ("S", 145, 70, font6, white)
        Font.Draw ("Up Arrow", 295, 125, font6, white)
        Font.Draw ("Down Arrow", 295, 70, font6, white)
        drawline (100, 50, 400, 50, white)
        drawline (100, 200, 400, 200, white)
        drawline (100, 50, 100, 200, white)
        drawline (400, 50, 400, 200, white)
        drawline (100, 175, 400, 175, white)
        drawline (250, 200, 250, 50, white)
        locate (maxrow - 1, maxcol div 2 - 2)
        Font.Draw ("Back", 230, 19, font, white)
        drawfilloval (210, 25, 6, 6, white)
        Input.KeyDown (keys)
        if keys (KEY_ENTER) then
            delay (150)
            cls
            exit
        end if
        View.Update
    end loop
end controls

procedure pong
    loop
        drawoptions
        Input.KeyDown (keys)
        maxnumber := 4
        minnumber := 1
        changeso := 1
        selectoptions
        select := altered
        if select = 1 then
            drawfilloval (200, 205, 6, 6, white)
            drawfilloval (200, 155, 6, 6, black)
            drawfilloval (200, 105, 6, 6, black)
            drawfilloval (200, 55, 6, 6, black)
        elsif select = 2 then
            drawfilloval (200, 205, 6, 6, black)
            drawfilloval (200, 155, 6, 6, white)
            drawfilloval (200, 105, 6, 6, black)
            drawfilloval (200, 55, 6, 6, black)
        elsif select = 3 then
            drawfilloval (200, 205, 6, 6, black)
            drawfilloval (200, 155, 6, 6, black)
            drawfilloval (200, 105, 6, 6, white)
            drawfilloval (200, 55, 6, 6, black)
        elsif select = 4 then
            drawfilloval (200, 205, 6, 6, black)
            drawfilloval (200, 155, 6, 6, black)
            drawfilloval (200, 105, 6, 6, black)
            drawfilloval (200, 55, 6, 6, white)
        end if
        if keys (KEY_ENTER) then
            if select = 1 then
                %fork click
                cls
                font1 := Font.New ("Fixedsys:30")
                font2 := Font.New ("Fixedsys:12")
                font3 := Font.New ("Fixedsys:16")
                Font.Draw ("                Select Opponent:", 50, 305, font2, 7)
                Font.Draw ("                1) Computer", 50, 285, font2, 7)
                Font.Draw ("                2) Another Player", 50, 265, font2, 7)
                locate (25, 1)
                get answer
                if answer = 1 then
                    %fork click
                    cp := 1
                elsif answer = 2 then
                  %  fork click
                    cp := 2
                end if
                cls
                if cp = 1 then
                    Font.Draw (" Select The Computer's Skill Level:", 110, 305, font2, 7)
                    Font.Draw ("1) Beginnner", 110, 285, font2, 7)
                    Font.Draw ("2) Average", 110, 265, font2, 7)
                    Font.Draw ("3) Pro", 110, 245, font2, 7)
                    locate (25, 1)
                    get answer
                    if answer = 1 then
                       % fork click
                        cs := 5
                    elsif answer = 2 then
                       % fork click
                        cs := 3
                    elsif answer = 3 then
                       % fork click
                        cs := 2
                    end if
                    cls
                end if
                Font.Draw (" At what speed do u want to play?", 110, 305, font2, 7)
                Font.Draw ("1) slow", 110, 285, font2, 7)
                Font.Draw ("2) Average", 110, 265, font2, 7)
                Font.Draw ("3) Fast", 110, 245, font2, 7)
                locate (25, 1)
                get answer
                if answer = 1 then
                   % fork click
                    spd := 4
                elsif answer = 2 then
                    %fork click
                    spd := 3
                elsif answer = 3 then
                    %fork click
                    spd := 2
                end if
                cls
                Font.Draw ("What score would you like to play to?", 110, 300, font2, 7)
                locate (25, 1)
                get answer
               % fork click
                s := answer
                cls
                Window.Close (winID)
                winID2 := Window.Open ("graphics:640;457;nobuttonbar;position:middle;center;title:Pong!")
                fork game
                exit
            end if
            if select = 2 then
               % fork click
                cls
                Window.Close (winID)
                winID3 := Window.Open ("graphics:500;400;nobuttonbar;position:middle;center;title:Pong Controls")
                drawfillbox (0, 0, maxx, maxy, 7)
               % Pic.Draw (pic2, 100, 200, 0)
                controls
            end if
            if select = 3 then
               % fork click
                cls
                Window.Close (winID)
                winID3 := Window.Open ("graphics:500;400;nobuttonbar;position:middle;center;title:Pong Credits")
                creditswatch
                exit
            end if
            if select = 4 then
                %fork click
                Window.Close (winID)
                exit
            end if
        end if
    end loop
end pong

pong



i put the "%" in front of the pics and the sounds so if u want to run it to see what i mean.

sorry again for the long code
Ultrahex




PostPosted: Sat Aug 26, 2006 10:42 pm   Post subject: (No subject)

Ok There appears to be something COMPLETELY wrong with the last thing you posted above ^ the sourcecode i tried to run it but when i hit back the screen goes complete white with 3 dots (black) you probably forgot to refill in the back black or something along those lines.

i have also wondered about a few things like why you have 4 winID's im not sure if you are using them but in reality i think every single turing program only needs one (except the odd one like that 3D model editor i believe made back [Was That in Turing?] well anyhow)

ill update another post like this one in a little bit im tired now so i was just putting feedback in at the moment.

Peace, Alex
Ultrahex




PostPosted: Sun Aug 27, 2006 1:14 am   Post subject: (No subject)

Ok, here is your program AGAIN

code:

var winID, maxnumber, minnumber, changeso, select, answer : int
var altered : int := 1
var keys : array char of boolean
var chars : array char of boolean
var font := Font.New ("Comicsans:14:bold")
var font1 := Font.New ("Fixedsys:30")
var font2 := Font.New ("Fixedsys:12")
var font3 := Font.New ("Fixedsys:16")
var font4 := Font.New ("Comicsans:12:bold,underline")
var font5 := Font.New ("Comicsans:12:bold")
var font6 := Font.New ("Comicsans:12")
var font7 := Font.New ("Continuum Light:14:bold")
var font8 := Font.New ("Continuum Light:14:italic")
var pic1 : int := Pic.FileNew ("Pong/PONG.bmp")
var pic2 : int := Pic.FileNew ("Pong/PONGcontrols.bmp")
var spd : int := 3
var x : int := 320
var y : int := 200
var a : int := +1
var b : int := -1
var y2, y1 : int := 230
var rx : real
var ry : real
var move : int := 1
var ply : int := 1
var p1, p2 : int := 0
var s : int := 5
var cp : int := 2
var cs : int := 4
var fscredits : int
var fontclr : int
var change : int
var heading, temp : string := " "
var credited : flexible array 1 .. 0 of string
var starx, stary, starspeed : array 1 .. 120 of int
var endtime : int
select := 0
var menuSection := "MainMenu"
winID := Window.Open ("graphics:500;400;nobuttonbar;position:middle;center;title:Pong!")
View.Set ("offscreenonly") %OffScreen Buffering
drawfillbox (0, 0, maxx, maxy, 7)
%Pic.Draw (pic1, 100, 200, 0)

procedure scoreboard
    locate (2, 13)
    put p2
    locate (2, maxcol - 3)
    put p1
    Draw.Box (3, maxy - 40, maxx - 3, maxy - 3, black)
    Font.Draw ("Pong!", 308, maxy - 25, font2, black)
    Font.Draw ("Player 1:", 15, maxy - 27, font2, black)
    Font.Draw ("Player 2:", maxx - 115, maxy - 27, font2, black)
end scoreboard

process ball
    loop
        scoreboard
        Draw.FillBox (0, 0, 640, 400, black)
        Draw.FillOval (320, 200, 10, 10, white)
        ply := 1
        delay (1000)
        y := 200
        x := 320
        rand (rx)
        if rx >= 0.5 then
            a := +1
        else
            a := -1
        end if

        rand (ry)
        if ry >= 0.5 then
            b := +1
        else
            b := -1
        end if

        move := 1

        loop
            Draw.FillOval (x, y, 10, 10, white)
            delay (spd)
            Draw.FillOval (x, y, 10, 10, black)
            y := y - b
            x := x - a
            if y >= 390 then
                b := +1
            elsif y <= 10 then
                b := -1
            end if
            if x >= 612 then
                if y <= y1 + 7 and y >= y1 - 67 then
                    a := +1
                end if
            end if
            if x >= 629 then
                Draw.FillOval (x, y, 10, 10, white)
                ply := 0
                move := 0
                p2 := p2 + 1
                exit
            end if
            if x <= 28 then
                if y <= y2 + 7 and y >= y2 - 67 then
                    a := -1
                end if
            end if
            if x <= 10 then
                Draw.FillOval (x, y, 10, 10, white)
                ply := 0
                move := 0
                p1 := p1 + 1
                exit
            end if
        end loop
        delay (450)
        cls
        locate (25, 1)
        if p1 = s then
            View.Set ("nooffscreenonly")
            cls
            put "Press Any Key To Continue Game"
            locate (12, 28)
            if cp = 2 then
                Window.Set (winID, "graphics:200;100")
                put "Player 2 Wins!"
                delay (1000)
                exit
            elsif cp = 1 then
                drawfillbox (0, 0, maxx, maxy, 7)
                for : 1 .. 25
                    Font.Draw ("YOU WIN!!!", 200, 250, font1, 39)
                    delay (50)
                    Font.Draw ("YOU WIN!!!", 200, 250, font1, 72)
                    delay (50)
                    Font.Draw ("YOU WIN!!!", 200, 250, font1, 19)
                    delay (50)
                end for
                exit
            end if
        elsif p2 = s then
            View.Set ("nooffscreenonly")
            cls
            put "Press Any Key To Continue Game"
            locate (12, 28)
            if cp = 2 then
                Window.Set (winID, "graphics:200;100")
                put "Player 1 Wins!"
                delay (1000)
                exit
            elsif cp = 1 then
                Window.Set (winID, "graphics:200;100")
                put "Computer Wins!"
                delay (1000)
                exit
            end if
        end if
        delay (750)
        Input.Pause
    end loop
end ball

process pdl1
    loop
        if ply = 1 then
            Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) and move = 1 then
                y1 := y1 + 1
            elsif chars (KEY_DOWN_ARROW) and move = 1 then
                y1 := y1 - 1
            end if
            if y1 <= 65 then
                y1 := y1 + 1
            elsif y1 >= 395 then
                y1 := y1 - 1
            end if
            Draw.FillBox (622, y1, 627, y1 - 60, white)
            delay (3)
            Draw.FillBox (622, y1, 627, y1 - 60, black)
        end if
        if (menuSection not= "InGame") then
            exit
        end if
    end loop
end pdl1

process pdl2
    loop
        if ply = 1 then
            Input.KeyDown (chars)
            if chars ('w') and move = 1 then
                y2 := y2 + 1
            elsif chars ('s') and move = 1 then
                y2 := y2 - 1
            end if
            if y2 <= 65 then
                y2 := y2 + 1
            elsif y2 >= 395 then
                y2 := y2 - 1
            end if
            Draw.FillBox (18, y2, 13, y2 - 60, white)
            delay (3)
            Draw.FillBox (18, y2, 13, y2 - 60, black)
        end if
        if (menuSection not= "InGame") then
            exit
        end if
    end loop
end pdl2

process comp
    loop
        if ply = 1 then
            if x < 320 then
                if y <= y2 - 30 then
                    y2 := y2 - 1
                elsif y >= y2 - 30 then
                    y2 := y2 + 1
                end if
                if y2 <= 65 then
                    y2 := y2 + 1
                elsif y2 >= 395 then
                    y2 := y2 - 1
                end if
            end if
            Draw.FillBox (18, y2, 13, y2 - 60, white)
            delay (cs)
            Draw.FillBox (18, y2, 13, y2 - 60, black)
        end if
        if (menuSection not= "InGame") then
            exit
        end if
    end loop
end comp

procedure startGame
    if cp = 1 then
        fork comp
    elsif cp = 2 then
        fork pdl2
    end if
    fork ball
    fork pdl1
    loop
        delay (5000)
        if (p1 = s or p2 = s) then
            menuSection := "MainMenu"
            exit
        end if
    end loop
end startGame

procedure creditswatch
    View.Set ("offscreenonly")
    colourback (18)
    cls
    for i : 1 .. 120
        starx (i) := Rand.Int (0, maxx)
        stary (i) := Rand.Int (65, maxy - 65)
        starspeed (i) := Rand.Int (5, 10)
    end for

    open : fscredits, "Pong Files/credits.dat", get

    fontclr := -20
    change := 1

    loop
        for i : 1 .. 120
            drawdot (starx (i), stary (i), 16 + starspeed (i))
            starx (i) -= starspeed (i)
            if starx (i) < 0 then
                starspeed (i) := Rand.Int (5, 15)
                starx (i) := maxx
            end if
        end for

        if fontclr = -20 and temp not= "---" then
            new credited, 0

            get : fscredits, heading : *

            loop
                if eof (fscredits) then
                    temp := "---"
                    endtime := Time.Elapsed
                    exit
                end if

                get : fscredits, temp : *

                if temp = "" then
                    exit
                else
                    new credited, upper (credited) + 1
                    credited (upper (credited)) := temp
                end if
            end loop
        end if

        if temp not= "---" then
            if fontclr div 3 < 16 then
            elsif fontclr div 3 > 31 then
                Font.Draw (heading, maxx div 2 - Font.Width (heading, font7) div 2, maxy div 2 + 25 * (upper (credited) - 1) div 2, font7, 31)
                for i : 1 .. upper (credited)
                    Font.Draw (credited (i), maxx div 2 - Font.Width (credited (i), font8) div 2, maxy div 2 + (upper (credited) - 1 - i - upper (credited) div 2) * 25, font8, 31)
                end for
            else
                Font.Draw (heading, maxx div 2 - Font.Width (heading, font7) div 2, maxy div 2 + 25 * (upper (credited) - 1) div 2, font7, fontclr div 3)
                for i : 1 .. upper (credited)
                    Font.Draw (credited (i), maxx div 2 - Font.Width (credited (i), font8) div 2, maxy div 2 + (upper (credited) - 1 - i - upper (credited) div 2) * 25, font8, fontclr div 3)
                end for
            end if
        end if

        fontclr += change
        if fontclr = 200 then
            change := -2
        elsif fontclr = -20 then
            change := 2
        end if

        View.Update
        delay (30)

        drawfillbox (0, 60, 600, 340, 7)
        exit when hasch

        if temp = "---" then
            exit when (Time.Elapsed - endtime) > 3000
        end if
    end loop
    close : fscredits
    menuSection := "MainMenu"
end creditswatch

/*
 You May Feel To Rather Seperate Each Sections and Run There
 Procedures From Inside the Case Instead of Putting The Commands Within!
 */


loop
    drawfillbox (0, 0, maxx, maxy, black) %Makes Background Black
    Window.Set(winID,"graphics:500;400;nobuttonbar;position:middle;center;title:Pong!,offscreenonly")
    case menuSection of
        label "MainMenu" :
            Font.Draw ("PONG!!!",150,300,font1,white)
            Font.Draw ("Start", 220, 200, font, white)
            Font.Draw ("Controls", 220, 150, font, white)
            Font.Draw ("Credits", 220, 100, font, white)
            Font.Draw ("Quit", 220, 50, font, white)

            Input.KeyDown (keys)

            %Movement Up and Down On Menu
            delay (100) %Delay So Doesn't Go Extremely Fast (Makes Easier to Select in Menu)
            if keys (KEY_UP_ARROW) then
                select -= 1
            end if
            if keys (KEY_DOWN_ARROW) then
                select += 1
            end if
            select := select mod 4 %Note 4 is Your Max + 1, Starting at 0, so 0..3 it goes through

            %You Were Drawing White on Black Background, Not Quite Sure Why...
            if select = 0 then
                drawfilloval (200, 205, 6, 6, white)
            elsif select = 1 then
                drawfilloval (200, 155, 6, 6, white)
            elsif select = 2 then
                drawfilloval (200, 105, 6, 6, white)
            elsif select = 3 then
                drawfilloval (200, 55, 6, 6, white)
            end if

            if keys (KEY_ENTER) then
                %fork click
                if select = 0 then
                    View.Set ("nooffscreenonly")
                    loop
                        cls
                        Font.Draw ("                Select Opponent:", 50, 305, font2, black)
                        Font.Draw ("                1) Computer", 50, 285, font2, black)
                        Font.Draw ("                2) Another Player", 50, 265, font2, black)
                        locate (25, 1)
                        get cp
                        %fork click
                        if cp = 1 or cp = 2 then
                            exit
                        end if
                    end loop
                    if cp = 1 then
                        loop
                            cls
                            Font.Draw (" Select The Computer's Skill Level:", 110, 305, font2, 7)
                            Font.Draw ("1) Beginnner", 110, 285, font2, 7)
                            Font.Draw ("2) Average", 110, 265, font2, 7)
                            Font.Draw ("3) Pro", 110, 245, font2, 7)
                            locate (25, 1)
                            get cs
                            %fork click
                            case cs of
                                label 1 :
                                    cs := 5
                                    exit
                                label 2 :
                                    cs := 3
                                    exit
                                label 3 :
                                    cs := 2
                                    exit
                                label :
                            end case
                        end loop
                    end if
                    loop
                        cls
                        Font.Draw (" At what speed do u want to play?", 110, 305, font2, 7)
                        Font.Draw ("1) Fast", 110, 285, font2, 7)
                        Font.Draw ("2) Average", 110, 265, font2, 7)
                        Font.Draw ("3) Slow", 110, 245, font2, 7)
                        locate (25, 1)
                        get spd
                        %fork click
                        if spd >= 1 and spd <= 3 then
                            spd += 1
                            exit
                        end if
                    end loop
                    cls
                    Font.Draw ("What score would you like to play to?", 110, 300, font2, 7)
                    locate (25, 1)
                    get s
                    %fork click
                    cls
                    Window.Set (winID, "graphics:640;457;nobuttonbar;position:middle;center;title:Pong!")
                    menuSection := "InGame"
                    startGame
                end if
                if select = 1 then
                    Window.Set (winID, "title:Pong Controls")
                    menuSection := "Controls"
                end if
                if select = 2 then
                    menuSection := "Credits"
                end if
                if select = 3 then
                    Window.Close (winID)
                    exit
                end if
            end if

        label "Controls" :
            Font.Draw ("PONG!!!",150,300,font1,white)
            Font.Draw ("Player 1", 145, 182, font4, white)
            Font.Draw ("Player 2", 295, 182, font4, white)
            Font.Draw ("Up:", 145, 145, font5, white)
            Font.Draw ("Down:", 145, 90, font5, white)
            Font.Draw ("Up:", 295, 145, font5, white)
            Font.Draw ("Down:", 295, 90, font5, white)
            Font.Draw ("W", 145, 125, font6, white)
            Font.Draw ("S", 145, 70, font6, white)
            Font.Draw ("Up Arrow", 295, 125, font6, white)
            Font.Draw ("Down Arrow", 295, 70, font6, white)
            drawline (100, 50, 400, 50, white)
            drawline (100, 200, 400, 200, white)
            drawline (100, 50, 100, 200, white)
            drawline (400, 50, 400, 200, white)
            drawline (100, 175, 400, 175, white)
            drawline (250, 200, 250, 50, white)
            locate (maxrow - 1, maxcol div 2 - 2)
            Font.Draw ("Back", 230, 19, font, white)
            drawfilloval (210, 25, 6, 6, white)
            Input.KeyDown (keys)
            if keys (KEY_ENTER) then
                menuSection := "MainMenu"
                delay (150)
            end if
        label "Credits" :
            Window.Set (winID, "title:Pong Credits")
            creditswatch
            cls
            put "CheeseBun"
            View.Update
        label "InGame" :
    end case
    View.Update
end loop


There is Still Some Errors To Be Worked Out, and All That...
But Overall I Rebuilt a lot, i would recommend going through the last 150 lines of the code that was rebuilt with a lot of your procedures tooken out, also it goes back to menu after losing, winning and only 1 winID
There is probably a lot of variables not used so you can remove those also, but if you need more help just post a reply

Need Info on how i did something ask also!
There is a lot you still need to learn about programming uberwalla i hope this might put you on the right path, note how i did things and why i did them that way, i commented every so often

Any Other Problems with the program you want to work on and cannot figure out yourself please post a reply! in this thread

Peace, Alex
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 19 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: