Thread: simple movement
View Single Post
  #2  
Old 02-18-2012, 03:06 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by alissalee View Post
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.64);
  
temp.offy 32 - (this.64);
  
this.centerx this.temp.offx;
  
this.centery this.temp.offy;
}

function 
startmove() {
  
this.newx random(this.centerx 32this.centerx 32);
  
this.newy random(this.centery 32this.centery 32);

There's probably a better way but this would give you a rough idea.

Last edited by ffcmike; 02-18-2012 at 03:25 AM..
Reply With Quote