Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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.x = int(player.x)+.5;
  
player.y = 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 == 0) player.x += 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.x += vecx(k)*i;
            
player.x = int(playerx+((size%2 == 1)*.5))+((size%2 == 0)*.5);
            break;
          }
        }
      }
      if (
verticalwall == 0) player.y += 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.y += vecy(k)*i;
            
player.y = int(playery+((size%2 == 0)*.5))+((size%2 == 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 >= 1 && newsize <= 20) clientr.movementSize = newsize;
    else if (
newsize > 20) player.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 > 0) clientr.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
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:10 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.