Logo

¡Bienvenido a Stratos!

Acceder

Foros





Menu

Mostrar Mensajes

Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menu

Mensajes - fmadrid

#1
Flash/Flex / Re: Ayuda con movimientos con el raton
04 de Enero de 2009, 04:30:11 PM
ok ya lo e revisado y para lo que quiero hacer va perfecto  ;)

ahora... toca marear la perdiz.

Se trata de hacer un mapa mas grande... digamos que 2 ó 3 veces la pantalla de un ordenador (vamos a darle unos 2000px X 1600px) y un enfoque de 550px X 400px(lo que se ve) por ejemplo. Y ahora tendriamos que conseguir que el jugador se mantuviera en el centro de la pantalla. Esto creo que se puede hacer moviendo lo que es el terreno y no el jugador... pero no lo se con seguridad. Alguien me podria decir como hacerlo?? ??? ???

saludos!
#2
Flash/Flex / Re: Ayuda con movimientos con el raton
04 de Enero de 2009, 10:13:05 AM
esta bastane bien ;)

mi intecion principal no era usar tiles, eso solo fue porque lo vi en un tutorial  :P

bueno  voy a seguir practicando con el njuevo codigo y ya te cuento como va.

saludos!
#3
Flash/Flex / Re: Ayuda con movimientos con el raton
03 de Enero de 2009, 10:54:28 AM
aaah :'( :'( :'( ya encontre el problema... y esque el jugador no rota  :-\ ...

dime, como lo puedo hacer?? lo he intenta insertando para de mi codigo pero no consigo nada...  :grrr:

:S si lo consigues me lo dices .

Saluds!!
#4
Flash/Flex / Re: Ayuda con movimientos con el raton
03 de Enero de 2009, 09:28:56 AM
 :o :o

Tio se acercca completamente a lo que buscaba  :D

El movimiento (aunque con algun fallillo) se ejecuta correctamente.

Gracias!! aunque ayer buscando yo tb encontre esto: http://www.flashkit.com/tutorials/Games/Detectin-Flash_Ju-79/index.php

En esa te enseña a detectar donde se situa el raton, y apartir de ahi tb se podria crear el movimiento.

Bueno con eso es suficiente, graicas por la ayuda.

Saludos!
#5
Flash/Flex / Re: Ayuda con movimientos con el raton
02 de Enero de 2009, 05:20:03 PM
OK!

Lo que quiero hacer es que el jugador se pueda mover en un mapa bidimensional solamente utilizando el raton. Y como explique antes, donde pinche el raton, hacia alli se debe dirigir el jugador.

Por ahora simplemente es eso, ya que posteriormente la camara debera seguir al jugador (no se si me e explicado bien en esto), añadiremos enemigos, objetos y miscelaneos.

Pero para seguir un orden, primero hay que conseguir la instancia y el correcto movimiento del jugador.

Aqui os aclaro el codigo:

Este es el codigo completo haciendo que el jugador rote con izquierda y derecha, y se mueva con arriba y abajo usando las flechas.

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, currentMap:1};
//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;
//non-existing tile
game.Tile4 = function () { };
game.Tile4.prototype.walkable = false;
game.Tile4.prototype.frame = 20;
//declare char object, xtile and ytile are tile where chars center is
char = {xtile:1, ytile:1, speed:4};
//building the world
function buildMap(map) {
//attach empty mc to hold all the tiles and char
_root.attachMovie("empty", "tiles", 1);
//get map dimensions
var mapWidth = map[0].length;
var mapHeight = map.length;
//declare clip in the game object
game.clip = _root.tiles;
//loop to place tiles on stage
for (var y = 0; y<mapHeight; ++y) {
for (var x = 0; x<mapWidth; ++x) {
//name of new tile
var name = "t_"+y+"_"+x;
//make new tile object in the game
game[name] = new game["Tile"+map[y][x]]();
//attach tile mc and place it
game.clip.attachMovie("tile", name, 1+y*100+x*2);
game.clip[name]._x = (x*game.tileW);
game.clip[name]._y = (y*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.tileH/2;
//add char dimensions to char object, half of clips width and height
char.width = char.clip._width/2;
char.height = char.clip._height/2;
//place char mc
char.clip._x = char.x;
char.clip._y = char.y;
}
function getMyCorners(x, y, ob) {
//find corner points
ob.downY = Math.floor((y+ob.height-1)/game.tileH);
ob.upY = Math.floor((y-ob.height)/game.tileH);
ob.leftX = Math.floor((x-ob.width)/game.tileW);
ob.rightX = Math.floor((x+ob.width-1)/game.tileW);
//check if they are walls
ob.upleft = game["t_"+ob.upY+"_"+ob.leftX].walkable;
ob.downleft = game["t_"+ob.downY+"_"+ob.leftX].walkable;
ob.upright = game["t_"+ob.upY+"_"+ob.rightX].walkable;
ob.downright = game["t_"+ob.downY+"_"+ob.rightX].walkable;
}
function moveChar(ob, dirx, diry) {
//vertical movement
//where are our edges?
//first we look for y movement, so x is old
getMyCorners(ob.x, ob.y+diry, ob);
//move got dammit... and check for collisions.
//going up
if (diry<-0.5) {
if (ob.upleft and ob.upright) {
//no wall in the way, move on
ob.y += diry;
} else {
//hit the wall, place char near the wall
ob.y = ob.ytile*game.tileH+ob.height;
}
}
//if going down
if (diry>0.5) {
if (ob.downleft and ob.downright) {
ob.y += diry;
} else {
ob.y = (ob.ytile+1)*game.tileH-ob.height;
}
}
//horisontal movement
//changing x with speed and taking old y
getMyCorners(ob.x+dirx, ob.y, ob);
//if going left
if (dirx<-0.5) {
if (ob.downleft and ob.upleft) {
ob.x += dirx;
} else {
ob.x = ob.xtile*game.tileW+ob.width;
}
}
//if going right
if (dirx>0.5) {
if (ob.upright and ob.downright) {
ob.x += dirx;
} else {
ob.x = (ob.xtile+1)*game.tileW-ob.width;
}
}
//update char position
ob.clip._x = ob.x;
ob.clip._y = ob.y;
//calculate the tile where chars center is
ob.xtile = Math.floor(ob.x/game.tileW);
ob.ytile = Math.floor(ob.y/game.tileH);
return (true);
}
function detectKeys() {
var ob = _root.char;
var keyPressed = false;
if (Key.isDown(Key.RIGHT)) {
ob.clip._rotation += 5;
} else if (Key.isDown(Key.LEFT)) {
ob.clip._rotation -= 5;
}
if (Key.isDown(Key.UP)) {
ob.speedx = ob.speed*Math.cos((ob.clip._rotation)*Math.PI/180);
ob.speedy = ob.speed*Math.sin((ob.clip._rotation)*Math.PI/180);
keyPressed = _root.moveChar(ob, ob.speedx, ob.speedy);
} else if (Key.isDown(Key.DOWN)) {
ob.speedx = -ob.speed*Math.cos((ob.clip._rotation)*Math.PI/180);
ob.speedy = -ob.speed*Math.sin((ob.clip._rotation)*Math.PI/180);
keyPressed = _root.moveChar(ob, ob.speedx, ob.speedy);
}
//walk animation
if (!keyPressed) {
ob.clip.char.gotoAndStop(1);
} else {
ob.clip.char.play();
}
}
//make the map
buildMap(_root["myMap"+game.currentMap]);
stop();


y en este otro es el movimiento con el raton en forma de L.

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();


En ambos casos estoy usando un mapa echo con baldosas.

Cualquier cosa decidme, yo voy a seguir intentar hacer lo que has mencionado   :)


Gracias por la ayuda y cualquier duda sobre el codigo os lo explico detalladamente

Saludos!
#6
Flash/Flex / Re: Ayuda con movimientos con el raton
02 de Enero de 2009, 12:02:28 AM
sip , conseguí hacerlo pero usando las flechas del ordenador pero a la hora de sustituir por el raton no funciona, y no encuentro el problema...

debe ser lo que mencionas de la posicion final, pero no  sabria como implementarlo y como colocarlo en el codigo final (debido a que en los manuales no se habla demasiado sobre el uso del raton de esta manera)

si quieres posteo el codigo fuente k llevo y lo examinamos mejor... no se me ocurre nada mas.

oye, muchas gracias por el interes.

saludos!
#7
Flash/Flex / Ayuda con movimientos con el raton
01 de Enero de 2009, 05:38:59 PM
Hola!

Estoy creando mi propio juego y ya se me ha presentado el primer problema.

En otros foros no e tenido mucha ayuda pero espero que aqui me podais ayudar mejor.

Se trata, por ahora, de un juego en un mapa bidimensional, con un jugador que se debe mover con el raton. Mi problema se presenta en que solo e sido capaz de que el jugador se mueva en forma de L (usando baldosas) y necesito que se mueve donde clicka el raton en linea recta.

Espero que me podais ayudar por que no consigo hacerlo. Supongo que se debera primero hacer que el jugador rote, y acontinuacion, se diriga donde pincho con el raton, pero por mas que lo intento no lo consigo. :(

Saludos a todos :)