void SmartBomber::Tick(float _timespan, std::vector<Projectile_ptr>& _spawn_prj, std::vector<Decoration_ptr>& _spawn_dec, Matrix4f _transform, std::vector<Core_ptr>& _enemies, ICollisionManager* _collision_manager) { Section::Tick(_timespan, _spawn_prj, _spawn_dec, _transform, _enemies, _collision_manager); cooldown_ -= _timespan; if(firing_) { if(cooldown_ <= 0.0f && PowerRequirement(35)) { BaseEntity* target = NULL; Core* core_target = root_->GetTarget(); if(core_target) { target = core_target; } else if(_enemies.size() > 0) { int index = Random::RandomIndex(static_cast<int>(_enemies.size())); target = _enemies[index]; } HomingBomb* bomb = new HomingBomb(Vector3f(0, 3, 0), target); fire_projectile(bomb, _spawn_prj); cooldown_ = cooldown_time_; PowerTick(25); SoundManager::Instance().PlaySample("Fire11.wav"); } } }
// NOTE: weaponnum is *not* weapon group qboolean fire_weapon(gentity_t *self, vec3_t start, vec3_t forward, vec3_t right, vec3_t up, int weaponnum, float quadFactor, int handSide) { if (weaponnum <= 0 || weaponnum >= BG_NumWeapons()) { return qfalse; } return fire_projectile(self, start, forward, right, up, bg_weaponinfo[weaponnum].projnum, quadFactor, bg_weaponinfo[weaponnum].mod, bg_weaponinfo[weaponnum].splashMod, handSide); }
void Blaster::Tick(float _timespan, std::vector<Projectile_ptr>& _spawn_prj, std::vector<Decoration_ptr>& _spawn_dec, Matrix4f _transform, std::vector<Core_ptr>& _enemies, ICollisionManager* _collision_manager) { Section::Tick(_timespan, _spawn_prj, _spawn_dec, _transform, _enemies, _collision_manager); cooldown_ -= _timespan; if(firing_) { if(cooldown_ <= 0.0f && PowerRequirement(5)) { fire_projectile(new SmallBullet(Vector3f(Random::RandomRange(-2, 2), Random::RandomRange(1, 7), 0)), _spawn_prj); cooldown_ = cooldown_time_; PowerTick(-1); SoundManager::Instance().PlaySample("fire1.wav"); } } }
qboolean fire_weaponDir(gentity_t *self, vec3_t start, vec3_t dir, int weaponnum, float quadFactor, int handSide) { vec3_t right, up; if (weaponnum <= 0 || weaponnum >= BG_NumWeapons()) { return qfalse; } // Get up and right from dir (which is "forward") PerpendicularVector( up, dir ); CrossProduct( up, dir, right ); return fire_projectile(self, start, dir, right, up, bg_weaponinfo[weaponnum].projnum, quadFactor, bg_weaponinfo[weaponnum].mod, bg_weaponinfo[weaponnum].splashMod, handSide); }
void ShotgunArtillery::Tick(float _timespan, std::vector<Projectile_ptr>& _spawn_prj, std::vector<Decoration_ptr>& _spawn_dec, Matrix4f _transform, std::vector<Core_ptr>& _enemies, ICollisionManager* _collision_manager) { Section::Tick(_timespan, _spawn_prj, _spawn_dec, _transform, _enemies, _collision_manager); cooldown_ -= _timespan; if(firing_) { if(cooldown_ <= 0.0f && PowerRequirement(10)) { Projectile_ptr p1 = new ShotgunShell(Vector3f(0, 2, 0), 0); fire_projectile(p1, _spawn_prj); cooldown_ = cooldown_time_; PowerTick(-8); SoundManager::Instance().PlaySample("Fire12.wav"); } } }
void PlasmaArtillery::Tick(float _timespan, std::vector<Projectile_ptr>& _spawn_prj, std::vector<Decoration_ptr>& _spawn_dec, Matrix4f _transform, std::vector<Core_ptr>& _enemies, ICollisionManager* _collision_manager) { Section::Tick(_timespan, _spawn_prj, _spawn_dec, _transform, _enemies, _collision_manager); cooldown_ -= _timespan; if(firing_) { if(cooldown_ <= 0.0f && PowerRequirement(25)) { Projectile_ptr plasmabolt = new PlasmaBolt(Vector3f(Random::RandomRange(-2, 2), Random::RandomRange(1, 7), 0)); fire_projectile(plasmabolt, _spawn_prj); cooldown_ = cooldown_time_; PowerTick(-25); SoundManager::Instance().PlaySample("fire2.wav"); } } }
void HeavyBlaster::Tick(float _timespan, std::vector<Projectile_ptr>& _spawn_prj, std::vector<Decoration_ptr>& _spawn_dec, Matrix4f _transform, std::vector<Core_ptr>& _enemies, ICollisionManager* _collision_manager) { Section::Tick(_timespan, _spawn_prj, _spawn_dec, _transform, _enemies, _collision_manager); cooldown_ -= _timespan; if(firing_) { if(cooldown_ <= 0.0f && PowerRequirement(15)) { Projectile_ptr p1 = new MediumBullet(Vector3f(0, 4, 0)); fire_projectile(p1, _spawn_prj); cooldown_ = cooldown_time_; PowerTick(-4); SoundManager::Instance().PlaySample("Fire10.wav"); } } }
void Deterer::Tick(float _timespan, std::vector<Projectile_ptr>& _spawn_prj, std::vector<Decoration_ptr>& _spawn_dec, Matrix4f _transform, std::vector<Core_ptr>& _enemies, ICollisionManager* _collision_manager) { Section::Tick(_timespan, _spawn_prj, _spawn_dec, _transform, _enemies, _collision_manager); cooldown_ -= _timespan; if(firing_) { if(cooldown_ <= 0.0f && PowerRequirement(50)) { Projectile_ptr p1 = new MiniBolt(Vector3f(Random::RandomRange(-2, 2), Random::RandomRange(-2, 2), 0)); p1->SetVelocity(Vector3f(1, 0, 0) * 200); Projectile_ptr p2 = new MiniBolt(Vector3f(Random::RandomRange(-2, 2), Random::RandomRange(-2, 2), 0)); p2->SetVelocity(Vector3f(1, 1, 0) * 200); Projectile_ptr p3 = new MiniBolt(Vector3f(Random::RandomRange(-2, 2), Random::RandomRange(-2, 2), 0)); p3->SetVelocity(Vector3f(0, 1, 0) * 200); Projectile_ptr p4 = new MiniBolt(Vector3f(Random::RandomRange(-2, 2), Random::RandomRange(-2, 2), 0)); p4->SetVelocity(Vector3f(-1, 1, 0) * 200); Projectile_ptr p5 = new MiniBolt(Vector3f(Random::RandomRange(-2, 2), Random::RandomRange(-2, 2), 0)); p5->SetVelocity(Vector3f(-1, 0, 0) * 200); Projectile_ptr p6 = new MiniBolt(Vector3f(Random::RandomRange(-2, 2), Random::RandomRange(-2, 2), 0)); p6->SetVelocity(Vector3f(-1, -1, 0) * 200); Projectile_ptr p7 = new MiniBolt(Vector3f(Random::RandomRange(-2, 2), Random::RandomRange(-2, 2), 0)); p7->SetVelocity(Vector3f(0, -1, 0) * 200); Projectile_ptr p8 = new MiniBolt(Vector3f(Random::RandomRange(-2, 2), Random::RandomRange(-2, 2), 0)); p8->SetVelocity(Vector3f(1, -1, 0) * 200); fire_projectile(p1, _spawn_prj); fire_projectile(p2, _spawn_prj); fire_projectile(p3, _spawn_prj); fire_projectile(p4, _spawn_prj); fire_projectile(p5, _spawn_prj); fire_projectile(p6, _spawn_prj); fire_projectile(p7, _spawn_prj); fire_projectile(p8, _spawn_prj); cooldown_ = cooldown_time_; PowerTick(-35); } } }
static void tick_combat(struct GameState *game_state, float dt) { for (uint32 i = 0; i < game_state->ship_count; ++i) { struct Ship *ship = &game_state->ships[i]; if (ship->fire_cooldown_timer <= 0.0f) { struct Ship *target = find_nearest_enemy(game_state, ship); if (target == NULL) continue; fire_projectile(game_state, ship, target, 1); } else { ship->fire_cooldown_timer -= dt; } } }
/* ================= fire_shuriken ================= */ qboolean fire_shuriken (gentity_t *self, vec3_t start, vec3_t forward, vec3_t right, vec3_t up, holdable_t holdable) { int projnum; float s_quadFactor; if (self->player->ps.powerups[PW_QUAD] ) { s_quadFactor = g_quadfactor.value; } else { s_quadFactor = 1; } #ifdef MISSIONPACK if( self->player->persistantPowerup && self->player->persistantPowerup->item && self->player->persistantPowerup->item->giTag == PW_DOUBLER ) { s_quadFactor *= 2; } #endif projnum = BG_ProjectileIndexForHoldable(holdable); G_AutoAim(self, projnum, start, forward, right, up); return fire_projectile(self, start, forward, right, up, projnum, s_quadFactor, MOD_UNKNOWN, MOD_UNKNOWN, HS_CENTER); }
/* * Main function to run one tick of the game */ int run_game() { cli(); /* Movement phase */ if(game_state == 1) { /* Move the reticule based on readings from the rotary encoder */ int16_t newRX = (playersX[current_player] + (RETICULE_DISTANCE * ml_cos(position))/100); int16_t newRY = (playersY[current_player] + (RETICULE_DISTANCE * ml_sin(position))/100); rectangle reticuleOld = {reticuleX - reticule_SPR->width / 2, reticuleX + reticule_SPR->width / 2 - 1, reticuleY - reticule_SPR->height / 2, reticuleY + reticule_SPR->height / 2 - 1}; draw_background(level_map, SILVER, reticuleOld, HEIGHT_NO_UI, WIDTH); //fill_rectangle(reticuleOld, BLACK); if(newRX >= 0 && newRX < WIDTH && newRY >= 0 && newRY < HEIGHT) fill_sprite(reticule_SPR, newRX, newRY, HEIGHT_NO_UI, WIDTH); reticuleX = newRX; reticuleY = newRY; /* Read firing input */ if (get_switch_long(_BV(SWC))) { game_state = 3; return 0; } /* Read directional input.*/ if (get_switch_rpt(_BV(SWE))) { direction = 4; free_sprite(player_SPR); player_SPR = botright(current_player); } else if (get_switch_rpt(_BV(SWW))) { direction = -4; free_sprite(player_SPR); player_SPR = botleft(current_player); } else { direction = 0; return 0; } /* Move the player */ int16_t newX = playersX[current_player] + direction; int16_t newY = ml_min(level_map[newX - PLAYER_WIDTH], level_map[newX + PLAYER_WIDTH - 1]) - PLAYER_HEIGHT; int8_t i; int8_t player_collision = 0; for(i = 0; i < players; i++) { if(players_HP[i] != 0 && i != current_player && newX >= playersX[i] - PLAYER_WIDTH && newX <= playersX[i] + PLAYER_WIDTH - 1) { player_collision = 1; break; } } /* Cancel movement if trying to climb to high or off the sides of the screen */ if(player_collision || playersY[current_player] - newY > MAX_CLIMB_HEIGHT || newX <= PLAYER_WIDTH || newX + PLAYER_WIDTH > WIDTH) { /* DEBUGGING prints: */ //display_string_xy("Error\n", 10, 10); //ml_printf("Cannot move there... (%u,%u) to (%u,%u)", playersX[0], playersY[0], newX, newY); return 0; } rectangle playerOld = {playersX[current_player] - PLAYER_WIDTH, playersX[current_player] + PLAYER_WIDTH - 1, playersY[current_player] - PLAYER_HEIGHT, playersY[current_player] + PLAYER_HEIGHT - 1}; fill_rectangle(playerOld, BLACK); fill_sprite(player_SPR, newX, newY, HEIGHT_NO_UI, WIDTH); playersX[current_player] = newX; playersY[current_player] = newY; } /* Projectile phase (missile in the air) */ else if(game_state == 2) { /* Find the new position of the projectile */ int16_t newX = projectileX + proVelX/1000; int16_t newY = projectileY + proVelY/1000; rectangle projectileOld = {projectileX, projectileX, projectileY, projectileY}; fill_rectangle(projectileOld, BLACK); /* End turn if projectile goes off the sides of the level */ if(newX < 0 || newX > WIDTH) { start_turn(); return 0; } /* If the new position is in the ground, EXPLODE! * (Also, if off the bottom of the level) */ if(newY >= level_map[newX] || newY > HEIGHT_NO_UI) { int i; for(i = -EXPLOSION_RADIUS; i <= EXPLOSION_RADIUS; i++) { /* Make sure that terrain is on screen */ if(newX + i >= 0 && newX + i < WIDTH) { uint16_t new_ground_level = newY + ml_sqrt(EXPLOSION_RADIUS * EXPLOSION_RADIUS - i * i); if(new_ground_level >= HEIGHT_NO_UI) level_map[newX + i] = HEIGHT_NO_UI - 1; //Clamp to bottom of level else if(new_ground_level > level_map[newX + i]) //Don't raise the ground level! level_map[newX + i] = new_ground_level; } } draw_level(level_map, SILVER, newX - EXPLOSION_RADIUS, newX + EXPLOSION_RADIUS); /* Check players for damage + redraw them */ for(i = 0; i < players; i++) { int16_t deltaX = playersX[i] - newX; int16_t deltaY = playersY[i] - newY; int16_t distance = ml_sqrt(deltaX * deltaX + deltaY * deltaY); if(distance < BLAST_RADIUS) { int16_t damage = ml_clamp(0, players_HP[i], MAX_EXPLOSION_DAMAGE - (distance * MAX_EXPLOSION_DAMAGE / BLAST_RADIUS)); players_HP[i] -= damage; } rectangle playerOld = {playersX[i] - PLAYER_WIDTH, playersX[i] + PLAYER_WIDTH - 1, playersY[i] - PLAYER_HEIGHT, playersY[i] + PLAYER_HEIGHT - 1}; fill_rectangle(playerOld, BLACK); /* If the player is still alive, redraw them */ if(players_HP[i] != 0) { free_sprite(player_SPR); player_SPR = botleft(i); playersY[i] = ml_min(level_map[playersX[i] - PLAYER_WIDTH], level_map[playersX[i] + PLAYER_WIDTH - 1]) - PLAYER_HEIGHT; fill_sprite(player_SPR, playersX[i], playersY[i], HEIGHT_NO_UI, WIDTH); } } start_turn(); return 0; } rectangle projectileNew = {newX, newX, newY, newY}; /* Continue turn if off top of level, but only draw if projectile onscreen */ if(newY >= 0) { fill_rectangle(projectileNew, RED); } projectileX = newX; projectileY = newY; /* Apply gravity and wind */ proVelY += 500; proVelX += (wind_velocity - 10) * 50; } /* Charging phase */ else if(game_state == 3) { /* Increase the launch speed while the fire button is held */ if (get_switch_state(_BV(SWC))) { launch_speed++; rectangle bar = {POWER_BAR_START, POWER_BAR_START + launch_speed, 231, 236}; fill_rectangle(bar, WHITE); /* Fire once max power is reached */ if(launch_speed == 100) fire_projectile(); } else { fire_projectile(); } } /* Menu phase */ else if(game_state == 4) { if (get_switch_press(_BV(SWE))) { if(players == 4) players = 2; else players++; } else if (get_switch_press(_BV(SWW))) { if(players == 2) players = 4; else players--; } ml_printf_at("< %u Players >", 5, 115, players); if (get_switch_long(_BV(SWC))) { start_game(); } } /* End game phase */ else if(game_state == 5) { if (get_switch_long(_BV(SWC))) { start_menu(); } } sei(); return 0; }