Tower Defense

A

Amoses

Guest
Im making a Tower Defense game, and I have everything setup, but i wanted to know how to delete a tower, so i click on the tower i want, and then place it, i need to make it so i can click it again after its been placed and place it into a garbage can type thing and have it get destroyed
 

Fabseven

Member
For me, you have to setup a building menu with avaible building, on click of one of these building, you have to check if ressources are enough and then you can create an fake obj_tower something like obj_tower_test_construction with the good sprite and good size. As you system state is sette to "test construction" this object follow your mouse and will be green if there is no collision with forest or mountain or other stuff (otherwise make it red). While green, a click will consume ressources and create the real obj_tower.

After that you could in your system have a var obj_selected and another obj_selected_type.
Use event left click on the obj_tower and others object to set theses var
ex for obj_tower : obj_system.obj_selected = id , obj_selected_type = "tower"
where obj_system is a singleton object running the game. (is always do this stuff)
in this obj_system in gui event, if obj_selected != noone then you can draw a gui according to the obj_selected_type with the differents values of obj_selected. Advice : draw à white rectangle at the right of the screen, draw HP, def,atk, etc of your tower, botton : draw buttons "Level up" "destroy" and others, when pressing buttons => do stuff. You win.
 
A

Amoses

Guest
For me, you have to setup a building menu with avaible building, on click of one of these building, you have to check if ressources are enough and then you can create an fake obj_tower something like obj_tower_test_construction with the good sprite and good size. As you system state is sette to "test construction" this object follow your mouse and will be green if there is no collision with forest or mountain or other stuff (otherwise make it red). While green, a click will consume ressources and create the real obj_tower.

After that you could in your system have a var obj_selected and another obj_selected_type.
Use event left click on the obj_tower and others object to set theses var
ex for obj_tower : obj_system.obj_selected = id , obj_selected_type = "tower"
where obj_system is a singleton object running the game. (is always do this stuff)
in this obj_system in gui event, if obj_selected != noone then you can draw a gui according to the obj_selected_type with the differents values of obj_selected. Advice : draw à white rectangle at the right of the screen, draw HP, def,atk, etc of your tower, botton : draw buttons "Level up" "destroy" and others, when pressing buttons => do stuff. You win.
i am pretty new to gamemaker and alot of this just looks like another language to me, could you perhaps help a big further by giving an example of the code?
 

Fabseven

Member
I can help a lot more, here is an old project (abondonned) of mine :
https://drive.google.com/open?id=0B4x4h7n1bmSIVURXN2VXd2pMQ1U

Gui : building menu :
upload_2019-6-25_10-51-32.png


You have to check code in obj_builder_controller and obj_building_controller
If i had to remake this feature i would not do it this way i think but you can still understand how to do it with theses

Run the game, set the windows on full screen, hit "commencer partie" then "commencer"
go at the center of the map, try building with the hammer top left, click on the center building => you have gui for this building to manage people , click on a tower => gui to manage the tower
 
Last edited:
A

Amoses

Guest
I can help a lot more, here is an old project (abondonned) of mine :
https://drive.google.com/open?id=0B4x4h7n1bmSIVURXN2VXd2pMQ1U

Gui : building menu :
View attachment 25410


You have to check code in obj_builder_controller and obj_building_controller
If i had to remake this feature i would not do it this way i think but you can still understand how to do it with theses

Run the game, set the windows on full screen, hit "commencer partie" then "commencer"
go at the center of the map, try building with the hammer top left, click on the center building => you have gui for this building to manage people , click on a tower => gui to manage the tower
hey, i appreciate this but it says that it is not a valid game maker studio 2 file?
 

Fabseven

Member
Oh i am sorry, it's a game maker 1.4 project, you can download it for free.
Most of the code should be usable in GM2 (i hope so)
 
A

Amoses

Guest
Oh i am sorry, it's a game maker 1.4 project, you can download it for free.
Most of the code should be usable in GM2 (i hope so)
i got a 1.4 download, but it wont let me sign in, so i cant get that file. do you have any gms2 files?
 

Fabseven

Member
??? Sign in with your usual game maker account ???

here is the code for obj_builder_controller
Code:
Information about object: obj_builder_controller
Sprite: 
Solid: false
Visible: true
Depth: -1500
Persistent: false
Parent: 
Children: 
Mask: 
No Physics Object
Create Event:
execute code:

///variables
enum e_builder_state
{
   show=0,
   building_selected=1,
   building_choose_xy=2,
   building_check=3,
   building_finish=4
}

bc_is_activated = false
bc_phase = e_builder_state.show
/*
global.show_bleft_x1 =  gui_tab_bleft[0,0]
global.show_bleft_y1 =  gui_tab_bleft[0,1]
*/
bc_show_back = spr_gui_builder_background
bc_show_www = sprite_get_width(bc_show_back)
bc_show_hhh = sprite_get_height(bc_show_back)



bc_show_startx = display_get_gui_width()/2 - bc_show_www/2 // global.show_bleft_x1
bc_show_margex = 7
bc_show_margey = 7
bc_show_starty = display_get_gui_height()/2 - bc_show_hhh/2//global.show_bleft_y1
bc_show_endy = bc_show_starty + bc_show_hhh
bc_show_endx = bc_show_startx + bc_show_www

bc_cancel_spr = spr_gui_builder_cancel
bc_cancel_x1 = bc_show_endx - sprite_get_width(bc_cancel_spr)/2
bc_cancel_y1 = bc_show_starty - sprite_get_height(bc_cancel_spr)/2
bc_cancel_x2 = bc_cancel_x1 + sprite_get_width(bc_cancel_spr)
bc_cancel_y2 = bc_cancel_y1 + sprite_get_height(bc_cancel_spr)
bc_cancel_hover = 0

//bc_show_max = 10

bc_show_mtitle_x = bc_show_startx + bc_show_www/2
bc_show_mtitle_y = bc_show_starty  + bc_show_margey

bc_show_max_per_line = 4
bc_show_cadre_www = 100
bc_show_cadre_hhh = 125

bc_building_id_selected= noone
bc_building_id_selected_sprite = noone
bc_building_id_selected_obj = noone
bc_building_selected_cost_gold =0
bc_building_selected_cost_special =0
bc_building_selected_cost_military =0
bc_alarm0_x = bc_show_startx
bc_alarm0_y = bc_show_starty

bc_show_stepx = bc_show_startx + bc_show_margex*2
bc_show_stepy = bc_show_starty + bc_show_margey*5

range=0
valid_xy = false
n=0

//info
bc_show_opt[0,4] = spr_tour_arrow
bc_show_opt[0,10] = e_batid.tower_arrow
bc_show_opt[0,11] = obj_tour_arrow
t = building_get_info(1,e_batid.tower_arrow,id)
bc_show_opt[0,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[0,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[0,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[0,60] = 1 //xscale
bc_show_opt[0,61] = 1 //yscale
bc_show_opt[0,24] = t[e_getinfobuilder.name]
bc_show_opt[0,25] = t[e_getinfobuilder.description]
bc_show_opt[0,23] = t[e_getinfobuilder.battype]
bc_show_opt[0,70] = t[e_getinfobuilder.can_shoot_flying]
bc_show_opt[0,71] = t[e_getinfobuilder.can_shoot_ground]



bc_show_opt[1,4] = spr_tour_hammer
bc_show_opt[1,10] = e_batid.tower_hammer
bc_show_opt[1,11] = obj_tour_hammer
t = building_get_info(1,e_batid.tower_hammer,id)
bc_show_opt[1,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[1,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[1,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[1,60] = 1 //xscale
bc_show_opt[1,61] = 1 //yscale
bc_show_opt[1,24] = t[e_getinfobuilder.name]
bc_show_opt[1,25] = t[e_getinfobuilder.description]
bc_show_opt[1,23] = t[e_getinfobuilder.battype]
bc_show_opt[1,70] = t[e_getinfobuilder.can_shoot_flying]
bc_show_opt[1,71] = t[e_getinfobuilder.can_shoot_ground]

bc_show_opt[2,4] = spr_tour_star
bc_show_opt[2,10] = e_batid.tower_star
bc_show_opt[2,11] = obj_tour_star
t = building_get_info(1,e_batid.tower_star,id)
bc_show_opt[2,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[2,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[2,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[2,60] = 1 //xscale
bc_show_opt[2,61] = 1 //yscale
bc_show_opt[2,24] = t[e_getinfobuilder.name]
bc_show_opt[2,25] = t[e_getinfobuilder.description]
bc_show_opt[2,23] = t[e_getinfobuilder.battype]
bc_show_opt[2,70] = t[e_getinfobuilder.can_shoot_flying]
bc_show_opt[2,71] = t[e_getinfobuilder.can_shoot_ground]


bc_show_opt[3,4] = spr_tour_bomb
bc_show_opt[3,10] = e_batid.tower_bomb
bc_show_opt[3,11] = obj_tour_bomb
t = building_get_info(1,e_batid.tower_bomb,id)
bc_show_opt[3,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[3,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[3,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[3,60] = 1 //xscale
bc_show_opt[3,61] = 1 //yscale
bc_show_opt[3,24] = t[e_getinfobuilder.name]
bc_show_opt[3,25] = t[e_getinfobuilder.description]
bc_show_opt[3,23] = t[e_getinfobuilder.battype]
bc_show_opt[3,70] = t[e_getinfobuilder.can_shoot_flying]
bc_show_opt[3,71] = t[e_getinfobuilder.can_shoot_ground]

bc_show_opt[4,4] = spr_trap_ironspike
bc_show_opt[4,10] = e_batid.trap_spike
bc_show_opt[4,11] = obj_trap_spike
t = building_get_info(1, e_batid.trap_spike,id)
bc_show_opt[4,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[4,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[4,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[4,60] = 0.75 //xscale
bc_show_opt[4,61] = 0.75 //yscale
bc_show_opt[4,24] = t[e_getinfobuilder.name]
bc_show_opt[4,25] = t[e_getinfobuilder.description]
bc_show_opt[4,23] = t[e_getinfobuilder.battype]
bc_show_opt[4,100] = t[e_getinfobuilder.speimg]


bc_show_opt[5,4] = spr_trap_ice
bc_show_opt[5,10] = e_batid.trap_ice
bc_show_opt[5,11] = obj_trap_ice
t = building_get_info(1, e_batid.trap_ice,id)
bc_show_opt[5,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[5,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[5,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[5,60] = 2 //xscale
bc_show_opt[5,61] = 2//yscale
bc_show_opt[5,24] = t[e_getinfobuilder.name]
bc_show_opt[5,25] = t[e_getinfobuilder.description]
bc_show_opt[5,23] = t[e_getinfobuilder.battype]
bc_show_opt[5,100] = t[e_getinfobuilder.speimg]

bc_show_opt[6,4] = spr_trap_acide
bc_show_opt[6,10] = e_batid.trap_acid
bc_show_opt[6,11] = obj_trap_acid
t = building_get_info(1, e_batid.trap_acid,id)
bc_show_opt[6,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[6,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[6,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[6,60] = 2 //xscale
bc_show_opt[6,61] = 2 //yscale
bc_show_opt[6,24] = t[e_getinfobuilder.name]
bc_show_opt[6,25] = t[e_getinfobuilder.description]
bc_show_opt[6,23] = t[e_getinfobuilder.battype]
bc_show_opt[6,100] = t[e_getinfobuilder.speimg]

bc_show_opt[7,4] = spr_defender_caserne
bc_show_opt[7,10] = e_batid.defender_caserne
bc_show_opt[7,11] = obj_defender_caserne
t = building_get_info(1,  e_batid.defender_caserne,id)
bc_show_opt[7,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[7,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[7,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[7,60] = 1 //xscale
bc_show_opt[7,61] = 1 //yscale
bc_show_opt[7,24] = t[e_getinfobuilder.name]
bc_show_opt[7,25] = t[e_getinfobuilder.description]
bc_show_opt[7,23] = t[e_getinfobuilder.battype]
bc_show_opt[7,100] = tab_info[e_getinfobuilder.defender_unit]

bc_show_opt[8,4] = spr_defender_maidhouse
bc_show_opt[8,10] = e_batid.defender_maidhouse
bc_show_opt[8,11] = obj_defender_maidhouse
t = building_get_info(1,  e_batid.defender_maidhouse,id)
bc_show_opt[8,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[8,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[8,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[8,60] = 1 //xscale
bc_show_opt[8,61] = 1 //yscale
bc_show_opt[8,24] = t[e_getinfobuilder.name]
bc_show_opt[8,25] = t[e_getinfobuilder.description]
bc_show_opt[8,23] = t[e_getinfobuilder.battype]
bc_show_opt[8,100] = tab_info[e_getinfobuilder.defender_unit]

bc_show_max = array_height_2d(bc_show_opt)
cur_type = e_battype.tower


//precalcul en largeur
for(i=0 ; i < bc_show_max ; i++)
{
   if(cur_type != bc_show_opt[i,23] or n >=  bc_show_max_per_line)
   {
       bc_show_stepx = bc_show_startx + bc_show_margex*2  // bc_show_startx + bc_show_margex*2
       bc_show_stepy += bc_show_cadre_hhh + bc_show_margey //sprite_get_height( spr_gui_builder ) + bc_show_margey*15
       n=0
       cur_type = bc_show_opt[i,23]
   }


   bc_show_opt[i,13] = bc_show_stepx //x1 cadre
   bc_show_opt[i,14] = bc_show_stepy //y1 cadre
   
   bc_show_opt[i,15] = bc_show_stepx  + bc_show_cadre_www // x2 cadre
   bc_show_opt[i,16] = bc_show_stepy  + bc_show_cadre_hhh //y2 cadre
   bc_show_opt[i,17] = bc_show_stepx + bc_show_cadre_www/2//x titre
   bc_show_opt[i,18] = bc_show_stepy + 10 //y titre

   bc_show_opt[i,0] = bc_show_stepx + bc_show_cadre_www/2 - sprite_get_width( spr_gui_builder )/2   //x1 img
   bc_show_opt[i,1] = bc_show_stepy + bc_show_cadre_hhh/2 - sprite_get_height( spr_gui_builder )/2 //y1    img
   bc_show_opt[i,2] = bc_show_opt[i,0] + sprite_get_width( spr_gui_builder ) //x2 img
   bc_show_opt[i,3] = bc_show_opt[i,1] + sprite_get_height( spr_gui_builder ) //y2 img   
   //bc_show_opt[i,4] = noone //sprite = affichage ?
   bc_show_opt[i,5] = false //hover
   bc_show_opt[i,6] = false //selected
   //bc_show_opt[i,10] = noone // id tower/building à construire
   //bc_show_opt[i,11] = noone // obj
   
   
   //bc_show_opt[i,12] = bc_show_opt[i,0] // bas du cadre gauche
   
   
   
   
   /* bc_show_opt[i,20] = 0 //cost gold
   bc_show_opt[i,21] = 0 //cost special
   bc_show_opt[i,22] = 0 //cost military
   bc_show_opt[i,23] = 0 //type
   bc_show_opt[i,24] = "nom" //nom
   bc_show_opt[i,25] = "description" //nom*/
   
    draw_set_font(font_gui_ressources_tiny)
   bc_show_opt[i,30] = bc_show_opt[i,0]// bc_show_stepx //x1 cost gold
   bc_show_opt[i,31] = bc_show_opt[i,3] + 5 //y1 cost gold
   bc_show_opt[i,32] = bc_show_stepx + string_width("9999") //x1 sprite cost gold
   bc_show_opt[i,33] = bc_show_opt[i,3] + 5 + sprite_get_height(spr_gold)/4+2 //y1 sprite cost gold
   
   bc_show_opt[i,40] = bc_show_opt[i,0]//bc_show_stepx //x1 cost special
   bc_show_opt[i,41] = bc_show_opt[i,31] + 10 //y1 cost special
   bc_show_opt[i,42] = bc_show_opt[i,32] //x1 sprite cost special
   bc_show_opt[i,43] = bc_show_opt[i,33] + 10 //y1 sprite cost special
   
   bc_show_opt[i,50] = bc_show_opt[i,0]// bc_show_stepx //x1 cost military
   bc_show_opt[i,51] = bc_show_opt[i,41] + 10 //y1 cost military
   bc_show_opt[i,52] = bc_show_opt[i,32] //x1 sprite cost military
   bc_show_opt[i,53] = bc_show_opt[i,43] + 10 //y1 sprite cost military
   
   bc_show_opt[i,54] =  bc_show_opt[i,30] + bc_show_margex*5 //x1 sprite flying
   bc_show_opt[i,55] = bc_show_opt[i,31] //y1 sprite flying
   bc_show_opt[i,56] =  bc_show_opt[i,30] + bc_show_margex*5 //x1 sprite ground
   bc_show_opt[i,57] = bc_show_opt[i,51] //y1 sprite ground
   
   
   
   /* bc_show_opt[i,60] = 1 //xscale
   bc_show_opt[i,61] = 1 //yscale
    bc_show_opt[i,70] = flying true false
    bc_show_opt[i,71] = ground true false
   */
   
   
   
        bc_show_stepx  += bc_show_cadre_www + bc_show_margex //sprite_get_width( spr_gui_builder ) + bc_show_margex*3
   
   n++
   /* if( n >=  bc_show_max_per_line)
   {
       bc_show_stepx = bc_show_startx + bc_show_margex*2  // bc_show_startx + bc_show_margex*2
       bc_show_stepy += bc_show_cadre_hhh + bc_show_margey //sprite_get_height( spr_gui_builder ) + bc_show_margey*15
       n=0
   }    */     
   
   
       
}


bc_show_description_ww = bc_show_www - bc_show_margex*2
bc_show_description_hh = 75
bc_show_description_x1 = bc_show_startx + bc_show_margex
bc_show_description_y1 = bc_show_endy - bc_show_description_hh
bc_show_description_x2 = bc_show_description_x1 + bc_show_description_ww
bc_show_description_y2 = bc_show_endy - bc_show_margey*1
bc_show_description_title_x = bc_show_description_x1 //+ bc_show_margex
bc_show_description_title_y = bc_show_description_y1 - bc_show_margey
bc_show_description_text_x = bc_show_description_x1 + bc_show_margex*3
bc_show_description_text_y = bc_show_description_y1 + bc_show_margey*2
bc_show_description_text_color = c_black
bc_show_description_text_alpha = 1
bc_show_description_bgcolor = c_white
bc_show_description_bgcolor_alpha = 0.50



/*
enum e_getinfobuilder
{
   idd=50,
   cost_gold = 0,
   cost_special=1,
   cost_military=2,
   hp=3,
   hpmax=4,
   range=6,
   attaque=7,
   defense=8,
   projectile_name=9,
   projectile_sprite=10,
   projectile_obj=11,
   projectile_bounce=12,
   projectile_bounce_nbr=13,
   projectile_explode=14,
   projectile_explode_nbr=15,
   cooldown=16
}*/




Alarm Event for alarm 0:
execute code:


if(alarm[0] > 0)
{
   alarm[0] --
}

Step Event:
execute code:

///check si un des batiments à été sélectionné pour construction
if(bc_phase == e_builder_state.show and bc_is_activated)
{
   var xxx = device_mouse_x_to_gui(0)
   var yyy = device_mouse_y_to_gui(0)
   
   for(i=0 ; i < bc_show_max ; i++)
   {
           if(bc_show_opt[i,4] != noone)
           {
            if( point_in_rectangle(xxx,yyy,bc_show_opt[i,0],bc_show_opt[i,1],bc_show_opt[i,2],bc_show_opt[i,3]))
            {
                    bc_show_opt[i,5] = true
                    if(device_mouse_check_button_released(0, mb_left))
                    {
                        bc_show_opt[i,6] = true
                        //vérification si ressources nécessaires disponibles
                        var test = building_use_ressource(true, bc_show_opt[i,20], bc_show_opt[i,21], bc_show_opt[i,22])
                        if(test == false)
                        {
                           alarm[0] = 50
                           return -1
                        }
                       
                        bc_building_selected_cost_gold = bc_show_opt[i,20]
                        bc_building_selected_cost_special = bc_show_opt[i,21]
                        bc_building_selected_cost_military = bc_show_opt[i,22]
                        show_debug_message("***need military = " + string( bc_building_selected_cost_military) + "***")
                       
                        //action à réaliser
                           bc_building_id_selected = bc_show_opt[i,10]
                           bc_building_id_selected_sprite = bc_show_opt[i,4]
                           sprite_index = bc_show_opt[i,4]
                           show_debug_message("builder : im_index = " + string(image_index))
                           bc_building_id_selected_obj =  bc_show_opt[i,11]
                           bc_phase =    e_builder_state.building_choose_xy
                        //fin action à réaliser
                    }
                    else
                    {
                       bc_show_opt[i,6] = false
                    }
            }
            else
            {
               bc_show_opt[i,5] = false
            }
           }
   
   }
 
   
}
else
{
   if(bc_phase == e_builder_state.building_choose_xy)
   {
        obj_town.building_selected = true
        global.building_selected = -1
       
        x = device_mouse_x(0)
        y = device_mouse_y(0)
//         range = distance_to_object(obj_town)
        range = distance_to_point(obj_town.building_middle_x,obj_town.building_middle_y)
        if(range > obj_town.building_range)
        {
         
          valid_xy = false
     
        }
        else
        {
       
           var test = place_meeting(x,y,obj_building)
           var test_trap = place_meeting(x,y,obj_trap_parent)
           //valid_xy = !test
           valid_xy = !(test or test_trap)
           
        }
       
        if(valid_xy and device_mouse_check_button_released(0, mb_left))
        {
           //utiliser ressources
           building_use_ressource(false, bc_building_selected_cost_gold, bc_building_selected_cost_special, bc_building_selected_cost_military)
           
           //construire
           b =instance_create(x,y,bc_building_id_selected_obj)
           if(b.building_type != e_battype.trap) //la building phase ne s'applique pas aux trap
           {
           
               b.building_under_construction_finished = false
               b.building_hp = 1
           }
           
           bc_phase=e_builder_state.show
           bc_is_activated = false
           sprite_index = noone
           obj_town.building_selected = false
           bc_building_id_selected= noone
           bc_building_id_selected_sprite = noone
           bc_building_id_selected_obj = noone
           //fin de construction
        }
       
   }
}

execute code:

///check si button cancel appuyé ou hover
///check si un des batiments à été sélectionné pour construction
if(bc_phase == e_builder_state.show and bc_is_activated)
{
   var xxx = device_mouse_x_to_gui(0)
   var yyy = device_mouse_y_to_gui(0)
   
 
   if( point_in_rectangle(xxx,yyy,bc_cancel_x1,bc_cancel_y1,bc_cancel_x2,bc_cancel_y2))
   {
      bc_cancel_hover=1
     if(device_mouse_check_button_released(0, mb_left))
     {
           bc_is_activated=false     
     }
   }
   else
   {
       bc_cancel_hover=0
   }
                   
}

execute code:

///check si ESC appuyé pendant phase de placement pour annuller
if(bc_phase == e_builder_state.building_choose_xy and bc_is_activated)
{
   if(keyboard_check_released(vk_escape))
   {
        bc_phase = e_builder_state.show
     
   }
}

Draw Event:
execute code:

///draw phase e_builder_state.building_choose_xy
if(bc_phase == e_builder_state.building_choose_xy)
{
   

  if(valid_xy)
  {
   //draw_self()
   draw_sprite( bc_building_id_selected_sprite,0, mouse_x, mouse_y)
  }
  else
  {
   draw_sprite_ext( bc_building_id_selected_sprite,0, mouse_x, mouse_y,1,1,0,c_red,1)
  }
   
   draw_text(x+10,y+10,range)
 
 
   
}

Draw GUI Event:
execute code:

///déssiner en fonction de la phase
if(bc_is_activated)
{

   switch(bc_phase)
   {
       case e_builder_state.building_choose_xy:
           draw_set_font(font_gui_menu_building)
           draw_text(50,50,"ESCHAP pour retour")
           break;
   
       case e_builder_state.show :
       case e_builder_state.building_selected:   
       
           draw_sprite(bc_show_back,0,bc_show_startx,bc_show_starty)
           draw_set_halign(fa_center)
           draw_set_color(c_black)
           draw_set_font(font_gui_menu_building)
           draw_text(bc_show_mtitle_x,bc_show_mtitle_y,"Construction de batiments : ")
           draw_sprite(bc_cancel_spr,bc_cancel_hover,bc_cancel_x1,bc_cancel_y1)
           for(i=0 ; i < bc_show_max ; i++)
           {
               if(bc_show_opt[i,4] != noone)
               {
                  /* if(bc_building_id_selected == bc_show_opt[i,10]) //selected
                   {
                       draw_set_color(c_green)
                       draw_rectangle(bc_show_opt[i,0]-5,bc_show_opt[i,1]-5,bc_show_opt[i,2]+5, bc_show_opt[i,3]+5,false)
                   }*/
                   var cadre_color= c_black;
                   
                   switch(bc_show_opt[i,23])
                   {
                       case e_battype.tower:
                              cadre_color = c_black   
                              if(bc_show_opt[i,70] == true)
                              {
                                   draw_sprite(spr_flying,0,bc_show_opt[i,54],bc_show_opt[i,55])
                              }
                              else
                              {
                                   draw_sprite(spr_not_flying,0,bc_show_opt[i,54],bc_show_opt[i,55])
                              }
                              if(bc_show_opt[i,71] == true)
                              {
                                   draw_sprite(spr_ground,0,bc_show_opt[i,56],bc_show_opt[i,57])
                              }
                              else
                              {
                                   draw_sprite(spr_not_ground,0,bc_show_opt[i,56],bc_show_opt[i,57])
                              }
                             
                               
                               break;
                       case e_battype.trap:
                               cadre_color = c_red   
                               var sprt =bc_show_opt[i,100]
                               draw_sprite(sprt,0,bc_show_opt[i,54],bc_show_opt[i,55])
                               
                               
                               break;       
                       case e_battype.defender:
                               cadre_color = c_green
                             
                                var sprt = object_get_sprite(bc_show_opt[i,100] )
                                draw_sprite(sprt,7,bc_show_opt[i,54],bc_show_opt[i,55])
                               
                               break;             
                   }
                   
                   
                   draw_set_alpha(0.35)
                   draw_set_color(cadre_color)
                   draw_roundrect(bc_show_opt[i,13]-2,bc_show_opt[i,14]-2,bc_show_opt[i,15]+2,  bc_show_opt[i,16]+2,true)
                   draw_set_color(cadre_color)
                   draw_roundrect(bc_show_opt[i,13],bc_show_opt[i,14],bc_show_opt[i,15],  bc_show_opt[i,16],false)
                   draw_set_alpha(1)
                   draw_set_halign(fa_center)
                    draw_set_color(c_black)
                    draw_set_font(font_gui_menu_building_middle)
                    draw_text_ext(bc_show_opt[i,17] ,bc_show_opt[i,18],string( bc_show_opt[i,24]),12, bc_show_cadre_www)
                   
                     
                       
                   if(bc_show_opt[i,5] == true) //hoover
                   {
                     
                        draw_sprite_ext(bc_show_opt[i,4],0, bc_show_opt[i,0], bc_show_opt[i,1],bc_show_opt[i,60],bc_show_opt[i,61],0,c_green,1)
                        draw_set_color(bc_show_description_bgcolor )
                        draw_set_alpha(bc_show_description_bgcolor_alpha)
                       
                        draw_roundrect(bc_show_description_x1,bc_show_description_y1,bc_show_description_x2,bc_show_description_y2,false)
                        draw_set_color(bc_show_description_text_color )
                        draw_set_alpha(bc_show_description_text_alpha)
                        draw_set_halign(fa_left)
                        draw_text(bc_show_description_title_x,bc_show_description_title_y,"Description :")
                        draw_text_ext(bc_show_description_text_x ,bc_show_description_text_y,string(bc_show_opt[i,25]),12,bc_show_description_ww)
                       
                   }
                   else
                   {
                        draw_sprite_ext(bc_show_opt[i,4],0, bc_show_opt[i,0], bc_show_opt[i,1],bc_show_opt[i,60],bc_show_opt[i,61],0,c_white,1)
                   }
                 
                   draw_set_alpha(1)
                   draw_set_halign(fa_left)
                   draw_set_color(c_black)
                   draw_set_font(font_gui_ressources_tiny)
                   draw_text( bc_show_opt[i,30], bc_show_opt[i,31], bc_show_opt[i,20])
                   draw_sprite_ext( spr_gold,0,  bc_show_opt[i,32], bc_show_opt[i,33],0.5,0.5,0,c_white,1)
               
                   draw_text( bc_show_opt[i,40], bc_show_opt[i,41], bc_show_opt[i,21])
                   draw_sprite_ext( spr_special,0,  bc_show_opt[i,42], bc_show_opt[i,43],0.5,0.5,0,c_white,1)
                   
                   draw_text( bc_show_opt[i,50], bc_show_opt[i,51], bc_show_opt[i,22])
                   draw_sprite_ext( spr_military,0,  bc_show_opt[i,52], bc_show_opt[i,53],0.5,0.5,0,c_white,1)
               }
           }
           break;
           
     
       
   
   }

}

execute code:

///dessiner alarm0 (= retour négatif )
if(alarm[0] > 0)
{
  var str = "Manque de ressources ou capacité militaire !"
  draw_set_color(c_white) 
  draw_rectangle(bc_alarm0_x-10,bc_alarm0_y-10,bc_alarm0_x+ string_width(str)+10,bc_alarm0_y + string_height(str)+10,false)
  draw_set_color(c_red) 
  draw_text(bc_alarm0_x,bc_alarm0_y,str)
}
 
A

Amoses

Guest
??? Sign in with your usual game maker account ???

here is the code for obj_builder_controller
Code:
Information about object: obj_builder_controller
Sprite:
Solid: false
Visible: true
Depth: -1500
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

///variables
enum e_builder_state
{
   show=0,
   building_selected=1,
   building_choose_xy=2,
   building_check=3,
   building_finish=4
}

bc_is_activated = false
bc_phase = e_builder_state.show
/*
global.show_bleft_x1 =  gui_tab_bleft[0,0]
global.show_bleft_y1 =  gui_tab_bleft[0,1]
*/
bc_show_back = spr_gui_builder_background
bc_show_www = sprite_get_width(bc_show_back)
bc_show_hhh = sprite_get_height(bc_show_back)



bc_show_startx = display_get_gui_width()/2 - bc_show_www/2 // global.show_bleft_x1
bc_show_margex = 7
bc_show_margey = 7
bc_show_starty = display_get_gui_height()/2 - bc_show_hhh/2//global.show_bleft_y1
bc_show_endy = bc_show_starty + bc_show_hhh
bc_show_endx = bc_show_startx + bc_show_www

bc_cancel_spr = spr_gui_builder_cancel
bc_cancel_x1 = bc_show_endx - sprite_get_width(bc_cancel_spr)/2
bc_cancel_y1 = bc_show_starty - sprite_get_height(bc_cancel_spr)/2
bc_cancel_x2 = bc_cancel_x1 + sprite_get_width(bc_cancel_spr)
bc_cancel_y2 = bc_cancel_y1 + sprite_get_height(bc_cancel_spr)
bc_cancel_hover = 0

//bc_show_max = 10

bc_show_mtitle_x = bc_show_startx + bc_show_www/2
bc_show_mtitle_y = bc_show_starty  + bc_show_margey

bc_show_max_per_line = 4
bc_show_cadre_www = 100
bc_show_cadre_hhh = 125

bc_building_id_selected= noone
bc_building_id_selected_sprite = noone
bc_building_id_selected_obj = noone
bc_building_selected_cost_gold =0
bc_building_selected_cost_special =0
bc_building_selected_cost_military =0
bc_alarm0_x = bc_show_startx
bc_alarm0_y = bc_show_starty

bc_show_stepx = bc_show_startx + bc_show_margex*2
bc_show_stepy = bc_show_starty + bc_show_margey*5

range=0
valid_xy = false
n=0

//info
bc_show_opt[0,4] = spr_tour_arrow
bc_show_opt[0,10] = e_batid.tower_arrow
bc_show_opt[0,11] = obj_tour_arrow
t = building_get_info(1,e_batid.tower_arrow,id)
bc_show_opt[0,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[0,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[0,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[0,60] = 1 //xscale
bc_show_opt[0,61] = 1 //yscale
bc_show_opt[0,24] = t[e_getinfobuilder.name]
bc_show_opt[0,25] = t[e_getinfobuilder.description]
bc_show_opt[0,23] = t[e_getinfobuilder.battype]
bc_show_opt[0,70] = t[e_getinfobuilder.can_shoot_flying]
bc_show_opt[0,71] = t[e_getinfobuilder.can_shoot_ground]



bc_show_opt[1,4] = spr_tour_hammer
bc_show_opt[1,10] = e_batid.tower_hammer
bc_show_opt[1,11] = obj_tour_hammer
t = building_get_info(1,e_batid.tower_hammer,id)
bc_show_opt[1,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[1,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[1,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[1,60] = 1 //xscale
bc_show_opt[1,61] = 1 //yscale
bc_show_opt[1,24] = t[e_getinfobuilder.name]
bc_show_opt[1,25] = t[e_getinfobuilder.description]
bc_show_opt[1,23] = t[e_getinfobuilder.battype]
bc_show_opt[1,70] = t[e_getinfobuilder.can_shoot_flying]
bc_show_opt[1,71] = t[e_getinfobuilder.can_shoot_ground]

bc_show_opt[2,4] = spr_tour_star
bc_show_opt[2,10] = e_batid.tower_star
bc_show_opt[2,11] = obj_tour_star
t = building_get_info(1,e_batid.tower_star,id)
bc_show_opt[2,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[2,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[2,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[2,60] = 1 //xscale
bc_show_opt[2,61] = 1 //yscale
bc_show_opt[2,24] = t[e_getinfobuilder.name]
bc_show_opt[2,25] = t[e_getinfobuilder.description]
bc_show_opt[2,23] = t[e_getinfobuilder.battype]
bc_show_opt[2,70] = t[e_getinfobuilder.can_shoot_flying]
bc_show_opt[2,71] = t[e_getinfobuilder.can_shoot_ground]


bc_show_opt[3,4] = spr_tour_bomb
bc_show_opt[3,10] = e_batid.tower_bomb
bc_show_opt[3,11] = obj_tour_bomb
t = building_get_info(1,e_batid.tower_bomb,id)
bc_show_opt[3,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[3,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[3,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[3,60] = 1 //xscale
bc_show_opt[3,61] = 1 //yscale
bc_show_opt[3,24] = t[e_getinfobuilder.name]
bc_show_opt[3,25] = t[e_getinfobuilder.description]
bc_show_opt[3,23] = t[e_getinfobuilder.battype]
bc_show_opt[3,70] = t[e_getinfobuilder.can_shoot_flying]
bc_show_opt[3,71] = t[e_getinfobuilder.can_shoot_ground]

bc_show_opt[4,4] = spr_trap_ironspike
bc_show_opt[4,10] = e_batid.trap_spike
bc_show_opt[4,11] = obj_trap_spike
t = building_get_info(1, e_batid.trap_spike,id)
bc_show_opt[4,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[4,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[4,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[4,60] = 0.75 //xscale
bc_show_opt[4,61] = 0.75 //yscale
bc_show_opt[4,24] = t[e_getinfobuilder.name]
bc_show_opt[4,25] = t[e_getinfobuilder.description]
bc_show_opt[4,23] = t[e_getinfobuilder.battype]
bc_show_opt[4,100] = t[e_getinfobuilder.speimg]


bc_show_opt[5,4] = spr_trap_ice
bc_show_opt[5,10] = e_batid.trap_ice
bc_show_opt[5,11] = obj_trap_ice
t = building_get_info(1, e_batid.trap_ice,id)
bc_show_opt[5,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[5,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[5,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[5,60] = 2 //xscale
bc_show_opt[5,61] = 2//yscale
bc_show_opt[5,24] = t[e_getinfobuilder.name]
bc_show_opt[5,25] = t[e_getinfobuilder.description]
bc_show_opt[5,23] = t[e_getinfobuilder.battype]
bc_show_opt[5,100] = t[e_getinfobuilder.speimg]

bc_show_opt[6,4] = spr_trap_acide
bc_show_opt[6,10] = e_batid.trap_acid
bc_show_opt[6,11] = obj_trap_acid
t = building_get_info(1, e_batid.trap_acid,id)
bc_show_opt[6,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[6,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[6,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[6,60] = 2 //xscale
bc_show_opt[6,61] = 2 //yscale
bc_show_opt[6,24] = t[e_getinfobuilder.name]
bc_show_opt[6,25] = t[e_getinfobuilder.description]
bc_show_opt[6,23] = t[e_getinfobuilder.battype]
bc_show_opt[6,100] = t[e_getinfobuilder.speimg]

bc_show_opt[7,4] = spr_defender_caserne
bc_show_opt[7,10] = e_batid.defender_caserne
bc_show_opt[7,11] = obj_defender_caserne
t = building_get_info(1,  e_batid.defender_caserne,id)
bc_show_opt[7,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[7,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[7,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[7,60] = 1 //xscale
bc_show_opt[7,61] = 1 //yscale
bc_show_opt[7,24] = t[e_getinfobuilder.name]
bc_show_opt[7,25] = t[e_getinfobuilder.description]
bc_show_opt[7,23] = t[e_getinfobuilder.battype]
bc_show_opt[7,100] = tab_info[e_getinfobuilder.defender_unit]

bc_show_opt[8,4] = spr_defender_maidhouse
bc_show_opt[8,10] = e_batid.defender_maidhouse
bc_show_opt[8,11] = obj_defender_maidhouse
t = building_get_info(1,  e_batid.defender_maidhouse,id)
bc_show_opt[8,20] = t[e_getinfobuilder.cost_gold] //cost gold
bc_show_opt[8,21] = t[e_getinfobuilder.cost_special] //cost special
bc_show_opt[8,22] = t[e_getinfobuilder.cost_military] //cost military
bc_show_opt[8,60] = 1 //xscale
bc_show_opt[8,61] = 1 //yscale
bc_show_opt[8,24] = t[e_getinfobuilder.name]
bc_show_opt[8,25] = t[e_getinfobuilder.description]
bc_show_opt[8,23] = t[e_getinfobuilder.battype]
bc_show_opt[8,100] = tab_info[e_getinfobuilder.defender_unit]

bc_show_max = array_height_2d(bc_show_opt)
cur_type = e_battype.tower


//precalcul en largeur
for(i=0 ; i < bc_show_max ; i++)
{
   if(cur_type != bc_show_opt[i,23] or n >=  bc_show_max_per_line)
   {
       bc_show_stepx = bc_show_startx + bc_show_margex*2  // bc_show_startx + bc_show_margex*2
       bc_show_stepy += bc_show_cadre_hhh + bc_show_margey //sprite_get_height( spr_gui_builder ) + bc_show_margey*15
       n=0
       cur_type = bc_show_opt[i,23]
   }


   bc_show_opt[i,13] = bc_show_stepx //x1 cadre
   bc_show_opt[i,14] = bc_show_stepy //y1 cadre
  
   bc_show_opt[i,15] = bc_show_stepx  + bc_show_cadre_www // x2 cadre
   bc_show_opt[i,16] = bc_show_stepy  + bc_show_cadre_hhh //y2 cadre
   bc_show_opt[i,17] = bc_show_stepx + bc_show_cadre_www/2//x titre
   bc_show_opt[i,18] = bc_show_stepy + 10 //y titre

   bc_show_opt[i,0] = bc_show_stepx + bc_show_cadre_www/2 - sprite_get_width( spr_gui_builder )/2   //x1 img
   bc_show_opt[i,1] = bc_show_stepy + bc_show_cadre_hhh/2 - sprite_get_height( spr_gui_builder )/2 //y1    img
   bc_show_opt[i,2] = bc_show_opt[i,0] + sprite_get_width( spr_gui_builder ) //x2 img
   bc_show_opt[i,3] = bc_show_opt[i,1] + sprite_get_height( spr_gui_builder ) //y2 img  
   //bc_show_opt[i,4] = noone //sprite = affichage ?
   bc_show_opt[i,5] = false //hover
   bc_show_opt[i,6] = false //selected
   //bc_show_opt[i,10] = noone // id tower/building à construire
   //bc_show_opt[i,11] = noone // obj
  
  
   //bc_show_opt[i,12] = bc_show_opt[i,0] // bas du cadre gauche
  
  
  
  
   /* bc_show_opt[i,20] = 0 //cost gold
   bc_show_opt[i,21] = 0 //cost special
   bc_show_opt[i,22] = 0 //cost military
   bc_show_opt[i,23] = 0 //type
   bc_show_opt[i,24] = "nom" //nom
   bc_show_opt[i,25] = "description" //nom*/
  
    draw_set_font(font_gui_ressources_tiny)
   bc_show_opt[i,30] = bc_show_opt[i,0]// bc_show_stepx //x1 cost gold
   bc_show_opt[i,31] = bc_show_opt[i,3] + 5 //y1 cost gold
   bc_show_opt[i,32] = bc_show_stepx + string_width("9999") //x1 sprite cost gold
   bc_show_opt[i,33] = bc_show_opt[i,3] + 5 + sprite_get_height(spr_gold)/4+2 //y1 sprite cost gold
  
   bc_show_opt[i,40] = bc_show_opt[i,0]//bc_show_stepx //x1 cost special
   bc_show_opt[i,41] = bc_show_opt[i,31] + 10 //y1 cost special
   bc_show_opt[i,42] = bc_show_opt[i,32] //x1 sprite cost special
   bc_show_opt[i,43] = bc_show_opt[i,33] + 10 //y1 sprite cost special
  
   bc_show_opt[i,50] = bc_show_opt[i,0]// bc_show_stepx //x1 cost military
   bc_show_opt[i,51] = bc_show_opt[i,41] + 10 //y1 cost military
   bc_show_opt[i,52] = bc_show_opt[i,32] //x1 sprite cost military
   bc_show_opt[i,53] = bc_show_opt[i,43] + 10 //y1 sprite cost military
  
   bc_show_opt[i,54] =  bc_show_opt[i,30] + bc_show_margex*5 //x1 sprite flying
   bc_show_opt[i,55] = bc_show_opt[i,31] //y1 sprite flying
   bc_show_opt[i,56] =  bc_show_opt[i,30] + bc_show_margex*5 //x1 sprite ground
   bc_show_opt[i,57] = bc_show_opt[i,51] //y1 sprite ground
  
  
  
   /* bc_show_opt[i,60] = 1 //xscale
   bc_show_opt[i,61] = 1 //yscale
    bc_show_opt[i,70] = flying true false
    bc_show_opt[i,71] = ground true false
   */
  
  
  
        bc_show_stepx  += bc_show_cadre_www + bc_show_margex //sprite_get_width( spr_gui_builder ) + bc_show_margex*3
  
   n++
   /* if( n >=  bc_show_max_per_line)
   {
       bc_show_stepx = bc_show_startx + bc_show_margex*2  // bc_show_startx + bc_show_margex*2
       bc_show_stepy += bc_show_cadre_hhh + bc_show_margey //sprite_get_height( spr_gui_builder ) + bc_show_margey*15
       n=0
   }    */    
  
  
      
}


bc_show_description_ww = bc_show_www - bc_show_margex*2
bc_show_description_hh = 75
bc_show_description_x1 = bc_show_startx + bc_show_margex
bc_show_description_y1 = bc_show_endy - bc_show_description_hh
bc_show_description_x2 = bc_show_description_x1 + bc_show_description_ww
bc_show_description_y2 = bc_show_endy - bc_show_margey*1
bc_show_description_title_x = bc_show_description_x1 //+ bc_show_margex
bc_show_description_title_y = bc_show_description_y1 - bc_show_margey
bc_show_description_text_x = bc_show_description_x1 + bc_show_margex*3
bc_show_description_text_y = bc_show_description_y1 + bc_show_margey*2
bc_show_description_text_color = c_black
bc_show_description_text_alpha = 1
bc_show_description_bgcolor = c_white
bc_show_description_bgcolor_alpha = 0.50



/*
enum e_getinfobuilder
{
   idd=50,
   cost_gold = 0,
   cost_special=1,
   cost_military=2,
   hp=3,
   hpmax=4,
   range=6,
   attaque=7,
   defense=8,
   projectile_name=9,
   projectile_sprite=10,
   projectile_obj=11,
   projectile_bounce=12,
   projectile_bounce_nbr=13,
   projectile_explode=14,
   projectile_explode_nbr=15,
   cooldown=16
}*/




Alarm Event for alarm 0:
execute code:


if(alarm[0] > 0)
{
   alarm[0] --
}

Step Event:
execute code:

///check si un des batiments à été sélectionné pour construction
if(bc_phase == e_builder_state.show and bc_is_activated)
{
   var xxx = device_mouse_x_to_gui(0)
   var yyy = device_mouse_y_to_gui(0)
  
   for(i=0 ; i < bc_show_max ; i++)
   {
           if(bc_show_opt[i,4] != noone)
           {
            if( point_in_rectangle(xxx,yyy,bc_show_opt[i,0],bc_show_opt[i,1],bc_show_opt[i,2],bc_show_opt[i,3]))
            {
                    bc_show_opt[i,5] = true
                    if(device_mouse_check_button_released(0, mb_left))
                    {
                        bc_show_opt[i,6] = true
                        //vérification si ressources nécessaires disponibles
                        var test = building_use_ressource(true, bc_show_opt[i,20], bc_show_opt[i,21], bc_show_opt[i,22])
                        if(test == false)
                        {
                           alarm[0] = 50
                           return -1
                        }
                      
                        bc_building_selected_cost_gold = bc_show_opt[i,20]
                        bc_building_selected_cost_special = bc_show_opt[i,21]
                        bc_building_selected_cost_military = bc_show_opt[i,22]
                        show_debug_message("***need military = " + string( bc_building_selected_cost_military) + "***")
                      
                        //action à réaliser
                           bc_building_id_selected = bc_show_opt[i,10]
                           bc_building_id_selected_sprite = bc_show_opt[i,4]
                           sprite_index = bc_show_opt[i,4]
                           show_debug_message("builder : im_index = " + string(image_index))
                           bc_building_id_selected_obj =  bc_show_opt[i,11]
                           bc_phase =    e_builder_state.building_choose_xy
                        //fin action à réaliser
                    }
                    else
                    {
                       bc_show_opt[i,6] = false
                    }
            }
            else
            {
               bc_show_opt[i,5] = false
            }
           }
  
   }
 
  
}
else
{
   if(bc_phase == e_builder_state.building_choose_xy)
   {
        obj_town.building_selected = true
        global.building_selected = -1
      
        x = device_mouse_x(0)
        y = device_mouse_y(0)
//         range = distance_to_object(obj_town)
        range = distance_to_point(obj_town.building_middle_x,obj_town.building_middle_y)
        if(range > obj_town.building_range)
        {
        
          valid_xy = false
    
        }
        else
        {
      
           var test = place_meeting(x,y,obj_building)
           var test_trap = place_meeting(x,y,obj_trap_parent)
           //valid_xy = !test
           valid_xy = !(test or test_trap)
          
        }
      
        if(valid_xy and device_mouse_check_button_released(0, mb_left))
        {
           //utiliser ressources
           building_use_ressource(false, bc_building_selected_cost_gold, bc_building_selected_cost_special, bc_building_selected_cost_military)
          
           //construire
           b =instance_create(x,y,bc_building_id_selected_obj)
           if(b.building_type != e_battype.trap) //la building phase ne s'applique pas aux trap
           {
          
               b.building_under_construction_finished = false
               b.building_hp = 1
           }
          
           bc_phase=e_builder_state.show
           bc_is_activated = false
           sprite_index = noone
           obj_town.building_selected = false
           bc_building_id_selected= noone
           bc_building_id_selected_sprite = noone
           bc_building_id_selected_obj = noone
           //fin de construction
        }
      
   }
}

execute code:

///check si button cancel appuyé ou hover
///check si un des batiments à été sélectionné pour construction
if(bc_phase == e_builder_state.show and bc_is_activated)
{
   var xxx = device_mouse_x_to_gui(0)
   var yyy = device_mouse_y_to_gui(0)
  
 
   if( point_in_rectangle(xxx,yyy,bc_cancel_x1,bc_cancel_y1,bc_cancel_x2,bc_cancel_y2))
   {
      bc_cancel_hover=1
     if(device_mouse_check_button_released(0, mb_left))
     {
           bc_is_activated=false    
     }
   }
   else
   {
       bc_cancel_hover=0
   }
                  
}

execute code:

///check si ESC appuyé pendant phase de placement pour annuller
if(bc_phase == e_builder_state.building_choose_xy and bc_is_activated)
{
   if(keyboard_check_released(vk_escape))
   {
        bc_phase = e_builder_state.show
    
   }
}

Draw Event:
execute code:

///draw phase e_builder_state.building_choose_xy
if(bc_phase == e_builder_state.building_choose_xy)
{
  

  if(valid_xy)
  {
   //draw_self()
   draw_sprite( bc_building_id_selected_sprite,0, mouse_x, mouse_y)
  }
  else
  {
   draw_sprite_ext( bc_building_id_selected_sprite,0, mouse_x, mouse_y,1,1,0,c_red,1)
  }
  
   draw_text(x+10,y+10,range)
 
 
  
}

Draw GUI Event:
execute code:

///déssiner en fonction de la phase
if(bc_is_activated)
{

   switch(bc_phase)
   {
       case e_builder_state.building_choose_xy:
           draw_set_font(font_gui_menu_building)
           draw_text(50,50,"ESCHAP pour retour")
           break;
  
       case e_builder_state.show :
       case e_builder_state.building_selected:  
      
           draw_sprite(bc_show_back,0,bc_show_startx,bc_show_starty)
           draw_set_halign(fa_center)
           draw_set_color(c_black)
           draw_set_font(font_gui_menu_building)
           draw_text(bc_show_mtitle_x,bc_show_mtitle_y,"Construction de batiments : ")
           draw_sprite(bc_cancel_spr,bc_cancel_hover,bc_cancel_x1,bc_cancel_y1)
           for(i=0 ; i < bc_show_max ; i++)
           {
               if(bc_show_opt[i,4] != noone)
               {
                  /* if(bc_building_id_selected == bc_show_opt[i,10]) //selected
                   {
                       draw_set_color(c_green)
                       draw_rectangle(bc_show_opt[i,0]-5,bc_show_opt[i,1]-5,bc_show_opt[i,2]+5, bc_show_opt[i,3]+5,false)
                   }*/
                   var cadre_color= c_black;
                  
                   switch(bc_show_opt[i,23])
                   {
                       case e_battype.tower:
                              cadre_color = c_black  
                              if(bc_show_opt[i,70] == true)
                              {
                                   draw_sprite(spr_flying,0,bc_show_opt[i,54],bc_show_opt[i,55])
                              }
                              else
                              {
                                   draw_sprite(spr_not_flying,0,bc_show_opt[i,54],bc_show_opt[i,55])
                              }
                              if(bc_show_opt[i,71] == true)
                              {
                                   draw_sprite(spr_ground,0,bc_show_opt[i,56],bc_show_opt[i,57])
                              }
                              else
                              {
                                   draw_sprite(spr_not_ground,0,bc_show_opt[i,56],bc_show_opt[i,57])
                              }
                            
                              
                               break;
                       case e_battype.trap:
                               cadre_color = c_red  
                               var sprt =bc_show_opt[i,100]
                               draw_sprite(sprt,0,bc_show_opt[i,54],bc_show_opt[i,55])
                              
                              
                               break;      
                       case e_battype.defender:
                               cadre_color = c_green
                            
                                var sprt = object_get_sprite(bc_show_opt[i,100] )
                                draw_sprite(sprt,7,bc_show_opt[i,54],bc_show_opt[i,55])
                              
                               break;            
                   }
                  
                  
                   draw_set_alpha(0.35)
                   draw_set_color(cadre_color)
                   draw_roundrect(bc_show_opt[i,13]-2,bc_show_opt[i,14]-2,bc_show_opt[i,15]+2,  bc_show_opt[i,16]+2,true)
                   draw_set_color(cadre_color)
                   draw_roundrect(bc_show_opt[i,13],bc_show_opt[i,14],bc_show_opt[i,15],  bc_show_opt[i,16],false)
                   draw_set_alpha(1)
                   draw_set_halign(fa_center)
                    draw_set_color(c_black)
                    draw_set_font(font_gui_menu_building_middle)
                    draw_text_ext(bc_show_opt[i,17] ,bc_show_opt[i,18],string( bc_show_opt[i,24]),12, bc_show_cadre_www)
                  
                    
                      
                   if(bc_show_opt[i,5] == true) //hoover
                   {
                    
                        draw_sprite_ext(bc_show_opt[i,4],0, bc_show_opt[i,0], bc_show_opt[i,1],bc_show_opt[i,60],bc_show_opt[i,61],0,c_green,1)
                        draw_set_color(bc_show_description_bgcolor )
                        draw_set_alpha(bc_show_description_bgcolor_alpha)
                      
                        draw_roundrect(bc_show_description_x1,bc_show_description_y1,bc_show_description_x2,bc_show_description_y2,false)
                        draw_set_color(bc_show_description_text_color )
                        draw_set_alpha(bc_show_description_text_alpha)
                        draw_set_halign(fa_left)
                        draw_text(bc_show_description_title_x,bc_show_description_title_y,"Description :")
                        draw_text_ext(bc_show_description_text_x ,bc_show_description_text_y,string(bc_show_opt[i,25]),12,bc_show_description_ww)
                      
                   }
                   else
                   {
                        draw_sprite_ext(bc_show_opt[i,4],0, bc_show_opt[i,0], bc_show_opt[i,1],bc_show_opt[i,60],bc_show_opt[i,61],0,c_white,1)
                   }
                
                   draw_set_alpha(1)
                   draw_set_halign(fa_left)
                   draw_set_color(c_black)
                   draw_set_font(font_gui_ressources_tiny)
                   draw_text( bc_show_opt[i,30], bc_show_opt[i,31], bc_show_opt[i,20])
                   draw_sprite_ext( spr_gold,0,  bc_show_opt[i,32], bc_show_opt[i,33],0.5,0.5,0,c_white,1)
              
                   draw_text( bc_show_opt[i,40], bc_show_opt[i,41], bc_show_opt[i,21])
                   draw_sprite_ext( spr_special,0,  bc_show_opt[i,42], bc_show_opt[i,43],0.5,0.5,0,c_white,1)
                  
                   draw_text( bc_show_opt[i,50], bc_show_opt[i,51], bc_show_opt[i,22])
                   draw_sprite_ext( spr_military,0,  bc_show_opt[i,52], bc_show_opt[i,53],0.5,0.5,0,c_white,1)
               }
           }
           break;
          
    
      
  
   }

}

execute code:

///dessiner alarm0 (= retour négatif )
if(alarm[0] > 0)
{
  var str = "Manque de ressources ou capacité militaire !"
  draw_set_color(c_white)
  draw_rectangle(bc_alarm0_x-10,bc_alarm0_y-10,bc_alarm0_x+ string_width(str)+10,bc_alarm0_y + string_height(str)+10,false)
  draw_set_color(c_red)
  draw_text(bc_alarm0_x,bc_alarm0_y,str)
}
what kind of code was used to deleting the item?
 
Top