コード例 #1
0
        public Soldier(EntityState es, string name, XmlParser xp)
            : base(es, name)
        {
            Name = name + ID;

            Body = new Body(this, "Body");
            AddComponent(Body);

            Physics = new Physics(this, "Physics");
            AddComponent(Physics);

            Animation = new Animation(this, "Animation");
            Animation.Start();
            AddComponent(Animation);

            Collision = new Collision(this, "Collision");
            AddComponent(Collision);

            Health = new Health(this, "Health");
            Health.DiedEvent += OnDeath;
            AddComponent(Health);

            _attacktimer = new Timer(this, "AttackTimer");
            _attacktimer.LastEvent += OnAttackTimer;
            AddComponent(_attacktimer);

            _attacksound = new Sound(this, "AttackSound");
            AddComponent(_attacksound);

            _hitsound = new Sound(this, "HitSound");
            AddComponent(_hitsound);

            _ge = new GibEmitter(this, "GibEmitter");
            AddComponent(_ge);

            string path = es.Name + "->" + "Soldier";
            ParseXml(xp, path);

            Animation.Flip = (_rand.RandomBool()) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
            Physics.Velocity.X = (Animation.Flip == SpriteEffects.None) ? -_speed : _speed;
            Body.Position.X = (Animation.Flip == SpriteEffects.None) ? es.GameRef.Viewport.Right + 10 : -10;
            Body.Position.Y = 520 - _rand.Next(-10, 10);

            //TODO: Set origin
            //TODO: Set Health.DiedEvent to emit blood particles and Destroy
        }
コード例 #2
0
        public Helicopter(EntityState es, string name, XmlParser xp)
            : base(es, name)
        {
            Name = name + ID;
            _xp = xp;

            Body = new Body(this, "Body");
            AddComponent(Body);

            Physics = new Physics(this, "Physics");
            AddComponent(Physics);

            Animation = new Animation(this, "Animation");
            AddComponent(Animation);

            Collision = new Collision(this, "Collision");
            AddComponent(Collision);

            Health = new Health(this, "Health");
            Health.DiedEvent += OnDeath;
            AddComponent(Health);

            _ge = new GibEmitter(this, "GibEmitter");
            AddComponent(_ge);

            _explodeanim = new Animation(this, "ExplodeAnim");
            _explodeanim.LastFrameEvent += Destroy;
            AddComponent(_explodeanim);

            _hitsound = new Sound(this, "HitSound");
            AddComponent(_hitsound);

            string path = es.Name + "->Helicopter";
            ParseXml(xp, path);

            Animation.Flip = (_rand.RandomBool()) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
            Physics.Velocity.X = (Animation.Flip == SpriteEffects.None) ? -.4f : .4f;
            Body.Position.Y = 300 - _rand.Next(-10, 10);
            Body.Position.X = (Animation.Flip == SpriteEffects.None) ? es.GameRef.Viewport.Right + 10 : -10;
        }