
-----------------------------------
matrix_dude
Sun Jan 23, 2005 9:59 pm

Closing EXE Files
-----------------------------------
Hi,
I'm new here and just had a question. Basically, when I try to run the program that a friend and I have made, we get a 'run time error' at line 764. It says the error is in the process end_game. The new EXE loads fine but the error is still there and it's annoying. We know processes are not the most efficient way to program with but we can't really change anything now. We need some way for the program to close when end_game is run. We also tried used Window.Close with appropriate window IDs. Any help is appreciated.


setscreen ("graphics: 640;480")
setscreen ("offscreenonly")

const esc : char := chr (27) %makes it so that 'esc' can be pressed to exit the program
var background1 : int := Pic.FileNew ("bg1.jpg") %holds the picture of the background
var player_ship : int := Pic.FileNew ("ship.bmp") %holds the picture of the player's ship
var enemy_ship1 : int := Pic.FileNew ("enemy.bmp") %holds the picture of the first enemy
var enemy_ship2 : int := Pic.FileNew ("enemy.bmp") %holds the picture of the second enemy
var enemy_ship3 : int := Pic.FileNew ("enemy.bmp") %holds the picture of the third enemy
var enemy_ship4 : int := Pic.FileNew ("enemy.bmp") %holds the picture of the fourth enemy
var enemy_ship5 : int := Pic.FileNew ("enemy.bmp") %holds the picture of the fifth
var beam : int := Pic.FileNew ("beam.bmp") %holds the picture of the laser beam
var enemy_death : int := Pic.FileNew ("enemy_die.bmp") %holds the picture of the enemy ship exploding
var repair_kit : int := Pic.FileNew ("repair.bmp") %holds the picture of the repair kit
var micro_kit : int := Pic.FileNew ("microrepair.bmp") %holds the picture of the microbot repair kit
var big_bang : int := Pic.FileNew ("bigbang.bmp") %holds the picture of the "Big Bang"
var bay : int := Pic.FileNew ("bay.bmp") %holds the picture of the enemy docking bay
var player_death : int := Pic.FileNew ("SHIP_DIE.bmp") %holds the picture of the player's ship exploding
var enemy1x : int := 20 %the x coordinate of the first enemy ship
var enemy2x : int := 150 %the x coordinate of the second enemy ship
var enemy3x : int := 280 %the x coordinate of the third enemy ship
var enemy4x : int := 410 %the x coordinate of the fourth enemy ship
var enemy5x : int := 540 %the x coordinate of the fifth enemy ship
var enemy1y, enemy2y, enemy3y, enemy4y, enemy5y : int := 400 % the y coordinates of all the enemy ships
var playerx : int := 295 %the player's x coordinate
var playery : int := 0 %the player's y coordinate
var chars : array char of boolean %variable to hold the key that's being pressed down
var finished : boolean := false %turns the music off and on
var drawbeam : boolean := false %determines if the laser beam should be drawn
var health : int := 150 % the health of the player
var kill_count : int := 2 %the number of kills required to win
var kill_count_string : string %changes the kills to a string
var font : int %the red font used
var drawbigbang : boolean := false %determines if the big bang should be drawn
var drawmicrobots : boolean := false %determines if the microbot repair kit should be drawn
var drawrepairkit : boolean := false %determines if the repair kit should be drawn
var random_upgrades : int %holds a random number
var random_positionx, random_positiony : int %holds a random number
var score : int := 0 %holds the score to be displayed
var score_string : string %changes score to a string
var score_count : int := 0 %counts the number of enemies killed - to be used in creating 'score'
var stream, stream2 : int % holds text files
var transfered_score : string %the score from previous levels
var transfered_score_int : int %transfered_score as an integer
var player_name : string %the player's name - to be used in the text files along with the score


%creates the red font used within the game
font := Font.New ("arial:12:bold")
var width : int := Font.Width ("This is in a serif font", font)
var height, ascent, descent, internalLeading : int
Font.Sizes (font, height, ascent, descent, internalLeading)

%procedure to get accumulated score and make it the starting score
procedure get_score
    open : stream, "scores.txt", get %opens the text file
    assert stream > 0 %makes sure the file exists
    %tansfers the name of the player as well as the score accumulated to next level
    loop
        get : stream, skip
        exit when eof (stream)
        get : stream, player_name
        get : stream, transfered_score
    end loop
    close : stream %closes the file
    %takes the score in the .txt and makes it the starting score
    transfered_score_int := strint (transfered_score)
    score_count := transfered_score_int div 1000
end get_score

get_score




%process to draw all pictures on the screen
process draw
    loop
        Pic.Draw (background1, 0, 0, picCopy) %draws background
        if drawbigbang = true then
            Pic.Draw (big_bang, random_positionx, random_positiony, picMerge) %draws the big bang
        end if
        if drawrepairkit = true then
            Pic.Draw (repair_kit, random_positionx, random_positiony, picMerge) %draws the repair kit
        end if
        if drawmicrobots = true then
            Pic.Draw (micro_kit, random_positionx, random_positiony, picMerge) %draws the microbot repair kit
        end if
        if drawbeam = true then
            Pic.Draw (beam, playerx + 22, playery + 22, picMerge) %draws the laser beam
            Time.Delay (100)
        end if
        Pic.Draw (player_ship, playerx, playery, picMerge) %draws the player's ship
        Pic.Draw (enemy_ship1, enemy1x, enemy1y, picMerge) %draws the first enemy
        Pic.Draw (enemy_ship2, enemy2x, enemy2y, picMerge) %draws the second enemy
        Pic.Draw (enemy_ship3, enemy3x, enemy3y, picMerge) %draws the third enemy
        Pic.Draw (enemy_ship4, enemy4x, enemy4y, picMerge) %draws the fourth enemy
        Pic.Draw (enemy_ship5, enemy5x, enemy5y, picMerge) %draws the fifth enemy
        Draw.Text ("Health:", 5, 25, font, 12) %draws the text 'Health'
        Draw.Box (5, 5, 151, 20, 12) %draws the border of the health bar
        Draw.FillBox (5, 5, health, 20, 12) %draws the health bar
        kill_count_string := intstr (kill_count) %changes the kill count to a string
        Draw.Text ("Kills Needed: ", 450, 10, font, 12) %draws 'Kills Needed: "
        Draw.Text (kill_count_string, 600, 10, font, 12) %draws the kills  needed
        Pic.Draw (bay, 0, 390, picMerge) %draws the enemy landing bay at the top of the screen
        score := 1000 * score_count %creates the score
        score_string := intstr (score) %changes the score to a string
        Draw.Text ("Score: ", 5, 50, font, 12) %displays the score header
        Draw.Text (score_string, 75, 50, font, 12) %draws the score
        View.Update
        drawbeam := false %changes the beam back to false
    end loop
end draw


var count : int := 0 %counts the number of times a loop goes around
%process to create upgrades
process upgrades
    loop
        randint (random_upgrades, 1, 200000) %generates a the random number that the upgrades are determined by

        randint (random_positionx, 1, 600) %generates a random number for the x coordinate of the upgrade
        randint (random_positiony, 1, 350) %generates a random number for the y coordinate of the upgrade

        %decides if a Big Bang upgrade should appear
        if random_upgrades = 2 or random_upgrades = 15 or random_upgrades = 320 then
            drawbigbang := true %activates the flag so the item is drawn
            loop
                count := count + 1 %adds one each time the loop goes around
                exit when count = 100000
                %detects collision
                if (random_positionx >= playerx and random_positionx = playery and random_positiony = playerx and
                        random_positionx +
                        24 =
                        playery and
                        random_positiony + 45 = playerx and random_positionx + 12 = playery and
                        random_positionx + 23 = playerx and random_positionx = playery and random_positiony = playerx and
                        random_positionx +
                        24 =
                        playery and
                        random_positiony + 45 = playerx and random_positionx + 12 = playery and
                        random_positionx + 23 = playerx and random_positionx = playery and random_positiony = playerx and
                        random_positionx +
                        24 =
                        playery and
                        random_positiony + 45 = playerx and random_positionx + 12 = playery and
                        random_positionx + 23 