var North = COMMAND_MOVE_NORTH; var South = COMMAND_MOVE_SOUTH; var West = COMMAND_MOVE_WEST; var East = COMMAND_MOVE_EAST; var Wait = COMMAND_WAIT; var Face_north = COMMAND_FACE_NORTH; var Face_south = COMMAND_FACE_SOUTH; var Face_east = COMMAND_FACE_EAST; var Face_west = COMMAND_FACE_WEST; var LastTileX = 0; var LastTileY = 0; var NowTileX = 0; var NowTileY = 0; var Fix_Warp = false; //=========================\\ //-------OBSTRUCTIONS--------\\ //=============================\\ // This is used to check if a given person can move // towards a given direction. function IsObstructed(name, command) { var H = 0, W = 0; var X = GetPersonX(name); var Y = GetPersonY(name); switch(command) { case COMMAND_MOVE_NORTH: H = -1; break; case COMMAND_MOVE_SOUTH: H = 1; break; case COMMAND_MOVE_EAST: W = 1; break; case COMMAND_MOVE_WEST: W = -1; break; default: return false; break; } if (IsPersonObstructed(name, X+W, Y+H)) return true; if (IsPersonObstructed(name, X+(W>>1), Y+(H>>1))) return true; return false; // just in case } //==========================\\ //-----Tile-Placement--------\\ //============================\\ function Txy(name, x, y) {SetPersonX(name, (x*16) + 7); SetPersonY(name, (y*16) + 7);} function Pxy(name, x, y) {SetPersonX(name, x); SetPersonY(name, y);} //==========================\\ //-------MOVEMENT------------\\ //============================\\ function Move(Name, Tiles, Direction, Face) { if (Direction == North) {QueuePersonCommand(Name, Face_north, false);} //Makes sprite face its proper direction. if (Direction == South) {QueuePersonCommand(Name, Face_south, false);} if (Direction == East) {QueuePersonCommand(Name, Face_east, false);} if (Direction == West) {QueuePersonCommand(Name, Face_west, false);} if (Direction != Wait) {QueuePersonCommand(Name, Face, false);} //If Direction commands sprite to Wait. It simply faces for (var j = 0; j < Tiles; ++j) //For as long as "j" is less than Tiles, +1 is added to variable "j." { //The "j" variable will get us to reach our Tile Number. Once Tiles starts to become than "j" we no longer move. for (var i = 0; i < 16; ++i) //For as long as "i" is less than 16 (tile width and height), "i" gets a +1. { //This measure how big each tile is, so that when you define variable "Tiles" it's accurate. QueuePersonCommand(Name, Direction, false); //For as long as "i" remains in loop, the sprite keeps walking in specified direction. } SetPersonFrame(Name, 0); //When Tile for-loop is finished, we reset the sprite's frame of currection direction to "0" } //Now we set the sprite's facing direction. if (Face == undefined) //Checks Face for undefined. { //If undefined, sprite faces towards the direction it's commanded to go in. if (Direction == North) {Face = North;} if (Direction == South) {Face = South;} if (Direction == East) {Face = East;} if (Direction == West) {Face = West;} } if (Face == North) {QueuePersonCommand(Name, Face_north, false);} //Makes sprite face its proper direction. if (Face == South) {QueuePersonCommand(Name, Face_south, false);} if (Face == East) {QueuePersonCommand(Name, Face_east, false);} if (Face == West) {QueuePersonCommand(Name, Face_west, false);} } //End of Move Function. //=========================\\ //------TILE-MOVEMENT--------\\ //=============================\\ function Movement() { var Player = GetInputPerson(); if (!IsCommandQueueEmpty(Player)) return; var Direction = null; if (IsKeyPressed(KEY_UP)) { if (IsPersonObstructed(Player, GetPersonX(Player), GetPersonY(Player)-16) == false) Counter++; Direction = COMMAND_MOVE_NORTH; QueuePersonCommand(Player, COMMAND_FACE_NORTH, true); LastTileY = GetPersonY(Player); NowTileY = GetPersonY(Player) - 16; } if (IsKeyPressed(KEY_DOWN)) { if (IsPersonObstructed(Player, GetPersonX(Player), GetPersonY(Player)+16) == false) Counter++; Direction = COMMAND_MOVE_SOUTH; QueuePersonCommand(Player, COMMAND_FACE_SOUTH, true); LastTileY = GetPersonY(Player); NowTileY = GetPersonY(Player) + 16; } if (IsKeyPressed(KEY_RIGHT)) { if (IsPersonObstructed(Player, GetPersonX(Player)+16, GetPersonY(Player)) == false) Counter++; Direction = COMMAND_MOVE_EAST; QueuePersonCommand(Player, COMMAND_FACE_EAST, true); LastTileX = GetPersonX(Player); NowTileX = GetPersonX(Player) + 16; } if (IsKeyPressed(KEY_LEFT)) { if (IsPersonObstructed(Player, GetPersonX(Player)-16, GetPersonY(Player)) == false) Counter++; Direction = COMMAND_MOVE_WEST; QueuePersonCommand(Player, COMMAND_FACE_WEST, true); LastTileX = GetPersonX(Player); NowTileX = GetPersonX(Player) - 16; } if (Direction != null && !IsObstructed(Player, Direction)) { for (var i = 0; i < 16; ++i) { QueuePersonCommand(Player, Direction, false); } } } //=========================\\ //---------TILE-CHECK--------\\ //=============================\\ // To get the tile in front of the player. function GetTileInFront() { var direction = GetPersonDirection(GetInputPerson()); var px = GetPersonX(GetInputPerson()), py = GetPersonY(GetInputPerson()); if (direction == "north") return GetTile(px/16,py/16-1,0); if (direction == "south") return GetTile(px/16,py/16+1,0); if (direction == "west") return GetTile(px/16-1,py/16,0); if (direction == "east") return GetTile(px/16+1,py/16,0); } // The jumping function: function TileChecker() { var Player = GetInputPerson(); var px = GetPersonX(GetInputPerson()), py = GetPersonY(GetInputPerson()); var direction = GetPersonDirection(GetInputPerson()); var Ntile = GetTileInFront(); //var tile = GetTile(px, py, 0); //------------------------------------------------------|| //Next Tile Obstructions //For NorthWest if (GetTileName(Ntile) == "obstruct_nw" && direction == "south") { SetPersonFrame(GetInputPerson(),1); UpdateMapEngine(); } if (GetTileName(Ntile) == "obstruct_nw" && direction == "south") { SetPersonFrame(GetInputPerson(),1); UpdateMapEngine(); } //For NorthEast if (GetTileName(Ntile) == "obstruct_ne" && direction == "south") { SetPersonFrame(GetInputPerson(),1); UpdateMapEngine(); } if (GetTileName(Ntile) == "obstruct_nw" && direction == "south") { SetPersonFrame(GetInputPerson(),1); UpdateMapEngine(); } //For North if (GetTileName(Ntile) == "obstruct_n" && direction == "south") { QueuePersonCommand(Player, COMMAND_WAIT, true); QueuePersonCommand(Player, COMMAND_FACE_SOUTH, true); SetPersonFrame(GetInputPerson(),0); UpdateMapEngine(); } //For West if (GetTileName(Ntile) == "obstruct_w" && direction == "south") { SetPersonFrame(GetInputPerson(),1); UpdateMapEngine(); } //For East if (GetTileName(Ntile) == "obstruct_e" && direction == "south") { SetPersonFrame(GetInputPerson(),1); UpdateMapEngine(); } /* //----------------------------------------------------------------|| //Present Tile Obstructions //For NorthWest if (GetTileName(tile) == "obstruct_nw" && direction == "south") { SetPersonFrame(GetInputPerson(),1); UpdateMapEngine(); } if (GetTileName(tile) == "obstruct_nw" && direction == "south") { SetPersonFrame(GetInputPerson(),1); UpdateMapEngine(); } //For NorthEast if (GetTileName(tile) == "obstruct_ne" && direction == "south") { SetPersonFrame(GetInputPerson(),1); UpdateMapEngine(); } if (GetTileName(tile) == "obstruct_nw" && direction == "south") { SetPersonFrame(GetInputPerson(),1); UpdateMapEngine(); } //For North if (GetTileName(tile) == "obstruct_n" && direction == "south") { SetPersonFrame(GetInputPerson(),1); UpdateMapEngine(); } //For West if (GetTileName(tile) == "obstruct_w" && direction == "south") { SetPersonFrame(GetInputPerson(),1); UpdateMapEngine(); } //For East if (GetTileName(tile) == "obstruct_e" && direction == "south") { SetPersonFrame(GetInputPerson(),1); UpdateMapEngine(); } */ }