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

Username:   Password: 
 RegisterRegister   
 integrating GUI 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: Thu May 11, 2006 10:56 am   Post subject: integrating GUI into a program

Hey guys. I am trying to integrate some GUI buttons into my game. i plan on using the buttons to determine which gun/map the user has chosen and to then have the pc draw the correct picture on the screen. I kno i have to use GUI.GetEventWidgetId somewhere but i am not sure where or where to place place the lines which create the buttons. Also what do i have to put in the button's reference procedure field in order to have it determine a given variable when it is clicked. Again, here is my code so u can get a better idea of what i am trying to do.
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
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: