
-----------------------------------
sakibur001
Mon Jan 16, 2017 5:46 pm

Need help, my program doesnt go back to a proc properly after an object reaches a certain point.
-----------------------------------
What is it you are trying to achieve?
I want my program to go to a congrats proc and then back to mainmenu after it reaches the finish line. 

What is the problem you are having?
I tried a few ways, but none seem to be working properly, i was able to open and close the congrats window, and open main menu, but for some reason, instead of the mainmenu content showing, it still shows the game content in the mainmenu window. Im kinda confused on whats happening.  

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

% Mr. Rosen
% Final Culminating Activity
% Second Version of Driving Simulator (V2.1)

%Import the GUI program/commands
import GUI

%Global Variable Declarations
var mainMenuButton : int := 0
var instructionButton : int := 0
var playGameButton : int := 0
var goodByeButton : int := 0
var mainMenuWindow : int := 0
var goodByeWin : int := 0
var instructWin : int := 0
var playGameWin : int := 0
var winOrLoseWind : int := 0
var crashWin : int := 0
var congratsWin : int := 0
var intfont : int
var intfont2 : int
var finished : boolean := false
%Font type and size
%Note: not being used for all text in program
intfont := Font.New ("Comic Sans MS:12")

% Procedure Forward Declaration Section
forward procedure introduction
forward procedure mainMenu
forward procedure playGame
forward procedure goodBye
forward procedure instruction


% Places a title at the top of the window
procedure title
    cls
    Font.Draw ("Driving Simulator", 180, 480, intfont, black)
end title

procedure introAni
    %This procedure is apart of the intro, it will show a streetlight turning green
    %Then it will play a car start-up sound and a car will move from the left to the right of the window.
    %It will continue with the intro
    var picture : int
    Text.ColourBack (54)
    title
    %Welcome message
    Font.Draw ("Welcome! Are you ready to play? Lets go!", 120, 370, intfont, black)
    %Street light turning green
    %Black box
    drawfillbox (15, 200, 85, 400, 7)
    delay (200)
    %Red light
    drawfilloval (50, 350, 20, 20, brightred)
    delay (500)
    drawfilloval (50, 350, 20, 20, brightred)
    %Yellow light
    drawfilloval (50, 300, 20, 20, yellow)
    delay (500)
    drawfilloval (50, 300, 20, 20, yellow)
    %Green light
    drawfilloval (50, 250, 20, 20, brightgreen)
    delay (500)
    drawfilloval (50, 250, 20, 20, brightgreen)
    delay (300)
    %Car start-up sound
    Music.PlayFile ("carstart.wav")
    % A car will move from the left to the right of the screen
    % Body
    Draw.FillOval (100, 100, 100, 25, blue)
    Draw.FillOval (190, 100, 8, 5, yellow)
    Draw.FillOval (3, 108, 3, 10, blue)
    % Tires
    Draw.FillOval (50, 75, 22, 22, 0)
    Draw.FillOval (50, 75, 20, 20, 255)
    Draw.FillOval (50, 75, 2, 2, 236)
    Draw.FillOval (150, 75, 22, 22, 0)
    Draw.FillOval (150, 75, 20, 20, 255)
    Draw.FillOval (150, 75, 2, 2, 236)
    % Cab
    Draw.ThickLine (50, 120, 70, 150, 4, blue)
    Draw.ThickLine (150, 120, 130, 150, 4, blue)
    Draw.ThickLine (130, 150, 70, 150, 4, blue)
    Draw.ThickLine (100, 120, 100, 150, 4, blue)
    Draw.Line (99, 75, 99, 152, 0)
    Draw.FillOval (60, 115, 4, 1, 0)
    Draw.FillOval (110, 115, 4, 1, 0)
    picture := Pic.New (0, 0, 220, 199)
    Draw.Cls
    for i : 0 .. 300 by 10
        Pic.Draw (picture, 0 + i, 0, picCopy)
        Time.Delay (35)
        cls
    end for
    delay (400)
end introAni

% Introduction of the program/game to the user
body proc introduction
    mainMenuWindow := Window.Open ("position:top;left;graphics:500;500")
    % introAni
    %Change background colour to blue
    Text.ColourBack (54)
    title
    locate (4, 1)
    put "This program will test your driving skills. You will have to  drive through a town with different cars and street lights    appearing. Your goal is to reach the end of the street safely."
    mainMenuButton := GUI.CreateButton (200, 100, 0, "Main Menu", mainMenu)
    %Introductory noise of a car
    %Music.PlayFile ("carstart.wav")
    %Simple street light animation
    drawfillbox (15, 100, 85, 300, 7)
    delay (200)
    drawfilloval (50, 250, 20, 20, brightred)
    delay (500)
    drawfilloval (50, 250, 20, 20, brightred)
    drawfilloval (50, 200, 20, 20, yellow)
    delay (500)
    drawfilloval (50, 200, 20, 20, yellow)
    drawfilloval (50, 150, 20, 20, brightgreen)
    delay (500)
    drawfilloval (50, 150, 20, 20, brightgreen)

end introduction

% Main Menu for the user to make choices regarding game play
body proc mainMenu
    %Menu background colour blue
    Text.ColourBack (54)
    title
    locate (3, 27)
    %put "Main Menu"
    Font.Draw ("Main Menu", 200, 460, intfont, black)
    Font.Draw ("Choose an option:", 10, 400, intfont, black)
    %put "Choose an option:"
    Window.Hide (defWinID)
    Window.Hide (instructWin)
    Window.Hide (playGameWin)
    Window.Show (mainMenuWindow)
    Window.SetActive (mainMenuWindow)
    %Create buttons to play, exit or get help
    instructionButton := GUI.CreateButton (290, 225, 0, "Help", instruction)
    playGameButton := GUI.CreateButton (145, 225, 0, "Play", playGame)
    goodByeButton := GUI.CreateButton (220, 225, 0, "Exit", goodBye)
    Window.Hide (playGameWin)
    %Music.PlayFile ("tweety.wav")
end mainMenu

procedure congrats
    %Window.Close (playGameWin)
    congratsWin := Window.Open ("position:400;200;graphics:500;500")
    Window.Show (congratsWin)
    Window.SetActive (congratsWin)
    put "Congrats"
    delay (2000)
    mainMenu
    Window.Hide (congratsWin)
    Window.Hide (playGameWin)
    finished := false
end congrats

% This is to provide instructions or help to the user
body proc instruction
    Window.Hide (mainMenuWindow)
    instructWin := Window.Open ("position:400;200;graphics:500;500")
    %Instructions window background colour red
    Text.ColourBack (12)
    title
    %Put intructions
    Font.Draw ("Instructions:", 0, 440, intfont, black)
    locate (6, 1)
    put "This game is a basic Driving Simulator, it will feature a car which you will be driving on a street through the town." ..
    put " There will be streets and lights appearing, which you will have to  obey." ..
    put "The goal of the game is to reach the end without hitting a building, if you do, then GAME OVER. To control the car, you have to use the arrow keys."
    %Picture of arrow keys
    var pictureID : int
   % pictureID := Pic.FileNew ("arrowkeys1.bmp")
    %Pic.Draw (pictureID, 169, 150, picMerge)
    %Button to return to the main menu
    mainMenuButton := GUI.CreateButton (166, 80, 0, "Return to the Main Menu", mainMenu)
end instruction

%if user crashes, then they will be redirected to this procedure
procedure crash
    crashWin := Window.Open ("graphics:max;max")
    Window.SetActive (crashWin)
    cls
    GUI.SetBackgroundColor (black)
    var pictureID : int
   % pictureID := Pic.FileNew ("wastedgta.bmp")
    %Pic.Draw (pictureID, 530, 230, picMerge)
  %  Music.PlayFile ("wasted.mp3")
end crash


% This is where the game is being played
body proc playGame
    var x, y : int
    x := 115
    y := 40
    var chars : array char of boolean
    Window.Hide (mainMenuWindow)
    %Fits the screen
    playGameWin := Window.Open ("graphics:max;max")
    Window.SetActive (playGameWin)
    % put ""
    %put "This is it! Get ready to drive!"
    %delay (1000)
    %cls
    %Moves the car
    loop
        View.Set ("offscreenonly")
        Input.KeyDown (chars)

        if chars (KEY_UP_ARROW) then
            y := y + 5
        end if
        if chars (KEY_RIGHT_ARROW) then
            x := x + 5
        end if
        if chars (KEY_LEFT_ARROW) then
            x := x - 5
        end if
        if chars (KEY_DOWN_ARROW) then
            y := y - 5
        end if
        drawfillbox (x, y, x + 30, y + 20, brightred)
        %   drawfillbox (x - 3, y - 3, x + 10, y + 10, 7)
        View.Update
        delay (15)
        %Draws the background and streets
        %background black
        drawfillbox (0, 0, maxx, maxy, 7)
        % Vertical roads
        drawfillbox (90, 0, 170, maxy, grey)
        drawfillbox (500, 0, 580, maxy, grey)
        drawfillbox (900, 0, 980, maxy, grey)
        %Horizontal Roads
        drawfillbox (0, 190, maxx, 290, grey)
        drawfillbox (0, 400, maxx, 500, grey)
        drawfillbox (980, 580, maxx, 650, grey)
        %person on a street
        % drawfilloval (200, 225, 7, 7, blue)  %head
        %drawline (200, 210, 200, 225, blue)  %body
        %drawline (200, 210, 196, 195, blue)  %left leg
        %drawline (200, 210, 204, 195, blue)  %right leg
        %drawline (195, 212, 205, 212, blue)  %arms
        %Start and finish word placement
        Font.Draw ("START", 100, 25, intfont, green)
        Font.Draw ("FINISH", 1180, 610, intfont, brightred)
        %Checks if the user has reached the "Finish" line
        if (x >= 1180 and x >= 1180) and (y >= 610 and y >= 610) then
            finished := true
            %cls
            Window.Hide (playGameWin)
            congrats
            x := 115
            y := 40

            %Checks if the user crashes into a wall/building (the black stuff)
            %If they crash then the game resets after the crash proc
            %All of these statements include all of the buildings (black) and the end of the roads
        elsif (x >= 138 and x = 0 and y = 0 and x = 0 and y = 138 and x = 270 and y = 0 and x = 270 and y = 0 and x = 190 and y = 0 and x = 400 and y = 0 and x = 480 and y = 94 and x = 660 and y = 94 and x = 0 and y = 138 and x = 480 and y = 550 and x = 0 and y = 550 and x = 270 and y = 550 and x = 480 and y = 950 and x = 0 and y = 950 and x = 270 and y = 950 and x = 480 and y = 950 and x = 630 and y = 500 and x = 0 and y = 500 and x = 660 and y = 900 and x = 0 and y = 900 and x = 660 and y = 1310 and x = 190 and y = 1310 and x = 400 and y = 180 and x = 195 and y = 90 and x = 40 and y = 150 and x = 100 and y = 90 and x = 70 and y = 90 and x = 125 and y = 90 and x = 280 and y = 90 and x = 350 and y = 130 and x = 280 and y = 300 and x = 280 and y = 500 and x = 280 and y = 810 and x = 280 and y = 920 and x = 280 and y = 100 and x = 190 and y = 300 and x = 190 and y = 500 and x = 190 and y = 810 and x = 190 and y = 920 and x = 190 and y = 920 and x = 540 and y 