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: [GM8]Tile-Movement: Read the topic  (Read 1369 times)

0 Members and 1 Guest are viewing this topic.
[GM8]Tile-Movement: Read the topic
« on: October 29, 2010, 03:08:51 pm »
  • The king of Awesome
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 198
This script is to replicate RPG Makers set-move-route, it does it perfectly, the only problem is.. it won't do diagonals, yes you would need to remove the "exit" command but than you got timing issues.
Hopefully someone can help

================================================================================================
Here's my diagonal moving code, and my RPG Maker like Move_step script.
Code: [Select]
// move diagonally
   if dir_8=true
   {
    if keyboard_check(vk_down) && keyboard_check(vk_left)
    {
       motion_set(point_direction(0, 0, -tile_x, tile_y), point_distance(0, 0, tile_x, tile_y) / movesteps);
    }
    if keyboard_check(vk_down) && keyboard_check(vk_right)
    {
       motion_set(point_direction(0, 0, tile_x, tile_y), point_distance(0, 0, tile_x, tile_y) / movesteps);
    }
    if keyboard_check(vk_up) && keyboard_check(vk_left)
    {
       motion_set(point_direction(0, 0, -tile_x, -tile_y), point_distance(0, 0, tile_x, tile_y) / movesteps);
    }
    if keyboard_check(vk_up) && keyboard_check(vk_right)
    {
       motion_set(point_direction(0, 0, tile_x, -tile_y), point_distance(0, 0, tile_x, tile_y) / movesteps);
    }
    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 dir_8=false
   {
    // 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); }
  
   }

RM like move_step.

Create event, should be in every object you make.
Code: [Select]
   move_speed = 4;
    tile_size_x = 32;
    tile_size_y = 32;
    tile_x = x / tile_size_x;
    tile_y = y / tile_size_y;
Step event, just place in before or after step.
Code: [Select]
if (tile_x * tile_size_x > x) { x += move_speed; exit; }
    else if (tile_x * tile_size_x < x) { x -= move_speed; exit; }
    else if (tile_y * tile_size_y > y) { y += move_speed; exit; }
    else if (tile_y * tile_size_y < y) { y -= move_speed; exit; }
Actual scrip:
Code: [Select]
// Moves the character based on tile position in direction argument0
{
    // This set of conditionals is strictly for Movement!
   /*
    move_up = 1
        move_down = 2
        move_left = 3
        move_right = 4
   */
    // example, scr_move_step(1,5) will move up 5 tiles.
    if (move_up = argument0) { if (!place_meeting(tile_x *tile_size_x, (tile_y - 1) * tile_size_y, obj_wall)) tile_y -= argument1; }
    else if (move_down = argument0) { if (!place_meeting(tile_x * 32, (tile_y + 1) * tile_size_y, obj_wall)) tile_y += argument1; }
    else if (move_left = argument0) { if (!place_meeting((tile_x - 1) * tile_size_x, tile_y * tile_size_y, obj_wall)) tile_x -= argument1; }
    else if (move_right = argument0) { if (!place_meeting((tile_x + 1) * tile_size_x, tile_y * 32, obj_wall)) tile_x += argument1; }
}

Basically once you can move in all 8 directions with this script, it's pretty easy to just use it for movement(and save a ton of time)

the script works like this.
scr_move_step(1,1);
First argument is direction, the second argument is how many tiles are you going to move. For actual players you're only going to use 1 as you're going to be using keyboard checks, but for cut scenes you won't have to. But you're going to have time issues with out exit.  hopefully someone can help as this could be a really useful script.

Thanks!

Here's a demo if it helps.
http://rapidshare.com/files/427798936/RPG_Maker_VX_Engine.gmk

Really need this for my engine, literally.. almost have everything done(you're only going to find movement here) don't both with obj_player and just worry about the contents of object6.

This script if someone can actually get 8-dir working on this without either moving exit or making it so tile_x or tile_y doesn't add rapidly when holding down the key, it should only add when it's on a new tile. Or stop on the current or next tile.
For 4-way this is done as is, I just can't get 8-dir working.  And I don't want to go back to really long(100+) for just getting directions, movement etc. This makes everything simpler and I don't have to code just use the script.
« Last Edit: October 29, 2010, 03:23:31 pm by Shiku »
Logged
Re: [GM8]Tile-Movement: Read the topic
« Reply #1 on: October 29, 2010, 07:21:22 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
I have a bit of a problem discerning what you really want. Do you want an 8 way movement engine that will keep Link alligned to a grid? If yes than why give up a direction of more than 1 tile. The user will probably have to hold the direction key to traverse multiple tiles.

Or do you want a movement engine where you give up a destination and Link will follow the shortest path (including diagonal movement) to that destination.

I could help but I don't know how RPG Maker works.
Logged
Re: [GM8]Tile-Movement: Read the topic
« Reply #2 on: October 29, 2010, 09:11:06 pm »
  • The king of Awesome
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 198
You have to give a destination, direction,tiles to move.

here's how the script words without programming mumbo jumbo.

script(direction, tiles_to_move)
1 = down
2 = left
3 = right
4 = up
,
1 // this moves the player 1 tile
if you set it to something like this

scr_move_step(1,1); scr_move_step(3,1);

This will move the character in a diagonal direction.

in RPG Maker you would use set_move_rout and just use move_up/down/left/or right.  you can also use move_lower_left/or right and move_upper_left or right.

I hope this helpes.

I'm curious though, would having the (tile_x*tile_size_x>x) { x+=move_speed; } actually work better WITH a keyboard check?  I'm really trying to make this as simple as possible and actually use it instead of the default movement script in the zelda mc engine(it's perfect except for diagonal movements)
« Last Edit: October 29, 2010, 11:58:56 pm by Shiku »
Logged
Re: [GM8]Tile-Movement: Read the topic
« Reply #3 on: October 30, 2010, 09:51:33 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
You do a keyboard check only once at the beginning of where you first need the information. After that any more calls to keyboard_check with any of the direction keys is useless overhead. It is better to store them in variables. Second tilesize is not something to add as a member variable to each object. When you change it you have to change it for every object. Add those things either as a global variable or a constant.

Now for movestep. I assume that move_step is to validate whether the movement is allowed and set the x and y displacement for each step until the target is reached. Otherwise the target is not really usefull to provide. I also think that direction is not something to provide in a single variable.

scr_move_step( hor, ver, tiles)
hor - Horizontal displacement along the x axis. (-1: left, 0: no, 1: right)
ver - Vertical displacement along the y axis. (-1: up, 0: no, 1: down)
tiles - The number of tiles removed in either horizontal and vertical direction.

Code: Text
  1. allow = true
  2.  
  3. //First check whether it is diagonal or isothetic movement.
  4. if  hor != 0  and  ver != 0
  5. // Diagonal
  6.  
  7.     loop for each target tile to destination "tiles" (using i)
  8.         target = x + hor * i * TILESIZE, y + ver * i * TILESIZE
  9.  
  10.         if the target is not in the room
  11.         or
  12.         if the target is blocked
  13.         or
  14.         if one of the two crossing tiles to the target is blocked
  15.         (cross1 = target.x - hor * TILESIZE, target.y      cross2 = target.x, target.y - ver * TILESIZE)
  16.             set allow to false and break the loop.
  17.  
  18.     end loop.
  19.  
  20. else if   hor != 0  or ver != 0
  21. // isothetic
  22.  
  23.     loop for each target tile to destination "tiles" (using i)
  24.         target = x + hor * i * TILESIZE, y + ver * i * TILESIZE
  25.  
  26.         if the target is not in the room
  27.         or
  28.         if the target is blocked
  29.             set allow to false and break the loop.
  30.  
  31.     end loop.
  32.  
  33. else
  34. //No movement
  35.  
  36.     Set allow to false.
  37.  
  38. end if
  39.  
  40. //now set movement for each step
  41. if  allow
  42.  
  43.      //Set x displacement
  44.      if  ver != 0
  45.         Set move_x (the speed) to hor * speed * 0.7071067811865
  46.      else
  47.         Set move_x (the speed) to hor * speed
  48.      end if
  49.  
  50.      //Set y displacement
  51.      if  hor != 0
  52.         Set move_y (the speed) to ver * speed * 0.7071067811865
  53.      else
  54.         Set move_y (the speed) to ver * speed
  55.      end if
  56.  
  57.      //Set target destination
  58.      Set dest_x to hor * TILESIZE * tiles
  59.      Set dest_y to ver * TILESIZE * tiles
  60.  
  61. else
  62.  
  63.      Set move_x (the speed) to 0
  64.      Set move_y (the speed) to 0
  65.      Set dest_x to x
  66.      Set dest_y to y
  67.  
  68. end if
  69.  
  70.  
  71. return allow
  72.  

Now the assumption I made was that the user input had already been determined and the actual movement is done in the step event of the object. A step event of an object might look like this

Code: Text
  1. if able_input
  2. //user input
  3.  
  4.     left is set to the keyboard left check
  5.     right is set to the keyboard right check
  6.     up is set to the keyboard up check
  7.     down is set to the keyboard down check
  8.    
  9.     hor is set to right - left
  10.     ver is set to down - up
  11.  
  12.     moving = scr_move_step( hor, ver, 1)
  13.  
  14.     if  moving
  15.        Set able_input to false
  16.     end if
  17.  
  18. else if  not moving  and  cutscene override
  19. // the object is not moving and in cutscene override
  20.  
  21.     moving is set to what the cutscene desires at the moment
  22.    
  23. end if
  24.  
  25. Set x to x + ( the minimum displacement between 1) move_x and 2) dest_x - x )
  26. Set y to y + ( the minimum displacement between 1) move_y and 2) dest_y - y )
  27.  
  28. if  x == dest_x  and  y == dest_y
  29.  
  30.        if  not cutscene override
  31.           Set input_able to true
  32.        else
  33.           Skip to the next cutscene part
  34.        end if
  35.  
  36. end if
  37.  
  38.  
« Last Edit: October 30, 2010, 10:58:20 am by Niek »
Logged
Re: [GM8]Tile-Movement: Read the topic
« Reply #4 on: October 30, 2010, 05:50:43 pm »
  • The king of Awesome
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 198
Thank you, problem has been resolved.
Logged
Pages: [1]   Go Up

 


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



Page created in 0.185 seconds with 44 queries.

anything