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

Username:   Password: 
 RegisterRegister   
 Returning to main manu after game finishes
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
bozi39




PostPosted: Fri Apr 28, 2006 12:54 pm   Post subject: Returning to main manu after game finishes

Hey guys. i have been working on my fps game for about 3 weeks now i am geting close to the end. However, i dont kno how to make the game loop back to the main menu once the player has died or they have chosen to. Can you please provide me with suggestions on how i can make this thing happen. i am posting the code but i doubt it will be of any use to you becuse it is so long and because it wont work unless you have the pics to run it and those r too large to upload.
code:

var window := Window.Open ("position:center;center,graphics:1267;953,title:Army's Elite")
buttonchoose ("multibutton")
var ak_47_button, desert_eagle_button, done_button : int
var selection, map_choice : int
var done : boolean := false
var mouse :
    record
        x, y, button, buttonUpDown, right, middle, left, reloading : int
    end record
var active_gun, active_gun_firing, active_map, active_enemy, original_position, weapon_ammo, max_weapon_ammo, active_enemy_x, active_enemy_y : int
var ak_47 := Pic.FileNew ("weapon1.bmp")
var firing_ak_47 := Pic.FileNew ("firing ak-47.bmp")
var desert_eagle := Pic.FileNew ("deagle.bmp")
var firing_desert_eagale := Pic.FileNew ("firing_deagle.bmp")
var level6 := Pic.FileNew ("level6.bmp")
var baghdad := Pic.FileNew ("Baghdad.bmp")
var kabul := Pic.FileNew ("Kabul.bmp")
var skeleton := Pic.FileNew ("skel1.bmp")
var panda := Pic.FileNew ("panda1.bmp")
var weaponsound : array 1 .. 11 of string
    := init ("ak_47.wav", "deagle.wav", "glock.wav",
    "m3.wav", "m4a1.wav", "mac10.wav", "mp5.wav", "p90.wav", "sg552.wav",
    "tmp.wav", "usp.wav")
var x_displacement, y_displacement, firing_displacement_x, firing_displacement_y : int
var x_enemy, y_enemy : int
var enemy_alive : boolean := false
var weapon_class : int
var shot : boolean := false
var font, font2 : int
var weapon_ammo_string : string
var reload : string
var if_reloading : boolean := false
var animation_counter : int := 0
var reloading_counter : int := 0
var weapon_sound : int
var reloadsound : string := "reload.wav"
var empty_sound : string := "empty.wav"
var score_int : int
var enemy_value : int
var score_string : string
var enemy_presence : int := 0
var enemy_damage : int
var player_health : int := 10
var player_health_string : string
var return_to_menue : boolean := false
font := Font.New ("serif:18:bold")
font2 := Font.New ("serif:12:bold,underline")
proc select_gun
    put "Please select your gun"
    put "enter 1 for AK_47"
    put "enter 2 for Desert Eagle"
    get selection
    if selection = 1 then
        active_gun := ak_47
        active_gun_firing := firing_ak_47
        x_displacement := 50
        y_displacement := 450
        firing_displacement_x := 40
        firing_displacement_y := 450
        original_position := 448
        max_weapon_ammo := 30
        weapon_ammo := max_weapon_ammo
        weapon_class := 2
        weapon_sound := 1
    elsif selection = 2 then
        active_gun := desert_eagle
        active_gun_firing := firing_desert_eagale
        x_displacement := -150
        y_displacement := 430
        firing_displacement_x := -250
        firing_displacement_y := 500
        weapon_class := 1
        original_position := 431
        max_weapon_ammo := 7
        weapon_ammo := max_weapon_ammo
        weapon_sound := 2
    end if
end select_gun
proc select_map
    put "Please select a level"
    put "enter 1 for Baghdad"
    put "enter 2 for Kabul"
    get map_choice
    if map_choice = 1 then
        active_map := baghdad
        active_enemy := skeleton
        active_enemy_x := 36
        active_enemy_y := 60
        enemy_value := 10
        score_int := -enemy_value
        enemy_damage := 5
    elsif map_choice = 2 then
        active_map := kabul
        active_enemy := panda
        active_enemy_x := 46
        active_enemy_y := 56
        enemy_value := 8
        score_int := -enemy_value
        enemy_damage := 3
    end if
end select_map

proc enemies_appear
    if active_map = baghdad and enemy_alive = false then
        randint (x_enemy, 209, 1008)
        randint (y_enemy, 159, 429)
        enemy_alive := true
    elsif active_map = kabul and enemy_alive = false then
        randint (x_enemy, 19, 1147)
        randint (y_enemy, 114, 448)
        enemy_alive := true
    end if
    Pic.SetTransparentColor (active_enemy, 23)
    Pic.Draw (active_enemy, x_enemy, y_enemy, picMerge)
end enemies_appear

proc weapon_movement
    Pic.Draw (active_map, 0, -80, picUnderMerge)
    mousewhere (mouse.x, mouse.y, mouse.button)
    Pic.SetTransparentColor (active_gun, 23)
    if shot = false and if_reloading = false then
        if mouse.y < original_position then
            Pic.Draw (active_gun, mouse.x - x_displacement, mouse.y - y_displacement, picMerge)
            Draw.Line (mouse.x - 2, mouse.y, mouse.x - 15, mouse.y, brightred)     %Left line of crosshair
            Draw.Line (mouse.x, mouse.y + 2, mouse.x, mouse.y + 15, brightred)     %Top line of crosshair
            Draw.Line (mouse.x + 2, mouse.y, mouse.x + 15, mouse.y, brightred)     %Right line of crosshair
        else
            Pic.Draw (active_gun, mouse.x - x_displacement, original_position - y_displacement, picMerge)
            Draw.Line (mouse.x - 2, original_position, mouse.x - 15, original_position, brightred)     %Left line of crosshair
            Draw.Line (mouse.x, original_position + 2, mouse.x, original_position + 15, brightred)     %Top line of crosshair
            Draw.Line (mouse.x + 2, original_position, mouse.x + 15, original_position, brightred)     %Right line of crosshair
        end if
    end if
end weapon_movement

proc weapon_assist
    if mouse.y < original_position and if_reloading = false then
        Pic.Draw (active_gun, mouse.x - x_displacement, mouse.y - y_displacement, picMerge)
        Draw.Line (mouse.x - 2, mouse.y, mouse.x - 15, mouse.y, brightred)         %Left line of crosshair
        Draw.Line (mouse.x, mouse.y + 2, mouse.x, mouse.y + 15, brightred)         %Top line of crosshair
        Draw.Line (mouse.x + 2, mouse.y, mouse.x + 15, mouse.y, brightred)         %Right line of crosshair
    elsif mouse.y > original_position and if_reloading = false then
        Pic.Draw (active_gun, mouse.x - x_displacement, original_position - y_displacement, picMerge)
        Draw.Line (mouse.x - 2, original_position, mouse.x - 15, original_position, brightred)         %Left line of crosshair
        Draw.Line (mouse.x, original_position + 2, mouse.x, original_position + 15, brightred)         %Top line of crosshair
        Draw.Line (mouse.x + 2, original_position, mouse.x + 15, original_position, brightred)         %Right line of crosshair
    end if
end weapon_assist

proc weapon_firing
    if weapon_class = 1 then
        if mouse.button = 1 and weapon_ammo > 0 and if_reloading = false then
            shot := true
            animation_counter := animation_counter + 1
        else
            shot := false
            animation_counter := 0
        end if
        if animation_counter >= 20 and mouse.button = 0 or weapon_ammo = 0 then
            animation_counter := 0
            shot := false
        end if
        if animation_counter = 1 or animation_counter = 2 or animation_counter = 3 or animation_counter = 4
                or animation_counter = 5 and Mouse.ButtonMoved ("up") and Mouse.ButtonMoved ("down") and if_reloading = false then
            mousewhere (mouse.x, mouse.y, mouse.button)
            if mouse.y < original_position then
                Pic.Draw (active_gun_firing, mouse.x - firing_displacement_x, mouse.y - firing_displacement_y, picMerge)
                Draw.Line (mouse.x - 2, mouse.y, mouse.x - 15, mouse.y, brightred) %Left line of crosshair
                Draw.Line (mouse.x, mouse.y + 2, mouse.x, mouse.y + 15, brightred) %Top line of crosshair
                Draw.Line (mouse.x + 2, mouse.y, mouse.x + 15, mouse.y, brightred)
            elsif mouse.y > original_position then
                Pic.Draw (active_gun_firing, mouse.x - x_displacement, original_position - y_displacement, picMerge)
                Draw.Line (mouse.x - 2, original_position, mouse.x - 15, original_position, brightred)         %Left line of crosshair
                Draw.Line (mouse.x, original_position + 2, mouse.x, original_position + 15, brightred) %Top line of crosshair
                Draw.Line (mouse.x + 2, original_position, mouse.x + 15, original_position, brightred) %Right line of crosshair
            end if
        else
            weapon_assist
        end if
        if animation_counter = 1 and weapon_ammo > 0 then
            weapon_ammo := weapon_ammo - 1
            Music.PlayFileReturn (weaponsound (weapon_sound))
        end if

    elsif weapon_class = 2 then
        Pic.SetTransparentColor (active_gun_firing, 23)
        if mouse.button = 1 and weapon_ammo > 0 and if_reloading = false then
            shot := true
            animation_counter := animation_counter + 1
        elsif mouse.button = 0 then
            shot := false
            animation_counter := 0
        end if
        if animation_counter >= 3 or weapon_ammo = 0 then
            animation_counter := 0
            shot := false
        end if
        if animation_counter = 1 or animation_counter = 2 or animation_counter = 3 and Mouse.ButtonMoved ("up") and Mouse.ButtonMoved ("down")
                and if_reloading = false then
            mousewhere (mouse.x, mouse.y, mouse.button)
            if mouse.y < original_position then
                Pic.Draw (active_gun_firing, mouse.x - firing_displacement_x, mouse.y - firing_displacement_y, picMerge)
                Draw.Line (mouse.x - 2, mouse.y, mouse.x - 15, mouse.y, brightred)      %Left line of crosshair
                Draw.Line (mouse.x, mouse.y + 2, mouse.x, mouse.y + 15, brightred) %Top line of crosshair
                Draw.Line (mouse.x + 2, mouse.y, mouse.x + 15, mouse.y, brightred)        %Right line of crosshair
            elsif mouse.y > original_position then
                Pic.Draw (active_gun_firing, mouse.x - x_displacement, original_position - y_displacement, picMerge)
                Draw.Line (mouse.x - 2, original_position, mouse.x - 15, original_position, brightred)      %Left line of crosshair
                Draw.Line (mouse.x, original_position + 2, mouse.x, original_position + 15, brightred) %Top line of crosshair
                Draw.Line (mouse.x + 2, original_position, mouse.x + 15, original_position, brightred) %Right line of crosshair
            end if
        else
            weapon_assist
        end if
        if animation_counter = 1 and weapon_ammo > 0 then
            weapon_ammo := weapon_ammo - 1
            Music.PlayFileReturn (weaponsound (weapon_sound))
        end if
    end if
    if shot and mouse.x > x_enemy and mouse.x < x_enemy + active_enemy_x and mouse.y > y_enemy and mouse.y < y_enemy + active_enemy_y then
        enemy_alive := false
    end if
    if enemy_alive = true then
        enemy_presence := enemy_presence + 1
    elsif enemy_alive = false then
        enemy_presence := 0
    end if
    if enemy_presence >= 15 then
        enemy_presence := 0
        player_health := player_health - enemy_damage
    end if
    % put enemy_presence
    % put player_health
    % put enemy_alive
    %put "COUNTER: ", animation_counter
    %put "SHOT: ", shot
end weapon_firing

proc reloading
    if mouse.button = 100 and weapon_ammo < max_weapon_ammo then
        animation_counter := 0
        shot := false
        reloading_counter := reloading_counter + 1
        if_reloading := true
        Draw.Box ((maxx div 2) - 50, maxy div 2 - 60, maxx div 2 + 57, maxy div 2 - 40, blue)
        Draw.FillBox ((maxx div 2) - 49, maxy div 2 - 59, maxx div 2 - 49 + (reloading_counter * 7), maxy div 2 - 41, red)
    else
        if_reloading := false
        reloading_counter := 0
    end if
    if reloading_counter = 9 then
        Music.PlayFileReturn ("reload.wav")
    end if
    if reloading_counter >= 15 then
        weapon_ammo := max_weapon_ammo
        reloading_counter := 0
        if_reloading := false
    end if
end reloading
proc scoring
    if enemy_alive = false then
        score_int := score_int + enemy_value
    end if
    if animation_counter = 1 then
        score_int := score_int + (weapon_class * -2)
    end if
end scoring

select_map
select_gun
Music.PlayFileReturn ("prepare.wav")
View.Set ("offscreenonly")
loop
    cls
    weapon_ammo_string := intstr (weapon_ammo)
    Draw.Text (weapon_ammo_string, maxx div 2, maxy - 20, font, blue)
    scoring
    score_string := intstr (score_int)
    Draw.Text ("Score: " + score_string, (maxx div 2) + 500, maxy - 20, font, blue)
    locate (3, 4)
    %put if_reloading, "  ", reloading_counter
    player_health_string := intstr (player_health)
    Draw.Text ("Health: " + player_health_string + "%", (maxx div 2) - 630, maxy - 20, font, blue)
    enemies_appear
    weapon_movement
    weapon_firing
    reloading
    View.Update
    delay (5)
end loop
Sponsor
Sponsor
Sponsor
sponsor
do_pete




PostPosted: Fri Apr 28, 2006 2:42 pm   Post subject: (No subject)

You can have the main loop inside another loop that contains the menu.
Thuged_Out_G




PostPosted: Fri Apr 28, 2006 10:04 pm   Post subject: (No subject)

code:

loop
    %main menu code
    loop
        %main game code
        if player = "dead" then
            exit
        end if
    end loop
end loop


When you exit the inside loop, it goes back to your main menu.
TheOneTrueGod




PostPosted: Fri Apr 28, 2006 10:36 pm   Post subject: (No subject)

You are also going to have to reset all of your variables when you return to the main menu... The easiest way i've found of doing this is just having a procedure to set them all to their initial value, and then calling this at the beginning of your program (before you start the "actual game" part of it)
do_pete




PostPosted: Sat Apr 29, 2006 9:38 am   Post subject: (No subject)

Or you culd declare all of the variables in the outer loop.
jamonathin




PostPosted: Sat Apr 29, 2006 4:13 pm   Post subject: (No subject)

do_pete wrote:
Or you culd declare all of the variables in the outer loop.

nnnnnegative. How would the procedures use the variables?

There's also some places you can save space on, for example:

code:

weapon_ammo_string := intstr (weapon_ammo)
Draw.Text (weapon_ammo_string, maxx div 2, maxy - 20, font, blue)
Can be turned into . .
Draw.Text (intstr (weapon_ammo), maxx div 2, maxy - 20, font, blue)


Also start commenting your code. As messy as it is, it'll get worse. Best to start now then forget later.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: