8 Directions

P

Phemus

Guest
I was using 4 directions movement and I want to change it ti 8 directions. I got 4 sprites for my player,

If character stop and looking to;
spr_player_lstop --> Looking left
spr_player_rstop --> Looking right

If character walks;
spr_player_wleft --> Walking to left
spr_player_wright --> Walking to right

Please tell me how can I do 8 directions movement with this sprites :)

NOTE: My game is like Minecraft 2D not rpg style game so there is no "Down".
 

Bingdom

Googledom
See if this works

STEP EVENT:
Code:
up = keyboard_check(ord('W'));
down = keyboard_check(ord('S'));
left = keyboard_check(ord('A'));
right = keyboard_check(ord('D'));

hspd = (right - left)*spd;
vspd = (down - up)*spd;

if hspd != 0 or vspd != 0 {
face = round(point_direction(0,0,hspd,vspd)/180);
if face == 2 face = 0;
switch (face) {
    case 0:
        //Right
        sprite_index = spr_player_wright;
        break;
    
    case 1:
        //Left
        sprite_index = spr_player_wleft;
        break;
}
} else {
    if sprite_index == spr_player_wright {
        sprite_index = spr_player_rstop;
    }
    if sprite_index == spr_player_wleft {
        sprite_index = spr_player_lstop;
    }
}
//Now move
x+=hspd;
y+=vspd+grav;
 
Last edited:
P

Phemus

Guest
I tried but there is problem with walk sprites. And how can I change player speed. By the way there is no gravity.
 

Bingdom

Googledom
I noticed a couple of mistakes in the code, hopefully it fixes your issue, i have made some changes too to meet your wants. I edited the original code
Variables now needed, put them in your create event
spd - for character speed
grav - for gravity,
 
Top