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

Username:   Password: 
 RegisterRegister   
 Closing EXE Files
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
matrix_dude




PostPosted: Sun Jan 23, 2005 10:00 pm   Post subject: 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.

code:

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 <= playerx + 50 and random_positiony >= playery and random_positiony <= playery + 46) or (random_positionx + 24 >= playerx and
                        random_positionx +
                        24 <= playerx + 50 and
                        random_positiony +
                        45 >=
                        playery and
                        random_positiony + 45 <= playery + 46) or (random_positionx + 12 >= playerx and random_positionx + 12 <= playerx + 50 and random_positiony + 23 >= playery and
                        random_positionx + 23 <= playery + 46) then
                    drawbigbang := false %deactivates the flag so the item is not drawn
                    %changes images of the enemy ships
                    Music.PlayFile ("laser2.wav") %plays music file
                    enemy_ship1 := enemy_death
                    enemy_ship2 := enemy_death
                    enemy_ship3 := enemy_death
                    enemy_ship4 := enemy_death
                    enemy_ship5 := enemy_death
                    Time.Delay (1000)
                    %puts the enemies at the top of the screen
                    enemy1y := 400
                    enemy2y := 400
                    enemy3y := 400
                    enemy4y := 400
                    enemy5y := 400
                    %changes the images of the enemies back to their original settings
                    enemy_ship1 := Pic.FileNew ("enemy.bmp")
                    enemy_ship2 := Pic.FileNew ("enemy.bmp")
                    enemy_ship3 := Pic.FileNew ("enemy.bmp")
                    enemy_ship4 := Pic.FileNew ("enemy.bmp")
                    enemy_ship5 := Pic.FileNew ("enemy.bmp")
                    score_count := score_count + 5 %adds 5 to the score_count variable
                    kill_count := kill_count - 5 %decreases the kills needed by 5
                    exit
                end if
            end loop
            drawbigbang := false %deactivates the flag so the item is not drawn
            %decides if a repair kit should be drawn
        elsif random_upgrades = 500 or random_upgrades = 1700 or random_upgrades = 4523 then
            drawrepairkit := 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 <= playerx + 50 and random_positiony >= playery and random_positiony <= playery + 46) or (random_positionx + 24 >= playerx and
                        random_positionx +
                        24 <= playerx + 50 and
                        random_positiony +
                        45 >=
                        playery and
                        random_positiony + 45 <= playery + 46) or (random_positionx + 12 >= playerx and random_positionx + 12 <= playerx + 50 and random_positiony + 23 >= playery and
                        random_positionx + 23 <= playery + 46) then
                    %adds 50 health to the player
                    if health < 150 then
                        for k : 1 .. 50
                            exit when health = 150
                            health := health + 1
                        end for
                    end if
                    exit
                end if
            end loop
            drawrepairkit := false %deactivates the flag so the item is not drawn
        elsif random_upgrades = 28 or random_upgrades = 2200 or random_upgrades = 4000 then
            drawmicrobots := 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 <= playerx + 50 and random_positiony >= playery and random_positiony <= playery + 46) or (random_positionx + 24 >= playerx and
                        random_positionx +
                        24 <= playerx + 50 and
                        random_positiony +
                        45 >=
                        playery and
                        random_positiony + 45 <= playery + 46) or (random_positionx + 12 >= playerx and random_positionx + 12 <= playerx + 50 and random_positiony + 23 >= playery and
                        random_positionx + 23 <= playery + 46) then
                    %refills the player's health to full
                    loop
                        exit when health = 150
                        health := health + 1
                    end loop
                    exit
                end if
            end loop
            drawmicrobots := false %deactivates the flag so the item is not drawn
        end if
    end loop
end upgrades

%process to detect which keys are pressed and what to do
process keys
    loop
        Input.KeyDown (chars)
        %exit
        if chars (esc) then
            open : stream, "scores.txt", put %opens file
            assert stream > 0 %makes sure file exists

            %resets values in the text file to the original
            put : stream, "beginning_value"
            put : stream, 0
            close : stream

            if not Sys.Exec ("menu.exe") then
                put "There was a problem running this program."
                put "Error: ", Error.LastMsg
            end if
            finished := true
            Music.PlayFileStop
            quit
        end if
        %moving right
        if chars ('d') then
            playerx := playerx + 1
        end if
        if playerx > 585 then                 %restricts ship from moving too far right
            playerx := 585
        end if
        % moving left
        if chars ('a') then
            playerx := playerx - 1
        end if
        if playerx < 0 then                 %restricts ship from moving too far left
            playerx := 0
        end if
        %moving up
        if chars ('w') then
            playery := playery + 1
        end if
        if playery > 430 then                 %restricts ship from moving too far left
            playery := 430
        end if
        %moving down
        if chars ('s') then
            playery := playery - 1
        end if
        if playery < 0 then                 %restricts ship from moving too far left
            playery := 0
        end if
        %firing beam
        if chars ('k') then
            Music.PlayFile ("laser.wav") %plays music file
            drawbeam := true %allows the beam to be drawn

            %detects collision between the laser and the enemy ships
            if playerx + 22 >= enemy1x and playerx + 22 <= enemy1x + 60 and playery < enemy1y then
                enemy_ship1 := enemy_death %changes the image of the enemy
                Pic.Draw (beam, playerx + 22, playery + 22, picMerge) %draws the beam again
                Time.Delay (1000)
                enemy1y := 400 %places enemy ship at the top of the screen
                enemy_ship1 := Pic.FileNew ("enemy.bmp") %changes enemy picture back to original
                score_count := score_count + 1 %adds to the score
                kill_count := kill_count - 1 %subtracts a kill needed
            end if

            if playerx + 22 >= enemy2x and playerx + 22 <= enemy2x + 60 and playery < enemy2y then
                enemy_ship2 := enemy_death %changes the image of the enemy
                Pic.Draw (beam, playerx + 22, playery + 22, picMerge) %draws the beam again
                Time.Delay (1000)
                enemy2y := 400 %places enemy ship at the top of the screen
                enemy_ship2 := Pic.FileNew ("enemy.bmp") %changes enemy picture back to original

                score_count := score_count + 1 %adds to the score
                kill_count := kill_count - 1 %subtracts a kill needed
            end if

            if playerx + 22 >= enemy3x and playerx + 22 <= enemy3x + 60 and playery < enemy3y then
                enemy_ship3 := enemy_death %changes the image of the enemy
                Pic.Draw (beam, playerx + 22, playery + 22, picMerge) %draws the beam again
                Time.Delay (1000)
                enemy3y := 400 %places enemy ship at the top of the screen
                enemy_ship3 := Pic.FileNew ("enemy.bmp") %changes enemy picture back to original

                score_count := score_count + 1 %adds to the score
                kill_count := kill_count - 1 %subtracts a kill needed
            end if

            if playerx + 22 >= enemy4x and playerx + 22 <= enemy4x + 60 and playery < enemy4y then
                enemy_ship4 := enemy_death %changes the image of the enemy
                Pic.Draw (beam, playerx + 22, playery + 22, picMerge) %draws the beam again
                Time.Delay (1000)
                enemy4y := 400 %places enemy ship at the top of the screen
                enemy_ship4 := Pic.FileNew ("enemy.bmp") %changes enemy picture back to original

                score_count := score_count + 1 %adds to the score
                kill_count := kill_count - 1 %subtracts a kill needed
            end if

            if playerx + 22 >= enemy5x and playerx + 22 <= enemy5x + 60 and playery < enemy5y then
                enemy_ship5 := enemy_death %changes the image of the enemy
                Pic.Draw (beam, playerx + 22, playery + 22, picMerge) %draws the beam again
                Time.Delay (1000)
                enemy5y := 400 %places enemy ship at the top of the screen
                enemy_ship5 := Pic.FileNew ("enemy.bmp") %changes enemy picture back to original

                score_count := score_count + 1 %adds to the score
                kill_count := kill_count - 1 %subtracts a kill needed
            end if
        end if
    end loop

end keys


%*************************ENEMY ONE************************
var count1_1, count1_2, count1_3, count1_4 : int := 0
var random_number1 : int %holds the random number to determine the direction

%determines the direction the enemy ship will take
process enemy1_logic
    loop
        count1_1 := 0
        count1_2 := 0
        count1_3 := 0
        count1_4 := 0

        randint (random_number1, 1, 4) %creates a random number

        %determines what action is taken depending on the number generated
        if random_number1 = 1 then
            loop
                Time.Delay (20)
                count1_1 := count1_1 + 1 %counts the number of time the loop goes around
                exit when count1_1 = 10 or enemy1x = 580
                enemy1x := enemy1x + 5 %moves the enemy right

                %determines if collision has occured between the player and the enemy
                if (enemy1x >= playerx and enemy1x <= playerx + 50 and enemy1y >= playery and enemy1y <= playery + 46) or (enemy1x + 60 >= playerx and enemy1x + 60 <= playerx + 50 and
                        enemy1y +
                        80 >=
                        playery and
                        enemy1y + 80 <= playery + 46) or (enemy1x + 30 >= playerx and enemy1x + 30 <= playerx + 50 and enemy1y + 40 >= playery and
                        enemy1y + 40 <= playery + 46) then
                    health := health - 4 %decreases health of player
                end if

            end loop
        elsif random_number1 = 2 then
            loop
                Time.Delay (20)
                count1_2 := count1_2 + 1 %counts the number of time the loop goes around
                exit when count1_2 = 10 or enemy1x = -5
                enemy1x := enemy1x - 5 %moves the enemy left

                %determines if collision has occured between the player and the enemy
                if (enemy1x >= playerx and enemy1x <= playerx + 50 and enemy1y >= playery and enemy1y <= playery + 46) or (enemy1x + 60 >= playerx and enemy1x + 60 <= playerx + 50 and
                        enemy1y +
                        80 >=
                        playery and
                        enemy1y + 80 <= playery + 46) or (enemy1x + 30 >= playerx and enemy1x + 30 <= playerx + 50 and enemy1y + 40 >= playery and
                        enemy1y + 40 <= playery + 46) then
                    health := health - 4 %decreases health of player
                end if

            end loop
        elsif random_number1 = 3 then
            loop
                Time.Delay (20)
                count1_3 := count1_3 + 1 %counts the number of time the loop goes around
                exit when count1_3 = 10 or enemy1y = 400
                enemy1y := enemy1y + 5 %moves the enemy up

                %determines if collision has occured between the player and the enemy
                if (enemy1x >= playerx and enemy1x <= playerx + 50 and enemy1y >= playery and enemy1y <= playery + 46) or (enemy1x + 60 >= playerx and enemy1x + 60 <= playerx + 50 and
                        enemy1y +
                        80 >=
                        playery and
                        enemy1y + 80 <= playery + 46) or (enemy1x + 30 >= playerx and enemy1x + 30 <= playerx + 50 and enemy1y + 40 >= playery and
                        enemy1y + 40 <= playery + 46) then
                    health := health - 4 %decreases health of player
                end if

            end loop
        elsif random_number1 = 4 then
            loop
                exit when count1_4 = 10 or enemy1y = -5
                Time.Delay (20)
                count1_4 := count1_4 + 1 %counts the number of time the loop goes around
                enemy1y := enemy1y - 5 %moves the enemy down

                %determines if collision has occured between the player and the enemy
                if (enemy1x >= playerx and enemy1x <= playerx + 50 and enemy1y >= playery and enemy1y <= playery + 46) or (enemy1x + 60 >= playerx and enemy1x + 60 <= playerx + 50 and
                        enemy1y +
                        80 >=
                        playery and
                        enemy1y + 80 <= playery + 46) or (enemy1x + 30 >= playerx and enemy1x + 30 <= playerx + 50 and enemy1y + 40 >= playery and
                        enemy1y + 40 <= playery + 46) then
                    health := health - 4 %decreases health of player
                end if
            end loop
        end if
    end loop
end enemy1_logic

%*****************ENEMY TWO*********************

%all actions are the same as the section entitled "ENEMY ONE"

var count2_1, count2_2, count2_3, count2_4 : int := 0
var random_number2 : int %holds the random number to determine the direction

%determines the direction the enemy ship will take

process enemy2_logic
    loop
        count2_1 := 0
        count2_2 := 0
        count2_3 := 0
        count2_4 := 0

        randint (random_number2, 1, 4)

        if random_number2 = 1 then
            loop
                Time.Delay (20)
                count2_1 := count2_1 + 1
                exit when count2_1 = 10 or enemy2x = 580
                enemy2x := enemy2x + 5
                if (enemy2x >= playerx and enemy2x <= playerx + 50 and enemy2y >= playery and enemy2y <= playery + 46) or (enemy2x + 60 >= playerx and enemy2x + 60 <= playerx + 50 and
                        enemy2y + 80 >=
                        playery and
                        enemy2y + 80 <= playery + 46) or (enemy2x + 30 >= playerx and enemy2x + 30 <= playerx + 50 and enemy2y + 40 >= playery and
                        enemy2y + 40 <= playery + 46) then
                    health := health - 4
                end if
            end loop
        elsif random_number2 = 2 then
            loop
                Time.Delay (20)
                count2_2 := count2_2 + 1
                exit when count2_2 = 10 or enemy2x = -5
                enemy2x := enemy2x - 5
                if (enemy2x >= playerx and enemy2x <= playerx + 50 and enemy2y >= playery and enemy2y <= playery + 46) or (enemy2x + 60 >= playerx and enemy2x + 60 <= playerx + 50 and
                        enemy2y + 80 >=
                        playery and
                        enemy2y + 80 <= playery + 46) or (enemy2x + 30 >= playerx and enemy2x + 30 <= playerx + 50 and enemy2y + 40 >= playery and
                        enemy2y + 40 <= playery + 46) then
                    health := health - 4
                end if
            end loop
        elsif random_number2 = 3 then
            loop
                Time.Delay (20)
                count2_3 := count2_3 + 1
                exit when count2_3 = 10 or enemy2y = 400
                enemy2y := enemy2y + 5
                if (enemy2x >= playerx and enemy2x <= playerx + 50 and enemy2y >= playery and enemy2y <= playery + 46) or (enemy2x + 60 >= playerx and enemy2x + 60 <= playerx + 50 and
                        enemy2y + 80 >=
                        playery and
                        enemy2y + 80 <= playery + 46) or (enemy2x + 30 >= playerx and enemy2x + 30 <= playerx + 50 and enemy2y + 40 >= playery and
                        enemy2y + 40 <= playery + 46) then
                    health := health - 4
                end if
            end loop
        elsif random_number2 = 4 then
            loop
                exit when count2_4 = 10 or enemy2y = -5
                Time.Delay (20)
                count2_4 := count2_4 + 1
                enemy2y := enemy2y - 5
                if (enemy2x >= playerx and enemy2x <= playerx + 50 and enemy2y >= playery and enemy2y <= playery + 46) or (enemy2x + 60 >= playerx and enemy2x + 60 <= playerx + 50 and
                        enemy2y + 80 >=
                        playery and
                        enemy2y + 80 <= playery + 46) or (enemy2x + 30 >= playerx and enemy2x + 30 <= playerx + 50 and enemy2y + 40 >= playery and
                        enemy2y + 40 <= playery + 46) then
                    health := health - 4
                end if

            end loop
        end if
    end loop
end enemy2_logic

%*****************ENEMY THREE*********************

%all actions are the same as the section entitled "ENEMY ONE"

var count3_1, count3_2, count3_3, count3_4 : int := 0
var random_number3 : int %holds the random number to determine the direction

%determines the direction the enemy ship will take

process enemy3_logic
    loop
        count3_1 := 0
        count3_2 := 0
        count3_3 := 0
        count3_4 := 0

        randint (random_number3, 1, 4)

        if random_number3 = 1 then
            loop
                Time.Delay (20)
                count3_1 := count3_1 + 1
                exit when count3_1 = 10 or enemy3x = 580
                enemy3x := enemy3x + 5
                if (enemy3x >= playerx and enemy3x <= playerx + 50 and enemy3y >= playery and enemy3y <= playery + 46) or (enemy3x + 60 >= playerx and enemy3x + 60 <= playerx + 50 and
                        enemy3y + 80 >=
                        playery and
                        enemy3y + 80 <= playery + 46) or (enemy3x + 30 >= playerx and enemy3x + 30 <= playerx + 50 and enemy3y + 40 >= playery and
                        enemy3y + 40 <= playery + 46) then
                    health := health - 4
                end if
            end loop
        elsif random_number3 = 2 then
            loop
                Time.Delay (20)
                count3_2 := count3_2 + 1
                exit when count3_2 = 10 or enemy3x = -5
                enemy3x := enemy3x - 5
                if (enemy3x >= playerx and enemy3x <= playerx + 50 and enemy3y >= playery and enemy3y <= playery + 46) or (enemy3x + 60 >= playerx and enemy3x + 60 <= playerx + 50 and
                        enemy3y + 80 >=
                        playery and
                        enemy3y + 80 <= playery + 46) or (enemy3x + 30 >= playerx and enemy3x + 30 <= playerx + 50 and enemy3y + 40 >= playery and
                        enemy3y + 40 <= playery + 46) then
                    health := health - 4
                end if
            end loop
        elsif random_number3 = 3 then
            loop
                Time.Delay (20)
                count3_3 := count3_3 + 1
                exit when count3_3 = 10 or enemy3y = 400
                enemy3y := enemy3y + 5
                if (enemy3x >= playerx and enemy3x <= playerx + 50 and enemy3y >= playery and enemy3y <= playery + 46) or (enemy3x + 60 >= playerx and enemy3x + 60 <= playerx + 50 and
                        enemy3y + 80 >=
                        playery and
                        enemy3y + 80 <= playery + 46) or (enemy3x + 30 >= playerx and enemy3x + 30 <= playerx + 50 and enemy3y + 40 >= playery and
                        enemy3y + 40 <= playery + 46) then
                    health := health - 4
                end if
            end loop
        elsif random_number3 = 4 then
            loop
                exit when count3_4 = 10 or enemy3y = -5
                Time.Delay (20)
                count3_4 := count3_4 + 1
                enemy3y := enemy3y - 5
                if (enemy3x >= playerx and enemy3x <= playerx + 50 and enemy3y >= playery and enemy3y <= playery + 46) or (enemy3x + 60 >= playerx and enemy3x + 60 <= playerx + 50 and
                        enemy3y + 80 >=
                        playery and
                        enemy3y + 80 <= playery + 46) or (enemy3x + 30 >= playerx and enemy3x + 30 <= playerx + 50 and enemy3y + 40 >= playery and
                        enemy3y + 40 <= playery + 46) then
                    health := health - 4
                end if

            end loop
        end if
    end loop
end enemy3_logic

%*****************ENEMY FOUR*********************

%all actions are the same as the section entitled "ENEMY ONE"

var count4_1, count4_2, count4_3, count4_4 : int := 0
var random_number4 : int %holds the random number to determine the direction

%determines the direction the enemy ship will take

process enemy4_logic
    loop
        count4_1 := 0
        count4_2 := 0
        count4_3 := 0
        count4_4 := 0

        randint (random_number4, 1, 4)

        if random_number4 = 1 then
            loop
                Time.Delay (20)
                count4_1 := count4_1 + 1
                exit when count4_1 = 10 or enemy4x = 580
                enemy4x := enemy4x + 5
                if (enemy4x >= playerx and enemy4x <= playerx + 50 and enemy4y >= playery and enemy4y <= playery + 46) or (enemy4x + 60 >= playerx and enemy4x + 60 <= playerx + 50 and
                        enemy4y + 80 >=
                        playery and
                        enemy3y + 80 <= playery + 46) or (enemy3x + 30 >= playerx and enemy3x + 30 <= playerx + 50 and enemy3y + 40 >= playery and
                        enemy3y + 40 <= playery + 46) then
                    health := health - 4
                end if
            end loop
        elsif random_number4 = 2 then
            loop
                Time.Delay (20)
                count4_2 := count4_2 + 1
                exit when count4_2 = 10 or enemy4x = -5
                enemy4x := enemy4x - 5
                if (enemy4x >= playerx and enemy4x <= playerx + 50 and enemy4y >= playery and enemy4y <= playery + 46) or (enemy4x + 60 >= playerx and enemy4x + 60 <= playerx + 50 and
                        enemy4y + 80 >=
                        playery and
                        enemy3y + 80 <= playery + 46) or (enemy3x + 30 >= playerx and enemy3x + 30 <= playerx + 50 and enemy3y + 40 >= playery and
                        enemy3y + 40 <= playery + 46) then
                    health := health - 4
                end if
            end loop
        elsif random_number4 = 3 then
            loop
                Time.Delay (20)
                count4_3 := count4_3 + 1
                exit when count4_3 = 10 or enemy4y = 400
                enemy4y := enemy4y + 5
                if (enemy4x >= playerx and enemy4x <= playerx + 50 and enemy4y >= playery and enemy4y <= playery + 46) or (enemy4x + 60 >= playerx and enemy4x + 60 <= playerx + 50 and
                        enemy4y + 80 >=
                        playery and
                        enemy3y + 80 <= playery + 46) or (enemy3x + 30 >= playerx and enemy3x + 30 <= playerx + 50 and enemy3y + 40 >= playery and
                        enemy3y + 40 <= playery + 46) then
                    health := health - 4
                end if
            end loop
        elsif random_number4 = 4 then
            loop
                exit when count4_4 = 10 or enemy4y = -5
                Time.Delay (20)
                count4_4 := count4_4 + 1
                enemy4y := enemy4y - 5
                if (enemy4x >= playerx and enemy4x <= playerx + 50 and enemy4y >= playery and enemy4y <= playery + 46) or (enemy4x + 60 >= playerx and enemy4x + 60 <= playerx + 50 and
                        enemy4y + 80 >=
                        playery and
                        enemy4y + 80 <= playery + 46) or (enemy4x + 30 >= playerx and enemy4x + 30 <= playerx + 50 and enemy4y + 40 >= playery and
                        enemy4y + 40 <= playery + 46) then
                    health := health - 4
                end if

            end loop
        end if
    end loop
end enemy4_logic

%*****************ENEMY FIVE*********************

%all actions are the same as the section entitled "ENEMY ONE"

var count5_1, count5_2, count5_3, count5_4 : int := 0
var random_number5 : int %holds the random number to determine the direction

%determines the direction the enemy ship will take

process enemy5_logic
    loop
        count5_1 := 0
        count5_2 := 0
        count5_3 := 0
        count5_4 := 0

        randint (random_number5, 1, 4)

        if random_number5 = 1 then
            loop
                Time.Delay (20)
                count5_1 := count5_1 + 1
                exit when count5_1 = 10 or enemy5x = 580
                enemy5x := enemy5x + 5
                if (enemy5x >= playerx and enemy5x <= playerx + 50 and enemy5y >= playery and enemy5y <= playery + 46) or (enemy5x + 60 >= playerx and enemy5x + 60 <= playerx + 50 and
                        enemy5y + 80 >=
                        playery and
                        enemy5y + 80 <= playery + 46) or (enemy5x + 30 >= playerx and enemy5x + 30 <= playerx + 50 and enemy5y + 40 >= playery and
                        enemy5y + 40 <= playery + 46) then
                    health := health - 4
                end if
            end loop
        elsif random_number5 = 2 then
            loop
                Time.Delay (20)
                count5_2 := count5_2 + 1
                exit when count5_2 = 10 or enemy5x = -5
                enemy5x := enemy5x - 5
                if (enemy5x >= playerx and enemy5x <= playerx + 50 and enemy5y >= playery and enemy5y <= playery + 46) or (enemy5x + 60 >= playerx and enemy5x + 60 <= playerx + 50 and
                        enemy5y + 80 >=
                        playery and
                        enemy5y + 80 <= playery + 46) or (enemy5x + 30 >= playerx and enemy5x + 30 <= playerx + 50 and enemy5y + 40 >= playery and
                        enemy5y + 40 <= playery + 46) then
                    health := health - 4
                end if
            end loop
        elsif random_number5 = 3 then
            loop
                Time.Delay (20)
                count5_3 := count5_3 + 1
                exit when count5_3 = 10 or enemy5y = 400
                enemy5y := enemy5y + 5
                if (enemy5x >= playerx and enemy5x <= playerx + 50 and enemy5y >= playery and enemy5y <= playery + 46) or (enemy5x + 60 >= playerx and enemy5x + 60 <= playerx + 50 and
                        enemy5y + 80 >=
                        playery and
                        enemy5y + 80 <= playery + 46) or (enemy5x + 30 >= playerx and enemy5x + 30 <= playerx + 50 and enemy5y + 40 >= playery and
                        enemy5y + 40 <= playery + 46) then
                    health := health - 4
                end if
            end loop
        elsif random_number5 = 4 then
            loop
                exit when count5_4 = 10 or enemy5y = -5
                Time.Delay (20)
                count5_4 := count5_4 + 1
                enemy5y := enemy5y - 5
                if (enemy5x >= playerx and enemy5x <= playerx + 50 and enemy5y >= playery and enemy5y <= playery + 46) or (enemy5x + 60 >= playerx and enemy5x + 60 <= playerx + 50 and
                        enemy5y + 80 >=
                        playery and
                        enemy5y + 80 <= playery + 46) or (enemy5x + 30 >= playerx and enemy5x + 30 <= playerx + 50 and enemy5y + 40 >= playery and
                        enemy5y + 40 <= playery + 46) then
                    health := health - 4
                end if
            end loop
        end if
    end loop
end enemy5_logic

%ends the game when parameters are met
process end_game

    loop
        %end the game when the player dies
        if health <= 1 then
            player_ship := player_death

            %resets the values in the text file to default
            open : stream, "scores.txt", put
            assert stream > 0

            put : stream, "beginning_value"
            put : stream, 0
            close : stream

            Time.Delay (5000)
            %goes to game over screen
            if not Sys.Exec ("game_over.exe") then
                put "There was a problem running this program."
                put "Error: ", Error.LastMsg
            end if
            finished := true
            Music.PlayFileStop
            quit
        end if

        %ends level when user accomplishes objectives
        if kill_count <= 0 then
            %takes the score earned in this level and adds it to the .txt one
            var total_score : int
            open : stream, "scores.txt", put
            assert stream > 0

            put : stream, player_name
            total_score := score + 1000
            put : stream, total_score
            close : stream

            %goes to next level
            quit
                finished := true
            Music.PlayFileStop
            quit
        end if
    end loop
end end_game

%plays the music
process level1music
    loop
        Music.PlayFile ("level1.mid")
    end loop
end level1music

%the forks run the processes at the same time
fork level1music
fork end_game
fork keys
fork enemy1_logic
fork enemy2_logic
fork enemy3_logic
fork enemy4_logic
fork enemy5_logic
fork draw
fork upgrades
Sponsor
Sponsor
Sponsor
sponsor
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 1  [ 1 Posts ]
Jump to:   


Style:  
Search: