4 registered members (dBc, clonman, TipmyPip, 1 invisible),
18,936
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Question
#278965
07/16/09 09:57
07/16/09 09:57
|
Joined: Jul 2009
Posts: 19 Poland
Varen
OP
Newbie
|
OP
Newbie
Joined: Jul 2009
Posts: 19
Poland
|
Hey, im amatour-programist and i still have lots of problem with programming. Pls dont tell me to "hide under the stone coz u r noob" :P My game is supposed to be 2d game, the player will control his character by clicking on the map . I hope the image explains all. I want the red spot(which is the character) to go slowly to the point clicked by player. How should i do it? THX in advance
|
|
|
Re: Question
[Re: Varen]
#279022
07/16/09 12:23
07/16/09 12:23
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Go hide under a KEYBOARD coz u r a geek noob! Serious, thats a hard question without knowing what youve done so far, how you maps are handled, ... the list goes on. All the same, in a general way, to do what you want, you need to... 1> Check if mouse was clicked, if so store the target location of the click. 2> Calculate the angle between the 'current" position and the target position. 3> Rotate the player-object to face the target. 4> Move the player-object "forward" by a fixed amount(of your choice). 5> Check if youve arrived at the target, if NOT, go back to step 1.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Question
[Re: Rei_Ayanami]
#279076
07/16/09 14:25
07/16/09 14:25
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
Expert
|
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
VECTOR newPos;
var newPosSet = OFF;
PANEL* theSpot = {
bmap = "stone.tga";
layer = 2;
flags = SHOW;
}
void set_new_pos()
{
newPos.x = mouse_pos.x; //store the current mouse position.
newPos.y = mouse_pos.y;
newPos.x -= bmap_width(theSpot.bmap)/2; //make sure the center of the player reaches the position, not the corner of the player
newPos.y -= bmap_height(theSpot.bmap)/2;
newPosSet = ON;
}
VECTOR temp;
var theSpotSpeed = 10; //play with this value
void move_to_mouse_pos()
{
VECTOR myVelocity;
vec_set(myVelocity,nullvector); //make player not move at beginning
while(1)
{
//if there's a new position: calculate the direction from my position to the new position.
if(newPosSet == ON)
{
vec_diff(myVelocity,newPos,vector(theSpot.pos_x,theSpot.pos_y,0));
newPosSet = OFF;
}
vec_set(temp,myVelocity);
vec_normalize(temp,time_step*theSpotSpeed); //pointing in the direction that I should move in, correct length
//speed*time = distance to be covered
theSpot.pos_x += temp.x; //add the to the position
theSpot.pos_y += temp.y;
if(vec_dist(vector(theSpot.pos_x,theSpot.pos_y,0),newPos) < theSpotSpeed*time_step) vec_set(myVelocity,nullvector);
wait(1);
}
}
void main()
{
//put these lines in your main function:
mouse_mode = 4;
vec_set(newPos,vector(-1,-1,0)); //new position.
on_mouse_left = set_new_pos;
move_to_mouse_pos();
}
hope this is what you're looking for. Note: there's no acceleration/breaking in there... wouldn't be hard to add though.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
|