Projectile *Projectile::create(int projectileID, Projectile *model) { Projectile *retVal = new Projectile(); if (retVal && retVal->initWithProjectileID(projectileID, model)) { retVal->autorelease(); return retVal; } CC_SAFE_DELETE(retVal); return NULL; }
void Application::InitProjectileList() { for (int i = 0; i < 100; ++i) { Projectile* p = new Projectile(); p->SetID(i); projectileList.push_back(p); } }
/* playSound center_x center_y */ void MessageObjects::serializeShot(const Projectile &shot) { /* Write playSound */ _messageString += QString::number(shot.playSound() ? 1 : 0) + " "; /* Write 2 points */ _messageString += QString::number((qint32)shot.center().x()) + " "; _messageString += QString::number((qint32)shot.center().y()) + " "; }
void _delete_projectile(void **projs, void *proj) { Projectile *p = proj; p->rule(p, EVENT_DEATH); if(p->clr) free(p->clr); del_ref(proj); delete_element(projs, proj); }
void Client::projectileHit(GameObjId projectileId) { Projectile *projectile = (worldModel.getProjectiles())[projectileId]; worldRenderer.projectileHit(projectile, projectile->getHitPos()); bool removed = worldModel.getProjectiles().remove(projectileId); assert(removed); //if (removed) std::cout << "projectile removed" << std::endl; }
Projectile *Projectile::createModel(ProjectileTypes type) { Projectile *retval = new Projectile(); if (retval && retval->initModelWithType(type)) { retval->autorelease(); return retval; } CC_SAFE_DELETE(retval); return NULL; }
void addCannonProjectiles() { for(int i = 0; i < 8; i++) { Projectile * p = new Projectile(false, projectileMesh, CANNON_PROJECTILE_SCALE); parts.push_back(p->getPart()); p->getPart()->setMaterialGreenProjectile(); cannonProjectiles.push_back(p); } }
void Attacker::fire() { Projectile *p = new Projectile; p->setLocation(this->rect.center()); p->setTarget(target); p->launch(); projectiles.push_back(p); }
void Weapon::shoot(list<Entity*> *bullets){ Projectile *p = new Projectile( Vector3(0,0,-10) , parent->getParent()); p->setFrame(parent->getFrame()^getFrame()); ModelWeapon *lol = new ModelWeapon(); lol->setSkin(1); //p->setModel(new ModelBullet()); p->setModel(lol); bullets->push_back(p); }
Projectile* FastMachineGunProjectile::projectile() { Projectile* projectile = Projectile::create(); projectile->projectileSprite = Sprite::create("Projectile.png"); projectile->addChild(projectile->projectileSprite); // projectile->setScale(0.6); projectile->projectileDamage = 0.8; projectile->type = ProjectileType::FastMachineGunProjectile; return projectile; }
bool Equipment::valid_to_use_projectile(const Projectile& proj) { if (!proj.valid_projectile()) return false; ProjectileEntry& pentry = proj.projectile_entry(); if (pentry.weapon_class == "unarmed") return true; if (pentry.weapon_class == weapon.weapon_entry().weapon_class) return true; return false; }
Projectile* MissleProjectile::projectile() { Projectile* projectile = Projectile::create(); projectile->projectileSprite = Sprite::create("Projectile.png"); projectile->addChild(projectile->projectileSprite); projectile->setScale(1.2); projectile->projectileDamage = 4; projectile->type = ProjectileType::MissleProjectile; return projectile; }
std::list<Projectile*> *RocketLauncher::fire (Rect pos, Direction h, dmg_chan type) { std::list<Projectile*> *proj_list = new std::list<Projectile*>(); Projectile * r = new Rocket (pos, h, (2 * h - 1) *PROJ_SPEED, 0, ROCKET_DAMAGE); r->set_chan (type); proj_list->push_back (r); m_munitions--; gSound->play_sound (FIRE_SOUNDS_R + "rocket.wav"); return proj_list; }
//spawn new projectile and add to list of projectiles void Player::spawnShortBeam() { Projectile *shortBeam = new ShortBeam(minX, minY); projMtx.lock(); shortBeam->render(); renderProjVector.push_back(shortBeam); projMtx.unlock(); }
//Logica do movimento void Player::update() { Point mousePos = input->getMousePos(); Vector mouseVector(mousePos.getX() - pos.getX() + Game::getCurrentLevel()->getMap()->getXOffs(), mousePos.getY() - pos.getY() + Game::getCurrentLevel()->getMap()->getYOffs()); mouseVector = mouseVector.getNormalized(); angleDirection = atan2(mouseVector.getY(),mouseVector.getX()) - atan2(-1,0); if(input->isLeft()) { if(!collision(pos.getX() - speed,pos.getY())) { pos.setX(pos.getX() - speed); } } else if(input->isRight()) { if(!collision(pos.getX() + speed,pos.getY())) { pos.setX(pos.getX() + speed); } } if(input->isUp()) { if(!collision(pos.getX(),pos.getY() - speed)) { pos.setY(pos.getY() - speed); } } else if(input->isDown()) { if(!collision(pos.getX(),pos.getY() + speed)) { pos.setY(pos.getY() + speed); } } if(input->isMouseClicked() == 1 ) { Projectile* p = new Projectile(); if(weapon->shoot(p)) { int xx = pos.getX() + 20*sin(angleDirection); int yy = pos.getY() + 20*-cos(angleDirection); p->setOrigin(Point(xx,yy)); p->setAngle(angleDirection); std::cout<<"Angle: "<<angleDirection<<std::endl; Game::getCurrentLevel()->getProjectiles()->add(p); } } }
void SDLCanvas::drawProjectile(Projectile& pro, Color& c) { if(!isDrawProjectilesEnabled()) return; Vector2D trail = pro.loc_; if(scale_ < 0.013) trail += pro.getDirection() * -1500; else trail += pro.getDirection() * -500; drawLine(trail.x_,trail.y_, pro.loc_.x_, pro.loc_.y_, c); }
void idle() { for (unsigned int i=0; i<weapons.size(); i++) { weapons.at(i).updateProjectiles(0.01f); for (unsigned int j=0; j<weapons.at(i).projectile.size(); j++) { Projectile p = weapons.at(i).projectile.at(j); if (p.hitBoxTest(&targets.at(0).hitBox)) { std::cout << "HIT" << std::endl; } } } glutPostRedisplay(); }
void ProjectileManager::update(double dt) { for(int i = 0; i < projectiles.size(); i++) { Projectile* proj = projectiles[i]; if(proj->update(dt)) { projectiles.erase(projectiles.begin() + i); i--; } } }
Projectile * Application::FindProjectileByID(int id) { for (vector<Projectile*>::iterator it = projectileList.begin(); it != projectileList.end(); ++it) { Projectile* p = *it; if (p->GetID() == id) { return p; } } return nullptr; }
Projectile* ProjectileManager::GetProjectile(int projID) { for(int i=0; i<projectiles.size(); i++) { Projectile* projectile = projectiles.get(i); if(projectile->getID()==projID) { return projectile; } } return null; }
//------------------------------------------------------------------------------ void Actor::attack() { Weapon w = getWeapon(); if( w.canFire() ) { Projectile* p = w.fire( getAimingDirection() ); p->setPosition( getPosition() ); mpEngine->addProjectile( p ); setWeapon( w ); } }
// This ship just got hit by the given projectile. Take damage according to // what sort of weapon the projectile it. int Ship::TakeDamage(const Projectile &projectile, bool isBlast) { int type = 0; const Outfit &weapon = projectile.GetWeapon(); double shieldDamage = weapon.ShieldDamage(); double hullDamage = weapon.HullDamage(); double hitForce = weapon.HitForce(); double heatDamage = weapon.HeatDamage(); double ionDamage = weapon.IonDamage(); bool wasDisabled = IsDisabled(); bool wasDestroyed = IsDestroyed(); if(shields > shieldDamage) { shields -= shieldDamage; heat += .5 * heatDamage; ionization += .5 * ionDamage; } else if(!shields || shieldDamage) { if(shieldDamage) { hullDamage *= (1. - (shields / shieldDamage)); shields = 0.; } hull -= hullDamage; heat += heatDamage; ionization += ionDamage; } if(hitForce && !IsHyperspacing()) { Point d = position - projectile.Position(); double distance = d.Length(); if(distance) ApplyForce((hitForce / distance) * d); } if(!wasDisabled && IsDisabled()) type |= ShipEvent::DISABLE; if(!wasDestroyed && IsDestroyed()) type |= ShipEvent::DESTROY; // If this ship was hit directly and did not consider itself an enemy of the // ship that hit it, it is now "provoked" against that government. if(!isBlast && projectile.GetGovernment() && !projectile.GetGovernment()->IsEnemy(government) && (Shields() < .9 || Hull() < .9 || !personality.IsForbearing()) && !personality.IsPacifist()) type |= ShipEvent::PROVOKE; return type; }
void MASOSApp::update() { if (mAngle != oldAngle) { scale = mProjectileUnderTest.calculateScale(mInitialVelocity, mAngle, mTerminalVelocity, getWindowCenter().x, getWindowCenter().y); } oldAngle = mAngle; if (scale != oldScale) { scale = mProjectileUnderTest.calculateScale(mInitialVelocity, mAngle, mTerminalVelocity, getWindowCenter().x, getWindowCenter().y); } oldScale = scale; if (mTerminalVelocity != oldTerminalVelocity) { scale = mProjectileUnderTest.calculateScale(mInitialVelocity, mAngle, mTerminalVelocity, getWindowCenter().x, getWindowCenter().y); } oldTerminalVelocity = mTerminalVelocity; if (mInitialVelocity != oldInitialVelocity) { scale = mProjectileUnderTest.calculateScale(mInitialVelocity, mAngle, mTerminalVelocity, getWindowCenter().x, getWindowCenter().y); } oldInitialVelocity =mInitialVelocity; float tmp = mProjectileUnderTest.mPosition.y; mProjectileUnderTest.update(mInitialVelocity, mAngle, mCurrentTime, mTerminalVelocity); if (mProjectileUnderTest.mPosition.y > 0) { mProjectileUnderTest.mPosition.y = 0; mIsPlaying = false; } if (tmp >= 0 && mProjectileUnderTest.mPosition.y >= 0) { mProjectileUnderTest.mPosition.y = 0; mIsPlaying = false; mCurrentTime = oldTime; } if (mProjectileUnderTest.mPosition.x < 0) { mProjectileUnderTest.mPosition.x = 0.f; } oldTime = mCurrentTime; currX = mProjectileUnderTest.mPosition.x; currY = -(mProjectileUnderTest.mPosition.y); if (currY == -0) currY = 0; mParams->setPosition(ivec2(0,0)); }
Projectile * Gun::fireProjectile( const Vec3d& pos0, const Mat3d& rot0, const Vec3d& gvel ){ //printf( " Gun fireProjectile \n" ); Projectile * p = new Projectile(); Mat3d rotmat; globalPos( pos0, rot0, p->pos ); globalRot( rot0, rotmat ); p->vel.set_mul( rotmat.a, muzzle_velocity ); p->vel.add( gvel ); p->setMass( projectile_mass ); p->update_old_pos(); //printf( " Gun fireProjectile DONE \n" ); return p; }
void GameWorld::AddRocket(Vehicle* shooter, Vector2D target) { Projectile* pProjectile = new Projectile_Rocket(shooter, target); pProjectile->autorelease(); // 添加进来 m_Projectiles.push_back(pProjectile); pProjectile->initWithFile("media/image/missile.png"); if (m_pUILayer) { m_pUILayer->addChild(pProjectile); } }
void WeaponSystem::shoot_gun(GunPosition gun_pos, long time) { Projectile *p = new Projectile; p->init(); Object *front = guns[gun_pos]->get_object("NUC_energy.nogravity$front"); Object *back = guns[gun_pos]->get_object("NUC_energy.nogravity$back"); Vector3 front_pos = front->get_matrix().get_translation(); Vector3 back_pos = back->get_matrix().get_translation(); Vector3 vel = front_pos - back_pos; vel.normalize(); p->set_velocity(vel); p->set_position(front_pos); p->set_speed(125.0); if (heat >= 70) { p->set_dmg(overheat_dmg); } else { p->set_dmg(dmg); } p->calc_matrix(time); NucEmitter *em = p->get_emitter(); Vector4 start_color = em->get_start_color(); Vector4 end_color = em->get_end_color(); float vec_term = (std::max)(0.0, (std::min)(1.0 - heat_factor * 1.51, 1.0)); Vector3 factor_vec = Vector3(1.0, vec_term, vec_term); em->set_start_color(Vector4(start_color.x, start_color.y * factor_vec.y, start_color.z * factor_vec.z, start_color.w)); em->set_end_color(Vector4(end_color.x, end_color.y * factor_vec.y, end_color.z * factor_vec.z, end_color.w)); em->calc_matrix(time); add_projectile(p); muzzle_emitters[gun_pos]->set_active(true); muzzle_emitters[gun_pos]->set_activation_time(time); int anim_idx = guns[gun_pos]->lookup_animation("shoot"); if (anim_idx == -1) return; guns[gun_pos]->start_animation(anim_idx, time); guns[gun_pos]->set_anim_speed(anim_idx, fire_rate); heat += log(heat_rate) * 1.1; heat_rate++; if (heat >= 100){ heat = 100; heat_rate = 0; overheated = true; game::engine::audio_manager->play_sample(game::utils::get_audio_sample_by_name("overheat"), 1.0, AUDIO_PLAYMODE_ONCE); game::engine::audio_manager->play_sample(game::utils::get_audio_sample_by_name("alarm"), 0.4, AUDIO_PLAYMODE_ONCE, Vector3(), &overheat_alarm_source_idx); game::engine::audio_manager->play_sample(game::utils::get_audio_sample_by_name("warning"), 1.5, AUDIO_PLAYMODE_LOOP, Vector3(), &warning_source_idx); } game::engine::audio_manager->play_sample(game::utils::get_audio_sample_by_name("laser_gun"), 1.0, AUDIO_PLAYMODE_ONCE, front_pos); }
void Projectile::Add(Body *parent, Equip::Type type, const vector3d &pos, const vector3d &baseVel, const vector3d &dirVel) { Projectile *p = new Projectile(); p->m_parent = parent; p->m_type = Equip::types[type].tableIndex; p->SetFrame(parent->GetFrame()); parent->GetRotMatrix(p->m_orient); p->SetPosition(pos); p->m_baseVel = baseVel; p->m_dirVel = dirVel; p->m_radius = p->GetRadius(); Pi::game->GetSpace()->AddBody(p); }
Projectile *Spell::GetProjectile(Scriptable *self, int header, int level, const Point &target) const { SPLExtHeader *seh = GetExtHeader(header); if (!seh) { Log(ERROR, "Spell", "Cannot retrieve spell header!!! required header: %d, maximum: %d", header, (int) ExtHeaderCount); return NULL; } Projectile *pro = core->GetProjectileServer()->GetProjectileByIndex(seh->ProjectileAnimation); if (seh->FeatureCount) { pro->SetEffects(GetEffectBlock(self, target, header, level, seh->ProjectileAnimation)); } return pro; }
Projectile* Projectile::createProjectile(string filename, Vec2 p, Vec2 speed, string name) { Projectile* ob = new Projectile(); if(ob && ob->initProjectile(filename, p, speed, name)) { ob->autorelease(); return ob; } CC_SAFE_DELETE(ob); return NULL; }
Ship * addShip(bool fullSize) { Ship * ship = new Ship(fullSize, ID_TIE_FIGHTER_IMG, sphereMesh, shipWingConnector, shipWing, textureMapSphere1); // projectile Projectile * p = new Projectile(true, projectileMesh, WALKER_PROJECTILE_SCALE); p->getPart()->setMaterialRedProjectile(); ship->setProjectile(p); shipsProjectiles.push_back(p); parts.push_back(p->getPart()); ships.push_back(ship); parts.push_back(ship->getBody()); return ship; }