GM:S 1.4 changing sprites when level increases!

Discussion in 'Programming' started by EZTALES, May 25, 2018.

  1. EZTALES

    EZTALES Member

    Joined:
    Apr 15, 2018
    Posts:
    166
    hey gang.
    just wondering if anyone could help me out with a little problem on my hands. i want to change the players sprite when his level goes up. the code is down below so please help me out!
    OBJ PLAYER
    CREATE
    /// set fixed rotation
    phy_fixed_rotation = true;
    spd = 2;
    image_speed = 0;
    STEP

    /// movement code (organize time)
    // right
    if (keyboard_check(vk_right)) {
    phy_position_x += spd;
    sprite_index = spr_player_R;
    }
    // up
    if (keyboard_check(vk_up)) {
    phy_position_y -= spd;
    sprite_index = spr_player_U;
    }
    // left
    if (keyboard_check(vk_left)) {
    phy_position_x -= spd;
    sprite_index = spr_player_L;
    }
    // down
    if (keyboard_check(vk_down)) {
    phy_position_y += spd;
    sprite_index = spr_player_D;
    }
    COLLIDE WITH XP:
    /// collect exp
    with (other) {instance_destroy();}
    with (obj_player_stats) {
    expr += 1;
    /// Level Up Code
    if (expr >= maxexpr) {
    level += 1;
    expr = expr-maxexpr;
    maxexpr *= 2;
    }

    }
    ok now the player stats...
    PLAYER STATS
    CREATE
    /// stats
    level = 1;
    expr = 0;
    maxexpr = 2;
    scrLoad();
    DRAW_GUI
    /// draw_stats
    if (room != rm_start) && (room!= rm_load){
    draw_set_color(c_black);
    draw_set_halign(fa_center);
    draw_set_font(font_score);
    draw_text(68, 33, "LEVEL: " + string(level));
    }
    Ok thats all. somebody plz help!
     
  2. Miradur

    Miradur Member

    Joined:
    Jan 16, 2018
    Posts:
    128
    Hi, maybe like this:

    Code:
    with (obj_Check)
       {
       if !collision_line(x, y, other.x, other.y, obj_Wall, false, true)
          {
          sprite_index = spr_spotted;
          }
       else
          {
          sprite_index = spr_clear;
          }
       }
    Miradur
     
  3. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,769
    Store the sprites to be used in each section of your code in variables, so that when the instance is created it'd have something like this:

    Code:
    sprite_left = spr_player_L;
    sprite_right = spr_player_R;
    sprite_up = spr_player_U;
    sprite_down = spr_player_D;

    You'd then change the rest of the code to use these variables, eg:

    Code:
    if (keyboard_check(vk_down)) {
    phy_position_y += spd;
    sprite_index = sprite_down;
    }

    Once you have that, you can change the sprites at any time by simply changing the resource the variable points to, so when the player levels up you'd call some code like:

    Code:
    with (obj_Player)
    {
    sprite_left = spr_player_L_Level2;
    sprite_right = spr_player_R_Level2;
    sprite_up = spr_player_U_level2;
    sprite_down = spr_player_D_level2;
    }

    Hope that helps!
     
    poinl and TimothyAllen like this.
  4. TimothyAllen

    TimothyAllen Member

    Joined:
    Aug 7, 2016
    Posts:
    429
    A modified version of Nocturne's suggestion. (Or maybe more of an extension)

    When setting the sprite_ variables, use asset_get_index. For instance:
    Code:
    sprite_left = asset_get_index("spr_player_L_level" + string(other.level));
    
    Another option is making the sprite_ variables arrays and index them using the player's level.
     
    Nocturne likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice