View Single Post
  #1  
Old 02-03-2010, 10:21 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Movement/Wall Detection for Variable sizes

A small script I threw together to show how you can create a movement system with various speeds(without skipping over walls), and more importantly: various sizes. This means you can shrink your player down to 1 tile and squeeze through cracks, or apply a better wall detection to larger players. What it is lacking is detail to anything else but those two things. It initially started as an experiment with onwall2 for a solid wall detection(instead of lots of onwall()'s), and I decided to add size support later. Lacks important things like sliding around corners, but that's not what this is focused on.

PHP Code:
function onCreated() {
  
clientr.movementSpeed .5;
  
clientr.movementSize 2;
}
//#CLIENTSIDE
function onCreated() {
  
showstats(1024);
  
disabledefmovement();
  
clientr.movementSpeed .5;
  
clientr.movementSize 2;
  
player.int(player.x)+.5;
  
player.int(player.y);

  
setTimer(0.05);
}

function 
onTimeout() {
  
temp.speed clientr.movementSpeed;
  
temp.size clientr.movementSize;
  
player.zoom size/2;
  for (
temp.k=0;k<4;k++) {
    if (
keydown(k)) {
      
player.dir k;

      
temp.cx = (player.x+.5)-((size 2)/2);
      
temp.cy = (player.y+1)-((size 2)/2);

      
temp.horizontalwall onwall2(cx vecx(k)*speed,cy,size-1/16,size-1/16);
      
temp.verticalwall onwall2(cx,cy vecy(k)*speed,size-1/16,size-1/16);

      if (
horizontalwall == 0player.+= vecx(k)*speed;
      else {
        for (
i=0;i<(speed client.size speed size);i+=1/16) {
          if (
onwall2(cx+vecx(k)*i,cy,size-1/16,size-1/16)) {
            
player.+= vecx(k)*i;
            
player.int(playerx+((size%== 1)*.5))+((size%== 0)*.5);
            break;
          }
        }
      }
      if (
verticalwall == 0player.+= vecy(k)*speed;
      else {
        for (
i=0;i<(speed size speed size);i+=1/16) {
          if (
onwall2(cx,cy+vecy(k)*i,size-1/16,size-1/16)) {
            
player.+= vecy(k)*i;
            
player.int(playery+((size%== 0)*.5))+((size%== 1)*.5);
            break;
          }
        }
      }
    }
  }
  
showpoly 200,{
    (
player.x+.5)-((size 2)/2),(player.y+1)-((size 2)/2),
    (
player.x+.5)-((size 2)/2)+size,(player.y+1)-((size-2)/2),
    (
player.x+.5)-((size 2)/2)+size,(player.y+1)-((size-2)/2)+size,
    (
player.x+.5)-((size 2)/2),(player.y+1)-((size 2)/2)+size,
    (
player.x+.5)-((size 2)/2),(player.y+1)-((size 2)/2),
    (
player.x+.5)-((size 2)/2),(player.y+1)-((size 2)/2)+(1/16),
    (
player.x+.5)-((size 2)/2)+size-(1/16),(player.y+1)-((size 2)/2)+(1/16),
    (
player.x+.5)-((size 2)/2)+size-(1/16),(player.y+1)-((size 2)/2)+size-(1/16),
    (
player.x+.5)-((size 2)/2)+(1/16),(player.y+1)-((size 2)/2)+size-(1/16),
    (
player.x+.5)-((size 2)/2)+(1/16),(player.y+1)-((size 2)/2)+(1/16)
  };
  
setTimer(0.05);
}

function 
onPlayerChats() {
  if (
player.chat.starts("size")) {
    
temp.newsize player.chat.substring(5);
    if (
newsize >= && newsize <= 20clientr.movementSize newsize;
    else if (
newsize 20player.chat "Seriously, are you nuts?";
    else 
player.chat "Not a compatible size!";
  } else if (
player.chat.starts("speed")) {
    
temp.newspeed player.chat.substring(6);
    if (
newspeed 0clientr.movementSpeed newspeed;
  }

Video as soon as I can get it uploaded without my internet timing out.
Attached Thumbnails
Click image for larger version

Name:	graal_1265184469.png
Views:	298
Size:	8.2 KB
ID:	50361   Click image for larger version

Name:	graal_1265184454.png
Views:	338
Size:	6.8 KB
ID:	50362   Click image for larger version

Name:	graal_1265184445.png
Views:	330
Size:	6.6 KB
ID:	50363  

Last edited by DustyPorViva; 02-04-2010 at 08:00 AM..
Reply With Quote