Created
February 21, 2018 13:37
-
-
Save Shilo/c6f81e336eefabc72e7423109b5969a7 to your computer and use it in GitHub Desktop.
VyScript to implement open world warping. When colliding with the map edge, it will automatically warp to the next map. (Vylocity engine: http://vylocity.com/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define MAP_NAME_COORD_DELIMITER "_" | |
Mob/Player | |
onBump(pB) | |
if (pB == Map.void) | |
var warpMap = null | |
var warpX = this.xPos; | |
var warpY = this.yPos; | |
var warpMapCoords = this.get_outside_map_coords(this.mapName) | |
if (this.xPos == -this.xOrigin) //left | |
warpMapCoords.x -= 1; | |
warpMap = this.get_outside_map_name(warpMapCoords) | |
warpX = Map.getMapSize(warpMap).xPos-this.xOrigin-this.width | |
else if (this.yPos == -this.yOrigin) //up | |
warpMapCoords.y -= 1; | |
warpMap = this.get_outside_map_name(warpMapCoords) | |
warpY = Map.getMapSize(warpMap).yPos-this.yOrigin-this.height | |
else if (this.xPos == Map.getMapSize(this.mapName).xPos-this.xOrigin-this.width) //right | |
warpMapCoords.x += 1; | |
warpMap = this.get_outside_map_name(warpMapCoords) | |
warpX = -this.xOrigin | |
else //down | |
warpMapCoords.y += 1; | |
warpMap = this.get_outside_map_name(warpMapCoords) | |
warpY = -this.yOrigin | |
if (warpMap != null) | |
this.setPos(warpX, warpY, warpMap) | |
function get_outside_map_coords(mapName) | |
var pathComponents = mapName.split("/") | |
mapName = pathComponents[pathComponents.length-1] | |
var components = mapName.split(MAP_NAME_COORD_DELIMITER) | |
return {'x':Util.parseInt(components[0]), 'y':Util.parseInt(components[1])} | |
function get_outside_map_name(coords) | |
return this.get_outside_map_name_2(coords.x, coords.y) | |
function get_outside_map_name_2(x, y) | |
var mapName = x+MAP_NAME_COORD_DELIMITER+y | |
return Map.getMapSize(mapName).x>0 ? mapName : null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script assumes you have maps named with the following syntax: "X_Y"
Example of a world with 9 maps connected: