Okay sorry if this is the wrong forum (:x ), I need some help with a game.I can’t get it to go to the next level.All I want is for all actions to stop and for some text to pop up that you can click to go to the next level (im making each level a scene) I know how to do this but I have no ide awere to put it.Heres the code.
_root.next1_btn._visible = false;
layout = new Array();
layout[0] = ([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
layout[1] = ([1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
layout[2] = ([1, 0, 0, 0, 0, 0, 2, 2, 0, 0, 2, 1, 0, 2, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 1]);
layout[3] = ([1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 1]);
layout[4] = ([4, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
layout[5] = ([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
enemies = new Array([3, 1]);
view = new Array([1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]);
xmax = layout[0].length;
ymax = layout.length;
function makeBoxes() {
totalmoney = 0;
createEmptyMovieClip('boxes', 0);
boxes._x = 275-((layout[0].length*20)/2);
boxes._y = 10;
with (boxes) {
for (i=0; i<ymax; i++) {
for (j=0; j<xmax; j++) {
attachMovie('box', 'b'+i+'_'+j, (i*(xmax+1)+j));
boxes['b'+i+'_'+j]._x = (boxes['b'+i+'_'+j]._width/2)+(boxes['b'+i+'_'+j]._width*j);
boxes['b'+i+'_'+j]._y = (boxes['b'+i+'_'+j]._height/2)+(boxes['b'+i+'_'+j]._height*i);
boxes['b'+i+'_'+j].gotoAndStop((layout*[j])+1);
}
}
}
}
function attachMan(x, y) {
boxes.attachMovie('man', 'man', 800);
boxes.man._x = 10+(x*29);
boxes.man._y = 10+(y*3);
boxes.man.health = 100;
boxes.man.money = 0;
boxes.man.onEnterFrame = function() {
this.gotoAndStop(_root.mov);
};
}
function attachEnemies() {
for (i=0; i<enemies.length; i++) {
boxes.attachMovie('enemy', 'enemy'+i, 810+i);
boxes['enemy'+i]._x = 10+(enemies*[1]*20);
boxes['enemy'+i]._y = 10+(enemies*[0]*20);
boxes['enemy'+i].speed = 1;
boxes['enemy'+i].shooting = false;
boxes['enemy'+i].viewlimit = 15;
boxes['enemy'+i].onEnterFrame = function() {
if (this._currentframe == 1) {
checkForEnemy(this);
} else {
}
};
}
}
function enemyMove() {
clearBoxes();
for (p=0; p<enemies.length; p++) {
if (boxes['enemy'+p]._currentframe == 1) {
j = Math.round(Math.random()*(boxes['enemy'+p].moveable.length-1));
boxes['enemy'+p]._x = (boxes['enemy'+p].moveable[j][1]*20)+10;
boxes['enemy'+p]._y = (boxes['enemy'+p].moveable[j][0]*20)+10;
enemyBrain(boxes['enemy'+p]);
} else {
}
}
}
function clearBoxes() {
for (n=0; n<ymax; n++) {
for (m=0; m<xmax; m++) {
if (boxes['b'+n+'_'+m]._alpha == 50) {
boxes['b'+n+'_'+m]._alpha = 100;
}
}
}
}
function enemyBrain(a) {
a.sight = new Array();
a.moving = new Array([1, 0], [0, 1], [-1, 0], [0, -1]);
a.moveable = new Array();
a.view = _root.view;
a.boxes = a._parent;
a.xpos = Math.round((a._x-(a._width/2))/20);
a.ypos = Math.round((a._y-(a._height/2))/20);
for (k=0; k<a.moving.length; k++) {
if (boxes['b'+(a.ypos+a.moving[k][0])+'_'+(a.xpos+a.moving[k][1])]._currentframe == 1) {
a.moveable.push([(a.ypos+a.moving[k][0]), (a.xpos+a.moving[k][1])]);
}
}
for (i=0; i<a.view.length; i++) {
for (j=1; j<a.viewlimit; j++) {
if (boxes['b'+(a.ypos+(a.view*[0]*j))+'_'+(a.xpos+(a.view*[1]*j))]._currentframe == 2) {
break;
} else {
a.sight.push([(a.ypos+(a.view*[0]*j)), (a.xpos+(a.view*[1]*j))]);
// boxes['b'+(a.ypos+(a.view*[0]*j))+'_'+(a.xpos+(a.view*[1]*j))]._alpha = 50;
}
}
}
}
function checkForEnemy(z) {
z.man = z._parent.man;
z.manxright = Math.round((z.man._x-(z.man._width/2))/20);
z.manxleft = Math.round((z.man._x-15)/20);
z.manybottom = Math.round((z.man._y-15)/20);
z.manytop = Math.round((z.man._y-(z.man._height/2))/20);
for (u=0; u<z.sight.length; u++) {
if (z.manxleft == z.sight[u][1] or z.manxright == z.sight[u][1]) {
if (z.manytop == z.sight[u][0] or z.manybottom == z.sight[u][0]) {
shootEnemy(z, z.sight[u][0], z.sight[u][1]);
}
}
}
}
function shootEnemy(q, r, s) {
if (!q.shooting) {
q.shooting = true;
q.hitman = false;
boxes.attachMovie('Ebullet', 'Ebullet'+g, 1000+g);
boxes['Ebullet'+g]._x = q._x;
boxes['Ebullet'+g]._y = q._y;
boxes['Ebullet'+g].difx = s-q.xpos;
boxes['Ebullet'+g].dify = r-q.ypos;
boxes['Ebullet'+g].absdifx = Math.abs(s-q.xpos);
boxes['Ebullet'+g].absdify = Math.abs(r-q.ypos);
boxes['Ebullet'+g].bulldirx = (boxes['Ebullet'+g].difx/boxes['Ebullet'+g].absdifx);
boxes['Ebullet'+g].bulldiry = (boxes['Ebullet'+g].dify/boxes['Ebullet'+g].absdify);
boxes['Ebullet'+g].onEnterFrame = function() {
this._x += 10*this.bulldirx;
this._y += 10*this.bulldiry;
tempo = (this._x-10)/20;
tempk = (this._y-10)/20;
if (boxes['b'+Math.round(tempk)+'_'+Math.round(tempo)]._currentframe == 2) {
this.removeMovieClip();
q.shooting = false;
// bullet -= 1;
} else if (this._x<0 or this._x>boxes._width or this._y<0 or this._y>boxes._height) {
this.removeMovieClip();
q.shooting = false;
// bullet -= 1;
}
if (this.hitTest(q.man)) {
this.removeMovieClip();
q.shooting = false;
q.man.health -= 10;
if (q.man.health>0) {
q.man._alpha = q.man.health;
} else {
q.man._alpha = q.man.health;
health.text = q.man.health;
q.man.removeMovieClip();
gameOver('lose');
}
}
};
g++;
}
}
function shoot() {
attachMovie('bullet', 'bullet'+depth, buldepth);
buldepth++;
bullet++;
_root['bullet'+depth]._x = boxes.man._x+boxes._x;
_root['bullet'+depth]._y = boxes.man._y+boxes._y;
if (motion.length == 0) {
_root['bullet'+depth].dirx = dirx;
_root['bullet'+depth].diry = diry;
} else {
_root['bullet'+depth].dirx = motion[0][2];
_root['bullet'+depth].diry = motion[0][3];
}
_root['bullet'+depth].onEnterFrame = function() {
for (f=0; f<enemies.length; f++) {
if (this.hitTest(_root.boxes['enemy'+f])) {
this.removeMovieClip();
bullet--;
_root.boxes['enemy'+f].play();
}
}
this._x += this.dirx;
this._y += this.diry;
tempo = ((this._x-10)-boxes._x)/20;
tempk = ((this._y-10)-boxes._y)/20;
if (boxes['b'+Math.round(tempk)+'_'+Math.round(tempo)]._currentframe == 2) {
this.removeMovieClip();
bullet--;
} else if (this._x<0 or this._x>boxes._width or this._y<0 or this._y>boxes._height) {
this.removeMovieClip();
bullet--;
}
};
depth++;
}
function movement() {
motion = new Array();
mcl = new Object();
mcl.onKeyDown = function() {
if (Key.getCode() == 90) {
if (boxes.man.health>0) {
if (shootup) {
shootup = false;
if (bullet<3) {
shoot();
}
}
}
}
if (Key.getCode() == 37) {
if (!lpressed) {
lpressed = true;
l = motion.length;
motion[l] = ['x', -1, -8, 0];
}
} else if (Key.getCode() == 38) {
if (!upressed) {
upressed = true;
u = motion.length;
motion[u] = ['y', -1, 0, -8];
}
} else if (Key.getCode() == 39) {
if (!rpressed) {
rpressed = true;
r = motion.length;
motion[r] = ['x', 1, 8, 0];
}
} else if (Key.getCode() == 40) {
if (!dpressed) {
dpressed = true;
d = motion.length;
motion[d] = ['y', 1, 0, 8];
}
}
};
mcl.onKeyUp = function() {
if (Key.getCode() == 90) {
shootup = true;
}
if (Key.getCode() == 37) {
for (z=0; z<motion.length; z++) {
if (motion[z][0] == 'x' and motion[z][1] == -1) {
dirx = motion[z][2];
diry = motion[z][3];
motion.splice(z, 1);
lpressed = false;
}
}
} else if (Key.getCode() == 38) {
for (z=0; z<motion.length; z++) {
if (motion[z][0] == 'y' and motion[z][1] == -1) {
dirx = motion[z][2];
diry = motion[z][3];
motion.splice(z, 1);
upressed = false;
}
}
} else if (Key.getCode() == 39) {
for (z=0; z<motion.length; z++) {
if (motion[z][0] == 'x' and motion[z][1] == 1) {
dirx = motion[z][2];
diry = motion[z][3];
motion.splice(z, 1);
rpressed = false;
}
}
} else if (Key.getCode() == 40) {
for (z=0; z<motion.length; z++) {
if (motion[z][0] == 'y' and motion[z][1] == 1) {
dirx = motion[z][2];
diry = motion[z][3];
motion.splice(z, 1);
dpressed = false;
}
}
}
};
Key.addListener(mcl);
onEnterFrame = function () {
moveOn(motion[0][0], motion[0][1]);
};
}
function moveOn(a, b) {
if (a == 'x' and b == 1) {
for (l=-1; l<3; l += 2) {
tempp = boxes.man._x+(boxes.man._width/2)+speed;
tempo = (tempp-(boxes.man._width))/(boxes.man._width*2);
templ = boxes.man._y+((boxes.man._height/2)*l);
tempk = (templ-(boxes.man._height))/(boxes.man._height*2);
if (boxes['b'+Math.round(tempk)+'_'+Math.round(tempo)]._currentframe == 2 or boxes['b'+Math.round(tempk)+'_'+Math.round(tempo)]._currentframe == 5) {
right++;
}
}
if (right != 0) {
} else {
boxes.man._x += speed*b;
left = 0;
up = 0;
down = 0;
mov = 1;
}
} else if (a == 'x' and b == -1) {
for (l=-1; l<3; l += 2) {
tempp = boxes.man._x-(boxes.man._width/2)-speed;
tempo = (tempp-(boxes.man._width))/(boxes.man._width*2);
templ = boxes.man._y+((boxes.man._height/2)*l);
tempk = (templ-(boxes.man._height))/(boxes.man._height*2);
if (boxes['b'+Math.round(tempk)+'_'+Math.round(tempo)]._currentframe == 2 or boxes['b'+Math.round(tempk)+'_'+Math.round(tempo)]._currentframe == 5) {
left++;
}
}
if (left != 0) {
} else {
boxes.man._x += speed*b;
right = 0;
up = 0;
down = 0;
mov = 3;
}
} else if (a == 'y' and b == 1) {
for (l=-1; l<3; l += 2) {
tempp = boxes.man._x+((boxes.man._width/2)*l);
tempo = (tempp-(boxes.man._width))/(boxes.man._width*2);
templ = boxes.man._y+(boxes.man._height/2)+speed;
tempk = (templ-(boxes.man._height))/(boxes.man._height*2);
if (boxes['b'+Math.round(tempk)+'_'+Math.round(tempo)]._currentframe == 2 or boxes['b'+Math.round(tempk)+'_'+Math.round(tempo)]._currentframe == 5) {
down++;
}
}
if (down != 0) {
} else {
boxes.man._y += speed*b;
left = 0;
up = 0;
right = 0;
mov = 2;
}
} else if (a == 'y' and b == -1) {
for (l=-1; l<3; l += 2) {
tempp = boxes.man._x+((boxes.man._width/2)*l);
tempo = (tempp-(boxes.man._width))/(boxes.man._width*2);
templ = boxes.man._y-(boxes.man._height/2)-speed;
tempk = (templ-(boxes.man._height))/(boxes.man._height*2);
if (boxes['b'+Math.round(tempk)+'_'+Math.round(tempo)]._currentframe == 2 or boxes['b'+Math.round(tempk)+'_'+Math.round(tempo)]._currentframe == 5) {
up++;
}
}
if (up != 0) {
} else {
boxes.man._y += speed*b;
left = 0;
down = 0;
right = 0;
mov = 4;
}
}
}
function gameOver(x) {
clearInterval(muh);
if (x == 'win'){
output.text = "you win!!";
boxes.man.removeMovieClip();
} else {
output.text = "mission failed - game over";
}
}
dis1.text = 'health';
dis2.text = 'files';
mov = 1;
g = 1;
dirx = 8;
diry = 0;
depth = 1;
buldepth = 900;
bullet = 0;
speed = 4;
right = 0;
left = 0;
up = 0;
down = 0;
lpressed = false;
rpressed = false;
upressed = false;
dpressed = false;
shootup = true;
setVars();
movement();
makeBoxes();
attachMan(16, 11);
attachEnemies();
if (enemies.length>0) {
for (p=0; p<enemies.length; p++) {
enemyBrain(boxes['enemy'+p]);
}
muh = setInterval(enemyMove, 1000);
}