I need to cast a Float to an Integer
Obviously the Indice for an Array are Integer so I just needed to basically round the Float to the nearest integer or Trutenate(sp?) it.
Casting the way I am is just cutting the decimal off and even though it seems to be working rather well at the moment IDK if the lack of precision is going to effect me later on.
This is what I am doing, I have an ARRAY exactly the same size as the amount of Pixels on the screen. My Creature is just a single pixel but he moves as a function of his Angle.
Pseudo Code Looks like:
X as FLOAT
Y as FLOAT
function _MOVECreature( Creature Index, DISTANCE, ANGLE)
x#= oldx+ (DISTANCE* COS(ANGLE)
y#= oldy+ (DISTANCE* SIN(ANGLE)
WORLD(X#,Y#) = Creature Index <--------------- Would Cause ERROR
endfunction
The X,Y and ANGLE MUST be float else the entire function goes to royal shit, believe me I tried lol. Casting the way I am do seems to be working, I even was able to make some COS and SIN look up tables that work well enough and were able to let me get an extra 40ms - 50ms of performance per cycle out of my Engine which is pretty good considering I I am running around 1000 Creatures and the savings will go up when I run my standard 5-10k creatures.
The standard STR$ and VAL commands just are not fitting for this sort of work but making a separate Variable like this does work:
function _MOVECreature( Creature Index, DISTANCE, ANGLE)
x#= oldx+ (DISTANCE* COS(ANGLE)
y#= oldy+ (DISTANCE* SIN(ANGLE)
WX = 0: WY = 0
WX = X#
WY = Y#
WORLD( WX, WY ) = Creature Index <--------------- No ERROR, Just hoping there was a Better way since every millisecond counts.(literally I am counting every millisecond lol.
endfunction
I am basically making a small Library of 2D commands that simulate DarkBasics 3D commands such as Rotate Object, Move Object, Ray Cast, Object Collision Etc... Etc....
I need these functions to properly convert my AI program over from 3D to 2D. I believe I am finished the ground work today and Its now a matter of adding the AI LOGIC to it now. I just worry that the truncation of the Floating point is going to cause my Characters to slowly shift their position when they shouldn't in one direction or another messing my system up.
Only problem I am having is SOMEHOW the creature (X,Y) position is going out of bounds for the World X,Y grid which is not making sense why considering I have a WrapValue function that should not allow the values to go out of range so Its left me quite confused at the moment. Just don't understand how its going out of bounds when I am specifically performing a check to prevent such a thing. Decided that Its thanks Giving and I would rather be ripping into some Turkey then getting a headache from my program. So I took a break from trying to figure out how its going wrong.
Happy Thanksgiving to all my US friends,
Sphere sphere = new Sphere(0.5f);
InsanelyRedundantJava insanelyredundantjava = new InsanelyRedundantJava(Redundancy1, Redundancy2);