![](smile.gif)
How to move a unit?
I work on a real time strategy game and i have one problem
during the development.Maybe some guys out there can help me.
I use Visual C++6 and Directx sdk 7. Of course I am using
direct draw for the graphics.The map is divided in a two
dimensional array ( [20] [20] ) and is based on tiles with
the size of 32*32 pixels.At the moment the screen is black,
there is only a grid,that means that there are no obstacles
for the unit.The start point of my unit is (0|0),top left
handcorner.I have to say that my unit has only one frame
at this time,that means that there are no animations to handle
during moving.But it is already possible to move the unit up,
down,left and right by hitting the cursor keys of my keyboard.
Now i want to move my unit from the start point to the target point,by clicking with the mouse on the desired target point.For example from point (0|0) to (10|0).I want to have it similiar to the games C&C and Warcraft II.If you can help me to solve my problem you can post a replie in this thread or send me message to Zackie62@gmx.de!
Thank you very much for your help!
Bye,
Zackie62
P.S. Sorry for my bad "English" it is not my native language
![](smile.gif)
Here is a very-very simple bit of code (*Not tested, just a pseudo code, there maybe errors, maybe not the best way to do it, and please don''t flame me for spelling errors ^^*)
if(mouse_clicked)
{
target_x = mouse_x;
target_y = mouse_y;
if(target_x < current_x)
current_x_speed = -speed;
else current_x_speed = speed;
if(target_y < current_y)
current_y_speed = -speed;
else current_y_speed = speed;
}
if(target_x != current_x)
current_x += current_x_speed;
if(target_y != current_y)
current_y += current_y_speed;
Offcourse this code doesn''t have any acceleration, deceleration, nor sprite heading adjustment. It handles just a straigt or diagonal path to the target point.
Hope that gives you some idea ^^
if(mouse_clicked)
{
target_x = mouse_x;
target_y = mouse_y;
if(target_x < current_x)
current_x_speed = -speed;
else current_x_speed = speed;
if(target_y < current_y)
current_y_speed = -speed;
else current_y_speed = speed;
}
if(target_x != current_x)
current_x += current_x_speed;
if(target_y != current_y)
current_y += current_y_speed;
Offcourse this code doesn''t have any acceleration, deceleration, nor sprite heading adjustment. It handles just a straigt or diagonal path to the target point.
Hope that gives you some idea ^^
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement