Code: Show/Hide arenadata->fakeplayer=fake->CreateFakePlayer("<Fake Player>", arena, SHIP_WARBIRD, 0);
pos->type = C2S_POSITION; pos->rotation = 0; pos->x = 500; pos->y = 500; pos->xspeed = 0; pos->yspeed = 0; pos->status = 0; pos->bounty = 0; pos->weapon.type = 0; pos->weapon.level = 1; pos->weapon.shraplevel = 1; pos->weapon.shrap = 0; pos->weapon.alternate = 0; game->FakePosition(arenadata->fakeplayer, pos, 22); |
Code: Show/Hide arenadata->update = current_ticks();
arenadata->fakeplayer=fake->CreateFakePlayer("<Fake>", arena, SHIP_WARBIRD, 0); pos.type = C2S_POSITION; pos.rotation = 0; pos.x = 500*16; pos.y = 520*16; arenadata->x = (double) pos.x; arenadata->y = (double) pos.y; srand(time(NULL)); pos.xspeed = -100 + rand() % 200; pos.yspeed = -100 + rand() % 200; pos.status = S_PLAYING; pos.bounty = 0; pos.weapon.type = 0; pos.weapon.level = 1; pos.weapon.shraplevel = 1; pos.weapon.shrap = 0; pos.weapon.alternate = 0; game->FakePosition(arenadata->fakeplayer, &pos, 22); |
Code: Show/Hide int update = current_ticks() - arenadata->update;
arenadata->update = current_ticks(); struct C2SPosition pos; pos.type = C2S_POSITION; //pixels arenadata->x += ((double)arenadata->fakeplayer->position.xspeed * (double)update/100.0); arenadata->y += ((double)arenadata->fakeplayer->position.yspeed * (double)update/100.0); pos.x = (int)arenadata->x; pos.y = (int)arenadata->y; //pixels per second pos.xspeed = arenadata->fakeplayer->position.xspeed; pos.yspeed = arenadata->fakeplayer->position.yspeed; pos.status = S_PLAYING; pos.bounty = 1337; pos.weapon.type = 0; pos.weapon.level = 1; pos.weapon.shraplevel = 1; pos.weapon.shrap = 0; pos.weapon.alternate = 0; // Rotate the fake if(pos.xspeed==0) { if(pos.yspeed >= 0) pos.rotation = 0; else pos.rotation = 20; } else if(pos.yspeed == 0) { if(pos.xspeed<0) pos.rotation = 30; else pos.rotation = 10; } else if(pos.xspeed > 0 && pos.yspeed > 0) pos.rotation = 20.5 - atan((double)pos.xspeed/(double)pos.yspeed)*40.0/2.0/pi; else if(pos.xspeed > 0 && pos.yspeed < 0) pos.rotation = 0.5 + atan((double)pos.xspeed/-(double)pos.yspeed)*40.0/2.0/pi; else if(pos.xspeed < 0 && pos.yspeed > 0) pos.rotation = 20.5 + atan(-(double)pos.xspeed/(double)pos.yspeed)*40.0/2.0/pi; else if(pos.xspeed < 0 && pos.yspeed < 0) pos.rotation = 40.5 - atan(-(double)pos.xspeed/-(double)pos.yspeed)*40.0/2.0/pi; game->FakePosition(arenadata->fakeplayer, &pos, 22); |
Code: Show/Hide struct TurretData
{ Player *p; int interval, weapon; ticks_t endtime, tofire, tosend; struct C2SPosition pos; //<-- look here }; //global list of turret data (but you can make this per-arena if you feel you really must) local LinkedList turrets; //inside create_turret: struct C2SPosition *pos; struct TurretData *td = amalloc(sizeof(*td)); ... pos = &td->pos; pos->type = C2S_POSITION; //blah blah more initialisation of the pos ... LLAdd(&turrets, td); //inside mlfunc: for (l = LLGetHead(&turrets); l; l = next) { struct TurretData *td = l->data; ... else if (TICK_GT(now, td->tosend)) { ... //you must update the pos's time to the current time before "sending" it td->pos.time = now; ... //here you can stick your math calculations td->pos.rotation = ... ... game->FakePosition(td->p, &td->pos, sizeof(td->pos)); |