• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Animation WASD walk, stand, image speed

T

Tchoup15

Guest
Hi, so I'm trying to do a couple things with moving my sprite using WASD keys. 1st, it's a stealth game, so his speed is controlled by a global.quiet that slows down and his movement creates a 'sound' object. 2nd, I want to have the image walking animation speed indexed to the global.quiet. 3rd, when he isn't walking, I want him standing in the direction that he was last walking. I tried using the following code, and now he won't move at all. Any suggestions on where my bug is?

Thanks!

Create:

sprite_index = spr_heroninja_standdown;

enum heroninja_state
{
up,
down,
left,
right
}

dir = heroninja_state.down;



Step:
if (keyboard_check_pressed(ord("Q")) && global.quiet > 1) {
global.quiet = (global.quiet - 1);
}

if (keyboard_check_pressed(ord("E")) && global.quiet < 5) {
global.quiet = global.quiet + 1;
}


if ((keyboard_check(ord("A"))) or (keyboard_check(ord("D"))) or (keyboard_check(ord("W"))) or (keyboard_check(ord("S"))))
{
if (keyboard_check(ord("A"))&& (place_free(x-global.quiet,y))) {
x -= global.quiet;
instance_create_layer(obj_hero.x, obj_hero.y, "Instances", obj_hero_sound);
sprite_index = spr_heroninja_left;
image_speed = global.quiet+4;
dir = heroninja_state.left;
}

if (keyboard_check(ord("D"))&& (place_free(x+global.quiet,y))) {
x += global.quiet;
instance_create_layer(obj_hero.x, obj_hero.y, "Instances", obj_hero_sound);
sprite_index = spr_heroninja_right;
image_speed = global.quiet+4;
dir = heroninja_state.right;
}

if (keyboard_check(ord("W"))&& (place_free(x,y-global.quiet))) {
y -= global.quiet;
instance_create_layer(obj_hero.x, obj_hero.y, "Instances", obj_hero_sound);
sprite_index = spr_heroninja_up;
image_speed = global.quiet+4;
dir = heroninja_state.up;
}

if (keyboard_check(ord("S"))&& (place_free(x,y+global.quiet))) {
y += global.quiet;
instance_create_layer(obj_hero.x, obj_hero.y, "Instances", obj_hero_sound);
sprite_index = spr_heroninja_down;
image_speed = global.quiet+4;
dir = heroninja_state.down;
}
}

else {
switch (dir)
{
case heroninja_state.up:
sprite_index = spr_heroninja_standup;
break;

case heroninja_state.down:
sprite_index = spr_heroninja_standdown;
break;

case heroninja_state.left:
sprite_index = spr_heroninja_standleft;
break;

case heroninja_state.right:
sprite_index = spr_heroninja_standright;
break;
}


}
 
Top