Post by Leif Bloomquist on Oct 24, 2006 9:45:03 GMT -5
Hey all,
I'm reasonably familiar with 6502 ML, but one big gap in my understanding is how to do floating-point math of any complexity.
For example - I have an idea for an "artillery duel"-type of game written entirely in ML. I have a pretty good idea about how I'd do every single aspect of it except calculating the bullet's trajectory.
I know exactly how I'd go about it in C. In fact, I wrote a function in about 5 minutes to do it (see below).
But I don't even know where to begin to do this in ML. Since the inputs are arbitrary, lookup tables aren't an option. And I'd prefer "sub-pixel resolution" for smooth motion. Sort of like in Robin's game "Frogs and Flies", but with an even wider input range.
I suppose I could always write just this section in C with CC65 and use it as a binary blob, but I'd like to keep it in ML for simplicity. Can anyone help?
Edit: changed to 'pre' tag
I'm reasonably familiar with 6502 ML, but one big gap in my understanding is how to do floating-point math of any complexity.
For example - I have an idea for an "artillery duel"-type of game written entirely in ML. I have a pretty good idea about how I'd do every single aspect of it except calculating the bullet's trajectory.
I know exactly how I'd go about it in C. In fact, I wrote a function in about 5 minutes to do it (see below).
But I don't even know where to begin to do this in ML. Since the inputs are arbitrary, lookup tables aren't an option. And I'd prefer "sub-pixel resolution" for smooth motion. Sort of like in Robin's game "Frogs and Flies", but with an even wider input range.
I suppose I could always write just this section in C with CC65 and use it as a binary blob, but I'd like to keep it in ML for simplicity. Can anyone help?
void main(void)
{
trajectory(0,200,45,55); //Bottom-left of screen, 45 degrees up, half power
}
void trajectory(int startx, int starty, int degrees, int speed)
{
// (TODO, check valid input)
// Current object position
float curx = (float)startx;
float cury = (float)starty;
//Object speed
float fspeed = (float)speed/100.0;
// Convert degrees input to radians
float radians = (float)degrees * PIby180;
// Break speed into component vectors
float dy =-fspeed * cos(radians); // -ve because "up" is -ve
float dx = fspeed * sin(radians);
while(1)
{
// Display on screen
plot((int)curx, (int)cury);
// Move the object
curx += dx;
cury += dy;
// TODO: Check for collision
// Check for out of screen
if ((curx > 320) || (curx < 0) || (cury > 200) || (cury < 0))
{
printf("Out of bounds!\n");
return;
}
// Simulate gravity
dy += 0.00098;
}
}
Edit: changed to 'pre' tag