Simon Donkers's Game Maker site siteSimon Donkers's Game Maker site
Version: GM 5+6 Views: 24311 Script, Game Maker 5 and 6 compatible
Filesize: 3020 byte Creative Commons License

Isometric grid based movement script

1/52/53/54/55/5 (15 votes)

An isometric grid based movement example. Handles collsions and everything


 Isometric grid based movement script
//////////////// Isometric grid based movement script ////////////////////
//
// Copyright Simon Donkers 27-1-2005
// www.simondonkers.com - gmmentor@simondonkers.com
//
// the arguments are:
// argument0 is horizontal grid
// argument1 is vertcal grid
// argument2 is speed (Use a speed for which both argument0 devided
// by this as argument1 devided by this will give an integer number!!!
//
// This script will generate a correct grid based movement for an isometric game
// make sure to use the built in grid with arguments0 and 1 and also make sure
// that the character is alligned at the begin
//
/////////////////////////////////////////////////////
if (argument0/argument2)mod(1)>0 then show_debug_message('Illigal speed used!');
if (argument1/argument2)mod(1)>0 then show_debug_message('Illigal speed used!');
if ((x)mod(argument0)=argument0/2 and (y)mod(argument1)=argument1/2) or ((x)mod(argument0)=0 and (y)mod(argument1)=0) then
{
        speed:=0;
        image_speed:=0.2;
        image_single:=0;
        if keyboard_check(vk_left) and place_free(x-argument0/2,y-argument1/2) then
        {
                hspeed:=-2*argument2;
                vspeed:=-1*argument2;
                sprite_index:=spr_nw;
                image_single:=-1;
        }
        if keyboard_check(vk_right) and place_free(x+argument0/2,y+argument1/2) then
        {
                hspeed:=+2*argument2;
                vspeed:=+1*argument2;
                sprite_index:=spr_se;
                image_single:=-1;
        }
        if keyboard_check(vk_up) and place_free(x+argument0/2,y-argument1/2) then
        {
                hspeed:=+2*argument2;
                vspeed:=-1*argument2;
                sprite_index:=spr_ne;
                image_single:=-1;
        }
        if keyboard_check(vk_down) and place_free(x-argument0/2,y+argument1/2) then
        {
                hspeed:=-2*argument2;
                vspeed:=+1*argument2;
                sprite_index:=spr_sw;
                image_single:=-1;
        }
}

Tip: Have a look at the tutorial How to execute a script

User comments

 PP Anonymous posted at 2005-06-02 01:44:32Quote
This doesn't have anything to do w/this script, I couldn't find anywhere else on your site for requests and stuff besides clicking on the script, tutorials and examples link.
You know those games where when you starta new game, let's say Golden Sun, and it asks for a name? Let's say you leave it as the default (Isaac). When you start the game [with the default name given to you] and chat w/a NPC that is somehow related to your char, that NPC would say something with your char's name on it, ex:"Hello, Isaac!". But if you choose your own name, i.e. chris, the NPC would say "Hello, Chris!", I wanna know how could you do that In GM6? I know you would probably store the string (name of char) into a variable, I just want to know how would you make it appear in messages.

SD: Hello PP,
There are many different methods in which one could do this. A few possibilities. At the start of the game use:
global.name:=get_string("What is your name?","Isaac");
So now we have the player name. You could say something like:
if string_length(global.name)<2 then global.name='Isaac');
to make sure people enter a useful name.
Now to show the messages a few possibilities.
show_message('Hello '+global.name);
will include the variable global.name after Hello and will show Hello Isaac or Hello PP.
An other method would be to make a script. Lets call it show_a_message. Now place within this script.
var message;
message:=string_replace(argument[0],'{name}',global.name);
message:=string_replace(message,'{score}',string(score));
message:=string_replace(message,'{lives}',string(lives));
show_message(message);
This means that it will change {name} everywhere with your name. It will also replace {score} everywhere with your score and it will change {lives} with your amount of lives.
You can now use:
show_a_message("Watch out {name}, that player has 15 lives and you only have {lives} so better avoid attacking him");
The last method takes a bit more difficulty to implement but does make it easier later on to make a message.

I believe I copied over the second method from an unreleased tutorial by Chronic.

Enjoy
 PP Anonymous posted at 2005-06-03 02:42:19Quote
Thank you thank you thank you thank you thank you!!! The start game thing 'global.name:=get_string("dah","Isaac:) is exaclty what I did except for 'what is your name?', creepy...
Thank you Thank you Thank you Thank you!!!
 norlick posted at 2006-04-09 11:07:36Quote
This script is small, versatile and highly customizable.

great job!

I was wondering if i may use a highly modified version of this script in a game.
 Simon Donkers posted at 2006-04-09 21:07:13Quote
There's a link called licence agreement on the bottom of this page. That will tell you everything you can and can't do with this resource.

Thanks for the compliment.
 norlick posted at 2006-04-16 16:43:06Quote
k thanks
you are real good at writing useful scripts.
not so much for use in games (though that would work well) but just real great to learn from.
 Nizbene posted at 2006-06-16 05:47:02Quote
excuse me... but i\'m kinda a beginner in GML, but i\'m a programmer in different languages. Where do i put this code in the game? Do i make a spriteless object and put the code there, then place it in the room? thanks a million. ^_^
 Simon Donkers posted at 2006-06-16 09:17:07Quote
Since the player is the one that should be moving this code needs to be placed in the step event of the player object.
 Nizbene posted at 2006-06-18 00:21:04Quote
thanks. another question, by the way. what if i want to move with my mouse? how can i select a character, then once selected, it will be the one to move isometricly thru the grid when i select the location with my mouse? thanks again! ^_^
 Nizbene posted at 2006-07-20 00:10:50Quote
uhm... hello?
 Simon Donkers posted at 2006-07-20 11:47:30Quote
http://gamemaker.simondonkers.com/index.php?mode=contact&section=question
 Uglyman/Juhkystar posted at 2008-04-27 00:19:14Quote
This works great for flat iso games, But something a bit more advanced is needed for height checking and the depth problems that go with it.
6/10
 Nusua posted at 2009-03-05 23:42:33Quote
Why are they called "arguments"??

Why doesn't GML refer to them as "factors"?

-VH
 Simon Donkers posted at 2009-03-07 15:45:56Quote
Nusua, I don't know a single programming language that does not refer to them as arguments although I'm sure there are some obscure languages that do.
Game Maker just uses the naming convention most common to the rest of the world.
 Zigmas posted at 2009-09-19 19:34:23Quote
Hi Simon, is it possible to download this as an example? I don't really know what to do with this script. Thanks.
 Zigmas posted at 2009-09-19 19:53:10Quote
Nevermind, I found out how to use it. It's perfect, thanks alot!!!
 Hellsoft posted at 2010-01-31 15:59:35Quote
Hi Sd!

Great work here! I too have search for long time how to choose my own name in my game project (an action game with some lite elements of rpg..),and only with your's help finally konw a working and flexible script!
Thanks, thanks and again thanks! Good game programming to all. Bye!
 MaxExpert94 posted at 2010-06-05 20:45:56Quote
Really cool!I've edited the code and it worked very well!Amazing! :D
 Noova posted at 2010-09-02 05:11:34Quote
Does this apply to RGSS/Ruby language as well?

Reply

Name:
Site: