Mail Archives: djgpp/1998/03/04/03:45:27
D. Huizenga wrote:
> Why don't you post some source code? This will give us a better idea of
> what is wrong.
> --
> Dan Huizenga
Theres a fair bit of it, but heres the part that deals w/ the doubles:
// function traverses the roster and moves what needs moved
void UpdateActors (roster_t *r, BITMAP *bkGround, BITMAP *surface)
{
actor_t *p_actor = r->p_first;
int distmoved_x, distmoved_y;
while(p_actor != NULL)
{
p_actor->timesincelastmove_x += 1.0 / TICS_PER_SEC;
p_actor->timesincelastmove_y += 1.0 / TICS_PER_SEC;
distmoved_x = (int)(p_actor->timesincelastmove_x * p_actor->vel.x);
distmoved_y = (int)(p_actor->timesincelastmove_y * p_actor->vel.y);
if( distmoved_x != 0 || distmoved_y != 0 )
{
// clear old sprite
blit(bkGround, // source
surface, // dest
p_actor->pos.x, // source_x
p_actor->pos.y, // source_y
p_actor->pos.x, // dest_x
p_actor->pos.y, // dest_y
p_actor->p_sprite->w,
p_actor->p_sprite->h);
// move it & bounds checking
p_actor->pos.x += distmoved_x;
if (p_actor->pos.x > 320)
{
p_actor->pos.x = 320;
p_actor->vel.x = - p_actor->vel.x;
}
if (p_actor->pos.x < 0)
{
p_actor->pos.x = 0;
p_actor->vel.x = - p_actor->vel.x;
}
p_actor->pos.y += distmoved_y;
if(p_actor->pos.y > 200)
{
p_actor->pos.y = 200;
p_actor->vel.y = - p_actor->vel.y;
}
if (p_actor->pos.y < 0)
{
p_actor->pos.y = 0;
p_actor->vel.y = - p_actor->vel.y;
}
// draw new sprite
draw_sprite(surface, p_actor->p_sprite, p_actor->pos.x,
p_actor->pos.y);
}
if (distmoved_x != 0) p_actor->timesincelastmove_x = 0.0;
if (distmoved_y != 0) p_actor->timesincelastmove_y = 0.0;
p_actor = p_actor->p_next;
}
return;
}
Some background info, type roster_t is basically the head node in a
linked list of actor_t's. timesincelastmove_x and .._y are members
(type double) of the actor_t struct that accumulate the time in seconds
since an actor's position changed on the screen. This function is only
called when a timer has changed, which is 25 times per second right now.
Thx for any help!
Jeff Farris
- Raw text -