Oh I see, your building up from a point.
Go 1 from X, Y to X, Y
Go 2 from X, Y to X, Y
Go 2 from X, Y to X, Y
etc
So each time the actual calculation is done from the same origin but the resulting value gets bigger and, more impotently, evenly on the X and Y. Yes that is a good idea because it would be very precise.
N, as you have labeled, is the characters movement speed (I think), which in my game will be something which develops with use and will therefore be in flux (i.e. the more running the character does, the faster and longer they can actually run).
In your last for loop, N is the characters speed and step is how many irritations of the characters speed is required to traverse the distance, right?
X1/Y1 is the origin point, step is the distance traversed measured in character speed and the slope indicates the direction(?).
...I'm just trying to work out how the for loop plugs into the coordinate redefinition of the character.
The Slope values multiplied by 10 and then put though:
//if ( dbSpriteX ( 1 ) > dbSpriteX ( 2 ) ) { dbSprite ( 2, dbSpriteX ( 2 )+Four, dbSpriteY ( 2 ), 2 ) ; }
//if ( dbSpriteX ( 1 ) < dbSpriteX ( 2 ) ) { dbSprite ( 2, dbSpriteX ( 2 )-Four, dbSpriteY ( 2 ), 2 ) ; }
//if ( dbSpriteY ( 1 ) > dbSpriteY ( 2 ) ) { dbSprite ( 2, dbSpriteX ( 2 ), dbSpriteY ( 2 )+Five, 2 ) ; }
//if ( dbSpriteY ( 1 ) < dbSpriteY ( 2 ) ) { dbSprite ( 2, dbSpriteX ( 2 ), dbSpriteY ( 2 )-Five, 2 ) ; }
Results in the same inaccurate method as before so I am guessing the accuracy of your algorithm comes from the for loop.
If you could explain how it's resultant values could be added to or moved from the sprites actual position so I can define it that would be helpful.
If it helps, here is my entire code so far is nothing but a load of functions in a prototype program that will later be compressed into classes and what have you. I must remember to post this stuff in the code base and that if I can get it working because doubtless people could use it in other games; the click movement function is present in most RTS games after all.
#include "DarkGDK.h"
#include <stdio.h>
#include <math.h>
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
// Window Setting
dbMaximizeWindow ( ) ;
dbSetWindowOff ( ) ;
dbSetDisplayMode ( 1680, 1050, 32 ) ;
// Transparency and Background
dbSetImageColorKey ( 0, 255, 255 ) ; // Non-render color.
dbCLS ( dbRGB ( 255, 255, 255 ) ) ;
// Global Varibles
float One = 0.0f, Two = 0.0f, Three = 0.0f, Four = 0.0f, Five = 0.0f ;
int CikMovChk = 0 ;
// Load the character image
dbLoadImage ( "Blank.bmp", 1 ) ;
dbLoadImage ( "Mage.bmp" , 2 ) ;
// Make the click move cursor sprite
dbSprite ( 1, dbScreenWidth ( )/2, dbScreenHeight ( )/2, 1 ) ;
dbSprite ( 2, dbScreenWidth ( )/2, dbScreenHeight ( )/2, 2 ) ;
dbOffsetSprite ( 2, dbSpriteWidth ( 2 )/2, dbSpriteHeight ( 2 )/2 ) ;
while ( LoopGDK ( ) )
{
// Clear background
dbCLS ( dbRGB ( 255, 255, 255 ) ) ;
// Click Move Cursor Sprite Placement
if ( dbMouseClick ( ) == 1 )
{
dbSprite ( 1, dbMouseX ( ), dbMouseY ( ), 1 ) ;
}
//int dx = x2 - x1; // how many x points
//int dy = y2 - y1; // how many y points
//int maxpoints = max(dx, dy); // which is the larger number
One = ( (dbSpriteX ( 1 )>dbSpriteX ( 2 ))?dbSpriteX ( 1 ):dbSpriteX ( 2 ) ) - ( (dbSpriteX ( 1 )<dbSpriteX ( 2 ))?dbSpriteX ( 1 ):dbSpriteX ( 2 ) ) ; // Distence X
Two = ( (dbSpriteY ( 1 )>dbSpriteY ( 2 ))?dbSpriteY ( 1 ):dbSpriteY ( 2 ) ) - ( (dbSpriteY ( 1 )<dbSpriteY ( 2 ))?dbSpriteY ( 1 ):dbSpriteY ( 2 ) ) ; // Distence Y
Three = ( (One>Two)?One:Two ) ; // Heightest between X and Y
// float xSlope = (float) dx/ (float) maxpoints;
// float ySlope = (float) dy/ (float) maxpoints;
Four = One / ( Three * 10 ) ; // X Slope
Five = Two / ( Three * 10 ) ; // Y Slope
//if ( dbSpriteX ( 1 ) > dbSpriteX ( 2 ) ) { dbSprite ( 2, dbSpriteX ( 2 )+Four, dbSpriteY ( 2 ), 2 ) ; }
//if ( dbSpriteX ( 1 ) < dbSpriteX ( 2 ) ) { dbSprite ( 2, dbSpriteX ( 2 )-Four, dbSpriteY ( 2 ), 2 ) ; }
//if ( dbSpriteY ( 1 ) > dbSpriteY ( 2 ) ) { dbSprite ( 2, dbSpriteX ( 2 ), dbSpriteY ( 2 )+Five, 2 ) ; }
//if ( dbSpriteY ( 1 ) < dbSpriteY ( 2 ) ) { dbSprite ( 2, dbSpriteX ( 2 ), dbSpriteY ( 2 )-Five, 2 ) ; }
// One = (10<20)?10:20; // Lesser of two values
// Two = (10>20)?10:20; // Higher of two values
// Make the text appear a color (currently black, all 0)
dbInk ( dbRGB ( 0, 0, 0 ), dbRGB ( 0, 0, 0 ) ) ;
// Testing Varible Display Code
dbText ( 840, 525, dbStr ( dbSpriteX ( 1 ) ) ) ;
dbText ( 840, 625, dbStr ( dbSpriteY ( 1 ) ) ) ;
dbText ( 840, 725, dbStr ( dbSpriteX ( 2 ) ) ) ;
dbText ( 840, 825, dbStr ( dbSpriteY ( 2 ) ) ) ;
dbText ( 940, 525, dbStr ( One ) ) ;
dbText ( 940, 625, dbStr ( Two ) ) ;
dbText ( 940, 725, dbStr ( Three ) ) ;
dbText ( 940, 825, dbStr ( Four ) ) ;
dbText ( 940, 925, dbStr ( Five ) ) ;
// update the screen
dbSync ( );
}
// return back to windows
return;
}
The code you provided (the Min/Max) did help to compress the code I already have too, so thanks for that by the way because I didn't know about them.
EDIT: One other thing, if you use if statements instead of for loops with counters which increase each time they run and then stop when the counters full they allow operations like sync to occur while performing the same functions as for loops. Just something you may want to think about.
We are here and it is now.