InstructionsEach NPC, Hero, Monster etc must have this creation code or else they will not be able to sync with this script.
if you changing the tile size to say 16, 8, or 5. You need to change the move speed to something lower, you may need to use something like.
move_speed = room_speed * 0.5;
motion_set(direction, tile_size_x/move_speed);
but for 32X32 or 16X16 just using move_speed= 4 or 2 are fine.
8X8 requires move_speed = 1. or you could just use motion_set method for easy movement.
Create EventCODE
//==================//
// Author: Rukiri
// 10/29/10
//==================//
// can this object move?
can_move = false;
//Movement speed
move_speed = 4;
// Animation Speed
ani_speed = 0.3;
// Tile Size
tile_size_x = 32;
tile_size_y = 32;
// Tile X/Y
tile_x = x/tile_size_x;
tile_y = y/tile_size_y;
// move
move_down = 1;
move_left = 2;
move_right = 3;
move_up = 4;
Do NOT make these variables global, these must be local variables. If you need to use say move_speed directly with the player object but through another event or script just use the with function.
Example:
CODE
with (obj_player) {
move_speed = 4; // change 4 to what you want
}
Step EventCODE
//step-event code
if can_move=true {
if (tile_x * tile_size_x > x) {
x += move_speed;
break;
} else if (tile_x * tile_size_x < x) {
x -= move_speed;
break;
}
if (tile_y * tile_size_y > y) {
y += move_speed;
break;
} else if (tile_y * tile_size_y < y) {
y -= move_speed;
break;
}
}
// stop event at the right tile.
if keyboard_check(vk_nokey) {
if (tile_x * tile_size_x = x) { can_move = false; }
if (tile_y * tile_size_y = y) { can_move = false; }
}
else { can_move = true; }
Keyboard Script The keyboard script used global variables as you're going to be using it with multiple objects, and it's for the hero and your allies only. Say you wanted to switch to an ally while in combat(got bored with your main hero)
CODE
globalvar kb_enter, kb_select, kb_up, kb_down, kb_left, kb_right, kb_nokey; // place all your keyboard keys in this line.
kb_enter = keyboard_check(vk_enter); // Enter Key
kb_select = keyboard_check(vk_space); // Select Key
kb_up = keyboard_check(vk_up); // Up Key
kb_down = keyboard_check(vk_down); // Down Key
kb_left = keyboard_check(vk_left); // Left Key
kb_right = keyboard_check(vk_right); // Right Key
kb_nokey = keyboard_check(vk_nokey); // No key
scr_move_stepCODE
// 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 = argument0n) { 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; }
// usage
// scr_move_step(argument0,argument1)
// argument 0 is for direction
// argument 1 is for how many tile should the object move
DemoWill be released soon!