Comunidad de diseño web y desarrollo en internet online

de .onRelease a .onKeyDown

Citar            
MensajeEscrito el 02 Sep 2008 02:52 pm
Hopla a todos tengo un juego de memoria (SIMON) que funciona perfectamente. El problema es que quiero que responda a as acciones del teclad y no del mouse. PORFAVOR!!!! Miren el codigo y ayudenme a sber como podria cambiar el mouse por el teclado, pero tomense el tiempo de ver el codigo no es tan facil de comprender. Muchisisisimas gracias!!!!!

Código :

fscommand("fullscreen",true);
var dim = 100;  //Alpha of pieces when clicked
aPieces = new Array(); //Array of pieces
aMoveList = new Array(); //Array of moves made
var ID;
var count = 0; //Number of moves made
var first;
var soSound0 = new Sound(this); //Creates a new Sound
soSound0.attachSound("simonSound1.mp3"); //Attaches simonSound1.mp3 to that sound
var soSound1 = new Sound(this);
soSound1.attachSound("simonSound2.mp3");
var soSound2 = new Sound(this);
soSound2.attachSound("simonSound3.mp3");
var soSound3 = new Sound(this);
soSound3.attachSound("simonSound4.mp3");
var step = 0;
muestra.stop();
for (var i = 1; i < 5; i++) //Adds the four movie clip quadrants to aPieces
{
        aPieces.push(this["m" + i]);
        this["m" + i].value = i - 1;
}
function buildPieces()
{
        for (var i = 0; i < aPieces.length; i++)
        {
                aPieces[i].onPress = function() //When the piece is pressed it dims
                {
                        this._alpha = dim;
                };
                aPieces[i].onRollOut = function() //When you roll your mouse off of the piece it undims
                {
                        this._alpha = 20;
                };
                aPieces[i].onRelease = function()  //When you release your mouse
                {
                        
                  this._alpha = 100;  //Set transparency to 100%
                        _root["soSound" + this.value].start(0); //Play the piece sound
                        if (aMoveList[step] != this.value) //If the piece you pressed does not equal the piece you were supposed to press
                        {
                                failure(); //failure method
                                return;
                        }
                        step++; //Add one to the amount of steps to do
                        if (step == aMoveList.length)
                        {
                                nextLevel();  //Go to the next level
                        }
                };
        }
}
function failure()
{
        tMainText.text = "Game Over.";
        killPieces();
      muestra.stop();
        mStart._alpha = 100;  //Set start button transparency back to 100%
      aMoveList = new Array();  //Delete array of moves
        mStart.onRelease = function()  //Recreate the start button
        {
                startGame();
        }
}
function killPieces()
{
        for (var i = 0; i < aPieces.length; i++) //Deletes all the functions of the pieces so you cant interact with them
        {
                delete aPieces[i].onPress;
                delete aPieces[i].onRollOut;
                delete aPieces[i].onRelease;
        }
}
function lightUp(num)
{
        clearInterval(ID);
        count--;
        if (count == 0)  //If no more pieces are left to light up, wait for user to input sequence
        {
                userTurn();
                return;
        }
        if (count == 1) //If the last piece in the list has just been lit up, pick a random light to light up
        {
                num = Math.floor(Math.random() * 4);
        }
        else //Set num to the next light to light up
        {
                num = aMoveList[aMoveList.length + 1 - count];
        }
        light(num); //Light up the light
}
function userTurn()
{
        step = 0; //Sets the step to 0
        buildPieces();  //Lets user interact with pieces
}
function light(num)
{
        dimIt(num); //dims the num piece
        ID = setInterval(pause, 1000, num); //Light up the piece for half of a second
}
function pause(num)
{
        clearInterval(ID);
        unDim(num);
        ID = setInterval(lightUp, 100, num); //Creates a 50ms pause between lighting up pieces
}
function dimIt(num)
{
        if (count == 1)
        {
                aMoveList.push(num);
        }
        _root["soSound" + num].start(0); //Plays the sound when lighting a piece up
        aPieces[num]._alpha = 100;
}
function unDim(num)
{
        aPieces[num]._alpha = 20;
}
function startGame()
{
        first = Math.floor(Math.random() * 4) //Picks first piece
        tMainText.text = ""; //Sets the text field to display nothing
        for (var i = 0; i < aPieces.length; i++)
        {
                aPieces[i]._alpha = 20; //Sets all the pieces to 100% transparency
        }
        mStart._alpha = 0; //Sets the start button to invisible
        delete mStart.onRelease; //Deletes the start button onRelease function
        muestra.play();
      buildPieces();
        count = 1;
        light(first); //Lights first piece
}
function nextLevel()
{
        killPieces(); //Disables interacting with pieces
        for (var i = 0; i < aPieces.length; i++)
        {
                aPieces[i]._alpha = 20; //Sets all pieces to 100% transparency
        }
        count = aMoveList.length + 1;
        var timer = getTimer();
        this.onEnterFrame = function()
        {
                if (timer < getTimer() - 1500) //Wait 1 second before starting sequence display after input
                {
                        delete this.onEnterFrame;
                        light(first);
                }
        };
}
mStart.onRelease = function()
{
        startGame();
};

Por darkesolutions

1 de clabLevel



 

firefox
Citar            
MensajeEscrito el 02 Sep 2008 03:46 pm
Miren el codigo y ayudenme a sber como podria cambiar el mouse por el teclado, pero tomense el tiempo de ver el codigo no es tan facil de comprender.


Los principios son simples, el tema son las implementaciones. Como soy muy vago y jamás entendería tu código, te paso algunos tips, pues ya que escribiste este código, no te costará mucho cambiarlo:

- ¿Quitar el Mouse? Mouse.hide() al principio y ya no tienes cursor (Mouse.show() para devolverlo)
- Busca los onRollOver, onRelease o onPress, esos son eventos de Mouse
- El Mouse hace dos cosas: se desplaza y presiona, entonces tu teclado debe hacer dos cosas, rollover sobre los elementos con las flechas de direcciones, onRelease (u on Press) con otras teclas a elección
- En la entrada Key.addListener del diccionario de AS tienes como detectar las teclas oprimidas
- Tienes que relacionar cada teclazo con una acción concreta del ratón

Dado que un teclado es mas limitado que el ratón, es muy probable que tengas que reescribir gran parte del código

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox

 

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