require some help making a random map.
1) When you click on the "Generate" button a 15x21 board of Tile symbols is created, with top-left corner at (10,10). Initially all tiles should be blank.
i need to somehow get that done.
here is my code so far, i have a lot of graphics, movie clips and a button relating to the script, although right now they are not important.
var ghosts:Array = new Array();
var timers:Array = new Array();
//======== ghosts and ghost behaviour =================//
var ghostHoriz=1;
for (var row = 0; row < 4; row++) {
var g = new Ghost();
var t:Timer=new Timer(400);
g.timer=t;
timers[row]=t;
g.horiz=ghostHoriz;
ghostHoriz*=-1;
if (row==0||row==1) {
g.vert=1;
}
else {
g.vert=-1;
}
t.addEventListener(TimerEvent.TIMER, moveGhost);
ghosts[row]=g;
g.visible=false;
addChild(g);
}
var ghostIndex=0;
function moveGhost(evt:TimerEvent) {
var t=evt.currentTarget;
var k=timers.indexOf(t);
var g=ghosts
if (g.visible) {
var r=g.row;
var c=g.col;
with (g) {
if (Math.random()<0.5) {
if (((horiz > 0 && (c+horiz)<21)||(horiz < 0 && (c+horiz)>=0)) && (map
col+=horiz;
x+=horiz*20;
map
map
}
else {
horiz*=-1;
}
}
else {
if ( (( vert > 0 && (r+vert)<15)||( vert < 0 &&(r+vert)>= 0)) && (map[r+vert]
row+=vert;
y+=vert*20;
map[r+vert]
map
}
else {
vert*=-1;
}
}
}
}
}
// ================= Button behaviour ========== //
generate_btn.addEventListener(MouseEvent.CLICK, generate);
function generate(m:MouseEvent = null) {
initMap();
ghostIndex=0;
// other stuff
displayMap();
}
var map:Array = new Array();
var tiles:Array = new Array();
function initMap(){
}
function displayMap() {
for (var row = 0; row < 15; row++) {
for (var col = 0; col < 21; col++) {
var test=map[row][col];
tiles[row][col].x=10+col*20;
tiles[row][col].y=10+row*20;
switch (test) {
case 2 :
g=ghosts[ghostIndex];
g.x=10+col*20;
g.y=10+row*20;
g.row=row;
g.col=col;
if (row==0) {
g.vert=1;
}
else {
g.vert=-1;
}
g.visible=true;
g.timer.start();
ghostIndex++;
break;
}
}
}
}
bit long 😕😕
anyway when I basically need it so when you press generate it comes up with a random, how do i put this....it comes up with a random pacman sort of design. And everytime generate is clicked it changes, anyone know anything?
also note, with the code up there, if I do click generate i get this error...
Fonts should be embedded for any text that may be edited at runtime, other than text with the "Use Device Fonts" setting. Use the Text > Font Embedding command to embed fonts.
TypeError: Error #1010: A term is undefined and has no properties.
at Pacmanscripting_fla::MainTimeline/displayMap()
at Pacmanscripting_fla::MainTimeline/generate()
thanks in advance.
