Comunidad de diseño web y desarrollo en internet online

ayuda con un juego en el codigo (creo)

Citar            
MensajeEscrito el 09 Oct 2008 12:59 am
les cuento que estoy haciendo un juego en flash (de etapas, personaje avanzando), y el problema que tengo es que no puedo apretar dos teclas a las vez, por ejemplo primero tengo que saltar y despues presionar hacia el lado, y lo que quiero es que apretar las dos teclas arriba (para saltar) y hacia el lado (para avanzar) el personaje haga lo que debe que es saltar hacia adelante. nose si me explique bien, les dejo el codigo aver si alguien me puede ayudar.
mi personaje es hero. monster son enemigos lo que esta bien
[/code]
moveLayer.hero.gotoAndStop(1);
// Hide the level complete dialog.
levelcomplete._visible = false;
// creo todas las variables globales y las inicializo
var onground = false;
var shooting = false;
var jumping = false;
var jumpsetup = false;
var hposx=undefined;
var hposy=undefined;
var rightArrow=39;
var leftArrow=37;
var upArrow=38
var spaceBarr=32;
var tecla=0;
var mensaje=undefined;
// This is the main character movement code

var oKeyListener:Object = new Object();
oKeyListener.onKeyDown = function() {
tecla=Key.getCode();
}
oKeyListener.onKeyUp = function() {
tecla=0;
}
Key.addListener(oKeyListener);

moveme = function () {
if (tecla==38) {
this.gotoAndStop(3);
this._y-=1;
}
}
moveme= function () {
// This is our very first iteration through the code, store some variables.
if (hposx == undefined) {
this.startx = hposx=this._x;
this.starty =hposy=this._y;
this.dy=0;
this.dx=0;
bg.xini=bg._x;
bg.yini=bg._y;
moveLayer.xini=moveLayer._x;
moveLayer.yini=moveLayer._y;
}
this.dy += 0.5;
// Fall down. This variable, dy, is going to be added to the player's y position each frame
var nexty = Math.ceil(hposy+this.dy);
// My next y position
var nextx = hposx+this.dx;
// My next x position
onground = false;
// Am I falling down?
if (this.dy>=0) {
// Have I hit a solid platform?
if (moveLayer.platforms.hitTest(hposx+moveLayer._x, nexty+moveLayer._y, true) && !jumpsetup) {
onground = true;
jumping = false;
var cnt = 0;
var ty = Math.floor(nexty);
// I may have my next position being 'through' the ground, so
// Count backwards from my 'next position' to see where the real ground is
while (moveLayer.platforms.hitTest(hposx+moveLayer._x, ty+moveLayer._y, true)) {
cnt++;
ty -= 2;
}
if (cnt<10) {
// correct my y position
hposy = ty;
this.dy = 0;
} else {
// I've hit a wall
// He golpeado un muro
hposx -= this.dx;
this.dx = 0;
}
} else if (this.dy>5 && !shooting) {
// Falling
this.gotoAndStop(3);
this.mc.gotoAndStop(11);
}
} else if (this.dy<0) {
// Hit my head on the ceiling
if (moveLayer.platforms.hitTest(hposx+moveLayer._x, nexty+moveLayer._y-40, true)) {
this.dy = 1;
}
}
// Have I hit the exit?
if (moveLayer.exit.hitTest(hposx+moveLayer._x, hposy+moveLayer._y-40, true)) {
// Play the exit door animation. At the end of this animation is code to
// hide the player, and show the "level complete" screen.
moveLayer.exit.play();
}
//*****************************************************
// Have I hit the escudo?
if (moveLayer.escudo.hitTest(hposx+moveLayer._x, hposy+moveLayer._y-40, true)) {
// Play the exit door animation. At the end of this animation is code to
// hide the player, and show the "level complete" screen.
moveLayer.elMensaje.gotoAndPlay("seguir");
this.gotoAndStop(1);
}
/*
if (moveLayer.escudo2.hitTest(hposx+moveLayer._x, hposy+moveLayer._y-40, true)) {
// Play the exit door animation. At the end of this animation is code to
// hide the player, and show the "level complete" screen.
moveLayer.elMensaje2.gotoAndPlay("seguir");
this.gotoAndStop(1);
}
*/
//*****************************************************

if (this.dy>9) {
this.dy = 9;
}
// Terminal falling velocity
if (!jumpsetup) {
// If not in the process of starting the jump animation, then move the character
// along his motion path. Add dy to y and dx to x, moving the player.
hposx += this.dx;
hposy += this.dy;

}
if ((tecla==rightArrow) && (!shooting)) {
if (jumping) {
this.dx += .8;
} else {
this.dx += 1;
}
// Set the direction the movieclip is facing.
this._xscale = 80;
} else if ((tecla==leftArrow) && (!shooting)) {
// Pressing LEFT button, set my x speed (dx)

if (jumping) {
this.dx -= .4;
} else {
this.dx -= 1;
}
// Set the direction the movieclip is facing.
this._xscale = -80;
} else {
this.dx *= 0.7;
}
// Slide to a stop because I'm not pressing left/right.
if (this.dx>7) {
this.dx = 7;
}
if (this.dx<-7) {
this.dx = -7;
}
if ((!jumpsetup)and(!jumping)and(!shooting)and(onground)) {
// Animation control - show me standing still, or moving depending on my speed.
if (Math.abs(this.dx)<0.5) {
this.dx = 0;
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
}
// Jumping initiated.
if ((tecla==upArrow)and(this.dy>=0)and(this.dy<1)and(!jumping)){
onground = false;
shooting = false;
jumping = true;
jumpsetup = true;
// Play the jump animation.
this.gotoAndStop(3);
}
lasty = this._y;
// Move the background relative to myself. Since the character doesn't move from
// dead center of screen, the background must instead move relative to the character.
//***********************************************
moveLayer._x = Math.round(350-hposx);// Aqui al centro de la pantalla en eje X
moveLayer._y = Math.round(370-hposy);//esto controla dónde aparecera el hero en vertical!!
//A MAYOR VALOR MAS HACIA EL FONDO
//***********************************************
if (moveLayer._y<-700) {
moveLayer._y = -700;
}
bg._x = (moveLayer._x/2)-100;// Desplaza el fondo al centro en eje X
bg._y = (moveLayer._y/2)-270;// Desplaza el fondo al centro en eje Y
// Fire the gun.
if ((tecla==spaceBarr) && (!shooting)) {
shooting = true;
jumping = false;
jumpsetup = false;
this.gotoAndStop(4);
}
// I have fallen off the bottom of the level and am dead. Restart.
if (hposy>1580) {
hposx = this.startx;
hposy = this.starty;
intro._visible = true;
bg._x=bg.xini;
bg._y=bg.yini;
moveLayer._x=moveLayer.xini;
moveLayer._y=moveLayer.yini;
moveLayer.hero.onEnterFrame=null;
if (mensaje=="open"){
moveLayer.elMensaje.gotoAndPlay("salir");
}
}
// Set my actual _x and _y properties to a rounded version of the x and y
// I've been using to compute my collision and position. Eliminates errors
// and a bad flickering effect.
this._x = Math.floor(hposx);
this._y = Math.floor(hposy);
};
// This function is used by the bullet when fired.
moveBullet = function () {
// Move along by my dx speed.
this._x += this.dx;
// If I'm out of visual range of the hero, then remove me.
if (this._x<moveLayer.hero._x-600 || this._x>moveLayer.hero._x+600) {
// 300 es la distancia en px que recorre la bala
this.removeMovieClip();
}
};
// Call this function to create a bullet.
createBullet = function () {
var dir = moveLayer.hero._xscale/80;
nm = "bul0";
moveLayer.attachMovie("poder", nm, 100);
moveLayer[nm]._x = moveLayer.hero._x+(35*dir);
moveLayer[nm]._y = moveLayer.hero._y-2*moveLayer.hero._height/3;
moveLayer[nm]._xscale = dir*100;
moveLayer[nm].dx = 20*dir;
moveLayer[nm].onEnterFrame = moveBullet;
};

moveSplat = function () {
this._x += this.dx;
if (this._x<moveLayer.hero._x-400 || this._x>moveLayer.hero._x+400) {
// 300 es la distancia en px que recorre la bala
this.removeMovieClip();
}
if (this.hitTest(moveLayer.hero)) {
moveLayer.hero.dx = this.dx*5;
moveLayer.hero.dy = -10;
this.removeMovieClip();
}
};
numsplats = 0;
createSplat = function () {
var dir = this._xscale/80;
nm = "splat" + numsplats;
moveLayer.attachMovie("splatBullet", nm, numsplats+200);
moveLayer[nm]._x = this._x+(35*dir);
moveLayer[nm]._y = this._y-25;
moveLayer[nm]._xscale = dir*100;
moveLayer[nm].dx = 10*dir;
moveLayer[nm].onEnterFrame = moveSplat;
numsplats++;
numsplats %= 20;
};
simpleMove = function () {
if (this.posx == undefined) {
this.posx = this._x;
this.posy = this._y;
}
this.posx += this.dx;
this.posy += this.dy;
if (this.posx<this.x1) {
this.posx = this.x1;
this.dx *= -1;
} else if (this.posx>this.x2) {
this.posx = this.x2;
this.dx *= -1;
}
if (this.dx>0) {
this._xscale = 80;
} else if (this.dx<0) {
this._xscale = -80;
}
this._x = Math.floor(this.posx);
this._y = Math.floor(this.posy);
if (this.hitTest(moveLayer.bul0)) {
this.gotoAndStop(2);
this.onEnterFrame = null;
}
if (random(100) == 0) {
this.gotoAndStop(3);
}
};


intro.playButton.onRelease = function() {
intro._visible = false;
moveLayer.hero.onEnterFrame = moveme;
};

Por statustap

8 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 09 Oct 2008 04:27 am
OMG! :shock: Nadie va a leer ese código.

Escribelo así:

Código ActionScript :

 [as] Tu código de ActionScript [/as] 


Despues tal vez puedas separar el código en donde creas que está el error. Tal vez así alguien se anime a leerle :)

Por violetisha

575 de clabLevel

1 tutorial
1 articulo

Genero:Femenino  

Mi silla en el estudio, México

opera
Citar            
MensajeEscrito el 09 Oct 2008 04:30 am
jajaja la mensaaa!!! no me habia dado cuenta.

Por statustap

8 de clabLevel



Genero:Masculino  

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.