Game Engine
An RPG engine built using HTML, CSS and Javascript
Select a function to view it’s properties and usage.
- create_grid() - core function
- rotate_grid()
- move_player()
- get_tile_id()
- get_tile_position()
- detect_collision()
- find_items() - core trigger
- tile_event() - core trigger
- keypress() - core function
- add_to_bag() - deprecated
- add_to_bag_2()
- attack_player()
- heal_player()
- update_player()
- update_bag()
- use_item()
- message()
- teleport()
- background_music()
- pause_game()
- auto_move_player() - incomplete
create_grid() – core function
The create grid function is called at runtime to draw the grid, players and setup the initial game state.
create_grid(); // initialise the grid
rotate_grid()
The rotate_grid function allows you to rotate the grid by a factor of 90 degrees, or to get the current rotation setting. To use this call the function like so.
rotate_grid('left'); // rotates the grid left by 90 degrees
rotate_grid('right'); // rotate the grid right by 90 degrees
rotate_grid(); // get the current rotation
move_player()
This function handles the movement of the players avatar. You can move the player by left, right, up, down or directly to a tile_id using only the tile number.
move_player('up'); // moves the player up a space
move_player('down'); // moves the player down a space
move_player('left'); // moves the player left a space
move_player('right'); // moves the player right a space
move_player('36'); // move the player to #tile_36
get_tile_id()
This function allows you to get a tile_id from it’s x and y coordinates. Use as follows.
get_tile_id(x,y); // returns the tile_id
get_tile_id(0,32); // this would return tile-1
get_tile_position()
This function allows you to get a tiles x and y coordinated from it’s tile_id. Usage is as follows.
get_tile_position(tile_id); // returns x and y as an object
To use the returned values
var position = get_tile_position(tile_id); var pos_x = position.x; var pos_y = position.y;
detect_collision()
This function detects collision and tile events. Items, signs, teleports and solid tiles.
Returns true if a collision is detected on the file, or false if no collision is detected.
detect_collision(tile_id);
if (detect_collision('tile-32') == true) { // collision detected } else { // collision not detected }
This function adds items to the plays bag. You must provide all item information to be added.
add_to_bag(item_code,quantity,title,property,value,item_damage);
add_to_bag_2()
This function allows you to add items to a players bag. This function replaced the previous version to provide item details from a single array.
attack()
This function allows you to remove health from a player.
attack(30); // do 30 damage to the player
heal_player()
This function allows you to add health to a player.
heal_player(30); // add 30 health to the player
update_player()
This function updates the player information displayed with player variables.
update_player();
update_bag()
This function updates the players bag to ensure items listed match those that are available in the bag array.
update_bag();
use_item()
This function processes the use of an item. Provide the index of the item you want the player to use.
use_item(index);
use_item(1); // this would use item number 1
message()
This function displays a message using the message lightbox.
message('Hello World');
teleport()
Teleport the user directly to a tile_id.
teleport('tile-32');
background_music()
This function triggers the background music. Music is selected from the background_music_playlist array.
background_music();
pause_game()
This function pauses the game, displaying the menu and preventing game events from proceeding.
pause_game();
auto_move_player() - incomplete
This function moves the player automatically to a specified tile.
auto_move_player(tile_id);