Ejemplo n.º 1
0
        public Town(EntityState es)
            : base(es)
        {
            Body = new Body(this, Vector2.Zero, new Vector2(20,15));
            Components.Add(Body);

            TileRender = new TileRender(this, es.GameRef.Game.Content.Load<Texture2D>(@"game/town"), new Vector2(20, 15));
            Render = TileRender;
            Render.Scale = 6f;
            Render.Layer = 1f;
            Components.Add(Render);

            Body.Position = new Vector2(StateRef.GameRef.Viewport.Width/2 - Render.DrawRect.Width / 2, 450);
            DeadCityAnim = new Animation(this, es.GameRef.Game.Content.Load<Texture2D>(@"game/deadcity"), new Vector2(20, 15), 4, "deadtown");
            DeadCityAnim.Layer = 1f;
            DeadCityAnim.Scale = 6.0f;

            Health = new Health(this, 100);
            Health.HurtEvent += ChangeColor;

            TileRender.Index = 2;
            Components.Add(Health);

            Gun = new Gun(this);
            Components.Add(Gun);

            Cursor = new Cursor(StateRef, this);
            StateRef.AddEntity(Cursor);

            Collision = new Collision(this);
            Components.Add(Collision);

            _fire = new Sound(this, es.GameRef.Game.Content.Load<SoundEffect>(@"game/sounds/bombfire"));
            Components.Add(_fire);
        }
Ejemplo n.º 2
0
        public Bomb(EntityState es, Vector2 position, float angle, float thrust)
            : base(es)
        {
            Body = new Body(this, position) {Angle = angle};
            Components.Add(Body);

            Physics = new Physics(this);
            Physics.Thrust(thrust);
            Components.Add(Physics);

            _explodeanim = new Animation(this, es.GameRef.Game.Content.Load<Texture2D>(@"game/explosion"),
                new Vector2(16,16), 30, "explode");
            _explodeanim.Layer = 0.2f;
            _explodeanim.Scale = 2.5f;
            _explodeanim.LastFrameEvent += Destroy;

            Render = new Render(this, es.GameRef.Game.Content.Load<Texture2D>(@"game/bomb"));
            Render.Layer = 0.1f;
            Render.Scale = 1.5f;
            Components.Add(Render);

            Collision = new Collision(this);
            Collision.CollideEvent += CollisionHandler;
            Components.Add(Collision);

            _ee = new ExplosionEmitter(this);
            Components.Add(_ee);

            _se = new SmokeEmitter(this);
            Components.Add(_se);

            _explodesound = new Sound(this, StateRef.GameRef.Game.Content.Load<SoundEffect>(@"game/sounds/explosion"));
            _explodesound.Volume = .5f;
            Components.Add(_explodesound);
        }
Ejemplo n.º 3
0
        public Asteroid(Texture2D asteroidtexture, EntityState es)
            : base(es)
        {
            Body = new Body(this, new Vector2(Rand.Next(0, es.GameRef.Viewport.Right), Rand.Next(0, es.GameRef.Viewport.Bottom)), new Vector2(asteroidtexture.Width, asteroidtexture.Height));
            Components.Add(Body);

            Render = new Render(this, asteroidtexture) { Scale = .75f };
            Components.Add(Render);

            Physics = new Physics(this) { Velocity = new Vector2((float)Rand.NextDouble() * Rand.Next(-2, 3) + .5f, (float)Rand.NextDouble() * Rand.Next(-2, 3) + .5f), Drag = 1.0f };
            Components.Add(Physics);

            Health = new Health(this, 3);
            Components.Add(Health);
            Health.HurtEvent += EmitEventHandler;
            Health.HurtEvent += SplitAsteroid;
            Health.DiedEvent += Destroy;

            Collision = new Collision(this);
            Components.Add(Collision);
            Collision.CollideEvent += onCollide;

            _emitter = new HurtEmitter(this, StateRef.GameRef.Game.Content.Load<Texture2D>(@"particles/thrustparticle"));
            Components.Add(_emitter);

            _hitemitter = new AsteroidHitEmitter(this, StateRef.GameRef.Game.Content.Load<Texture2D>(@"particles/thrustparticle"));
            Components.Add(_hitemitter);
        }
Ejemplo n.º 4
0
        public Text(EntityState es, Vector2 position, string text, SpriteFont font)
            : base(es)
        {
            Body = new Body(this, position, Vector2.Zero);
            Components.Add(Body);

            Physics= new Physics(this);
            Components.Add(Physics);

            Render = new TextRender(this, font, text, position);
            Components.Add(Render);
        }
Ejemplo n.º 5
0
        public Image(EntityState es, Texture2D texture, Vector2 position)
            : base(es)
        {
            Body = new Body(this, position, new Vector2(texture.Width, texture.Height));
            Components.Add(Body);

            Physics = new Physics(this);
            Components.Add(Physics);

            Render = new Render(this, texture);
            Components.Add(Render);
        }
Ejemplo n.º 6
0
        public Particle(int index, Vector2 position, int ttl, Emitter e)
            : base(e.Entity.StateRef)
        {
            Body = new Body(this, position, e.TileSize);
            Components.Add(Body);

            _tr = new TileRender(this, e.Texture, e.TileSize);
            Render = _tr;
            Components.Add(Render);
            Index = index;

            Physics = new Physics(this);
            Components.Add(Physics);

            Emitter = e;
            TimeToLive = ttl;
            MaxTimeToLive = TimeToLive;
        }
Ejemplo n.º 7
0
        public Soldier(EntityState es)
            : base(es)
        {
            Points = 10;

            Body = new Body(this, Vector2.Zero);
            Components.Add(Body);
            _soldieranim = new Animation(this, es.GameRef.Game.Content.Load<Texture2D>(@"game/soldier"), new Vector2(5, 10), 4,
                                   "soldier");
            Render = _soldieranim;
            Render.Flip = (_rand.RandomBool()) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
            Render.Layer = .5f;
            _soldieranim.Start();
            Components.Add(Render);

            Body.Position.Y = 520 -  _rand.Next(-10,10);
            Body.Position.X = (Render.Flip == SpriteEffects.None) ? es.GameRef.Viewport.Right + 10 : -10;

            Collision = new Collision(this);
            Components.Add(Collision);

            Physics = new Physics(this);
            Physics.Velocity.X = (Render.Flip == SpriteEffects.None) ? -.25f : .25f;
            Components.Add(Physics);

            Health = new Health(this, 1);
            Health.DiedEvent += OnDeath;
            Components.Add(Health);

            _attacktimer = new Timer(this);
            _attacktimer.Milliseconds = 500;
            _attacktimer.LastEvent += OnAttackTimer;
            Components.Add(_attacktimer);

            _ge = new GibEmitter(this);
            Components.Add(_ge);

            _hitsound = new Sound(this, StateRef.GameRef.Game.Content.Load<SoundEffect>(@"game/sounds/hit"));
            Components.Add(_hitsound);

            _attacksound = new Sound(this, StateRef.GameRef.Game.Content.Load<SoundEffect>(@"game/sounds/shoot"));
            _attacksound.Volume = .3f;
            Components.Add(_attacksound);
        }
Ejemplo n.º 8
0
        public Helicopter(EntityState es)
            : base(es)
        {
            Points = 50;

            Body = new Body(this, Vector2.Zero);
            Components.Add(Body);

            _helicopteranim = new Animation(this, es.GameRef.Game.Content.Load<Texture2D>(@"game/helicopter"), new Vector2(20, 16), 30,
                                   "helicopter");
            Render = _helicopteranim;
            Render.Flip = (_rand.RandomBool()) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
            Render.Layer = .5f;
            _helicopteranim.Start();
            Components.Add(Render);

            Body.Position.Y = 300 - _rand.Next(-10, 10);
            Body.Position.X = (Render.Flip == SpriteEffects.None) ? es.GameRef.Viewport.Right + 10 : -10;

            Collision = new Collision(this);
            Components.Add(Collision);

            Physics = new Physics(this);
            Physics.Velocity.X = (Render.Flip == SpriteEffects.None) ? -.4f : .4f;
            Components.Add(Physics);

            Health = new Health(this, 1);
            Health.DiedEvent += OnDeath;
            Components.Add(Health);

            _hge = new HeliGibEmitter(this);
            Components.Add(_hge);

            _explodeanim = new Animation(this, es.GameRef.Game.Content.Load<Texture2D>(@"game/explosion"),
                new Vector2(16, 16), 30, "explode");
            _explodeanim.Layer = 0.2f;
            _explodeanim.Scale = 1.5f;
            _explodeanim.LastFrameEvent += Destroy;
        }
Ejemplo n.º 9
0
        public Ship(Texture2D shiptexture, Texture2D bullettexture, EntityState es)
            : base(es)
        {
            Body = new Body(this, new Vector2(es.GameRef.Viewport.Width / 2.0f, es.GameRef.Viewport.Height / 2.0f),
                            new Vector2(shiptexture.Width, shiptexture.Height));
            Components.Add(Body);

            Physics = new Physics(this) { Drag = 0.9f };
            Components.Add(Physics);

            Render = new Render(this, shiptexture) { Scale = .5f };
            Components.Add(Render);

            Weapon = new Gun(this, bullettexture);
            Components.Add(Weapon);

            Health = new Health(this, 5);
            Health.DiedEvent += Destroy;
            Health.DiedEvent += EmitEventHandler;
            Components.Add(Health);

            Collision = new Collision(this);
            Components.Add(Collision);

            ThrustEmitter = new ThrustEmitter(this, StateRef.GameRef.Game.Content.Load<Texture2D>(@"particles/thrustparticle"));
            Components.Add(ThrustEmitter);

            DeathEmitter = new DeathEmitter(this, StateRef.GameRef.Game.Content.Load<Texture2D>(@"particles/shipdeathparticle123"));
            Components.Add(DeathEmitter);

            _attackkey = new KeyboardInput(Keys.Enter);
            _upkey = new KeyboardInput(Keys.W);
            _downkey = new KeyboardInput(Keys.S);
            _leftkey = new KeyboardInput(Keys.A);
            _rightkey = new KeyboardInput(Keys.D);
            _debugkey = new KeyboardInput(Keys.L);
        }
Ejemplo n.º 10
0
        public Cursor(EntityState es, Town town)
            : base(es)
        {
            Town = town;

            _aimleftkey = new DoubleInput(Keys.A, Buttons.DPadLeft, PlayerIndex.One);
            _aimrightkey = new DoubleInput(Keys.D, Buttons.DPadRight, PlayerIndex.One);
            _quickaimkey = new DoubleInput(Keys.LeftShift, Buttons.RightShoulder, PlayerIndex.One);

            Physics = new Physics(this);
            Components.Add(Physics);

            Render = new Render(this, StateRef.GameRef.Game.Content.Load<Texture2D>(@"game/cursor"))
                {
                    Layer = 1f,
                    Scale = 6f
                };
            Components.Add(Render);

            Body = new Body(this, town.Body.Position + (town.Render.Origin - Vector2.UnitY * 40 - Render.Origin) * Render.Scale, Vector2.One * 5);
            Components.Add(Body);

            Town.Health.DiedEvent += Destroy;
        }