public Bullet(long object_id, Player player, float x, float y, float vx, float vy, long updateTime) { id = object_id; pos_x = x; pos_y = y; vect_x = vx; vect_y = vy; weapon = player.weapon; lastUpdate = updateTime; }
protected void sendBullet(float bx, float by, float vx, float vy, Player p, long id) { Weapons.instance.send("spawn_bullet", s => { var writer = new BinaryWriter(s, Encoding.UTF8, false); writer.Write(id); writer.Write(p.id); writer.Write(bx); writer.Write(by); writer.Write(vx); writer.Write(vy); writer.Write(size); }); }
private void CheckIfBulletCollideWithPlayers(Player p) { foreach (Bullet b in _bullets.Values) { var bullet_x = b.pos_x + (b.vect_x * (_env.Clock - b.lastUpdate) / 1000f); var bullet_y = b.pos_y + (b.vect_y * (_env.Clock - b.lastUpdate) / 1000f); double x = Math.Pow(p.pos_x - (double)bullet_x, 2); double y = Math.Pow(p.pos_y - (double)bullet_y, 2); var dist = Math.Sqrt(x + y); if (dist < 0) dist = -dist; if (dist < 5.0f) { _scene.GetComponent<ILogger>().Debug("main", "A bullet hit a player !"); p.life -= b.weapon.damage; if (p.life <= 0) { p.lastHit = _env.Clock; p.status = StatusTypes.DEAD; _scene.Broadcast("update_status", s => { using (var w = new BinaryWriter(s, Encoding.UTF8, false)) { w.Write(p.id); w.Write(1); } }, PacketPriority.MEDIUM_PRIORITY, PacketReliability.RELIABLE); } } } }
private async void CreatePlayerBullet(Player p, float x, float y, long time) { await p.weapon.Fire(p, x, y, time); }
protected void CalcNextBullet(Player p, float bx, float by, long time) { double vx = (double)(bx - p.pos_x); double vy = (double)(by - p.pos_y); Normalize(ref vx, ref vy); vx = vx + ((rand.NextDouble() - 0.5f) * spread); vy = vy + ((rand.NextDouble() - 0.5f) * spread); Normalize(ref vx, ref vy); long clock = Weapons.instance.getTime(); bx = p.pos_x + (float)vx * 1.5f;// + (p.vect_x * (float)(((clock - p.lastUpdate)) / 50)); by = p.pos_y + (float)vy * 1.5f;// + (p.vect_y * (float)(((clock - p.lastUpdate)) / 50)); vx = vx * speed; vy = vy * speed; long id = Weapons.instance.id; Weapons.instance.bullets.TryAdd(id, new Bullet(id, p, bx, by, (float)vx, (float)vy, time)); Weapons.instance.id++; if (Weapons.instance.id > 2000000) Weapons.instance.id = 0; sendBullet(bx, by, (float) vx, (float) vy, p, id); }
public override Task Fire(Player p, float target_x, float target_y, long time) { CalcNextBullet(p, target_x, target_y, time); CalcNextBullet(p, target_x, target_y, time); CalcNextBullet(p, target_x, target_y, time); CalcNextBullet(p, target_x, target_y, time); CalcNextBullet(p, target_x, target_y, time); return Task.FromResult(true); }
public override async Task Fire(Player p, float target_x, float target_y, long time) { if (p.status == StatusTypes.ALIVE) CalcNextBullet(p, target_x, target_y, time); await Task.Delay(100); if (p.status == StatusTypes.ALIVE) CalcNextBullet(p, target_x, target_y, time); await Task.Delay(100); if (p.status == StatusTypes.ALIVE) CalcNextBullet(p, target_x, target_y, time); }
virtual public Task Fire(Player p, float target_x, float target_y, long time) { return Task.FromResult(true); }