function jeep_moving()
{
VECTOR jeep_speed;
var keys_pressed;
VECTOR temp; // temp 1 is what the gun faces
VECTOR paneldirection;
VECTOR temp2; //temp 2 is what the bullet faces
VECTOR missile;
VECTOR temp3;
jeep_pan.center_x = jeep_pan.size_x * 0.5; // set the rotation point at the center of the panel
jeep_pan.center_y = jeep_pan.size_y * 0.5;
turret_pan.center_x = turret_pan.size_x * 0.5; // set the rotation center at the panel center
turret_pan.center_y = turret_pan.size_y * 0.5;
while (1)
{
vec_set(temp, turret_pan.pos_x);
vec_add(temp, turret_pan.center_x);
vec_sub(temp, mouse_cursor.x);
//bullet stuff here
if (!player_bullet)
{
vec_set(temp2, turret_pan.pos_x);
vec_add(temp2, turret_pan.center_x);
vec_sub(temp2, mouse_cursor.x);
vec_normalize(temp2, 1);
vec_set(paneldirection, temp2);
}
// ///////////////
vec_to_angle(temp,temp);
turret_pan.angle = 90-temp.x;
jeep_speed.x = 20 * (key_d - key_a) * time_step; // MOVEMENT! <----------------------------------
jeep_speed.y = 20 * (key_s - key_w) * time_step;
jeep_pan.pos_x += jeep_speed.x;
jeep_pan.pos_y += jeep_speed.y;
turret_pan.pos_x = jeep_pan.pos_x +20;
turret_pan.pos_y = jeep_pan.pos_y -10;
keys_pressed = 0;
if (key_d) keys_pressed += 1;
if (key_a) keys_pressed += 2;
if (key_s) keys_pressed += 4;
if (key_w) keys_pressed += 8;
if (keys_pressed == 1) // only the cursor right key is pressed?
{
jeep_pan.angle = 180;
}
if (keys_pressed == 2) // only the cursor left key is pressed?
{
jeep_pan.angle = 0;
}
if (keys_pressed == 4) // only the cursor down key is pressed?
{
jeep_pan.angle = 90;
}
if (keys_pressed == 8) // only the cursor up key is pressed?
{
jeep_pan.angle = 270;
}
if (keys_pressed == 5) // the right and down keys are pressed?
{
jeep_pan.angle = 135;
}
if (keys_pressed == 6) // the left and down keys are pressed?
{
jeep_pan.angle = 45;
}
if (keys_pressed == 9) // the right and up keys are pressed?
{
jeep_pan.angle = 225;
}
if (keys_pressed == 10) // the left and up keys are pressed?
{
jeep_pan.angle = 315;
}
jeep_pan.pos_x = clamp(jeep_pan.pos_x, 12, 760); // CLAMPS THE TANK SPRITE, CO-ORDINATES ARE SET TO THE BOUNDARY OF THE SCREEN
jeep_pan.pos_y = clamp(jeep_pan.pos_y, 11, 442);
if ((mouse_left) && (!player_bullet_pan))
{
player_bullet_pan = pan_create("bmap = bullet.bmp;", 35); // then create player's bullet panel
player_bullet_pan.pos_x = turret_pan.pos_x;
player_bullet_pan.pos_y = turret_pan.pos_y;
player_bullet_pan.angle = 90-temp.x;
player_bullet_pan.layer = 1;
player_bullet_pan.flags |= VISIBLE | OVERLAY;
player_bullet_pan.center_x = player_bullet_pan.size_x * 0.5;
player_bullet_pan.center_y = player_bullet_pan.size_y * 0.5;
}
if(player_bullet_pan)
{ if (player_bullet_pan.pos_x < 760)
{
player_bullet_pan.pos_x = paneldirection.x + 5;
}
else // the bullet has reached the side of the screen?
{
kill_bullet();
}
}
// //// PLAYER MISSILE MOVING CODE HERE //// //
/*
if (player_bullet_pan) // the bullet exists?
{ if (player_bullet_pan.pos_x < 760)
{
player_bullet_pan.pos_x -= 25 * paneldirection.x * time_step; // Move bullet in the direction the gun is facing
player_bullet_pan.pos_y -= 25 * paneldirection.y * time_step;
}
else // the bullet has reached the side of the screen?
{
// kill_bullet();
}
}
if (player_bullet_pan) // the bullet exists?
{
if (player_bullet_pan.pos_x > -10)
{
} // No need for the speed/direction declaration here as it's already declared above
else
{
// kill_bullet();
}
}
if (player_bullet_pan) // the bullet exists?
{
if (player_bullet_pan.pos_y > -10)
{
}
else
{
// kill_bullet();
}
}
if (player_bullet_pan) // the bullet exists?
{
if (player_bullet_pan.pos_y < 442)
{
}
else // the bullet has reached the top of the screen?
{
// kill_bullet();
}
}
//end of moving code
*/
wait(1);
}
}
I have commented the stuff that uses paneldirection out, it is exactly what I had used before - SORRY FOR MESSY TEXT
haha