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

Username:   Password: 
 RegisterRegister   
 integrating a high scores procedure into a program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
bozi39




PostPosted: Wed May 10, 2006 10:49 am   Post subject: integrating a high scores procedure into a program

hey guys. i am making an fps game for my final project and i am almost done with the main components of the game. All i need now is to integrate a high schores procedure to make my game look fancier. I have seen some different examples of high scores procedure but i am not sure how to integrate neither one of them into my program - i dont kno where to place them in the program. Can you helm me please. Here is the code i have so far - the mainline procedure is the actual game and i think anything related to scores should be placed there either with an "include" statement or by simply pasting the code in there. Can you help me place it properly please
code:
import GUI
%setpriority (2 ** 15 - 1)
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 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 : int
var titleName := Pic.FileNew ("maintitlename.bmp")
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 enemy_presence : int := 0
var enemy_damage : int
var player_health : int := 100
var introduction := Pic.FileNew ("introduction.bmp")
var titlePic := Pic.FileNew ("maintitle.bmp")
font := Font.New ("serif:18:bold")
var font1 := Font.New ("serif:50") %fonts
var font2 := Font.New ("serif:30")
var font3 := Font.New ("serif:15")
var reloading_meter, hitting_time : int
var difficulty_choice, difficulty : int
var done, quitBtn : int
var file : int
var name : string
var getname : string
var getscore : int
var moving : int := 0
proc new_value
    player_health := 100
    animation_counter := 0
    reloading_counter := 0
    difficulty_choice := 0
end new_value

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
    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
    end if
end select_map
proc select_difficulty
    put "Select a difficulty setting"
    put "enter 1 for Private"
    put "enter 2 for Corporal"
    put "enter 3 for General"
    get difficulty_choice
end select_difficulty
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 mouse.button = 0 then
            animation_counter := (animation_counter * 100) - 1
        end if
        if mouse.button = 1 and weapon_ammo = 0 then
            reloading_meter := reloading_meter + 1
        else
            reloading_meter := 0
        end if
        if reloading_meter = 1 then
            Music.PlayFileReturn (empty_sound)
        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 mouse.button = 1 and weapon_ammo = 0 then
            reloading_meter := reloading_meter + 1
        else
            reloading_meter := 0
        end if
        if reloading_meter = 1 then
            Music.PlayFileReturn (empty_sound)
        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 difficulty_choice = 1 then
        randint (enemy_damage, 1, 9)
        hitting_time := 25
    elsif difficulty_choice = 2 then
        randint (enemy_damage, 9, 15)
        hitting_time := 20
    elsif difficulty_choice = 3 then
        randint (enemy_damage, 15, 20)
        hitting_time := 15
    end if
    if enemy_presence >= hitting_time 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
    %put animation_counter
    put hitting_time

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
    if score_int not= 0 and enemy_alive = false then
        score_int := score_int + enemy_value + difficulty_choice
    end if
end scoring

proc close_window
    Window.Close (window)
    GUI.Quit
end close_window

proc main_line
    setpriority (2 ** 15 - 1)
    loop
        View.Set ("nooffscreenonly")
        cls
        select_map
        select_gun
        select_difficulty
        Music.PlayFileReturn ("prepare.wav")
        View.Set ("offscreenonly")
        loop
            cls
            scoring
            Draw.Text (intstr (weapon_ammo), maxx div 2, maxy - 20, font, blue)
            Draw.Text ("Score: " + intstr (score_int), (maxx div 2) + 500, maxy - 20, font, blue)
            locate (3, 4)
            %put if_reloading, "  ", reloading_counter
            Draw.Text ("Health: " + intstr (player_health) + "%", (maxx div 2) - 630, maxy - 20, font, blue)
            enemies_appear
            weapon_movement
            weapon_firing
            reloading
            View.Update
            delay (5)
            exit when player_health <= 0
        end loop
        cls
        Draw.Text (intstr (weapon_ammo), maxx div 2, maxy - 20, font, blue)
        Draw.Text ("Score: " + intstr (score_int), (maxx div 2) + 500, maxy - 20, font, blue)
        locate (3, 4)
        %put if_reloading, "  ", reloading_counter
        if player_health <= 0 then
            Draw.Text ("Health: 0%", (maxx div 2) - 630, maxy - 20, font, blue)
        end if
        scoring
        enemies_appear
        weapon_movement
        weapon_firing
        reloading
        View.Update
        delay (500)
        new_value
    end loop
end main_line
%include "maintitle.t" %play the main intro
Music.PlayFileStop
introduction := Pic.Scale (introduction, 1267, 953)
Pic.Draw (introduction, 0, 0, picMerge)
done := GUI.CreateButton (maxx div 2, maxy div 2, 0, "PLAY",
    main_line)
quitBtn := GUI.CreateButton (maxx div 2, maxy div 2 - 50, 0, "Quit", close_window)
loop
    exit when GUI.ProcessEvent
end loop
Sponsor
Sponsor
Sponsor
sponsor
do_pete




PostPosted: Wed May 10, 2006 11:47 am   Post subject: (No subject)

Are you going to save your high scores list or is it just going to be temporary?
bozi39




PostPosted: Wed May 10, 2006 12:49 pm   Post subject: (No subject)

i want to save my highscores list onto a .txt file so that you can backtrack all the way to the beginning of the game's score history. I think that having a temporary high schores list would be kind of useless
bozi39




PostPosted: Wed May 10, 2006 12:51 pm   Post subject: (No subject)

i want to save my highscores list onto a .txt file so that you can backtrack all the way to the beginning of the game's score history. I think that having a temporary high schores list would be kind of useless
jamonathin




PostPosted: Wed May 10, 2006 1:16 pm   Post subject: (No subject)

Here's a link I recommend, that has other links inside of it, now for placing it in your code.

It honestly doesn't matter where in your code you put the highscore procedure (assuming its in a procedure), as long as you have it organized.
So basically, here's what your procedure can look like:

pseudo:

proc highScore (name : string, score : real)
     - Get .txt values
     - sort new value with .txt values
     - save scores in .txt
     - display all scores
end


it's just as simple as that, and since that procedure wont need any of the other variables in your progran (you can declare inside), this procedure can be stuck anywhere.

Now in your main loop, you're going to want to put it at the very end.

code:

        View.Update
        delay (500)

        - highScore
        Input.Pause or something (maybe put that inside highScore)

        new_value
    end loop
end main_line
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  [ 5 Posts ]
Jump to:   


Style:  
Search: