Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-06-2007, 08:08 AM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
Simple Movement

Here is a good way to move your object in all directions very easily.

PHP Code:
//#CLIENTSIDE  // Makes events all processed on the client comp

function onCreated()  //Action is called when script is read
{

  
disAbleDefMovement();  //Disables Default movement for player
}

function 
onKeyPressedcodechar)  //Called when ever the client pushes a key on the keyboard
{

  
code;  //make k equal the code number of what ever key is pushed

  
player.+= (( == 39) - ( == 37))/16;  //  if k equals number, it is 1, if not it is 0

  //so if the player pushes left arrow it be player.x += 0 - 1;  

  
player.+= (( == 40) - ( == 38))/16;  //same as above just on the y-axis


__________________
Deep into the Darkness peering...
Reply With Quote
  #2  
Old 10-06-2007, 08:15 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
Hmm, there's a problem with this.
One, there's no loop, you're calling it on keypressed(unless you want it to be a more systematic movement than fluid). As I believe, keypressed is called when the key is first pressed, then the repeat(which is defined personally in the keyboard properties, so this will react very slowly if the person has the key repeat very low). Also, I think it'd be better if you used keydown(0-3), they're the default keys for arrow movement, and are also compatible with gamepads.
Reply With Quote
  #3  
Old 10-06-2007, 08:21 AM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
Update


PHP Code:
//#CLIENTSIDE 

function onCreated()
{

  
disAbleDefMovement();
  
onTimeout();
}

function 
onTimeout()
{

  
player.+= (( keydown(3)) - ( keydown(1)))/16;  

  
player.+= (( keydown(2)) - ( keydown(0)))/16;  

  
setTimer0.05);

__________________
Deep into the Darkness peering...
Reply With Quote
  #4  
Old 10-06-2007, 09:14 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Do you want to add some onwall checks later? :]
Reply With Quote
  #5  
Old 10-06-2007, 10:43 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Disable is one word -.-

disableDefMovement();

instead of disAbleDefMovement();
__________________
Reply With Quote
  #6  
Old 10-06-2007, 07:18 PM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
Quote:
Originally Posted by Crow View Post
Do you want to add some onwall checks later? :]
Not, really, guess I could but I just wanted to show how to move an object.


Quote:
Originally Posted by Inverness View Post
Disable is one word -.-

disableDefMovement();

instead of disAbleDefMovement();
I know, I like to capitalize the A so i can simple delete the dis and put in the en.
__________________
Deep into the Darkness peering...
Reply With Quote
  #7  
Old 10-06-2007, 07:42 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Angel_Light View Post
I know, I like to capitalize the A so i can simple delete the dis and put in the en.
You could do that without a capital A ;P
Anyways, I think you should add the checks, just for the sake of it. May help out some peeps.
Reply With Quote
  #8  
Old 10-06-2007, 07:55 PM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
Quote:
Originally Posted by Crow View Post
You could do that without a capital A ;P
Anyways, I think you should add the checks, just for the sake of it. May help out some peeps.
It doesnt really matter how the A is...

update

PHP Code:
//#CLIENTSIDE 

function onCreated()
{

  
disAbleDefMovement();
  
onTimeout();
}

function 
onTimeout()
{
  
  
nx player.x;
  
ny player.y;

  
nx += (( keydown(3)) - ( keydown(1)))/16;  
  
ny += (( keydown(2)) - ( keydown(0)))/16;  

  if ( !( 
onwallnx 1.5ny 2)))  {

    
player.nx;
    
player.ny;
  } 

  
setTimer0.05);

__________________
Deep into the Darkness peering...

Last edited by Angel_Light; 10-06-2007 at 08:07 PM..
Reply With Quote
  #9  
Old 10-06-2007, 08:06 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
I would atleast define the middle of the player ;P

PHP Code:
if ( !( onwallnx 1.5ny 2)))  {

  
player.nx;
  
player.ny;

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 08:30 PM.


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