estoy en la encrucijada de aprender a programar juegos en flash jeje.....y la vdd no se me ocurre mejores personas que ustedes para ayudarme, la cosa esta asi:
ya logre dibujar el mapa y hacer una array para ello, ya coloque al heroe en la posicion correcta, lo que no he podido es mover al heroe a traves del mapa, por cierto que el mapa esta formado por hexagonos, osea que tenemos 6 direcciones de movimiento, aqui les paso el codigo que toy armando......en si lo que no se muy bien es como establecer las direcciones y que flash me detecte dos teclas (direcciones en diagonal) pa mover al heroe.
Código :
game = {tileHeight:20};
game.cos30 = Math.cos(30*Math.PI/180);
game.tileSize = game.tileHeight/(game.cos30/2);
function buildMap(map) {
_root.attachMovie("empty", "tiles", 1);
game.clip = _root.tiles;
game.clip._x = game.tileSize;
game.clip._y = game.tileHeight/2;
for (var y = 0; y<8; ++y) {
for (var x = 0; x<6; ++x) {
var name = "t_"+x+"_"+y;
game.clip.attachMovie("tile", name, y*100+x*2);
game.clip[name]._x = x*game.tileHeight*1.7;
game.clip[name]._y = y*game.tileHeight+x%2*game.tileHeight/2;
}
}
}
function getMouse() {
var x = Math.round(game.clip._xmouse/game.tileHeight/1.7);
var y = Math.round((game.clip._ymouse-(x%2)*game.tileHeight/2)/game.tileHeight);
_root.xtile = "X: "+x;
_root.ytile = "Y: "+y;
}
buildMap();
myMap = [[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]];
game.Tile0 = function () { };
game.Tile0.prototype.walkable = true;
game.Tile0.prototype.frame = 1;
game.Tile1 = function () { };
game.Tile1.prototype.walkable = false;
game.Tile1.prototype.frame = 2;
char = {xtile:-0.5, ytile:-1, speed:2};
game.clip.attachMovie("char", "char", 10000);
char.clip = game.clip.char;
char.x = (char.xtile*game.tileSize)+game.tileSize/2;
char.y = (char.ytile*game.tileHeight)+game.tileHeight/1.7;
char.width = char.clip._width/2;
char.height = char.clip._height/2;
char.clip._x = char.x;
char.clip._y = char.y;
function moveChar(ob, dirne, dirse, diry) {
ob.noreste += dirne*ob.speed;
ob.sureste += dirse*ob.speed;
ob.y += diry*ob.speed;
ob.clip.gotoAndStop(dirx+diry*2+3);
ob.clip._x = ob.x;
ob.clip._y = ob.y;
return (true);
}
function detectKeys() {
var ob = _root.char;
var keyPressed = false;
if (Key.isDown(Key.RIGHT)) {
if (Key.isDown(Key.UP))
keyPressed = _root.moveChar(ob, 1, 0, 1);
} else if (Key.isDown(Key.LEFT)) {
if (Key.isDown(Key.UP))
keyPressed = _root.moveChar(ob, 0, -1, 1);
if (Key.isDown(Key.RIGHT)) {
if (Key.isDown(Key.DOWN))
keyPressed = _root.moveChar(ob, 0, 1, 1);
} else if (Key.isDown(Key.LEFT)) {
if (Key.isDown(Key.DOWN))
keyPressed = _root.moveChar(ob, -1, 0, 1);
} else if (Key.isDown(Key.UP)) {
keyPressed = _root.moveChar(ob, 0, 0, 1);
} else if (Key.isDown(Key.DOWN)) {
keyPressed = _root.moveChar(ob, 0, 0, -1);
}
}
}
stop();bien xic@ asias por su ayuda
Un Saludote
