Flashhilfe.de - Flash Community

tetris tutorial - schaltflächen hinzufügen die als tastatur dienen. [Flash 8]

Forum > ActionScript 2.0 > tetris tutorial - schaltflächen hinzufügen die als tastatur dienen.

 


AntwortenRegistrieren Seite1  

 21.05.2009, 23:58 
Beiträge: 6
Registriert: May 2009

tetris tutorial - schaltflächen hinzufügen die als tastatur dienen.
Hallo

Ich habe im Internet ein Tutorial gefunden, bei dem man ein Tetris-Spiel macht.
Jetzt würde ich das ganze gern auch auf meinem Handy Spielen. Da ich aber keine tasten an dem Handy habe, muss ich ja irgendwie Schaltflächen integrieren. Damit ich das über touchscreen bedienen kann. Aber wie mach ich das am besten. Kann man den schaltflächen einfach sagen, dass sie das gleiche machen wie die pfeiltasten auf der tastatur?

Ich kenn mich mit dem Programmieren nicht aus. Ich habe es zwar wenigsten geschafft den code auf die neue Display grösse umzuschreiben, aber das war es dann schon.
Geändert von HFJuli am 22.05.09 um 00:03 Uhr

 22.05.2009, 00:03Re1
Beiträge: 6
Registriert: May 2009

Themenautor/in

var unitsize = 40;  //One unit is one Block
var unitheight = 17;  //How many units stack vertically in tetris.
var unitwidth = 12;  //How many units stack horizontally in tetris.
var piececount = 0;
var piecetype;
var oldlines = 0;
var speed = 10;  //Starting speed
var frame = 1;
var level = 1;
var realpaused = false;
var levelspeed = 8;
lines = 0;
score = 0;
moviecliplist = new Array();
xx = new Array("1", "2", "3", "4");
yy = new Array("1", "1", "1", "1");
framecount = 0;
var paused = true;
var rotatedcount = 0;
unitmap = new Array();
for (var i = 0; i < unitwidth; i++)  //Creates a 2 dimensional array to store the pieces in tetris.
{
        unitmap[i] = new Array();
        unitmap[i][unitheight + 1] = 1;
}
mouseListener = new Object();
mouseListener.onMouseDown = function()  //When the mouse is clicked
{
        if (paused && realpaused == false)
        {
                for (var i = 0; i <= unitheight; i++)
                {
                        for (var j = 0; j <= unitwidth; j++)
                        {
                                unitmap[j][i] = undefined;
                        }
                }
                for (var i = 0; i < moviecliplist.length; i++)
                {
                        removeMovieClip(moviecliplist[i]);
                }
                startgame();  //start the game
        }
};
Mouse.addListener(mouseListener);
kListener = new Object();
kListener.onKeyDown = function()  //When a key is pressed
{
        var k = Key.getCode(); //Get the ASCII code of the key pressed
        if (paused)
        {
                if (k == 80)  //If it is paused and you press p it will unpause
                {
                        paused = false;
                }
        }
        else
        {
                if (k == 80)  //If it's not paused and p is pressed it will pause the game.
                {
                        realpaused = true;
                        paused = true;
                }
                if (k == 38)  //Up button is pressed
                {
                      /*Piece Types (piecetype == number)
                        * 0 - Line
                        * 1 - L shape
                        * 2 - Other L shape
                        * 3 - Square
                        * 4 - S shape
                        * 5 - Z shape
                        * 6 - T shape
                        */
                        if (piecetype == 0)
                        {
                                if (rotatedcount == 0)  //If it has been rotated 0 times.
                                {
                                        if (unitmap[xx[0] + 2][yy[0] - 1] == undefined && unitmap[xx[1] + 1][yy[1]] == undefined && unitmap[xx[2]][yy[2] + 1] == undefined && unitmap[xx[3] - 1][yy[3] + 2] == undefined)  //Checks if the space it will rotate to is available
                                        {
                                                                                                //Changes the coordinates of the piece in the xx and yy arrays that hold the position of the piece.
                                                xx[0] = xx[0] + 2;
                                                yy[0] = yy[0] - 1;
                                                xx[1] = xx[1] + 1;
                                                yy[2] = yy[2] + 1;
                                                xx[3] = xx[3] - 1;
                                                yy[3] = yy[3] + 2;
                                                rotatedcount++;  //Adds one to the rotatedcount variable.
                                        }
                                }
                                else
                                {
                                        if (unitmap[xx[0] - 2][yy[0] + 1] == undefined && unitmap[xx[1] - 1][yy[1]] == undefined && unitmap[xx[2]][yy[2] - 1] == undefined && unitmap[xx[3] + 1][yy[3] - 2] == undefined && currentpiece._x != 0 && currentpiece._x != 20 && currentpiece._x != 440)
                                        {
                                                xx[0] = xx[0] - 2;
                                                yy[0] = yy[0] + 1;
                                                xx[1] = xx[1] - 1;
                                                yy[2] = yy[2] - 1;
                                                xx[3] = xx[3] + 1;
                                                yy[3] = yy[3] - 2;
                                                rotatedcount = 0;
                                        }
                                }
                                reposition();  //Repositions the piece according to how you just moved it.
                        }
                        else if (piecetype == 1)
                        {
                                if (rotatedcount == 0)
                                {
                                        if (unitmap[xx[0] + 1][yy[0] - 1] == undefined && unitmap[xx[2] - 1][yy[2] + 1] == undefined && unitmap[xx[3]][yy[3] - 2] == undefined)
                                        {
                                                xx[0] = xx[0] + 1;
                                                yy[0] = yy[0] - 1;
                                                xx[2] = xx[2] - 1;
                                                yy[2] = yy[2] + 1;
                                                yy[3] = yy[3] - 2;
                                                rotatedcount++;
                                        }
                                }
                                else if (rotatedcount == 1)
                                {
                                        if (unitmap[xx[0] - 1][yy[0] + 1] == undefined && unitmap[xx[2] - 1][yy[2] - 2] == undefined && unitmap[xx[3]][yy[3] + 1] == undefined && currentpiece._x != 0)
                                        {
                                                xx[0] = xx[0] - 1;
                                                yy[0] = yy[0] + 1;
                                                xx[2] = xx[2] - 1;
                                                yy[2] = yy[2] - 2;
                                                yy[3] = yy[3] + 1;
                                                rotatedcount++;
                                        }
                                }
                                else if (rotatedcount == 2)
                                {
                                        if (unitmap[xx[0]][yy[0] + 1] == undefined && unitmap[xx[2] + 1][yy[2]] == undefined && unitmap[xx[3] - 1][yy[3] + 1] == undefined)
                                        {
                                                yy[0] = yy[0] + 1;
                                                xx[2] = xx[2] + 1;
                                                xx[3] = xx[3] - 1;
                                                yy[3] = yy[3] + 1;
                                                rotatedcount++;
                                        }
                                }
                                else
                                {
                                        if (unitmap[xx[0]][yy[0] - 1] == undefined && unitmap[xx[2] + 1][yy[2] + 1] == undefined && unitmap[xx[3] + 1][yy[3]] == undefined && xx[0] != 8)
                                        {
                                                yy[0] = yy[0] - 1;
                                                xx[2] = xx[2] + 1;
                                                yy[2] = yy[2] + 1;
                                                xx[3] = xx[3] + 1;
                                                rotatedcount = 0;
                                        }
                                }
                                reposition();
                        }
                        else if (piecetype == 2)
                        {
                                if (rotatedcount == 0)
                                {
                                        if (unitmap[xx[0] + 1][yy[0] - 1] == undefined && unitmap[xx[2] + 1][yy[2]] == undefined && unitmap[xx[3]][yy[3] + 1] == undefined)
                                        {
                                                xx[0] = xx[0] + 1;
                                                yy[0] = yy[0] - 1;
                                                xx[2] = xx[2] + 1;
                                                yy[3] = yy[3] + 1;
                                                rotatedcount++;
                                        }
                                }
                                else if (rotatedcount == 1)
                                {
                                        if (unitmap[xx[0] - 1][yy[0] + 1] == undefined && unitmap[xx[2] + 1][yy[2] - 1] == undefined && unitmap[xx[3]][yy[3] - 2] == undefined && currentpiece._x != 0)
                                        {
                                                xx[0] = xx[0] - 1;
                                                yy[0] = yy[0] + 1;
                                                xx[2] = xx[2] + 1;
                                                yy[2] = yy[2] - 1;
                                                yy[3] = yy[3] - 2;
                                                rotatedcount++;
                                        }
                                }
                                else if (rotatedcount == 2)
                                {
                                        if (unitmap[xx[0]][yy[0] - 1] == undefined && unitmap[xx[2] - 1][yy[2] + 1] == undefined && unitmap[xx[3] - 1][yy[3]] == undefined)
                                        {
                                                yy[0] = yy[0] - 1;
                                                xx[2] = xx[2] - 1;
                                                yy[2] = yy[2] + 1;
                                                xx[3] = xx[3] - 1;
                                                rotatedcount++;
                                        }
                                }
                                else
                                {
                                        if (unitmap[xx[0]][yy[0] + 1] == undefined && unitmap[xx[2] - 1][yy[2]] == undefined && unitmap[xx[3] + 1][yy[3] + 1] == undefined && xx[0] != 8)
                                        {
                                                yy[0] = yy[0] + 1;
                                                xx[2] = xx[2] - 1;
                                                xx[3] = xx[3] + 1;
                                                yy[3] = yy[3] + 1;
                                                rotatedcount = 0;
                                        }
                                }
                                reposition();
                        }
                        else if (piecetype == 4)
                        {
                                if (rotatedcount == 0)
                                {
                                        if (unitmap[xx[0] + 1][yy[0] - 2] == undefined && unitmap[xx[1] + 1][yy[1]] == undefined)
                                        {
                                                xx[0] = xx[0] + 1;
                                                yy[0] = yy[0] - 2;
                                                xx[1] = xx[1] + 1;
                                                rotatedcount++;
                                        }
                                }
                                else
                                {
                                        if (unitmap[xx[0] - 1][yy[0] + 2] == undefined && unitmap[xx[1] - 1][yy[1]] == undefined && currentpiece._x != 0)
                                        {
                                                xx[0] = xx[0] - 1;
                                                yy[0] = yy[0] + 2;
                                                xx[1] = xx[1] - 1;
                                                rotatedcount = 0;
                                        }
                                }
                                reposition();
                        }
                        else if (piecetype == 5)
                        {
                                if (rotatedcount == 0)
                                {
                                        if (unitmap[xx[0] + 1][yy[0]] == undefined && unitmap[xx[1] + 1][yy[1]] == undefined && unitmap[xx[3]][yy[3] - 2] == undefined)
                                        {
                                                xx[0] = xx[0] + 1;
                                                xx[1] = xx[1] + 1;
                                                yy[3] = yy[3] - 2;
                                                rotatedcount++;
                                        }
                                }
                                else
                                {
                                        if (unitmap[xx[0] - 1][yy[0]] == undefined && unitmap[xx[1] - 1][yy[1]] == undefined && unitmap[xx[3]][yy[3] + 2] == undefined && currentpiece._x != 0)
                                        {
                                                xx[0] = xx[0] - 1;
                                                xx[1] = xx[1] - 1;
                                                yy[3] = yy[3] + 2;
                                                rotatedcount = 0;
                                        }
                                }
                                reposition();
                        }
                        else if (piecetype == 6)
                        {
                                if (rotatedcount == 0)
                                {
                                        if (unitmap[xx[0] + 1][yy[0] - 1] == undefined)
                                        {
                                                xx[0] = xx[0] + 1;
                                                yy[0] = yy[0] - 1;
                                                rotatedcount++;
                                        }
                                }
                                else if (rotatedcount == 1)
                                {
                                        if (unitmap[xx[0] - 1][yy[0] + 1] == undefined && unitmap[xx[2]][yy[2] - 2] == undefined && currentpiece._x != 0)
                                        {
                                                xx[0] = xx[0] - 1;
                                                yy[0] = yy[0] + 1;
                                                yy[2] = yy[2] - 2;
                                                rotatedcount++;
                                        }
                                }
                                else if (rotatedcount == 2)
                                {
                                        if (unitmap[xx[3] - 1][yy[3] + 1] == undefined)
                                        {
                                                xx[3] = xx[3] - 1;
                                                yy[3] = yy[3] + 1;
                                                rotatedcount++;
                                        }
                                }
                                else
                                {
                                        if (unitmap[xx[2]][yy[2] + 2] == undefined && unitmap[xx[3] + 1][yy[3] - 1] == undefined && currentpiece._x != 160)
                                        {
                                                yy[2] = yy[2] + 2;
                                                xx[3] = xx[3] + 1;
                                                yy[3] = yy[3] - 1;
                                                rotatedcount = 0;
                                        }
                                }
                                reposition();
                        }
                }
                if (k == 39 && current4piece._x != 440 && unitmap[xx[0] - 1][yy[0]] == undefined && unitmap[xx[1] - 1][yy[1]] == undefined && unitmap[xx[2] - 1][yy[2]] == undefined && unitmap[xx[3] - 1][yy[3]] == undefined && unitmap[xx[0] + 1][yy[0]] == undefined && unitmap[xx[1] + 1][yy[1]] == undefined && unitmap[xx[2] + 1][yy[2]] == undefined && unitmap[xx[3] + 1][yy[3]] == undefined)  //Checks if it is safe to move right.
                {
                        for (var i = 0; i < 4; i++)
                        {
                                xx[i]++;  //Changes the x coordinate of the piece to one to the right
                        }
                        reposition();  //Repositions piece
                }
                if (k == 37 && currentpiece._x != 0 && unitmap[xx[0] - 1][yy[0]] == undefined && unitmap[xx[1] - 1][yy[1]] == undefined && unitmap[xx[2] - 1][yy[2]] == undefined && unitmap[xx[3] - 1][yy[3]] == undefined && unitmap[xx[0] + 1][yy[0]] == undefined && unitmap[xx[1] + 1][yy[1]] == undefined && unitmap[xx[2] + 1][yy[2]] == undefined && unitmap[xx[3] + 1][yy[3]] == undefined) //Left
                {
                        for (var i = 0; i < 4; i++)
                        {
                                xx[i]--;
                        }
                        reposition();
                }
        }
};
Key.addListener(kListener);
gameover = function ()  //When gameOver is called the popup movie is called which says Game Over.
{
        popup.swapDepths(5000);
        popup.gotoAndStop(2);
        realpaused = false;
        paused = true;
};
reposition = function ()  //Changes all the x coordinates according to the spots in the array.
{
        currentpiece._x = xx[0] * unitsize;
        current2piece._x = xx[1] * unitsize;
        current3piece._x = xx[2] * unitsize;
        current4piece._x = xx[3] * unitsize;
        currentpiece._y = yy[0] * unitsize;
        current2piece._y = yy[1] * unitsize;
        current3piece._y = yy[2] * unitsize;
        current4piece._y = yy[3] * unitsize;
};
startgame = function ()
{
        paused = false;
        score = 0;
        lines = 0;
        level = 1;
        popup.gotoAndStop(3);  //Changes the popup to a blank frame so you can't see it.
        newpiece();  //Adds a new piece to the stage.
};
newpieceattach = function ()
{
        if (unitmap[3][0] != undefined || unitmap[4][0] != undefined || unitmap[5][0] != undefined || unitmap[6][0] != undefined)  //Checks if the top middle spots have a piece in them, if they do, you lose.
        {
                gameover();
        }
        else
        {
                oldlines = 0;
                for (var i = 0; i <= unitheight; i++)
                {
                        if (unitmap[0][i] != undefined && unitmap[1][i] != undefined && unitmap[2][i] != undefined && unitmap[3][i] != undefined && unitmap[4][i] != undefined && unitmap[5][i] != undefined && unitmap[6][i] != undefined && unitmap[7][i] != undefined && unitmap[8][i] != undefined && unitmap[9][i] != undefined && unitmap[10][i] != undefined && unitmap[11][i] != undefined)  //Checks for a horizontal line of tetris blocks
                        {
                                for (var j = 0; j < unitwidth; j++)
                                {
                                        removeMovieClip(unitmap[j][i]);  //Removes the blocks in the line
                                        for (var k = 0; k < unitheight; k++)  //Moves all blocks above the line down.
                                        {
                                                unitmap[j][i - k]._y += unitsize;
                                                unitmap[j][i - k] = unitmap[j][i - k - 1];
                                        }
                                }
                                oldlines++;
                                score += level * oldlines * oldlines * 100;
                                lines++;
                                if (lines % 10 == 0 && levelspeed > 1)  //If you are at a line count divisible by ten, increase the speed.
                                {
                                        levelspeed--;
                                        level++;
                                }
                        }
                }
                xx[0] = xx[0] + 3;
                xx[1] = xx[1] + 3;
                xx[2] = xx[2] + 3;
                xx[3] = xx[3] + 3;
                                //Attach four blocks to create a piece.
                _root.attachMovie("piece", "currentpiece" + piececount, piececount * 4);
                this["currentpiece" + piececount]._x = xx[0] * unitsize;
                this["currentpiece" + piececount]._y = yy[0] * unitsize;
                this["currentpiece" + piececount]._width = unitsize;
                this["currentpiece" + piececount]._height = unitsize;
                _root.attachMovie("piece", "current2piece" + piececount, piececount * 4 + 1);
                this["current2piece" + piececount]._x = xx[1] * unitsize;
                this["current2piece" + piececount]._y = yy[1] * unitsize;
                this["current2piece" + piececount]._width = unitsize;
                this["current2piece" + piececount]._height = unitsize;
                _root.attachMovie("piece", "current3piece" + piececount, piececount * 4 + 2);
                this["current3piece" + piececount]._x = xx[2] * unitsize;
                this["current3piece" + piececount]._y = yy[2] * unitsize;
                this["current3piece" + piececount]._width = unitsize;
                this["current3piece" + piececount]._height = unitsize;
                _root.attachMovie("piece", "current4piece" + piececount, piececount * 4 + 3);
                this["current4piece" + piececount]._x = xx[3] * unitsize;
                this["current4piece" + piececount]._y = yy[3] * unitsize;
                this["current4piece" + piececount]._width = unitsize;
                this["current4piece" + piececount]._height = unitsize;
                currentpiece = _root["currentpiece" + piececount];
                currentpiece.gotoAndStop(frame);  //Changes the color of the piece to match the type.
                current2piece = _root["current2piece" + piececount];
                current2piece.gotoAndStop(frame);
                current3piece = _root["current3piece" + piececount];
                current3piece.gotoAndStop(frame);
                current4piece = _root["current4piece" + piececount];
                current4piece.gotoAndStop(frame);
                moviecliplist.push(currentpiece);  //Adds the movie clips to an array of movieclips.
                moviecliplist.push(current2piece);
                moviecliplist.push(current3piece);
                moviecliplist.push(current4piece);
        }
};
newpiece = function ()
{
        rotatedcount = 0;
        piececount++;
        var rand = (Math.floor(Math.random() * 7));  //Random number 0-6
        frame = rand + 1;
        piecetype = rand;
        if (rand == 0) //Fill the array of x and y coordinates with the piece so we can add it.
        {
                for (var i = 0; i < 4; i++)
                {
                        xx[i] = i;
                        yy[i] = 0;
                }
        }
        else if (rand == 1)  //refer to chart of pieces.
        {
                xx[0] = 0;
                yy[0] = 0;
                xx[1] = 1;
                yy[1] = 0;
                xx[2] = 2;
                yy[2] = 0;
                xx[3] = 2;
                yy[3] = 1;
        }
        else if (rand == 2)
        {
                xx[0] = 0;
                yy[0] = 0;
                xx[1] = 1;
                yy[1] = 0;
                xx[2] = 0;
                yy[2] = 1;
                xx[3] = 2;
                yy[3] = 0;
        }
        else if (rand == 3)
        {
                xx[0] = 0;
                yy[0] = 0;
                xx[1] = 0;
                yy[1] = 1;
                xx[2] = 1;
                yy[2] = 1;
                xx[3] = 1;
                yy[3] = 0;
        }
        else if (rand == 4)
        {
                xx[0] = 0;
                yy[0] = 1;
                xx[1] = 1;
                yy[1] = 1;
                xx[2] = 1;
                yy[2] = 0;
                xx[3] = 2;
                yy[3] = 0;
        }
        else if (rand == 5)
        {
                xx[0] = 0;
                yy[0] = 0;
                xx[1] = 1;
                yy[1] = 0;
                xx[2] = 1;
                yy[2] = 1;
                xx[3] = 2;
                yy[3] = 1;
        }
        else if (rand == 6)
        {
                xx[0] = 0;
                yy[0] = 0;
                xx[1] = 1;
                yy[1] = 0;
                xx[2] = 1;
                yy[2] = 1;
                xx[3] = 2;
                yy[3] = 0;
        }
        newpieceattach(); //add the new piece
};
_root.onEnterFrame = function()
{
        framecount++;
        current4piece._y = (yy[3] - 1) * unitsize;
        current3piece._y = (yy[2] - 1) * unitsize;
        current2piece._y = (yy[1] - 1) * unitsize;
        currentpiece._y = (yy[0] - 1) * unitsize;
        if (Key.isDown(Key.DOWN) && !paused)  //Increases speed when DOWN key is pressed.
        {
                score += level;
                speed = 1;
        }
        else
        {
                speed = levelspeed;
        }
        if (framecount % speed == 0)
        {
                if (!paused)
                {
                        if (unitmap[xx[0]][yy[0] + 1] == undefined && unitmap[xx[1]][yy[1] + 1] == undefined && unitmap[xx[2]][yy[2] + 1] == undefined && unitmap[xx[3]][yy[3] + 1] == undefined) //If the piece does not hit anything below it, move it down.
                        {
                                current4piece._y = yy[3] * unitsize;
                                current3piece._y = yy[2] * unitsize;
                                current2piece._y = yy[1] * unitsize;
                                currentpiece._y = yy[0] * unitsize;
                                for (var i = 0; i < 4; i++)
                                {
                                        yy[i]++;
                                }
                        }
                        else //If the piece hits something below it, stop moving it and create a new piece.
                        {
                                unitmap[xx[0]][yy[0]] = currentpiece;
                                unitmap[xx[1]][yy[1]] = current2piece;
                                unitmap[xx[2]][yy[2]] = current3piece;
                                unitmap[xx[3]][yy[3]] = current4piece;
                                newpiece();
                                framecount = 7;
                        }
                }
        }
};
Geändert von HFJuli am 22.05.09 um 00:06 Uhr

 22.05.2009, 00:07Re2
Beiträge: 567
Registriert: May 2007

was haste denn für nen handy bei dem g1 dürfte das ganze sogar gehen aberwenn du einen ipodtouch bzw iphone hast muss dud ir das ganze von apple absegnen lassen
Bitte keine pn´s wegen irgendwelchen fragen zu Threads, dafür gibt es sie ja schließich
 
nicht sichtbar bei eingeloggten Mitgliedern
 22.05.2009, 00:10Re3
Beiträge: 6
Registriert: May 2009

Themenautor/in

Es ist für ein LG Arena KM900

edit: wie füge ich hier ein script richtig ein. mit dem <script> knopf funktioniert es nicht.
Geändert von HFJuli am 22.05.09 um 00:12 Uhr

 22.05.2009, 00:18Re4
Beiträge: 567
Registriert: May 2007

puh ja gute frage sry aber ich hab mich noch nie mit lg und was man da so machen kann befasst kannste denn irgendwelche fläsh dateien überhaupt ausführen ?
Bitte keine pn´s wegen irgendwelchen fragen zu Threads, dafür gibt es sie ja schließich
 22.05.2009, 01:06Re5
Beiträge: 6
Registriert: May 2009

Themenautor/in

Ja. Das handy kann mit Flash lite 3.0 umgehen. Ich habe auch eine einfache fla mit ein par buttons als Flash 8 abgespeichert und das  wurde angezeigt. Ich habe jetzt auch noch mal das tetris spiel ausprobiert und als lite 3.0 und Flash 8 abgespeichert. Leider erkennt es keins von beiden und wird nicht angezeigt. Das könnte aber auch noch ein bug von der Firmware sein. Die ist noch nicht so ausgereift. Sound dateien werden auch noch nicht abgespielt.

Vielleicht hilft das pdf weiter:

Flash lite tutorial
Geändert von HFJuli am 22.05.09 um 01:09 Uhr

 
nicht sichtbar bei eingeloggten Mitgliedern
 24.05.2009, 14:34Re6
Beiträge: 6
Registriert: May 2009

Themenautor/in

Hallo
Ich hab noch ein bisschen im internet nach lösungen gesucht. Doch bei allen, die das gleiche erreichen wollten, konnte nicht geholfen werden. Scheint wohl garnicht so einfach zu machen sein.
Ich hab jetzt das script so umgeschrieben das es nur noch mit den Buttons funktioniert. Doch leider habe ich es mit dem key.down nicht so richtig geschafft. Der steckt in einem onEnterFrame. Ich konnte zwar ein zusätzliches script einfügen, damit der Button funktioniert, doch leider geht es nur wenn man ganz schnell hintereinander draufklickt. Habe das auch schon wieder rausgelöscht.

Desweiteren habe ich jetzt das Problem, dass beim Klicken auf einen der Richtungsbottons, der Block kurz eine Einheit nach unten springt und dann wieder an seine ursprüngliche Position geht. Und dann erst wieder normal nach unten fällt.

Kann mir da jemand weiter helfen?

PS: Wenn ich das Spiel als Flash lite 2.0 abspeicher funktioniert das ganze schon mal auf dem Handy. juhuuu

Gruss Juli
Geändert von HFJuli am 24.05.09 um 14:36 Uhr

 24.05.2009, 14:37Re7
Beiträge: 6
Registriert: May 2009

Themenautor/in

Ein script einzufügen geht immer noch nicht!!!

var unitsize = 40;  //One unit is one Block
var unitheight = 17;  //How many units stack vertically in tetris.
var unitwidth = 12;  //How many units stack horizontally in tetris.
var piececount = 0;
var piecetype;
var oldlines = 0;
var speed = 10;  //Starting speed
var frame = 1;
var level = 1;
var realpaused = false;
var levelspeed = 8;
lines = 0;
score = 0;
moviecliplist = new Array();
xx = new Array("1", "2", "3", "4");
yy = new Array("1", "1", "1", "1");
framecount = 0;
var paused = true;
var rotatedcount = 0;
unitmap = new Array();
for (var i = 0; i < unitwidth; i++)  //Creates a 2 dimensional array to store the pieces in tetris.
{
        unitmap[i] = new Array();
        unitmap[i][unitheight + 1] = 1;
}
popup.onRelease = function()  //When the popup is clicked
{
        if (paused && realpaused == false)
        {
                for (var i = 0; i <= unitheight; i++)
                {
                        for (var j = 0; j <= unitwidth; j++)
                        {
                                unitmap[j][i] = undefined;
                        }
                }
                for (var i = 0; i < moviecliplist.length; i++)
                {
                        removeMovieClip(moviecliplist[i]);
                }
                startgame();  //start the game
        }
};
right.onRelease = function()
{
   if (right && current4piece._x != 440 && unitmap[xx[0] - 1][yy[0]] == undefined && unitmap[xx[1] - 1][yy[1]] == undefined && unitmap[xx[2] - 1][yy[2]] == undefined && unitmap[xx[3] - 1][yy[3]] == undefined && unitmap[xx[0] + 1][yy[0]] == undefined && unitmap[xx[1] + 1][yy[1]] == undefined && unitmap[xx[2] + 1][yy[2]] == undefined && unitmap[xx[3] + 1][yy[3]] == undefined)  //Checks if it is safe to move right.
                {
                        for (var i = 0; i < 4; i++)
                        {
                                xx[i]++;  //Changes the x coordinate of the piece to one to the right
                        }
                        reposition();  //Repositions piece
                }
}
left.onRelease = function()
{
   if (left && currentpiece._x != 0 && unitmap[xx[0] - 1][yy[0]] == undefined && unitmap[xx[1] - 1][yy[1]] == undefined && unitmap[xx[2] - 1][yy[2]] == undefined && unitmap[xx[3] - 1][yy[3]] == undefined && unitmap[xx[0] + 1][yy[0]] == undefined && unitmap[xx[1] + 1][yy[1]] == undefined && unitmap[xx[2] + 1][yy[2]] == undefined && unitmap[xx[3] + 1][yy[3]] == undefined) //Left
                {
                        for (var i = 0; i < 4; i++)
                        {
                                xx[i]--;
                        }
                        reposition();
                }
}
rotate.onRelease = function ()
{
   if (rotate)  //Rotate button is pressed
                {
                      /*Piece Types (piecetype == number)
                        * 0 - Line
                        * 1 - L shape
                        * 2 - Other L shape
                        * 3 - Square
                        * 4 - S shape
                        * 5 - Z shape
                        * 6 - T shape
                        */
                        if (piecetype == 0)
                        {
                                if (rotatedcount == 0)  //If it has been rotated 0 times.
                                {
                                        if (unitmap[xx[0] + 2][yy[0] - 1] == undefined && unitmap[xx[1] + 1][yy[1]] == undefined && unitmap[xx[2]][yy[2] + 1] == undefined && unitmap[xx[3] - 1][yy[3] + 2] == undefined)  //Checks if the space it will rotate to is available
                                        {
                                                                                                //Changes the coordinates of the piece in the xx and yy arrays that hold the position of the piece.
                                                xx[0] = xx[0] + 2;
                                                yy[0] = yy[0] - 1;
                                                xx[1] = xx[1] + 1;
                                                yy[2] = yy[2] + 1;
                                                xx[3] = xx[3] - 1;
                                                yy[3] = yy[3] + 2;
                                                rotatedcount++;  //Adds one to the rotatedcount variable.
                                        }
                                }
                                else
                                {
                                        if (unitmap[xx[0] - 2][yy[0] + 1] == undefined && unitmap[xx[1] - 1][yy[1]] == undefined && unitmap[xx[2]][yy[2] - 1] == undefined && unitmap[xx[3] + 1][yy[3] - 2] == undefined && currentpiece._x != 0 && currentpiece._x != 20 && currentpiece._x != 440)
                                        {
                                                xx[0] = xx[0] - 2;
                                                yy[0] = yy[0] + 1;
                                                xx[1] = xx[1] - 1;
                                                yy[2] = yy[2] - 1;
                                                xx[3] = xx[3] + 1;
                                                yy[3] = yy[3] - 2;
                                                rotatedcount = 0;
                                        }
                                }
                                reposition();  //Repositions the piece according to how you just moved it.
                        }
                        else if (piecetype == 1)
                        {
                                if (rotatedcount == 0)
                                {
                                        if (unitmap[xx[0] + 1][yy[0] - 1] == undefined && unitmap[xx[2] - 1][yy[2] + 1] == undefined && unitmap[xx[3]][yy[3] - 2] == undefined)
                                        {
                                                xx[0] = xx[0] + 1;
                                                yy[0] = yy[0] - 1;
                                                xx[2] = xx[2] - 1;
                                                yy[2] = yy[2] + 1;
                                                yy[3] = yy[3] - 2;
                                                rotatedcount++;
                                        }
                                }
                                else if (rotatedcount == 1)
                                {
                                        if (unitmap[xx[0] - 1][yy[0] + 1] == undefined && unitmap[xx[2] - 1][yy[2] - 2] == undefined && unitmap[xx[3]][yy[3] + 1] == undefined && currentpiece._x != 0)
                                        {
                                                xx[0] = xx[0] - 1;
                                                yy[0] = yy[0] + 1;
                                                xx[2] = xx[2] - 1;
                                                yy[2] = yy[2] - 2;
                                                yy[3] = yy[3] + 1;
                                                rotatedcount++;
                                        }
                                }
                                else if (rotatedcount == 2)
                                {
                                        if (unitmap[xx[0]][yy[0] + 1] == undefined && unitmap[xx[2] + 1][yy[2]] == undefined && unitmap[xx[3] - 1][yy[3] + 1] == undefined)
                                        {
                                                yy[0] = yy[0] + 1;
                                                xx[2] = xx[2] + 1;
                                                xx[3] = xx[3] - 1;
                                                yy[3] = yy[3] + 1;
                                                rotatedcount++;
                                        }
                                }
                                else
                                {
                                        if (unitmap[xx[0]][yy[0] - 1] == undefined && unitmap[xx[2] + 1][yy[2] + 1] == undefined && unitmap[xx[3] + 1][yy[3]] == undefined && xx[0] != 8)
                                        {
                                                yy[0] = yy[0] - 1;
                                                xx[2] = xx[2] + 1;
                                                yy[2] = yy[2] + 1;
                                                xx[3] = xx[3] + 1;
                                                rotatedcount = 0;
                                        }
                                }
                                reposition();
                        }
                        else if (piecetype == 2)
                        {
                                if (rotatedcount == 0)
                                {
                                        if (unitmap[xx[0] + 1][yy[0] - 1] == undefined && unitmap[xx[2] + 1][yy[2]] == undefined && unitmap[xx[3]][yy[3] + 1] == undefined)
                                        {
                                                xx[0] = xx[0] + 1;
                                                yy[0] = yy[0] - 1;
                                                xx[2] = xx[2] + 1;
                                                yy[3] = yy[3] + 1;
                                                rotatedcount++;
                                        }
                                }
                                else if (rotatedcount == 1)
                                {
                                        if (unitmap[xx[0] - 1][yy[0] + 1] == undefined && unitmap[xx[2] + 1][yy[2] - 1] == undefined && unitmap[xx[3]][yy[3] - 2] == undefined && currentpiece._x != 0)
                                        {
                                                xx[0] = xx[0] - 1;
                                                yy[0] = yy[0] + 1;
                                                xx[2] = xx[2] + 1;
                                                yy[2] = yy[2] - 1;
                                                yy[3] = yy[3] - 2;
                                                rotatedcount++;
                                        }
                                }
                                else if (rotatedcount == 2)
                                {
                                        if (unitmap[xx[0]][yy[0] - 1] == undefined && unitmap[xx[2] - 1][yy[2] + 1] == undefined && unitmap[xx[3] - 1][yy[3]] == undefined)
                                        {
                                                yy[0] = yy[0] - 1;
                                                xx[2] = xx[2] - 1;
                                                yy[2] = yy[2] + 1;
                                                xx[3] = xx[3] - 1;
                                                rotatedcount++;
                                        }
                                }
                                else
                                {
                                        if (unitmap[xx[0]][yy[0] + 1] == undefined && unitmap[xx[2] - 1][yy[2]] == undefined && unitmap[xx[3] + 1][yy[3] + 1] == undefined && xx[0] != 8)
                                        {
                                                yy[0] = yy[0] + 1;
                                                xx[2] = xx[2] - 1;
                                                xx[3] = xx[3] + 1;
                                                yy[3] = yy[3] + 1;
                                                rotatedcount = 0;
                                        }
                                }
                                reposition();
                        }
                        else if (piecetype == 4)
                        {
                                if (rotatedcount == 0)
                                {
                                        if (unitmap[xx[0] + 1][yy[0] - 2] == undefined && unitmap[xx[1] + 1][yy[1]] == undefined)
                                        {
                                                xx[0] = xx[0] + 1;
                                                yy[0] = yy[0] - 2;
                                                xx[1] = xx[1] + 1;
                                                rotatedcount++;
                                        }
                                }
                                else
                                {
                                        if (unitmap[xx[0] - 1][yy[0] + 2] == undefined && unitmap[xx[1] - 1][yy[1]] == undefined && currentpiece._x != 0)
                                        {
                                                xx[0] = xx[0] - 1;
                                                yy[0] = yy[0] + 2;
                                                xx[1] = xx[1] - 1;
                                                rotatedcount = 0;
                                        }
                                }
                                reposition();
                        }
                        else if (piecetype == 5)
                        {
                                if (rotatedcount == 0)
                                {
                                        if (unitmap[xx[0] + 1][yy[0]] == undefined && unitmap[xx[1] + 1][yy[1]] == undefined && unitmap[xx[3]][yy[3] - 2] == undefined)
                                        {
                                                xx[0] = xx[0] + 1;
                                                xx[1] = xx[1] + 1;
                                                yy[3] = yy[3] - 2;
                                                rotatedcount++;
                                        }
                                }
                                else
                                {
                                        if (unitmap[xx[0] - 1][yy[0]] == undefined && unitmap[xx[1] - 1][yy[1]] == undefined && unitmap[xx[3]][yy[3] + 2] == undefined && currentpiece._x != 0)
                                        {
                                                xx[0] = xx[0] - 1;
                                                xx[1] = xx[1] - 1;
                                                yy[3] = yy[3] + 2;
                                                rotatedcount = 0;
                                        }
                                }
                                reposition();
                        }
                        else if (piecetype == 6)
                        {
                                if (rotatedcount == 0)
                                {
                                        if (unitmap[xx[0] + 1][yy[0] - 1] == undefined)
                                        {
                                                xx[0] = xx[0] + 1;
                                                yy[0] = yy[0] - 1;
                                                rotatedcount++;
                                        }
                                }
                                else if (rotatedcount == 1)
                                {
                                        if (unitmap[xx[0] - 1][yy[0] + 1] == undefined && unitmap[xx[2]][yy[2] - 2] == undefined && currentpiece._x != 0)
                                        {
                                                xx[0] = xx[0] - 1;
                                                yy[0] = yy[0] + 1;
                                                yy[2] = yy[2] - 2;
                                                rotatedcount++;
                                        }
                                }
                                else if (rotatedcount == 2)
                                {
                                        if (unitmap[xx[3] - 1][yy[3] + 1] == undefined)
                                        {
                                                xx[3] = xx[3] - 1;
                                                yy[3] = yy[3] + 1;
                                                rotatedcount++;
                                        }
                                }
                                else
                                {
                                        if (unitmap[xx[2]][yy[2] + 2] == undefined && unitmap[xx[3] + 1][yy[3] - 1] == undefined && currentpiece._x != 160)
                                        {
                                                yy[2] = yy[2] + 2;
                                                xx[3] = xx[3] + 1;
                                                yy[3] = yy[3] - 1;
                                                rotatedcount = 0;
                                        }
                                }
                                reposition();
                        }
                }
}

kListener = new Object();
kListener.onKeyDown = function()  //When a key is pressed
{
        var k = Key.getCode(); //Get the ASCII code of the key pressed
        if (paused)
        {
                if (k == 80)  //If it is paused and you press p it will unpause
                {
                        paused = false;
                }
        }
        else
        {
                if (k == 80)  //If it's not paused and p is pressed it will pause the game.
                {
                        realpaused = true;
                        paused = true;
                } 
        }
};
Key.addListener(kListener);

gameover = function ()  //When gameOver is called the popup movie is called which says Game Over.
{
        popup.swapDepths(5000);
        popup.gotoAndStop(2);
        realpaused = false;
        paused = true;
};
reposition = function ()  //Changes all the x coordinates according to the spots in the array.
{
        currentpiece._x = xx[0] * unitsize;
        current2piece._x = xx[1] * unitsize;
        current3piece._x = xx[2] * unitsize;
        current4piece._x = xx[3] * unitsize;
        currentpiece._y = yy[0] * unitsize;
        current2piece._y = yy[1] * unitsize;
        current3piece._y = yy[2] * unitsize;
        current4piece._y = yy[3] * unitsize;
};
startgame = function ()
{
        paused = false;
        score = 0;
        lines = 0;
        level = 1;
        popup.gotoAndStop(3);  //Changes the popup to a blank frame so you can't see it.
        newpiece();  //Adds a new piece to the stage.
};
newpieceattach = function ()
{
        if (unitmap[3][0] != undefined || unitmap[4][0] != undefined || unitmap[5][0] != undefined || unitmap[6][0] != undefined)  //Checks if the top middle spots have a piece in them, if they do, you lose.
        {
                gameover();
        }
        else
        {
                oldlines = 0;
                for (var i = 0; i <= unitheight; i++)
                {
                        if (unitmap[0][i] != undefined && unitmap[1][i] != undefined && unitmap[2][i] != undefined && unitmap[3][i] != undefined && unitmap[4][i] != undefined && unitmap[5][i] != undefined && unitmap[6][i] != undefined && unitmap[7][i] != undefined && unitmap[8][i] != undefined && unitmap[9][i] != undefined && unitmap[10][i] != undefined && unitmap[11][i] != undefined)  //Checks for a horizontal line of tetris blocks
                        {
                                for (var j = 0; j < unitwidth; j++)
                                {
                                        removeMovieClip(unitmap[j][i]);  //Removes the blocks in the line
                                        for (var k = 0; k < unitheight; k++)  //Moves all blocks above the line down.
                                        {
                                                unitmap[j][i - k]._y += unitsize;
                                                unitmap[j][i - k] = unitmap[j][i - k - 1];
                                        }
                                }
                                oldlines++;
                                score += level * oldlines * oldlines * 100;
                                lines++;
                                if (lines % 10 == 0 && levelspeed > 1)  //If you are at a line count divisible by ten, increase the speed.
                                {
                                        levelspeed--;
                                        level++;
                                }
                        }
                }
                xx[0] = xx[0] + 3;
                xx[1] = xx[1] + 3;
                xx[2] = xx[2] + 3;
                xx[3] = xx[3] + 3;
                                //Attach four blocks to create a piece.
                _root.attachMovie("piece", "currentpiece" + piececount, piececount * 4);
                this["currentpiece" + piececount]._x = xx[0] * unitsize;
                this["currentpiece" + piececount]._y = yy[0] * unitsize;
                this["currentpiece" + piececount]._width = unitsize;
                this["currentpiece" + piececount]._height = unitsize;
                _root.attachMovie("piece", "current2piece" + piececount, piececount * 4 + 1);
                this["current2piece" + piececount]._x = xx[1] * unitsize;
                this["current2piece" + piececount]._y = yy[1] * unitsize;
                this["current2piece" + piececount]._width = unitsize;
                this["current2piece" + piececount]._height = unitsize;
                _root.attachMovie("piece", "current3piece" + piececount, piececount * 4 + 2);
                this["current3piece" + piececount]._x = xx[2] * unitsize;
                this["current3piece" + piececount]._y = yy[2] * unitsize;
                this["current3piece" + piececount]._width = unitsize;
                this["current3piece" + piececount]._height = unitsize;
                _root.attachMovie("piece", "current4piece" + piececount, piececount * 4 + 3);
                this["current4piece" + piececount]._x = xx[3] * unitsize;
                this["current4piece" + piececount]._y = yy[3] * unitsize;
                this["current4piece" + piececount]._width = unitsize;
                this["current4piece" + piececount]._height = unitsize;
                currentpiece = _root["currentpiece" + piececount];
                currentpiece.gotoAndStop(frame);  //Changes the color of the piece to match the type.
                current2piece = _root["current2piece" + piececount];
                current2piece.gotoAndStop(frame);
                current3piece = _root["current3piece" + piececount];
                current3piece.gotoAndStop(frame);
                current4piece = _root["current4piece" + piececount];
                current4piece.gotoAndStop(frame);
                moviecliplist.push(currentpiece);  //Adds the movie clips to an array of movieclips.
                moviecliplist.push(current2piece);
                moviecliplist.push(current3piece);
                moviecliplist.push(current4piece);
        }
};
newpiece = function ()
{
        rotatedcount = 0;
        piececount++;
        var rand = (Math.floor(Math.random() * 6));  //Random number 0-6
        frame = rand + 1;
        piecetype = rand;
        if (rand == 0) //Fill the array of x and y coordinates with the piece so we can add it.
        {
                for (var i = 0; i < 4; i++)
                {
                        xx[i] = i;
                        yy[i] = 0;
                }
        }
        else if (rand == 1)  //refer to chart of pieces.
        {
                xx[0] = 0;
                yy[0] = 0;
                xx[1] = 1;
                yy[1] = 0;
                xx[2] = 2;
                yy[2] = 0;
                xx[3] = 2;
                yy[3] = 1;
        }
        else if (rand == 2)
        {
                xx[0] = 0;
                yy[0] = 0;
                xx[1] = 1;
                yy[1] = 0;
                xx[2] = 0;
                yy[2] = 1;
                xx[3] = 2;
                yy[3] = 0;
        }
        else if (rand == 3)
        {
                xx[0] = 0;
                yy[0] = 0;
                xx[1] = 0;
                yy[1] = 1;
                xx[2] = 1;
                yy[2] = 1;
                xx[3] = 1;
                yy[3] = 0;
        }
        else if (rand == 4)
        {
                xx[0] = 0;
                yy[0] = 1;
                xx[1] = 1;
                yy[1] = 1;
                xx[2] = 1;
                yy[2] = 0;
                xx[3] = 2;
                yy[3] = 0;
        }
        else if (rand == 5)
        {
                xx[0] = 0;
                yy[0] = 0;
                xx[1] = 1;
                yy[1] = 0;
                xx[2] = 1;
                yy[2] = 1;
                xx[3] = 2;
                yy[3] = 1;
        }
        else if (rand == 6)
        {
                xx[0] = 0;
                yy[0] = 0;
                xx[1] = 1;
                yy[1] = 0;
                xx[2] = 1;
                yy[2] = 1;
                xx[3] = 2;
                yy[3] = 0;
        }
        newpieceattach(); //add the new piece
};
_root.onEnterFrame = function()
{
        framecount++;
        current4piece._y = (yy[3] - 1) * unitsize;
        current3piece._y = (yy[2] - 1) * unitsize;
        current2piece._y = (yy[1] - 1) * unitsize;
        currentpiece._y = (yy[0] - 1) * unitsize;
        if (Key.isDown(Key.DOWN) && !paused)  //Increases speed when DOWN key is pressed.
        {
                score += level;
                speed = 1;
        }
        else
        {
                speed = levelspeed;
        }
        if (framecount % speed == 0)
        {
                if (!paused)
                {
                        if (unitmap[xx[0]][yy[0] + 1] == undefined && unitmap[xx[1]][yy[1] + 1] == undefined && unitmap[xx[2]][yy[2] + 1] == undefined && unitmap[xx[3]][yy[3] + 1] == undefined) //If the piece does not hit anything below it, move it down.
                        {
                                current4piece._y = yy[3] * unitsize;
                                current3piece._y = yy[2] * unitsize;
                                current2piece._y = yy[1] * unitsize;
                                currentpiece._y = yy[0] * unitsize;
                                for (var i = 0; i < 4; i++)
                                {
                                        yy[i]++;
                                }
                        }
                        else //If the piece hits something below it, stop moving it and create a new piece.
                        {
                                unitmap[xx[0]][yy[0]] = currentpiece;
                                unitmap[xx[1]][yy[1]] = current2piece;
                                unitmap[xx[2]][yy[2]] = current3piece;
                                unitmap[xx[3]][yy[3]] = current4piece;
                                newpiece();
                                framecount = 7;
                        }
                }
        }
};

Angehängte Dateien:
Adobe Flash Animationen LG-Tetris 02.swf5.33 KB
Geändert von HFJuli am 24.05.09 um 14:38 Uhr

 02.02.2010, 10:03Re8
Beiträge: 1
Registriert: Feb 2010

Vielen Dank. Super sache
 
Themen
Ähnliche Beiträge zum Thema
 

AntwortenRegistrieren Seite1  

Schnellantwort

Du musst registriert sein, um diese Funktion nutzen zu können.
Partner Webseiten: DesignerInAction.de   Designnation.de   Mediengestalter.info   php-resource.de   phpforum.de   phpwelt.de   Pixelio.de   PSD-Tutorials.de   Tutorials.de

Haftungsausschluss   Datenschutzerklärung   Hier Werben   Impressum
© 1999-2012 Sebastian Wichmann - Flashhilfe.de