G
graviax
Guest
My project is a topview action game.
The player can move freely in any direction.
I wanted to add a "speed" mode, where the player, instead of moving pending on your keyboard direction (up down left right), could move pending on the direction of the mouse.
He would be a lot faster than walk mode the counter part being that if you change direction quickly you will lose speed. the amount of speed you lose is determined by ratio :
In *theory* this should work, but angles are between 0 and 360 for the game.
It understand when you give it something above 360 or below 0 but he would change that value to something between 0 and 360.
Here's my problem, I don't know how to work with that.
If I do a comparison like that :
It would not work.
I came up with an other way to do it, but in the end I have the same issue.
here's my code (not working as intended):
the draw_set_color in the middle of the code are for debug purpose
The player can move freely in any direction.
I wanted to add a "speed" mode, where the player, instead of moving pending on your keyboard direction (up down left right), could move pending on the direction of the mouse.
He would be a lot faster than walk mode the counter part being that if you change direction quickly you will lose speed. the amount of speed you lose is determined by ratio :
Code:
acceleration = 1 / ((speed * 10) + 1);
ratio = 1 - (deltaAngle * (speed / 2 + 1) / 180);
speed += acceleration * ratio;
It understand when you give it something above 360 or below 0 but he would change that value to something between 0 and 360.
Here's my problem, I don't know how to work with that.
If I do a comparison like that :
Code:
if(mouse_angle < desired_angle)
{
do that
}
else
{
do this
}
I came up with an other way to do it, but in the end I have the same issue.
here's my code (not working as intended):
Code:
aimtab[0] = aimtab[1];
aimtab[1] = point_direction(x,y,mouse_x,mouse_y);
acc = 1/((vitesse*10)+1);
angle_direction = aimtab[0] + 180;
if(angle_direction >= 360)
{
angle_direction -= 360;
}
if(aimtab[1] > aimtab[0] && aimtab[1] < angle_direction)
{
ratio = (1 - ((aimtab[1] - aimtab[0]) * (vitesse/2+1)/180));
draw_set_color(c_black);
}
else
{
ratio = -(1 - ((aimtab[0] + (360 - aimtab[1])) * (vitesse/2+1)/180));
draw_set_color(c_white);
}
vitesse += acc * ratio;
if(vitesse > 10)
{
vitesse = 10;
}
if(vitesse < 0)
{
vitesse = 0;
}
x += lengthdir_x(vitesse,aimtab[1]);
y += lengthdir_y(vitesse,aimtab[1]);