/// <summary> /// Called from the Arena, when a bot calls the Arena.Cannon() method /// /// The Cannon() function fires a missile heading a specified range and direction. /// Cannon() returns 1 (true) if a missile was fired, or 0 (false) if the cannon is reloading. /// Degree is forced into the range 0-359 as in Scan() and Drive(). /// Range can be 0-700, with greater ranges truncated to 700. /// /// Examples: /// degree = 45; // set a direction to test /// if ((range=Scan(robot, degree, 2)) > 0) // see if a target is there /// Cannon(robot, degree, range); // fire a missile /// </summary> /// <param name="robot"></param> /// <param name="degree"></param> /// <param name="range"></param> /// <returns></returns> public bool FireCannon(Robot robot, int degree, int range) { degree = Arena.DegreeTo360(degree); if (range < 0) { range = 0; } if (range > 700) { range = 700; } BotAssembly bot = Bots.Find(botAssembly => botAssembly.Id == robot.Id); if (bot.MissilesInFlight < MaxMissles) { bot.MissilesInFlight++; Missiles.Add(new Missile { Id = robot.Id, Speed = 100, Location = new PointF { X = bot.Location.X, Y = bot.Location.Y }, Direction = degree, Range = range }); return(true); } return(false); }
private void OnEntityAdd(MyEntity myEntity) { try { if (DsState.State.ReInforce) { return; } if (myEntity?.Physics == null || !myEntity.InScene || myEntity.MarkedForClose || myEntity is MyFloatingObject || myEntity is IMyEngineerToolBase) { return; } var isMissile = myEntity.DefinitionId.HasValue && myEntity.DefinitionId.Value.TypeId == typeof(MyObjectBuilder_Missile); if (!isMissile && !(myEntity is MyCubeGrid)) { return; } var aabb = myEntity.PositionComp.WorldAABB; if (!ShieldBox3K.Intersects(ref aabb)) { return; } Asleep = false; if (_isServer && isMissile) { Missiles.Add(myEntity); } } catch (Exception ex) { Log.Line($"Exception in Controller OnEntityAdd: {ex}"); } }
public Player(Game1 game, World world, float ratio, float strength, Vector2 position,string texture_0_path,string texture_1_path, string texture_2_path, string texture_3_path, string textureMissilePath, string textureParticlePath) : base(game, world, texture_0_path,texture_1_path,texture_2_path,texture_3_path) { var texture_0 = Content.Load<Texture2D>(texture_0_path); var texture_1 = Content.Load<Texture2D>(texture_1_path); var texture_2 = Content.Load<Texture2D>(texture_2_path); var texture_3 = Content.Load<Texture2D>(texture_3_path); _missiles = new Missiles(game, world, ratio, textureMissilePath); particles = new ParticleEngine(game, textureParticlePath); _textureReference = texture_0; _ratio = ratio; Broken = false; Boosting = false; _boostTimer = 0; _Index = 0; Bullets = 4; Reload = false; CreatePlayerBreakableBody(strength, position); //ball = BodyFactory.CreateCircle(world, 5, 1, position: new Vector2(40,36)); //ball.BodyType = BodyType.Static; //ball.CollisionCategories = Category.Cat1; //ball.CollidesWith = Category.All; avion = new Sprite[4]; avion[0] = new Sprite(texture_0) { Position = this.Position, Rotation = this.Rotation }; avion[1] = new Sprite(texture_1) { Position = this.Position, Rotation = this.Rotation }; avion[2] = new Sprite(texture_2) { Position = this.Position, Rotation = this.Rotation }; avion[3] = new Sprite(texture_3) { Position = this.Position, Rotation = this.Rotation }; }
//create a function to control the interaction between enemy and player private void OnTriggerEnter(Collider other) { if (other.tag == "PlayerRocket") //if spaceship run into the shell { Missiles rocket = other.GetComponent <Missiles>(); //decrease its health if (rocket != null) { GameManager.Instance.GetEnemyHealth(hp); //碰到就要显示血量 hp -= rocket.m_attack; GameManager.Instance.GetEnemyHealth(hp); //减少也要显示血量变化 if (this.hp <= 0) { GameManager.Instance.AddScore(100); //通过已经实例化的GameManager的Instance调用AddScore函数,而且摧毁一架敌机加一百分 Destroy(this.gameObject); //destroy itself GameObject.Instantiate(enemy_explosion, this.transform.position, this.transform.rotation); //直接在敌人的位置生成爆炸特效 } } } //if spaceship run into the player, destroy itself immediately if (other.tag == "Player") { GameManager.Instance.AddScore(100); Destroy(this.gameObject); GameObject.Instantiate(enemy_explosion, this.transform.position, this.transform.rotation); //直接在敌人的位置生成爆炸特效 } }
private void OnTriggerExit2D(Collider2D collision) { if (collision.gameObject.CompareTag("Missile")) { missile = collision.gameObject.GetComponent <Missiles>(); missile.isSlow = false; } }
public void Reset() { Bots.Clear(); Bombs.Clear(); Missiles.Clear(); Explosions.Clear(); Board = new BoardTile[Board.GetLength(0), Board.GetLength(1)]; OnArenaChanged(); }
public InvaderMother(Game1 game, World world, float ratio, string texturePath, string textureMissilePath, string textureParticlePath, BreakableBody target) : base(game, world, texturePath) { _texture = Content.Load<Texture2D>(texturePath); _ratio = ratio; this.target = target; _missiles = new Missiles(game, world, ratio, textureMissilePath); // particles = new ParticleEngine(game, textureParticlePath); Practice = false; Alive = false; }
public void CreateMissile(double fps) { if (_lastShot >= fps / _shotsPerSec) { Position p = Pos; p.Y += Height / 2; Missile m = new Missile(_grid, p, new GBsharp2.Primitives.Vector(Missile.Acceleration, 0) + Vec); m.Draw(); Missiles.Add(m); _lastShot = 0; } }
public Battlefield ExportState() { var arena = new Battlefield(Board.GetLength(0), Board.GetLength(1)); Board.ForEveryElement((x, y, val) => { arena.Board[x, y] = val; }); arena.Bots = Bots.Select(bot => new TankBlasterBot(bot)).ToList(); arena.Bombs = Bombs.Select(bomb => new Bomb(bomb)).ToList(); arena.Missiles = Missiles.Select(missile => new Missile(missile)).ToList(); return(arena); }
public override void Update(double fps = 1) { base.Update(fps); TickDamping(fps); if (_pos.X < 0) { _pos.X = 0; _vec.X = -_vec.X / BumpDamping; } else if (_pos.X > _grid.Width - _canvas.Width - 30) { _pos.X = _grid.Width - _canvas.Width - 30; _vec.X = -_vec.X / BumpDamping; } if (_pos.Y < 0) { _pos.Y = 0; _vec.Y = -_vec.Y / BumpDamping; } else if (_pos.Y > _grid.ActualHeight - _canvas.ActualHeight - 45) { _pos.Y = _grid.ActualHeight - _canvas.ActualHeight - 45; _vec.Y = -_vec.Y / BumpDamping; } for (int i = 0; i < Missiles.Count; i++) { Missiles[i].Update(fps); if (Missiles[i].ToRemove) { Missiles[i].Remove(); Missiles.Remove(Missiles[i]); } } if (_lastShot < fps / _shotsPerSec) { _lastShot++; } if (HP <= 0) { Death?.Invoke(this, new EventArgs()); } }
public void Update(GameTime gameTime) { Level.Update(gameTime); Globals.Camera.Update(gameTime); Beings.ForEach(b => b.Update(gameTime)); Enemies = Enemies.Where(e => e.IsActive).ToList(); Enemies.ForEach(e => e.GetAI().Run(gameTime)); Allies = Allies.Where(e => e.IsActive).ToList(); Allies.ForEach(e => e.GetAI().Run(gameTime)); Missiles = Missiles.Where(m => m.IsActive).ToList(); Missiles.ForEach(m => m.Update(gameTime)); Items = Items.Where(i => i.IsActive).ToList(); Items.ForEach(i => i.Update(gameTime)); DamageTexts = DamageTexts.Where(d => d.IsActive).ToList(); DamageTexts.ForEach(d => d.Update(gameTime)); EnemyCreatorFactory.Update(gameTime); }
public void Fire(ServerShip ship, bool isLeft, int number, int idTarget, Ecm jammer) { lock (m_locker) { if (ship.Missiles == 0) { return; } var target = Ships.ById(idTarget); if (target == null || isLeft != ship.IsLeftBoard(target)) { return; } var board = isLeft ? ship.Left : ship.Right; var missileClass = board.GetRack(number).MissileClass; if (!board.Fire(number)) { return; } ship.Missiles--; int id = Interlocked.Increment(ref IdNext); var missile = new Missile { Id = id, Position = ship.Position, Speed = ship.Speed, Acceleration = ship.Acceleration, }; var control = new MissileControl { Id = id, Arrow = missile, Origin = ship, Target = target, IdOrigin = ship.Id, IdTarget = target.Id, Jammer = jammer, Thrust = missileClass.Acceleration, Remaining = missileClass.FlyTime, HitDistance = missileClass.HitDistance, Started = Time.TotalSeconds, }; Missiles.Add(id, control); } }
public IParticle ById(ParticleType type, int id) { if (id == 0) { return(null); } switch (type) { case ParticleType.Star: return(Stars.ById(id)); case ParticleType.Ship: return(Ships.ById(id)); case ParticleType.Missile: return(Missiles.ById(id)); } throw new IndexOutOfRangeException("Unknown particle type."); }
private void OnEntityRemove(MyEntity myEntity) { try { if (myEntity == null || !_isServer || DsState.State.ReInforce) { return; } if (!(myEntity.DefinitionId.HasValue && myEntity.DefinitionId.Value.TypeId == typeof(MyObjectBuilder_Missile))) { return; } Missiles.Remove(myEntity); FriendlyMissileCache.Remove(myEntity); } catch (Exception ex) { Log.Line($"Exception in Controller OnEntityRemove: {ex}"); } }
private void OnTriggerEnter(Collider other) { if (other.tag == "PlayerRocket") { GameManager.Instance.GetEnemyHealth(heathlevel); //碰到就要显示血量 Missiles mis = other.GetComponent <Missiles>(); this.heathlevel -= mis.m_attack; //decrease its health level GameManager.Instance.GetEnemyHealth(this.heathlevel); //减少也要显示血量变化 if (this.heathlevel <= 0) { GameManager.Instance.AddScore(1000); //通过已经实例化的GameManager的Instance调用AddScore函数,而且摧毁一架高级敌机加一千分 Destroy(this.gameObject); //if the advanced enemy being run into the player's rocket GameObject.Instantiate(AdvancedenemyExplosionEffects, this.transform.position, this.transform.rotation); //在当前位置生成爆炸效果 } } if (other.tag == "Player") { GameManager.Instance.GetEnemyHealth(heathlevel); //碰到就要显示血量 Player player = other.GetComponent <Player>(); heathlevel -= (player.playerdefend - enemydefend); GameManager.Instance.GetEnemyHealth(this.heathlevel); //减少也要显示血量变化 if (heathlevel <= 0) { GameManager.Instance.AddScore(1000); //通过已经实例化的GameManager的Instance调用AddScore函数,而且摧毁一架高级敌机加一千分 Destroy(this.gameObject); GameObject.Instantiate(AdvancedenemyExplosionEffects, this.transform.position, this.transform.rotation); //在当前位置生成爆炸效果 } //if the advancedenemy run into the player, decrease the heathlevel } }
/// <summary> /// Remove any dead missiles from our list /// </summary> private void RemoveDeadMissles() { List <Missile> missiles = Missiles.Where(missile => !missile.Dead).ToList(); Missiles = missiles; }
void Awake() { Instance = this; }