Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [Request] Diagonal Grid movement  (Read 1210 times)

0 Members and 1 Guest are viewing this topic.
[Request] Diagonal Grid movement
« on: May 28, 2010, 09:51:55 am »
  • The king of Awesome
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 198
This is a pretty common problem from what I'm reading, it's generally easy creating 8-dir movement without the grid but I'm creating an engine that requires the player and npcs to be on it but still able to move diagonally.

To really keep this short and simple here's the code.

Create Event:
Code: [Select]
// RPG Maker VX Movement setup

tile_x = 32;
tile_y = 32;
dir = "d";
movespeed = 4;
tile_solid = false;
moving = 0;
image_speed = 0.3;
place_snapped(tile_x,tile_y);

Step Event:
Code: [Select]
if place_snapped(tile_x,tile_y)
{
   // get the direction
   if keyboard_check(vk_down) { dir="d"; }
   else if keyboard_check(vk_left) { dir="l"; }
   else if keyboard_check(vk_right) { dir="r"; }
   else if keyboard_check(vk_up) { dir="u"; }
   
   // move/stop the character
   if keyboard_check(vk_down) { moving=1; motion_set(270,movespeed); }
   if keyboard_check(vk_left) { moving=1;  motion_set(180,movespeed); }
   if keyboard_check(vk_right) { moving=1;  motion_set(0,movespeed); }
   if keyboard_check(vk_up) { moving=1;  motion_set(90,movespeed); }
   if keyboard_check(vk_nokey) { moving=0; motion_set(0,0); }   
   
   // stop ilregular movement ( if diagonal movement is needed this is the area to add it )
   if keyboard_check(vk_down) && keyboard_check(vk_up) { moving=0; motion_set(0,0); }
   if keyboard_check(vk_left) && keyboard_check(vk_right) { moving=0; motion_set(0,0); }
   if keyboard_check(vk_left) && keyboard_check(vk_down) { moving=0; motion_set(0,0); }
   if keyboard_check(vk_left) && keyboard_check(vk_up) { moving=0; motion_set(0,0); }
   if keyboard_check(vk_right) && keyboard_check(vk_down) { moving=0; motion_set(0,0); }
   if keyboard_check(vk_right) && keyboard_check(vk_up) { moving=0; motion_set(0,0); }
   
   // check for collisions
   // control the sprites. Since VX uses 2 walk frames (walk,stand,walk) it's easier to just switch back and forth
   if moving = 1
   {
     if dir="d"
     {
       sprite_index = spr_player_d;
     }
     else if dir = "l"
     {
       sprite_index = spr_player_l;
     }
     else if dir = "r"
     {
       sprite_index = spr_player_r;
     }
     else if dir = "u"
     {
       sprite_index = spr_player_u;
     }
   }
   else { image_index = 1; }
}
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.107 seconds with 39 queries.