Computer Science Canada

Pong Menu help and WidgetModule.tu opens

Author:  uknowhoiam [ Wed Mar 25, 2009 6:23 pm ]
Post subject:  Pong Menu help and WidgetModule.tu opens

I dont know how to hide my button, after it is clicked, and my instructions wont show up untill i click somewhere else... any help...........here is my code......(sorry i forgot the syntax code >.<)

import GUI
View.Set ("graphics:650;400,offscreenonly,nobuttonbar")
Mouse.ButtonChoose ("multibutton")

var xpos, ypos, ypos1, ypos2, ypos3, ypos4 : int := 1
var x : int := maxx div 2
var y : int := maxy div 2
var y1 : int := maxy div 2 - 35
var y2 : int := maxy div 2 + 35
var y3 : int := maxy div 2 - 35
var y4 : int := maxy div 2 + 35
var key : array char of boolean
var x5, y5, button : int
var speed : int := 5
var counter : int := 0
var score1, score2 := 0
var answer : string (1)
var fontID, height, ascent, descent, internalLeading : int

colourback (black) %Macking the whole background Black

cls %the Black colour can take over the whole screen



process DoMusic %Music process

Music.PlayFile ("swizz_beat-It_s_me_snitches_instrumental.mp3") %File name

end DoMusic

procedure leftbar %Left bar procedure
drawfillbox (0, y1, 5, y2, white) %The left paddle
end leftbar

procedure rightbar %Right bar procedure
drawfillbox (maxx - 5, y3, maxx, y4, white) %The right paddle
end rightbar

procedure keyboard %The whole keyboard procedure
%player 1
drawfillbox (0, y1, 5, y2, white) %The left paddle
delay (2)
cls %The paddle is deleted
y1 := y1 + 5 %movement of the paddle
y2 := y2 + 5
end keyboard
% ^
procedure keyboard2 %same thing as above |
%player 1
drawfillbox (0, y1, 5, y2, white)
delay (2)
cls
y1 := y1 - 5
y2 := y2 - 5
end keyboard2

procedure mouse %Mouse procedure
%player 2
drawfillbox (maxx - 5, y3, maxx, y4, white) %The right paddle
View.Update %Avoiding flickering
delay (5)
cls %deleting the paddle

if button = 1 and y3 > 0 then %If left button is clicked then
y3 := y3 - 5 %Move the object down
y4 := y4 - 5
elsif button = 100 and y4 < maxy then %If right is clicked then
y3 := y3 + 5 %Move Up
y4 := y4 + 5
end if
end mouse

procedure ball %Ball procedure

%ball
drawfilloval (x, y, 5, 5, white)

if counter = 100 then %Changing the speed of the ball
speed := speed - 1
end if

if counter = 200 then
speed := speed - 1
end if

if counter = 300 then
speed := speed - 1
end if

if counter = 400 then
speed := speed - 1
end if

if counter = 500 then
speed := speed - 1
end if

delay (speed)

if x = 10 and y >= y1 and y <= y2 then %If it hits the left paddle then
xpos := -xpos %bounce back

elsif y >= y3 and y <= y4 and x = maxx - 10 then %If it hits the right paddle
xpos := -xpos %then bounce back
end if

if x < 5 or x >= maxx - 5 then %If the ball hits the wall, then
xpos := -xpos %bounce back
end if

if y < 5 or y >= maxy - 5 then
ypos := -ypos
end if

end ball

procedure loc_ball %If the user does not hit the ball then, relocate the
x := maxx div 2 %the ball to the centre
y := maxy div 2
end loc_ball

procedure instruction
colour (yellow)
put repeat ("%", maxcol)
locate (2, maxcol div 2 - 6)

put "Instructions"
locate (4, 1)

put "Move the Left Paddle with the Left and Right Arrows"
put "Move the Right Paddle with the mouse buttons"
put "First person to get 5 points Wins"
end instruction



procedure menu
fontID := Font.New ("Ariel:72:bold")
Font.Sizes (fontID, height, ascent, descent, internalLeading)
Font.Draw ("PONG!!", maxrow div 2, maxcol div 2 - 6, fontID, white)


var Instruc : int := GUI.CreateButton (maxx - 200, 10, 0, "Instructions",
instruction)

loop
exit when GUI.ProcessEvent
end loop

end menu

menu

Author:  saltpro15 [ Wed Mar 25, 2009 7:14 pm ]
Post subject:  RE:Pong Menu help and WidgetModule.tu opens

sorry, it really is impossible to read without the tags, once a mod fixes it i'll take a look at it

Author:  DemonWasp [ Wed Mar 25, 2009 8:18 pm ]
Post subject:  RE:Pong Menu help and WidgetModule.tu opens

Your screen is set to "offscreenonly", which means you need to call View.Update() whenever you need the screen to update. You should call this right after making your button and right after drawing your instructions.

Author:  andrew. [ Wed Mar 25, 2009 9:08 pm ]
Post subject:  RE:Pong Menu help and WidgetModule.tu opens

Just for the record, syntax code is:
code:
[syntax="Turing"][/syntax]

Author:  uknowhoiam [ Thu Mar 26, 2009 4:14 pm ]
Post subject:  RE:Pong Menu help and WidgetModule.tu opens

thank you for the syntax code

ok now my menu is alright, but when i ask for the name from the user, the letters wont show up as they are typing, it will only show up when they hit enter

here is my code

Turing:
import GUI
View.Set ("graphics:650;400,offscreenonly,nobuttonbar")
Mouse.ButtonChoose ("multibutton")

var xpos, ypos, ypos1, ypos2, ypos3, ypos4 : int := 1
var x : int := maxx div 2
var y : int := maxy div 2
var y1 : int := maxy div 2 - 35
var y2 : int := maxy div 2 + 35
var y3 : int := maxy div 2 - 35
var y4 : int := maxy div 2 + 35
var key : array char of boolean
var x5, y5, button : int
var speed : int := 5
var counter : int := 0
var score1, score2 := 0
var answer : string (1)
var fontID, height, ascent, descent, internalLeading : int
var name1, name2 : string
var Bcolour : int

colourback (black)      %Making the whole background Black

cls                     %the Black colour can take over the whole screen



process DoMusic         %Music process

    Music.PlayFile ("swizz_beat-It_s_me_snitches_instrumental.mp3")     %File name
    View.Update
end DoMusic

procedure leftbar       %Left bar procedure
    drawfillbox (0, y1, 5, y2, white)       %The left paddle
end leftbar

procedure rightbar      %Right bar procedure
    drawfillbox (maxx - 5, y3, maxx, y4, white)         %The right paddle
end rightbar

procedure keyboard      %The whole keyboard procedure
    %player 1
    drawfillbox (0, y1, 5, y2, white)       %The left paddle
    delay (2)
    cls         %The paddle is deleted
    y1 := y1 + 5        %movement of the paddle
    y2 := y2 + 5
end keyboard
%                                                      ^
procedure keyboard2     %same thing as above           |
    %player 1
    drawfillbox (0, y1, 5, y2, white)
    delay (2)
    cls
    y1 := y1 - 5
    y2 := y2 - 5
end keyboard2

procedure mouse         %Mouse procedure
    %player 2
    drawfillbox (maxx - 5, y3, maxx, y4, white)     %The right paddle
    View.Update         %Avoiding flickering
    delay (5)
    cls                 %deleting the paddle

    if button = 1 and y3 > 0 then       %If left button is clicked then
        y3 := y3 - 5                    %Move the object down
        y4 := y4 - 5
    elsif button = 100 and y4 < maxy then       %If right is clicked then
        y3 := y3 + 5                            %Move Up
        y4 := y4 + 5
    end if
end mouse

procedure ball          %Ball procedure

    %ball
    drawfilloval (x, y, 5, 5, white)
    if speed = 1 then
        delay (5)
    elsif speed = 2 then
        delay (0)
    end if
    if x = 10 and y >= y1 and y <= y2 then      %If it hits the left paddle then
        xpos := -xpos                           %bounce back

    elsif y >= y3 and y <= y4 and x = maxx - 10 then  %If it hits the right paddle
        xpos := -xpos                                 %then bounce back
    end if

    if x < 5 or x >= maxx - 5 then          %If the ball hits the wall, then
        xpos := -xpos                       %bounce back
    end if

    if y < 5 or y >= maxy - 5 then
        ypos := -ypos
    end if

end ball

procedure loc_ball      %If the user does not hit the ball then, relocate the
    x := maxx div 2     %the ball to the centre
    y := maxy div 2
end loc_ball

procedure instruction
    colour (yellow)
    put repeat ("%", maxcol)
    locate (2, maxcol div 2 - 6)

    put "Instructions"
    locate (4, 1)

    put "Move the Left Paddle with the Left and Right Arrows"
    put "Move the Right Paddle with the mouse buttons"
    put "First person to get 5 points Wins"
    put repeat ("%", maxcol)
    View.Update
end instruction

procedure game
    cls
    locate (1, 1)
    colour (white)
    put "Player 1 enter your name :" ..
    View.Update
    get name1 : *
    View.Update
    locate (3, 1)
    put "Player 2 enter your name :" ..
    View.Update
    get name2 : *
    View.Update
    loop
        locate (5, 1)
        put "What Background colour do you want? (255 for Black and 32 for Dark Blue) :" ..
        View.Update
        get Bcolour
        View.Update
        if Bcolour = 255 or Bcolour = 32 then
            exit
        else
            put "Wrong background colour"
            View.Update
        end if
    end loop
    loop
        locate (7, 1)
        put "What speed? (1 for slow and 2 for fast) :" ..
        View.Update
        get speed
        View.Update
        if speed = 1 or speed = 2 then
            exit
        else
            put "Wrong speed"
            View.Update
        end if
    end loop
    colourback (Bcolour)
    cls

    fork DoMusic %Playing the music

    loop
        ball %Outputting the ball
        leftbar %The left paddle
        rightbar %The right paddle


        View.Update %Avoiding the flicker
        x := x + xpos %Movement of the ball
        y := y + ypos

        counter := counter + 1 %The speed of the ball

        Mouse.Where (x5, y5, button) %You always need this for mouse usage
        mouse %Using the mouse procedure

        Input.KeyDown (key)
        if key (KEY_LEFT_ARROW) and y2 < maxy then %if left key is pressed then use
            keyboard                     %keyboard procedure
        elsif key (KEY_RIGHT_ARROW) and y1 > 0 then %if left key is pressed then use
            keyboard2                    %keyboard2 procedure
        end if

        if x = 5 or x = maxx - 5 then %If a player  misses then

            delay (200)
            loc_ball %Locate the ball in the middle

        end if

        if x <= 6 then %if player 1 misses then

            score2 := score2 + 1 %Give score to player 2
        elsif x >= maxx - 6 then %if player 2 misses then

            score1 := score1 + 1 %Give score to player 1
        end if

        locate (1, 1) %The score location
        colour (white)
        put score1   %The score

        locate (1, maxcol)
        colour (white)
        put score2

        if score1 = 5 then %If score = 5
            locate (maxrow div 2, maxcol div 2 - 6) %Locate in the middle
            colour (white)
            put name1, " WON!"
            delay (500)
            Music.PlayFileStop
            exit
        elsif score2 = 5 then
            locate (maxrow div 2, maxcol div 2 - 6)
            colour (white)
            put name2, " WON!"
            delay (500)
            Music.PlayFileStop
            exit
        end if
    end loop  %Ending the final loop
end game

procedure menu
    fontID := Font.New ("Ariel:72:bold")
    Font.Sizes (fontID, height, ascent, descent, internalLeading)
    Font.Draw ("PONG!!", maxrow div 2, maxcol div 2 - 6, fontID, white)


    var Instruc : int := GUI.CreateButton (maxx - 200, 10, 0, "Instructions",
        instruction)
    View.Update
    var Play : int := GUI.CreateButton (maxx - 100, 10, 0, "Play",
        game)
    View.Update
    loop
        exit when GUI.ProcessEvent
    end loop

end menu

menu



Author:  andrew. [ Thu Mar 26, 2009 5:12 pm ]
Post subject:  RE:Pong Menu help and WidgetModule.tu opens

I believe the reason that the text doesn't show is that you have offscreenonly on. It doesn't update the screen while typing text. You have to turn off offscreenonly before you get the names, then turn it back on after. Like this:
Turing:
View.Set ("nooffscreenonly")
get name : *
View.Set ("offscreenonly")

Author:  uknowhoiam [ Fri Mar 27, 2009 11:36 pm ]
Post subject:  RE:Pong Menu help and WidgetModule.tu opens

thank you it works now Very Happy


: