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.x, Joystick_Controller.x + 70 | && mousescreeny in | Joystick_Controller.y, Joystick_Controller.y + 70 | ) {
//Makes the pointers x and y at the mouse.
Joystick_Pointer.x = mousescreenx - 10;
Joystick_Pointer.y = 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.x += this.mx * this.speed;
player.y += 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.x = 10;
Joystick_Controller.y = screenheight - Joystick_Controller.height - 10;
settimer(0.05);
}