Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Virtual Joystick (https://forums.graalonline.com/forums/showthread.php?t=134265092)

Gunderak 11-23-2011 08:02 AM

Virtual Joystick
 
1 Attachment(s)
This is just a little something I scripted up while playing around.
Note there is no wall checks as of yet.
This was just for fun.
PS: If anyone knows how to check if the mouse x and y are inside the image and not the actual box around it it'd be appreciated.
Other was the joystick isn't proper.
Attached is an image of what I mean.
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
//Sets the speed of movement.
  
this.speed 0.05;
  
//Creates the virtual joystick.
  
CreateJoystick();
  
onTimeout();
}

function 
CreateJoystick() {
  
//Shows the joystick image.
  
new GuiBitmapCtrl("Joystick_Controller") {
    
bitmap "g4_particle_bluelight.png";
    
width 70;
    
height 70;
    
alpha 0.9;
    
thiso.catchevent(this.name"onMouseDown""onMD");
    
thiso.catchevent(this.name"onMouseUp""onMU");
  }
  
//Shows a little circle at your cursors x and y.
  
new GuiBitmapCtrl("Joystick_Pointer") {
    
bitmap "g4_particle_yellowlight.png";
    
width 20;
    
height 20;
    
thiso.catchevent(this.name"onMouseUp""onMU");
    
thiso.catchevent(this.name"onMouseDown""onMD");
  }
}

//If the mouse is released outside the joystick.
function GraalControl.onMouseUp() {
  
this.mdr 0;
}

//When the mouse is pressed down on the joystick.
function onMD() {
  
//Sets the mouse moving variable to true.
  
this.mdr 1;
  
//The start mouse x so we can determine where to move the player.
  
this.sx mousescreenx;
  
//The start mouse y.
  
this.sy mousescreeny;
}

//If the mouse button is released.
function onMU() {
  
//Sets the mouse moving variable to false.
  
this.mdr 0;
}

function 
onTimeout() {
  
//If the mouse moving variable is true.
  
if (this.mdr == 1) {
    
//Show the pointer at the mouse x and y.
    
Joystick_Pointer.alpha 1;
    
//If the mouses x and y is inside the joystick.
    
if (mousescreenx in Joystick_Controller.xJoystick_Controller.70 | && mousescreeny in Joystick_Controller.yJoystick_Controller.70 | ) {
      
//Makes the pointers x and y at the mouse.
      
Joystick_Pointer.mousescreenx 10;
      
Joystick_Pointer.mousescreeny 10;
      
//Sets the movement x and y so it can determine where and how far to move the player.
      
this.mx mousescreenx this.sx;
      
this.my mousescreeny this.sy;
    }
    
//Moves the player.
    
player.+= this.mx this.speed;
    
player.+= this.my this.speed;
  } else {
    
//If the mouse moving variable is false hide the pointer.
    
Joystick_Pointer.alpha 0;
  }
  
//Ensures the joysticks x and y are always correct.
  
Joystick_Controller.10;
  
Joystick_Controller.screenheight Joystick_Controller.height 10;
  
settimer(0.05);



DustyPorViva 11-23-2011 08:34 AM

There's a difference between a joystick and a dpad.

Gunderak 11-23-2011 08:47 AM

Well this isn't quite a dpad seeming as the player goes towards the angle from the centre point of where you click and to where your mouse is.

Tolnaftate2004 11-23-2011 06:57 PM

As for your question regarding the concentric circles above, ....
PHP Code:

temp.dx mousescreenx - (Joystick_Controller.35), 
temp.dy mousescreeny - (Joystick_Controller.35);
if ((
dx^2+dy^2)^0.5 in |035|) {
  
// etc.



xAndrewx 11-23-2011 07:41 PM

wow no gs1?

callimuc 11-23-2011 08:10 PM

Quote:

Originally Posted by xAndrewx (Post 1675189)
wow no gs1?

Why do you want GS1 in it?

Gunderak 11-23-2011 11:07 PM

-_-
I don't script in GS1 Andrew.

@Tolnaftate
Thanks for the help, I'll have to test when I am home.

iBeatz 11-24-2011 12:04 AM

Quote:

Originally Posted by callimuc (Post 1675192)
Why do you want GS1 in it?

He's making fun of him. LOL

Emera 11-24-2011 12:14 AM

1 Attachment(s)
Lol

callimuc 11-24-2011 12:15 AM

Oh xD

0PiX0 11-24-2011 12:37 AM

Quote:

Originally Posted by Gunderak (Post 1675144)
PS: If anyone knows how to check if the mouse x and y are inside the image and not the actual box around it it'd be appreciated.

Check if the distance between the center of the image and the mouse position is greater than the radius of the circle.


All times are GMT +2. The time now is 07:19 AM.

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