Quote:
Originally Posted by alissalee
im trying to set a simple movement within a level area but it keeps heading up to the top of the gmap instead of staying in the level and doing the random movements.
PHP Code:
function onCreated(){
showcharacter();
setcharani ("ghostani",NULL);
dontblock();
this.speed = 8;
this.options = 8+16;
startmove();
}
function startmove() {
this.newx=random(1,63);
this.newy=random(1,63);
dx=(this.newx-x);
dy=(this.newy-y);
this.distance = ((this.newy-y)^2+(this.newx-x)^2)^.5;
this.time = (this.distance/this.speed);
move(dx,dy,this.time,this.options);
}
function onMvementFinished) {
startmove();
}
|
On GMAPs you have to take into consideration the entire width/height of the map, where 1 - 63 would always be the top left corner level.
You could try something like:
PHP Code:
function onCreated(){
temp.offx = 32 - (this.x % 64);
temp.offy = 32 - (this.y % 64);
this.centerx = this.x + temp.offx;
this.centery = this.y + temp.offy;
}
function startmove() {
this.newx = random(this.centerx - 32, this.centerx + 32);
this.newy = random(this.centery - 32, this.centery + 32);
}
There's probably a better way but this would give you a rough idea.