Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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:	211
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
 

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:31 AM.


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