difficulty level engine

skofrant

Member
Hi all,

how to add difficulty level in room - easy, normal and hard?

Easy
In the easy mode your hero is quite strong in comparisson with enemies additionally you have faster guns

Medium
The normal medium difficulty offers standard mode without any handicap and additional obstacles

Hard
The game hates you.You have less starting energy points.The enemies are more dangerous for you.Moreover some obstacles behaves differently


Thanks:)
 
If you know how to use variables and if statements it's not all that hard. You just have a global difficulty variable which is checked to change certain things at the start of the room or creation event of things like enemies. Most of those behaviors you describe would have to be programmed independently, there isn't really a general solution to change the difficulty. But if you build it in from the start you should find it quite doable.
 

skofrant

Member
That's how much i know that it can be done on global variables.:)
I would ask for example code on difficulty level. And for example, I put it in a separate room as obj_difficulty.
 
W

WoNkY

Guest
Use arrays, then when an instance is created it can set it's speed, bullet speed etc by refering to the array for the difficulty level.
 

skofrant

Member
This code above should be in the obj_enemy? can it be a separate object placed on the game map?
I would like to create an object that would be in a separate room, after clicking on a new game, this room would be started with a choice of difficulty levels, easy, normal, difficult.
and depending on what I press, this level of difficulty of the game would start:
for example, I choose the difficulty level easy, it starts the game in this mode, etc.

I am asking for help ... maybe someone could write it to me?

obj_Enemy
HTML:
//Deafult values //
max_hp = 100;
attack_damage = 5;
movement_speed = 3;

//easy difficult
if(global.difficult  == "easy")
{
    max_hp = 80;
    attack_damage = 3;
    movement_speed = 2;
}

//medium difficult
if(global.difficult  == "medium")
{
    max_hp = 100;
    attack_damage = 5;
    movement_speed = 3;
}

//hard difficult
if(global.difficult  == "hard")
{
    max_hp = 120;
    attack_damage = 7;
    movement_speed = 4;
 
G

Gillen82

Guest
Use scripts to load in the necessary settings as required
 

skofrant

Member
What should be in the middle of the script?
some illustrative example of how it should look like skrypt?
 

Yal

🐧 *penguin noises*
GMC Elder
Simplest solution: make 3 different rooms, Easy, Medium and Hard. Make 3 different hero objects with different timings and put one in each room. Make 3 button objects, Easy, Medium and Hard with different sprites. In the Mouse Left Pressed event, go to the corresponding room.
 

skofrant

Member
Creating three rooms of three heroes and each map of the game after x3is a lot of work:/

I did something like this because I use the hero of global variables, but still something does not work when choosing the level of difficulty.


I use global variables

global.live = 5;

global.hp = 100;


and it looks like this:


obj_hero

HTML:
/// Glowne deklaracje zmiennych Anatola
                    
                     //////////////////////////////
                    ///////ZMIENNE STALE//////////
                    /////////////////////////////
///Ustawienia
event_inherited();
zbieranie=true;
eksplozja = false;
zasiegEksplozji = 22;
silaEksplozji = 10;

global.damage=0; //zmiena odzpowiedzialna za obrazenia zadawane po upadku z duzej wysokosci
global.hp = 100;
global.hit=0; //zmienna odpowiada za obrazenia kuli i miganie
maxHp = 100;
zegarAtaku = 0;
odejmij = 0; //zmienna potrzebna do przesuwanie skrzynki w end step
atakBierzacy = 0;
global.zegarObrazen = 0;
kierunekPlywania = 0;
wysKierunek = 0;
silaSkoku = 0;
czasSkoku = 0;
drabina = false;
rs_timer = 0; //licznik czasowy w grze
tlen=10;//ilosc tlenu

//Moce specjalne
pwrupSpd = 0;
pwrupStr = 0;
pwrupJmp = 0;

//Pozycja odrodzenia Anatola i wywolanie skryptu widoku centralnego na graczu
spawnX = x;
spawnY = y;
centerViewOnMe();

//zachowanie pozycji gracza przy checkpointach
if (global.checkpointR == room)
{
    x = global.checkpointx;
    y = global.checkpointy;
}
start_x = x;
start_y = y;
//funkcja dodaje HUD gracza na planszach bossowych
if instance_exists(obj_game_controller)
obj_game_controller.visible=1
else instance_create(0,0,obj_game_controller);


//zamrazanie bohatera
zamroz = false;
zamroz_x = x;
zamroz_y = y;



playerSlot = 1; //ustalamy slot dla gracza numer 1
kierunekPlywaniaGamepad = 0;


///poziomy trudnosci

global.difficulty = 0; //ustaw latwy
global.difficulty = 1; //ustaw sredni
global.difficulty = 2; //ustaw trudny


//easy difficult
if(global.difficulty  == "easy")
{
   global.hp = 100;
   global.live = 7;
}

//medium difficult
if(global.difficulty  == "medium")
{
   global.hp = 80;
   global.live = 5;
}

//hard difficult
if(global.difficulty  == "hard")
{
    global.hp = 50;
    global.live = 3;
    
  
}

now obj_difficult (
he is in a separate room)


CREATE

HTML:
options_difficulty=ds_list_create()
options_difficulty[|0]=("Easy")
options_difficulty[|1]=("Medium")
options_difficulty[|2]=("hard")

selected=0

gp_up=false
gup_down=false
gp_left=false
gp_right=false

//Używane do animacji menu
animation_speed=room_speed/4
for(var i=0; i<ds_list_size(options_difficulty); i++) {
    animation[i]=0
}

STEP

HTML:
if(abs(gamepad_axis_value(0,gp_axislv))<0.3 && !keyboard_check(vk_anykey))
    {
    gp_up=0
    gp_down=0
    }
    
if(abs(gamepad_axis_value(0,gp_axislh))<0.3 && !keyboard_check(vk_anykey))
    {
    gp_left=0
    gp_right=0
    } 

if(keyboard_check_pressed(vk_down) || gamepad_button_check_pressed(0,gp_padd) || (gamepad_axis_value(0,gp_axislv)>0.7 && !gp_up)) {
    selected++
    if(selected>=ds_list_size(options_difficulty)) {
        selected=ds_list_size(options_difficulty)-1
    }
    gp_up=true
}

if(keyboard_check_pressed(vk_up) || gamepad_button_check_pressed(0,gp_padu) || (gamepad_axis_value(0,gp_axislv)<-0.7 && !gp_down)) {
    selected--
    if(selected<0) {
        selected=0
    }
    gp_down=true
}

if(keyboard_check_pressed(vk_enter) || gamepad_button_check_pressed(0,gp_face1))
{
    if(selected == 0) then global.difficulty = 0; //ustaw latwy
    room_goto(inicjacja)
    if(selected == 1) then global.difficulty = 1; //ustaw sredni
    room_goto(inicjacja)
    if(selected == 2) then global.difficulty = 2; //ustaw trudny
    room_goto(inicjacja)
}

DRAW


HTML:
draw_set_valign(1)
draw_set_halign(1)
draw_set_font(fontIntro)

var line_height=ceil(string_height("M")*1.1)

for(var i=0; i<ds_list_size(options_difficulty); i++) {
    if(i=selected) {
        //Wybrana opcja
        animation[i]=clamp(animation[i]+(1/animation_speed),0,1)
    } else {
        animation[i]=clamp(animation[i]-(1/animation_speed),0,1)
    }
    var color=merge_colour(c_black,c_red,animation[i])
    draw_text_transformed_color(x,y+(line_height*i),options_difficulty[|i],1+animation[i]/5,1+animation[i]/5,0,color,color,color,color,1)
}
 

Yal

🐧 *penguin noises*
GMC Elder
Creating three rooms of three heroes and each map of the game after x3is a lot of work:/

I did something like this because I use the hero of global variables, but still something does not work when choosing the level of difficulty.
Yeah, it is. It's good that you realized that before actually doing it... see, variables makes everything easier :p

Having three different hero objects + three different "go to next room" objects might be easier if you're having problems separating the menu logic / difficulty change effects properly.



In your code, you're resetting the difficulty variables in the player object, so you're gonna undo the work the menu object did.
upload_2019-6-6_21-32-47.png
 

skofrant

Member
Still does not work after choosing the level of difficulty. I do not know what I'm doing wrong :-(

obj_hero

Create

HTML:
/// Glowne deklaracje zmiennych Anatola
                   
                     //////////////////////////////
                    ///////ZMIENNE STALE//////////
                    /////////////////////////////
///Ustawienia
event_inherited();
zbieranie=true;
eksplozja = false;
zasiegEksplozji = 22;
silaEksplozji = 10;

global.damage=0; //zmiena odzpowiedzialna za obrazenia zadawane po upadku z duzej wysokosci
global.hp = 100;
global.hit=0; //zmienna odpowiada za obrazenia kuli i miganie
maxHp = 100;
zegarAtaku = 0;
odejmij = 0; //zmienna potrzebna do przesuwanie skrzynki w end step
atakBierzacy = 0;
global.zegarObrazen = 0;
kierunekPlywania = 0;
wysKierunek = 0;
silaSkoku = 0;
czasSkoku = 0;
drabina = false;
rs_timer = 0; //licznik czasowy w grze
tlen=10;//ilosc tlenu

//Moce specjalne
pwrupSpd = 0;
pwrupStr = 0;
pwrupJmp = 0;

//Pozycja odrodzenia Anatola i wywolanie skryptu widoku centralnego na graczu
spawnX = x;
spawnY = y;
centerViewOnMe();

//zachowanie pozycji gracza przy checkpointach
if (global.checkpointR == room)
{
    x = global.checkpointx;
    y = global.checkpointy;
}
start_x = x;
start_y = y;
//funkcja dodaje HUD gracza na planszach bossowych
if instance_exists(obj_game_controller)
obj_game_controller.visible=1
else instance_create(0,0,obj_game_controller);


//zamrazanie bohatera
zamroz = false;
zamroz_x = x;
zamroz_y = y;



playerSlot = 1; //ustalamy slot dla gracza numer 1
kierunekPlywaniaGamepad = 0;

///poziomy trudnosci

//Ustaw domyślne wartości życia i szans, gdyby nie wyszukało jaki jest poziom trudności
global.hp = 100;
global.live = 7;

/// Wyszukaj poziom trudności i ustaw odpowiednio życie i szanse

//easy difficult
if(global.difficulty  == "easy")
{
   global.hp = 100;
   global.live = 7;
}

//medium difficult
if(global.difficulty  == "medium")
{
   global.hp = 80;
   global.live = 5;
}

//hard difficult
if(global.difficulty  == "hard")
{
    global.hp = 50;
    global.live = 3;
   
 
}
now obj_difficult (he is in a separate room)

CREATE

HTML:
options_difficulty=ds_list_create()
options_difficulty[|0]=("Easy")
options_difficulty[|1]=("Medium")
options_difficulty[|2]=("hard")

selected=0

gp_up=false
gup_down=false
gp_left=false
gp_right=false

//Używane do animacji menu
animation_speed=room_speed/4
for(var i=0; i<ds_list_size(options_difficulty); i++) {
    animation[i]=0
}

STEP

HTML:
if(abs(gamepad_axis_value(0,gp_axislv))<0.3 && !keyboard_check(vk_anykey))
    {
    gp_up=0
    gp_down=0
    }
   
if(abs(gamepad_axis_value(0,gp_axislh))<0.3 && !keyboard_check(vk_anykey))
    {
    gp_left=0
    gp_right=0
    }

if(keyboard_check_pressed(vk_down) || gamepad_button_check_pressed(0,gp_padd) || (gamepad_axis_value(0,gp_axislv)>0.7 && !gp_up)) {
    selected++
    if(selected>=ds_list_size(options_difficulty)) {
        selected=ds_list_size(options_difficulty)-1
    }
    gp_up=true
}

if(keyboard_check_pressed(vk_up) || gamepad_button_check_pressed(0,gp_padu) || (gamepad_axis_value(0,gp_axislv)<-0.7 && !gp_down)) {
    selected--
    if(selected<0) {
        selected=0
    }
    gp_down=true
}

if(keyboard_check_pressed(vk_enter) || gamepad_button_check_pressed(0,gp_face1))
{
    if(selected == 0) then global.difficulty = 0; //ustaw latwy
    room_goto(inicjacja)
    if(selected == 1) then global.difficulty = 1; //ustaw sredni
    room_goto(inicjacja)
    if(selected == 2) then global.difficulty = 2; //ustaw trudny
    room_goto(inicjacja)
}

DRAW

HTML:
draw_set_valign(1)
draw_set_halign(1)
draw_set_font(fontIntro)

var line_height=ceil(string_height("M")*1.1)

for(var i=0; i<ds_list_size(options_difficulty); i++) {
    if(i=selected) {
        //Wybrana opcja
        animation[i]=clamp(animation[i]+(1/animation_speed),0,1)
    } else {
        animation[i]=clamp(animation[i]-(1/animation_speed),0,1)
    }
    var color=merge_colour(c_black,c_red,animation[i])
    draw_text_transformed_color(x,y+(line_height*i),options_difficulty[|i],1+animation[i]/5,1+animation[i]/5,0,color,color,color,color,1)
}
 

Yal

🐧 *penguin noises*
GMC Elder
You're setting "global.difficulty" to numbers in some places and strings in some other places... you should look into using constants/macros for this instead (you can have a macro named DIFFICULTY_HARD which has numeric value 2, combining the best of both worlds)
 
Top