Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-23-2011, 08:02 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Virtual Joystick

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);

Attached Thumbnails
Click image for larger version

Name:	Example.png
Views:	130
Size:	14.2 KB
ID:	53997  
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 11-23-2011 at 08:14 AM..
Reply With Quote
  #2  
Old 11-23-2011, 08:34 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
There's a difference between a joystick and a dpad.
Reply With Quote
  #3  
Old 11-23-2011, 08:47 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #4  
Old 11-23-2011, 06:57 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
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.

__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #5  
Old 11-23-2011, 07:41 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
wow no gs1?
__________________
Reply With Quote
  #6  
Old 11-23-2011, 08:10 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by xAndrewx View Post
wow no gs1?
Why do you want GS1 in it?
__________________
MEEP!
Reply With Quote
  #7  
Old 11-23-2011, 11:07 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
-_-
I don't script in GS1 Andrew.

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

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #8  
Old 11-24-2011, 12:04 AM
iBeatz iBeatz is offline
Kavan
iBeatz's Avatar
Join Date: Dec 2010
Location: Northern Ireland, UK
Posts: 154
iBeatz will become famous soon enough
Send a message via Yahoo to iBeatz
Quote:
Originally Posted by callimuc View Post
Why do you want GS1 in it?
He's making fun of him. LOL
__________________

Intelligence without ambition is like a bird without wings.

Reply With Quote
  #9  
Old 11-24-2011, 12:14 AM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Lol
Attached Thumbnails
Click image for larger version

Name:	gs1.png
Views:	109
Size:	15.6 KB
ID:	54007  
__________________
Reply With Quote
  #10  
Old 11-24-2011, 12:15 AM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Oh xD
__________________
MEEP!
Reply With Quote
  #11  
Old 11-24-2011, 12:37 AM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
Quote:
Originally Posted by Gunderak View Post
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.
__________________
Reply With Quote
Reply


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 02:51 PM.


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