/** * @brief Gets the sprite that corresponds to a direction. * * @usage sx, sy = t:spriteFromdir( math.pi ) * * @luaparam t Texture to get sprite of. * @luaparam a Direction to have sprite facing (in radians). * @luareturn x and y positions of the sprite. * @luafunc spriteFromDir( t, a ) */ static int texL_spriteFromDir( lua_State *L ) { double a; LuaTex *lt; int sx, sy; /* Params. */ lt = luaL_checktex( L, 1 ); a = luaL_checknumber( L, 2 ); /* Calculate with parameter sanity.. */ if ((a >= 2.*M_PI) || (a < 0.)) { a = fmod( a, 2.*M_PI ); if (a < 0.) a += 2.*M_PI; } gl_getSpriteFromDir( &sx, &sy, lt->tex, a ); /* Return. */ lua_pushinteger( L, sx+1 ); lua_pushinteger( L, sy+1 ); return 2; }
/** * @brief Updates an individual weapon. * * @param w Weapon to update. * @param dt Current delta tick. * @param layer Layer to which the weapon belongs. */ static void weapon_update( Weapon* w, const double dt, WeaponLayer layer ) { int i, psx,psy; glTexture *gfx; Vector2d crash[2]; Pilot *p; /* Get the sprite direction to speed up calculations. */ if (!outfit_isBeam(w->outfit)) { gfx = outfit_gfx(w->outfit); gl_getSpriteFromDir( &w->sx, &w->sy, gfx, w->solid->dir ); } for (i=0; i<pilot_nstack; i++) { p = pilot_stack[i]; psx = pilot_stack[i]->tsx; psy = pilot_stack[i]->tsy; if (w->parent == pilot_stack[i]->id) continue; /* pilot is self */ /* Beam weapons have special collisions. */ if (outfit_isBeam(w->outfit)) { /* Check for collision. */ if (weapon_checkCanHit(w,p) && CollideLineSprite( &w->solid->pos, w->solid->dir, w->outfit->u.bem.range, p->ship->gfx_space, psx, psy, &p->solid->pos, crash)) { weapon_hitBeam( w, p, layer, crash, dt ); /* No return because beam can still think, it's not * destroyed like the other weapons.*/ } } /* smart weapons only collide with their target */ else if (weapon_isSmart(w)) { if ((pilot_stack[i]->id == w->target) && (w->status != WEAPON_STATUS_OK) && /* Must not be locking on. */ weapon_checkCanHit(w,p) && CollideSprite( gfx, w->sx, w->sy, &w->solid->pos, p->ship->gfx_space, psx, psy, &p->solid->pos, &crash[0] )) { weapon_hit( w, p, layer, &crash[0] ); return; /* Weapon is destroyed. */ } } /* dumb weapons hit anything not of the same faction */ else { if (weapon_checkCanHit(w,p) && CollideSprite( gfx, w->sx, w->sy, &w->solid->pos, p->ship->gfx_space, psx, psy, &p->solid->pos, &crash[0] )) { weapon_hit( w, p, layer, &crash[0] ); return; /* Weapon is destroyed. */ } } } /* smart weapons also get to think their next move */ if (weapon_isSmart(w)) (*w->think)(w,dt); /* Update the solid position. */ (*w->solid->update)(w->solid, dt); /* Update the sound. */ sound_updatePos(w->voice, w->solid->pos.x, w->solid->pos.y, w->solid->vel.x, w->solid->vel.y); }