// Tank Joystick Button Method void Tank::OnControllerButton(const SDL_ControllerButtonEvent event) { // if the player's number is 0 and the joystick button is from joystick 0 if (event.which == 0 && playerNum == 0) { // if A Button if (event.button == 0) { // Create a bullet CreateBullet(); } } // if the player's number is 1 and the joystick button is from joystick 1 if (event.which == 1 && playerNum == 1) { // if A Button if (event.button == 0) { // Create a bullet CreateBullet(); } } }
void Turret::Update(float deltaTime, SDL_Rect tankRect){ x = (tankRect.x + (tankRect.w / 2)) - (baseRect.x + (baseRect.w / 2)); y = (tankRect.y + (tankRect.h / 2)) - (baseRect.y + (baseRect.h / 2)); turretangle = atan2(y, x) * 180 / 3.14; if (SDL_GetTicks() > fireTime){ if(baseRect.x> 0 && baseRect.x < 1024 && baseRect.y > 0 && baseRect.y < 768){ CreateBullet(tankRect); } fireTime = SDL_GetTicks() + (rand() % 3 + 1) * 1000; } for (int i = 0; i < bulletList.size(); i++) { if (bulletList[i].active) { bulletList[i].Update(deltaTime); } } }
void Enemy::CheckShooting(float dist, float deltaTime) { PxExtendedVec3 tpPos = physics->player->getPosition(); PxVec3 pPos = playerPos; PxVec3 ori = actor->getGlobalPose().p; PxVec3 dir = pPos - ori; dir.normalize(); int numHits = 0; PxRaycastHit* hit = physics->RaycastMultiple(ori,dir,dist,&numHits, PxQueryFlag::eSTATIC | PxQueryFlag::eDYNAMIC); for(unsigned int i = 1; i < numHits; i++) { if(hit[i-1].actor == actor && hit[i].actor == physics->player->getActor()) { sawPlayer = true; lastTimeShot+=deltaTime; if(lastTimeShot > shootDelay) { obj->PlayAnimation("Shoot",true); moveDir *= 0.1f; if(obj->GetCurrentAnim()->doAction) { CreateBullet(ori+dir*2,dir); currentMoveTime = 9999.0f; lastTimeShot = 0; resources->GetSoundHandler()->PlayWaveFile("piew"); obj->GetCurrentAnim()->doAction = false; } } } } }
int CcdChapter::Init() { CreateScene(); // load resource LoadResource(); CreateBullet(); Plane plane(Vector3::UNIT_Y, 0); MeshManager::getSingleton().createPlane("ground", ResourceGroup, plane, 500, 500, 1, 1, true, 1, 5, 5, Vector3::UNIT_Z); Entity *groundEntity = m_pkSceneManager->createEntity("GroundEntity", "ground"); groundEntity->setMaterialName("BulletPlane", ResourceGroup); groundEntity->setCastShadows(true); SceneNode *pkNode = m_pkRootNode->createChildSceneNode(); pkNode->attachObject(groundEntity); btCollisionShape *shape = CreateCollisionShape(SHAPE_TYPE::SHAPE_PLANE, Vector3::ZERO); m_CollisionShapes.push_back(shape); btRigidBody *body = CreateRigidBody(shape, false, pkNode, 100); m_RigidBodies.push_back(body); m_pkDynamicsWorld->addRigidBody(body); body->setUserPointer(pkNode); //body->setFriction(100); return 0; }
bool SW_EMPulse::Activate(SuperClass* pThis, const CellStruct &Coords, bool IsPlayer) { auto pType = pThis->Type; auto pData = SWTypeExt::ExtMap.Find(pType); if(!pData) { return false; } auto pOwner = pThis->Owner; pOwner->EMPTarget = Coords; // the maximum number of buildings to fire. negative means all. const auto Count = (pData->SW_MaxCount >= 0) ? static_cast<size_t>(pData->SW_MaxCount) : std::numeric_limits<size_t>::max(); // if linked, only one needs to be in range (and CanFireAt checked that already). const bool ignoreRange = pData->EMPulse_Linked || pData->EMPulse_TargetSelf; auto IsEligible = [&](BuildingClass* pBld) { return IsLaunchSiteEligible(pData, Coords, pBld, ignoreRange); }; // only call on up to Count buildings that suffice IsEligible Helpers::Alex::for_each_if_n(pOwner->Buildings.begin(), pOwner->Buildings.end(), Count, IsEligible, [&](BuildingClass* pBld) { if(!pData->EMPulse_TargetSelf) { // set extended properties auto pExt = TechnoExt::ExtMap.Find(pBld); pExt->SuperWeapon = pThis; pExt->SuperTarget = MapClass::Instance->TryGetCellAt(Coords); // setup the cannon and start the fire mission pBld->FiringSWType = pType->ArrayIndex; pBld->QueueMission(Mission::Missile, false); pBld->NextMission(); } else { // create a bullet and detonate immediately if(auto pWeapon = pBld->GetWeapon(0)->WeaponType) { auto pExt = BulletTypeExt::ExtMap.Find(pWeapon->Projectile); if(auto pBullet = pExt->CreateBullet(pBld, pBld, pWeapon)) { pBullet->SetWeaponType(pWeapon); pBullet->Remove(); pBullet->Detonate(BuildingExt::GetCenterCoords(pBld)); pBullet->Release(); } } } }); return true; }
void Player::OnControllerButton(const SDL_ControllerButtonEvent event) { if(event.which == 0 && playerNum ==0) { if(event.button==0) { CreateBullet(); } } if(event.which == 1 && playerNum ==1) { if(event.button==0) { CreateBullet(); } } }
void Player::OnControllerButton(const SDL_ControllerButtonEvent event) { if(event.which == 0 && playerNum == 0) { if(event.button == 0) { cout << "Player 1 - Button A" << endl; CreateBullet(); } } if(event.which == 1 &&playerNum == 1) { if(event.button == 0) { cout << "Player 2 - Button A" << endl; CreateBullet(); } } }
//Player Joystick button method void Player::OnControllerButton(const SDL_ControllerButtonEvent event) { //if the player's number is 0 and the joystick button is from joystick 0 if (event.which == 0 && playerNum == 0) { //if a button if (event.button == 0) { //cout << "Player 1 - Button A" << endl; //create a bullet CreateBullet(); } } //if the player's number is 1 and the joystick button is from joystick 1 if (event.which == 1 && playerNum == 1) { //if A button if (event.button == 0) { //cout << "Player 2 - Button A" << endl; //create a bullet CreateBullet(); } } }
void updateBulletPool(BulletPool *bp){ int i; for (i = 0; i < 5; i++) { if (bp->particles_[i]->inUse == 1 && bp->particles_[i]->explosion_counter == 0){ moveBullet(bp->particles_[i]); if(checkScreenCollision(bp->particles_[i])){ bp->particles_[i]->inUse = 0; bp->particles_[i]->explosion_counter = 1; bp->particles_[i]->bullet_exp = loadBitmap("/home/lcom/Tanks/res/Spark1.bmp"); } } else if(bp->particles_[i]->inUse == 0 && bp->particles_[i]->explosion_counter == 5) bp->particles_[i] = CreateBullet(0); } }
std::unique_ptr<Entity> EntityFactory::CreateEntity(SpawnEntityMessage *msg) { std::unique_ptr<Entity> e(new Entity); switch (msg->GetEntityType()) { case EntityType::BULLET: CreateBullet(e.get(), msg); break; case EntityType::HEALTH_PICKUP: CreateHealthPickup(e.get(), msg); break; default: throw std::runtime_error("Default case reached in EntityFactory::CreateEntity() reached"); break; } return e; }
int Zombie_Shoot(GameObject* zombie, Scene* scene) { if(zombie->ai.fireCount > 0) { zombie->ai.fireCount--; } if(zombie->ai.fireCount == 0) { printf("Zombie fired.\n"); GameObject obj; obj = CreateBullet(scene->nextId++, zombie->rect.x, zombie->rect.y, zombie->ai.damage, zombie->rotation, zombie->ai.bulletSpeed, BULLET_ZOMBIE); AddObject(scene, obj, false); SendBullet(obj); zombie->ai.fireCount = zombie->ai.fireRate;} return EXIT_SUCCESS; }
void MovePlayer(SDL_Renderer *r, Player *p) { const Uint8* keys = SDL_GetKeyboardState(NULL); if(keys[SDL_SCANCODE_UP]) p->speed = PLAYER_SPEED; if(!keys[SDL_SCANCODE_UP]) p->speed = 0; if(keys[SDL_SCANCODE_LEFT]) { p->angle -= 3; if(p->angle <= 0) p->angle = 360; } if(keys[SDL_SCANCODE_RIGHT]) { p->angle += 3; if(p->angle >= 360) p->angle = 0; } if(keys[SDL_SCANCODE_SPACE] && p->bulletIndex < BULLET_MAX && p->prevBullet > BULLET_DELAY) { p->b[p->bulletIndex++] = CreateBullet(r, p->dest.x + (p->dest.w / 2), p->dest.y + (p->dest.h / 2), p->angle); p->prevBullet = 0.0; } }
bool BulletLauncher::Shoot() { // 如果标记可以射击才会发射出子弹 if (_bShoot) { Bullet* bullet = CreateBullet(); bullet->SetPosition( GetPositionX(), GetPositionY(), GetPositionZ()); bullet->SetAngleZ(GetAngleZ()); bullet->SetDirectionAngle(GetAngleZ()); bullet->SetOrder(GetOrder()); _belongPlane->GetScene()->Add(bullet); // 发射过了,标记为不可发射 _bShoot = false; return true; } return false; }
void Game::OnKeyUp(SDL_KeyboardEvent keyBoardEvent) { switch (keyBoardEvent.keysym.scancode) { case SDL_SCANCODE_W: up = false; break; case SDL_SCANCODE_A: left = false; break; case SDL_SCANCODE_D: right = false; break; case SDL_SCANCODE_R: RespawnPlayer(); break; case SDL_SCANCODE_TAB: if (m_player) { m_player->ChangeShip(); } break; case SDL_SCANCODE_SPACE: // if (m_player) { CreateBullet(); } break; case SDL_SCANCODE_ESCAPE: OnExit(); break; default: //DO NOTHING break; } }
void CEffectsGame::DoPicking() { bool hit = false; Vector3 tileHitPos; SMapTile *tileHit; Vector3 start = pCamera->GetWorldPosition(); Vector3 end = start + pCamera->forward * 1000.0f; Vector3 pos; pLevel->UnHighlightTile(); // find tile we are pointing at if (hit = pLevel->CastRay(start, end, OUT tileHitPos, OUT &tileHit, OUT &pos)) { pLevel->HighlightTile(tileHitPos.x, tileHitPos.y, tileHitPos.z); } static float force = 10; if (gInput.WasKeyPressed(K_PGUP)) force += 5.0f; if (gInput.WasKeyPressed(K_PGDN)) force -= 5.0f; //gVGUI.AddTextMessage(300,200,WHITE,"Force: %f",force); //car->pBarrel->DrawAxis(); // shooting - delete tile if (gInput.IsKeydown(K_MOUSE1)) { static float delay = 0; delay += frametime; if (delay > 0.05f) { // shoot a bullet CreateBullet(car->pBarrel->GetWorldPosition(), car->pBarrel->up); float puffSpeed = 0.35; // add puff effect for (int i = 0; i<3; i++) { static CTexture *puffTex = new CTexture("particles/explosion4.dds"); CParticle *p = new CParticle(puffTex); p->size = Vector2(0.15, 0.15); p->position = car->pBarrel->GetWorldPosition() + car->pBarrel->up/2; p->velocity = Vector3( frand(-puffSpeed,puffSpeed), frand(-puffSpeed,puffSpeed)+1, frand(-puffSpeed,puffSpeed) ); //p->gravity = -10; p->lifetime = 0.25; p->color = SRGBA(255,255,255,50); p->sizeVel = Vector2(1,1); p->colorChange = SRGBA(255,255,255,0); particles->Add(p); } // add muzzle flash static CTexture *muzzleTex[] = { new CTexture("particles/flame1.dds"), new CTexture("particles/explosion1.dds") }; { CParticle *p = new CParticle(muzzleTex[rand()%2]); p->size = Vector2(0.7, 0.7); p->position = car->pBarrel->GetWorldPosition() + car->pBarrel->up/2; p->lifetime = 0.01; p->additive = true; //p->color = SRGBA(255,255,255,50); //p->sizeVel = Vector2(1,1); //p->colorChange = SRGBA(255,255,255,0); particles->Add(p); } delay = 0; // if hit a tile, destroy it /* if (hit) { EnterCriticalSection(&renderCS); tileHit->type = 0; LeaveCriticalSection(&renderCS); SMapChunk *chunk = pLevel->GetChunk( floor(tileHitPos.x/SMapChunk::Size), floor(tileHitPos.y/SMapChunk::Size), floor(tileHitPos.z/SMapChunk::Size) ); chunk->dirtyBody = true; chunk->dirty = true; //pLevel->UpdateTile(tileHitPos.x, tileHitPos.y, tileHitPos.z); SSpawnTile s; s.pos = tileHitPos; s.vel = pCamera->forward * force; boxesToSpawn.push(s); // create a physical entity in this place /*NewtonBody *box = AddBox(pScene, pWorld, tileHitPos+Vector3(0.5, 0.5, 0.5), Vector3(0.95f,0.95f,0.95f), Vector3(), 100); // add some velocity Vector3 vel = pCamera->forward * force; Vector3 pos; NewtonBodySetVelocity(box, &vel[0]);*/ // } } } static float lastRocketFire = -100; if (gInput.WasKeyPressed(K_MOUSE2) ) { float r = 3; int x = tileHitPos.x; int y = tileHitPos.y; int z = tileHitPos.z; if (lastRocketFire + 0 < realtime) { Debug("Create rocket!"); lastRocketFire = realtime; if (!hit) { CreateRocket(car->pBarrel->GetWorldPosition() + car->pBarrel->up/2, car->pBarrel->up); } else { Vector3 dir = (p os-(car->pBarrel->GetWorldPosition() + Vector3(0,10,0))).Normalize(); if (dir.y < -0.25) { dir.y = -0.25; dir.Normalize(); } CreateRocket(car->pBarrel->GetWorldPosition() + car->pBarrel->up/2, dir ); } } } // show car meshes if (car) { CArray<CObject3D*> meshes; GetMeshesList(car, meshes); float minT = 99999.0f; static int current = 0; if (KeyPressed(']')) { meshes[current]->color = WHITE; current++; if (current == meshes.Size()) current = 0; meshes[current]->color = RED; } if (KeyPressed('[')) { meshes[current]->color = WHITE; current--; if (current < 0) current = meshes.Size()-1; meshes[current]->color = RED; } //gVGUI.AddTextMessage(200,90,YELLOW,"%d",current); car->aimTarget = end; } }
// 発射 void CPlayer::Shot(){ if (GetKey(KEY_INPUT_LCONTROL) == 0 || GetKey(KEY_INPUT_LCONTROL) > 1)return; CreateBullet(); }
void ai_missile_shot(Object *o) { int index = o->shot.level + ((o->type == OBJ_SUPERMISSILE_SHOT) ? 3 : 0); MissileSettings *settings = &missile_settings[index]; if (o->state == 0) { o->shot.damage = 0; if (o->shot.level == 2) { // initilize wavey effect o->xmark = o->x; o->ymark = o->y; o->speed = (o->type == OBJ_SUPERMISSILE_SHOT) ? -64 : -32; // don't let it explode until the "recoil" effect is over. o->state = STATE_WAIT_RECOIL_OVER; // record position we were fired at (we won't explode until we pass it) o->xmark2 = player->x; o->ymark2 = player->y; } else { o->state = STATE_MISSILE_CAN_EXPLODE; } } // accelerate according to current type and level of missile // don't use LIMITX here as it can mess up recoil of level 3 super missiles switch (o->shot.dir) { case RIGHT: o->xinertia += o->shot.accel; if (o->xinertia > settings->maxspeed) o->xinertia = settings->maxspeed; break; case LEFT: o->xinertia -= o->shot.accel; if (o->xinertia < -settings->maxspeed) o->xinertia = -settings->maxspeed; break; case UP: o->yinertia -= o->shot.accel; if (o->yinertia < -settings->maxspeed) o->yinertia = -settings->maxspeed; break; case DOWN: o->yinertia += o->shot.accel; if (o->yinertia > settings->maxspeed) o->yinertia = settings->maxspeed; break; } // wavey effect for level 3 // (markx/y is used as a "speed" value here) if (o->shot.level == 2) { if (o->shot.dir == LEFT || o->shot.dir == RIGHT) { if (o->y >= o->ymark) o->speed = (o->type == OBJ_SUPERMISSILE_SHOT) ? -64 : -32; else o->speed = (o->type == OBJ_SUPERMISSILE_SHOT) ? 64 : 32; o->yinertia += o->speed; } else { if (o->x >= o->xmark) o->speed = (o->type == OBJ_SUPERMISSILE_SHOT) ? -64 : -32; else o->speed = (o->type == OBJ_SUPERMISSILE_SHOT) ? 64 : 32; o->xinertia += o->speed; } } // check if we hit an enemy // level 3 missiles can not blow up while they are "recoiling" // what we do is first wait until they're traveling in the direction // they're pointing, then wait till they pass the player's original position. switch (o->state) { case STATE_WAIT_RECOIL_OVER: switch (o->shot.dir) { case LEFT: if (o->xinertia <= 0) o->state = STATE_RECOIL_OVER; break; case RIGHT: if (o->xinertia >= 0) o->state = STATE_RECOIL_OVER; break; case UP: if (o->yinertia <= 0) o->state = STATE_RECOIL_OVER; break; case DOWN: if (o->yinertia >= 0) o->state = STATE_RECOIL_OVER; break; } if (o->state != STATE_RECOIL_OVER) break; case STATE_RECOIL_OVER: switch (o->shot.dir) { case LEFT: if (o->x <= o->xmark2 - (2 * CSFI)) o->state = STATE_MISSILE_CAN_EXPLODE; break; case RIGHT: if (o->x >= o->xmark2 + (2 * CSFI)) o->state = STATE_MISSILE_CAN_EXPLODE; break; case UP: if (o->y <= o->ymark2 - (2 * CSFI)) o->state = STATE_MISSILE_CAN_EXPLODE; break; case DOWN: if (o->y >= o->ymark2 + (2 * CSFI)) o->state = STATE_MISSILE_CAN_EXPLODE; break; } if (o->state != STATE_MISSILE_CAN_EXPLODE) break; case STATE_MISSILE_CAN_EXPLODE: { bool blow_up = false; if (damage_enemies(o)) { blow_up = true; } else { // check if we hit a wall if (o->shot.dir == LEFT && o->blockl) blow_up = true; else if (o->shot.dir == RIGHT && o->blockr) blow_up = true; else if (o->shot.dir == UP && o->blocku) blow_up = true; else if (o->shot.dir == DOWN && o->blockd) blow_up = true; } if (blow_up) { NXE::Sound::SoundManager::getInstance()->playSfx(NXE::Sound::SFX::SND_MISSILE_HIT); // create the boom-spawner object for the flashes, smoke, and AoE damage int y = o->CenterY(); if (o->shot.dir == LEFT || o->shot.dir == RIGHT) y -= 3 * CSFI; Object *sp = CreateBullet(o->CenterX(), y, OBJ_MISSILE_BOOM_SPAWNER); sp->shot.boomspawner.range = settings->hitrange; sp->shot.boomspawner.booms_left = settings->lifetime; sp->shot.damage = settings->boomdamage; sp->shot.level = settings->boomdamage; o->Delete(); return; } } break; } if (--o->shot.ttl < 0) shot_dissipate(o, EFFECT_STARPOOF); // smoke trails if (++o->timer > 2) { o->timer = 0; Caret *trail = effect(o->CenterX() - o->xinertia, o->CenterY() - o->yinertia, EFFECT_SMOKETRAIL); const int trailspd = 0x400; switch (o->shot.dir) { case LEFT: trail->xinertia = trailspd; trail->y -= (2 * CSFI); break; case RIGHT: trail->xinertia = -trailspd; trail->y -= (2 * CSFI); break; case UP: trail->yinertia = trailspd; trail->x -= (1 * CSFI); break; case DOWN: trail->yinertia = -trailspd; trail->x -= (1 * CSFI); break; } } }