Aargh!

beginning to question my sanity!! for some reason

the first horiz line is overlooked!! the peace stops on second line just fine(ok, at this point thought it could be logical) but it stops on the last line too(when last is only)!! i'm making no sense i know...

i'm making a tetris clone, with a 10x15 area(12x16 with borders) where i have a 2dim array area[col][row] 0=empty, 1=occupied, ok. i have a 3dim array for peaces shape[rotpos][squareno][0=x,1=y].

to complicate things im trying to make it OO. i made a rotation cw+ccw methods, a refresh, and started coding the vert movement(for this i needed a peace of code to stop my peace if encounters a "1"), but it all seems illogical now

cause it overlooks "1" in area array for first time ONLY,trace says its "0", after playing around with the area array (0,1,0,0,0,1,0,0,0,1,0,0,0,1)->(0,0,0,0,0,1,0,0,0,1,0,0,0,1)->(0,0,0,0,0,0,0,0,0,1,0,0,0,1)etc. etc. it always stops on the 2ND LINE!! OH WHY OH WHY! give me medication!!!

here's the code:

frame 1 (main stage)

area = new Array();

for (l=0; l<12; l++) {

area[l] = new Array(0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1); //1=horiz line

}

no = 50;

for (l=0; l<16; l++) {

area[0][l]="1";

area[11][l]="1";

} //vert lines

for (l=0; l<16; l++) {

line = "";

for (c=0; c<12; c++) {

line += area[c][l];

_root.attachMovie("box", ["pohja"+no], no);

if (area[c][l] == "0") {

_root["pohja"+no].gotoAndStop(5);

} else {

_root["pohja"+no].gotoAndStop(6);

}

_root["pohja"+no]._x = 50+20*c;

_root["pohja"+no]._y = 50+20*l;

no++;

}

trace (line);

}//just a visual aid

function dummyCheck () {

for (r=0; r<15; r++) {

sum = 0;

for (c=0; c<10; c++) {

if (area[c][r] != 0) {

sum++;

}

}

if (sum == 10) {

return r;

}

}

return -1;

}

scrollDown(5);

trace (dummyCheck());

function clearRow (row) {

for (c=0; c<10; c++) {

area[c][row] = 0;

}

}

clearRow(dummyCheck());

trace (dummyCheck());

function scrollDown (row) {

for (r=row; r>0; r--) {

for (c=0; c<10; c++) {

area[c][r] = area[c][r-1];

}

}

area[0] = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

}

function pala (muoto) {

this.shape = new Array();

for (s=0; s<10; s++) {

this.shape[s] = new Array();

for (s1=0; s1<10; s1++) {

this.shape[s][s1] = new Array();

}

}

if (muoto == "viiva") {

this.shape[0][0][0] = 2;

this.shape[0][0][1] = 1;

this.shape[0][1][0] = 2;

this.shape[0][1][1] = 2;

this.shape[0][2][0] = 2;

this.shape[0][2][1] = 3;

this.shape[0][3][0] = 2;

this.shape[0][3][1] = 4;

this.shape[1][0][0] = 1;

this.shape[1][0][1] = 2;

this.shape[1][1][0] = 2;

this.shape[1][1][1] = 2;

this.shape[1][2][0] = 3;

this.shape[1][2][1] = 2;

this.shape[1][3][0] = 4;

this.shape[1][3][1] = 2;

this.lngth = 2;

}

if (muoto == "s1") {

this.shape[0][0][0] = 1;

this.shape[0][0][1] = 2;

this.shape[0][1][0] = 2;

this.shape[0][1][1] = 2;

this.shape[0][2][0] = 2;

this.shape[0][2][1] = 1;

this.shape[0][3][0] = 3;

this.shape[0][3][1] = 1;

this.shape[1][0][0] = 1;

this.shape[1][0][1] = 1;

this.shape[1][1][0] = 1;

this.shape[1][1][1] = 2;

this.shape[1][2][0] = 2;

this.shape[1][2][1] = 2;

this.shape[1][3][0] = 2;

this.shape[1][3][1] = 3;

this.lngth = 2;

}

if (muoto == "s2") {

this.shape[0][0][0] = 1;

this.shape[0][0][1] = 1;

this.shape[0][1][0] = 2;

this.shape[0][1][1] = 1;

this.shape[0][2][0] = 2;

this.shape[0][2][1] = 2;

this.shape[0][3][0] = 3;

this.shape[0][3][1] = 2;

this.shape[1][0][0] = 2;

this.shape[1][0][1] = 1;

this.shape[1][1][0] = 2;

this.shape[1][1][1] = 2;

this.shape[1][2][0] = 1;

this.shape[1][2][1] = 2;

this.shape[1][3][0] = 1;

this.shape[1][3][1] = 3;

this.lngth = 2;

}

if (muoto == "nelio") {

this.shape[0][0][0] = 1;

this.shape[0][0][1] = 1;

this.shape[0][1][0] = 2;

this.shape[0][1][1] = 1;

this.shape[0][2][0] = 1;

this.shape[0][2][1] = 2;

this.shape[0][3][0] = 2;

this.shape[0][3][1] = 2;

this.lngth = 1;

}

if (muoto == "tee") {

this.shape[0][0][0] = 2;

this.shape[0][0][1] = 1;

this.shape[0][1][0] = 1;

this.shape[0][1][1] = 2;

this.shape[0][2][0] = 2;

this.shape[0][2][1] = 2;

this.shape[0][3][0] = 3;

this.shape[0][3][1] = 2;

this.shape[1][0][0] = 3;

this.shape[1][0][1] = 2;

this.shape[1][1][0] = 2;

this.shape[1][1][1] = 1;

this.shape[1][2][0] = 2;

this.shape[1][2][1] = 2;

this.shape[1][3][0] = 2;

this.shape[1][3][1] = 3;

this.shape[2][0][0] = 2;

this.shape[2][0][1] = 3;

this.shape[2][1][0] = 3;

this.shape[2][1][1] = 2;

this.shape[2][2][0] = 2;

this.shape[2][2][1] = 2;

this.shape[2][3][0] = 1;

this.shape[2][3][1] = 2;

this.shape[3][0][0] = 1;

this.shape[3][0][1] = 2;

this.shape[3][1][0] = 2;

this.shape[3][1][1] = 3;

this.shape[3][2][0] = 2;

this.shape[3][2][1] = 2;

this.shape[3][3][0] = 2;

this.shape[3][3][1] = 1;

this.lngth = 4;

}

if (muoto == "l1") {

this.shape[0][0][0] = 1;

this.shape[0][0][1] = 1;

this.shape[0][1][0] = 1;

this.shape[0][1][1] = 2;

this.shape[0][2][0] = 1;

this.shape[0][2][1] = 3;

this.shape[0][3][0] = 2;

this.shape[0][3][1] = 3;

this.shape[1][0][0] = 3;

this.shape[1][0][1] = 1;

this.shape[1][1][0] = 2;

this.shape[1][1][1] = 1;

this.shape[1][2][0] = 1;

this.shape[1][2][1] = 1;

this.shape[1][3][0] = 1;

this.shape[1][3][1] = 2;

this.shape[2][0][0] = 2;

this.shape[2][0][1] = 3;

this.shape[2][1][0] = 2;

this.shape[2][1][1] = 2;

this.shape[2][2][0] = 2;

this.shape[2][2][1] = 1;

this.shape[2][3][0] = 1;

this.shape[2][3][1] = 1;

this.shape[3][0][0] = 1;

this.shape[3][0][1] = 2;

this.shape[3][1][0] = 2;

this.shape[3][1][1] = 2;

this.shape[3][2][0] = 3;

this.shape[3][2][1] = 2;

this.shape[3][3][0] = 3;

this.shape[3][3][1] = 1;

this.lngth = 4;

}

if (muoto == "l2") {

this.shape[0][0][0] = 1;

this.shape[0][0][1] = 3;

this.shape[0][1][0] = 2;

this.shape[0][1][1] = 3;

this.shape[0][2][0] = 2;

this.shape[0][2][1] = 2;

this.shape[0][3][0] = 2;

this.shape[0][3][1] = 1;

this.shape[1][0][0] = 1;

this.shape[1][0][1] = 1;

this.shape[1][1][0] = 1;

this.shape[1][1][1] = 2;

this.shape[1][2][0] = 2;

this.shape[1][2][1] = 2;

this.shape[1][3][0] = 3;

this.shape[1][3][1] = 2;

this.shape[2][0][0] = 2;

this.shape[2][0][1] = 1;

this.shape[2][1][0] = 1;

this.shape[2][1][1] = 1;

this.shape[2][2][0] = 1;

this.shape[2][2][1] = 2;

this.shape[2][3][0] = 1;

this.shape[2][3][1] = 3;

this.shape[3][0][0] = 3;

this.shape[3][0][1] = 2;

this.shape[3][1][0] = 3;

this.shape[3][1][1] = 1;

this.shape[3][2][0] = 2;

this.shape[3][2][1] = 1;

this.shape[3][3][0] = 1;

this.shape[3][3][1] = 1;

this.lngth = 4;

}

this.dir = 0;

}

pala.prototype.rotcw = function () {

if (++this.dir == this.lngth) {

this.dir = 0;}dir = this.dir;

for (l=0; l<4; l++) {

_root["nelio"+l]._x = 50+this.X*20+this.shape[dir][l][0]*20;

_root["nelio"+l]._y = 50+this.Y*20+this.shape[dir][l][1]*20;

}

};

pala.prototype.rotccw = function () {

if (--this.dir<0) {

this.dir = this.lngth-1;

}

dir = this.dir;

for (l=0; l<4; l++) {

_root["nelio"+l]._x = 50+this.X*20+this.shape[dir][l][0]*20;

_root["nelio"+l]._y = 50+this.Y*20+this.shape[dir][l][1]*20;

}

};

pala.prototype.refresh = function () {

dir = this.dir;

for (l=0; l<4; l++) {

_root["nelio"+l]._x = 50+this.X*20+this.shape[dir][l][0]*20;

_root["nelio"+l]._y = 50+this.Y*20+this.shape[dir][l][1]*20;

}

};

pala.prototype.moveok = function (Xmov, Ymov) {

dir = this.dir;

ok = true;

for (l=0; l<4; l++) {

c=Xmov+this.X+this.shape[dir][l][0];

r=Ymov+this.Y+this.shape[dir][l][1];

if (_parent.area[c][r] == "1") ok = false;

trace(_parent.area[c][r]);

}

return ok;

}; //something wrong with this????

peace = new pala("tee");//init a peace to screen[viiva,tee,s1,s2,l1,l2,nelio]

peace.X = 0;

peace.Y = -1;

dir = 0;

for (l=0; l<4; l++) {

_root.attachMovie("box", ["nelio"+l], l+2000); //box is 6 frame mc, 20x20 square with diff. colors each frame

_root["nelio"+l].gotoAndStop(l+1);

_root["nelio"+l]._x = 50+peace.X*20+peace.shape[dir][l][0]*20;

_root["nelio"+l]._y = 50+peace.Y*20+peace.shape[dir][l][1]*20;

}

trace (viiva.lngth);

and a control mc on stage has following code:

onClipEvent(enterFrame) {

if(Key.isDown(Key.UP) ) _root.peace.rotcw();

if(Key.isDown(Key.DOWN) ) _root.peace.rotccw();

c++;

if(c==5){

c=0;

//trace(_root.peace.Y);

if(_root.peace.moveok(0,1)){

_root.peace.Y++;

_root.peace.refresh();

}

}

}

i know ill have to abstract the code more (get rid of direct references[_root] etc. ) im going to do it after i get the damn thing to work!! (movement) the worst thing is, i know flash isnt fool proof! awhile ago i made a cup game, u know under one cup is a pea or something, shuffle them fast, and u have follow the "pea"... a STRANGE bug forced me to use a "dummy" cup at one point!! After adding it (it had no reference, code, only a instace name(witch wasnt referenced) ) and the damn thing worked!! ,but help me out with this one, and ill give it to u as a gift!!! (or if u ask me nicely, lol)

Phef, in case u missed it, im tired, hope i made SOME sense, lol!

PS. all u have to do is copy/paste the code; make 1 mc 6 frames 20x20 square, diff. colors each frame, and export it in library;

S@m