I am working on a "Car" for Graal Ghetto and so far all I have is the movement.
For my example I have added a block image to show the "Car".
Although the movement is working perfectly the acceleration isn't.
The problem is when accelerating if you turn it stops accelerating.
Here is what I have so far.
I am entrusting that the Graal community will NOT steal this, as I have spent about an hour and a half just getting this much.
2330 Characters long and 87 lines.
Thanks.
PHP Code:
/*
Scripted by Gunderak.
Intended to be used on Graal Ghetto and Graal Ghetto ONLY.
You may however study this and try to learn from it.
*/
//#CLIENTSIDE
function onCreated() {
//Disables default movement.
disabledefmovement();
//Speed variables
this.speed = "1";
this.leftrightspeed = "0.13";
this.movespeed = "0";
this.acceleration = "0.10";
//Begins the timeout.
onTimeout();
}
function GraalControl.onKeyDown(code) {
//If the Right-arrow key is pressed.
if (code == 37) {
//And if the car is moving.
//This makes car movements seem more realistic.
if (this.movespeed > 0) {
//Raises the angle.
this.dir += this.leftrightspeed;
}
}
//If the left-arrow key is pressed.
if (code == 39) {
//And if the car is moving.
//This makes car movements seem more realistic.
if (this.movespeed > 0) {
//Lowers the angle.
this.dir -= this.leftrightspeed;
}
}
//If the up-arrow key is released.
if(code == "38"){
//Start moving the car and begin to accelerate.
this.moving = 1;
}
}
function GraalControl.onKeyUp(code){
//If the up-arrow key is released.
if(code == 38){
//Stop moving the car and begin to decelerate.
this.moving = 0;
}
}
function onTimeout() {
//Shows a block image.
showimg(3, "block.png", player.x, player.y );
//Changes the blocks rotation to the correct angle.
findimg(3).rotation = this.dir;
findimg(3).zoom = 2;
//If the angle is less than the minimum resets it to zero.
if (this.dir < "-6.25") {
this.dir = 0;
}
//If the angle is greater than the maximum resets it to zero.
if (this.dir > "6.25") {
this.dir = 0;
}
//Just some basic Trigonometry.
//This part has been removed.
//If you really want to steal this script you will have to
//figure the sine and cosine out yourself!
//If the car isnt accelerating slowly decrease speed.
if (this.moving == 0) {
this.movespeed -= this.acceleration / 3;
} else {
if (this.movespeed < this.speed) {
this.movespeed += this.acceleration;
}
}
//If your move speed is less than zero for some reason
//It will set it back to zero.
if (this.movespeed < 0) {
this.movespeed = 0;
}
//Continues to loop through the timeout.
settimer(0.05);
}
Update
Removed the players movement seeming as it isn't necessary.
Also to make it harder for people to steal this script and actually use it.