Bien tengo un codigo, i kiero que sea multijugador
Es decir, que se adapte con smart...
Alguien me aydua?
fscommand("allowscale", false);
fscommand("allowscale", false);
// our map is 2-dimensional array
myMap1 = [[1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1]];
// declare game object that holds info
game = {tileW:30, tileH:30};
// walkable tile
game.Tile0 = function () { };
game.Tile0.prototype.walkable = true;
game.Tile0.prototype.frame = 1;
// wall tile
game.Tile1 = function () { };
game.Tile1.prototype.walkable = false;
game.Tile1.prototype.frame = 2;
// declare char object, xtile and ytile are tile where chars center is
char = {xtile:2, ytile:1, speed:2, moving:false};
// building the world
function buildMap(map) {
// attach mouse cursor
_root.attachMovie("mouse", "mouse", 2);
// attach empty mc to hold all the tiles and char
_root.attachMovie("empty", "tiles", 1);
// declare clip in the game object
game.clip = _root.tiles;
// get map dimensions
var mapWidth = map[0].length;
var mapHeight = map.length;
// loop to place tiles on stage
for (var i = 0; i<mapHeight; ++i) {
for (var j = 0; j<mapWidth; ++j) {
// name of new tile
var name = "t_"+i+"_"+j;
// make new tile object in the game
game[name] = new game["Tile"+map[i][j]]();
// attach tile mc and place it
game.clip.attachMovie("tile", name, i*100+j*2);
game.clip[name]._x = (j*game.tileW);
game.clip[name]._y = (i*game.tileH);
// send tile mc to correct frame
game.clip[name].gotoAndStop(game[name].frame);
}
}
// add the character mc
game.clip.attachMovie("char", "char", 10000);
// declare clip in the game object
char.clip = game.clip.char;
// calculate starting position
char.x = (char.xtile*game.tileW)+game.tileW/2;
char.y = (char.ytile*game.tileW)+game.tileW/2;
// place char mc
char.clip._x = char.x;
char.clip._y = char.y;
char.clip.gotoAndStop(char.frame);
}
function moveChar(ob) {
// is char in the center of tile
if ((ob.x-game.tileW/2)%game.tileW == 0 and (ob.y-game.tileH/2)%game.tileH == 0) {
// calculate the tile where chars center is
ob.xtile = Math.floor(ob.x/game.tileW);
ob.ytile = Math.floor(ob.y/game.tileH);
// choose direction
// right
if (game["t_"+ob.ytile+"_"+(ob.xtile+1)].walkable and game.targetx>ob.xtile) {
ob.dirx = 1;
ob.diry = 0;
// left
} else if (game["t_"+ob.ytile+"_"+(ob.xtile-1)].walkable and game.targetx<ob.xtile) {
ob.dirx = -1;
ob.diry = 0;
// up
} else if (game["t_"+(ob.ytile+1)+"_"+ob.xtile].walkable and game.targety>ob.ytile) {
ob.dirx = 0;
ob.diry = 1;
// down
} else if (game["t_"+(ob.ytile-1)+"_"+ob.xtile].walkable and game.targety<ob.ytile) {
ob.dirx = 0;
ob.diry = -1;
// none
} else {
ob.moving = false;
return;
}
}
// move
ob.y += ob.speed*ob.diry;
ob.x += ob.speed*ob.dirx;
// update char position
ob.clip._x = ob.x;
ob.clip._y = ob.y;
// face the direction
ob.clip.gotoAndStop(ob.dirx+ob.diry*2+3);
}
function getTarget() {
// must click on walkable tile
if (game["t_"+game.ymouse+"_"+game.xmouse].walkable) {
// update target tile
game.targetx = game.xmouse;
game.targety = game.ymouse;
// get moving
char.moving = true;
}
}
function work() {
// find on which tile mouse is
game.xmouse = Math.round((_root._xmouse-game.tileW/2)/game.tileW);
game.ymouse = Math.round((_root._ymouse-game.tileH/2)/game.tileH);
// place mouse mc
_root.mouse._x = game.xmouse*game.tileW;
_root.mouse._y = game.ymouse*game.tileH;
var ob = char;
// move char
if (!ob.moving) {
// stop walk animation
ob.clip.char.gotoAndStop(1);
} else {
moveChar(ob);
// walk animation
ob.clip.char.play();
}
}
// make the map
buildMap(_root["myMap1"]);
stop();
Salu2