Legacy GM changing sprites when level increases!

EZTALES

Member
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!
 

Miradur

Member
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
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
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!
 
T

TimothyAllen

Guest
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.
 
Top