There are lots of different movements, the one sort that you use in plattform games, 3d games, top-down games, isometric games etc. This article describes a very simple walk-engine that is applicable to any top-down character. Mark gives this example in the Game Maker help-file:
{
if (keyboard_check(vk_left)) x -= 4;
if (keyboard_check(vk_right)) x += 4;
if (keyboard_check(vk_up)) y -= 4;
if (keyboard_check(vk_down)) y += 4;
}
It is fully functioning, although there are some things you might want to add:
{
if (keyboard_check(vk_left)) {
if (position_empty(x-4,y)) {
x -= 4;
sprite_index = character_left;
}
}
if (keyboard_check(vk_right)) {
if (position_empty(x+4,y)) {
x += 4;
sprite_index = character_right;
}
}
if (keyboard_check(vk_up)) {
if (position_empty(x,y-4)) {
y -= 4;
sprite_index = character_up;
}
}
if (keyboard_check(vk_down)) {
if (position_empty(x,y+4)) {
y += 4;
sprite_index = character_down;
}
}
}
Like what I added; collision checking and sprite change. Also IsmAvatar has written a very good script which I recommend, and you can get it as ismavatar.tk … It priorities the keys in the right order and only move in one direction at the time etc. this gives a better visual effect.
.
Users logged in:
Comments
Loading comments...