Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Akow), 1,365 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Ohmygosh - Need help moving a panel to the mouse please!! #262970
04/27/09 09:29
04/27/09 09:29
Joined: Nov 2008
Posts: 9
C
Couzin_Pete Offline OP
Newbie
Couzin_Pete  Offline OP
Newbie
C

Joined: Nov 2008
Posts: 9
I have managed to do this before, but for some reason I can't make it work!

Basically, a jeep moves around, a turret copies the movement (with a bit of offset to look right)

I want the 'player_bullet_pan' to move in the direction of the mouse - this uses a var called 'paneldirection' which is worked out when '!player_bullet_pan' <-(doesn't exist) IN A WHILE LOOP.

It works when i just say player_bullet_pan.x = player_bullet_pan.x +5 or something.. but not when I try anything with 'paneldirection'

It's probably something really stupid and small, but if anyone can help i'd appreciate it greatly!!

Code will be in next post!

Re: Ohmygosh - Need help moving a panel to the mouse please!! [Re: Couzin_Pete] #262971
04/27/09 09:30
04/27/09 09:30
Joined: Nov 2008
Posts: 9
C
Couzin_Pete Offline OP
Newbie
Couzin_Pete  Offline OP
Newbie
C

Joined: Nov 2008
Posts: 9

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

laugh

Re: Ohmygosh - Need help moving a panel to the mouse please!! [Re: Couzin_Pete] #263113
04/27/09 21:55
04/27/09 21:55
Joined: Nov 2008
Posts: 9
C
Couzin_Pete Offline OP
Newbie
Couzin_Pete  Offline OP
Newbie
C

Joined: Nov 2008
Posts: 9
frown

Re: Ohmygosh - Need help moving a panel to the mouse please!! [Re: Couzin_Pete] #264598
05/07/09 08:14
05/07/09 08:14
Joined: Nov 2008
Posts: 9
C
Couzin_Pete Offline OP
Newbie
Couzin_Pete  Offline OP
Newbie
C

Joined: Nov 2008
Posts: 9
Is anyone able to help me? =]

Re: Ohmygosh - Need help moving a panel to the mouse please!! [Re: Couzin_Pete] #264727
05/07/09 20:05
05/07/09 20:05
Joined: May 2008
Posts: 331
Lithuania, Vilnius
Jaxas Offline
Senior Member
Jaxas  Offline
Senior Member

Joined: May 2008
Posts: 331
Lithuania, Vilnius
so you making a game..2D? 3D? give more info..;)


The smaller the bug, the harder it is to kill.
_________________________________________
Forklift DEMO (3dgs)

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1