예제 #1
0
        private void CreateBossOne(int enemyBulletDelay, int scale = 1)
        {
            var xPosition = GameHelper.GetRelativeScaleX(0.5f);
            var enemy     = new GameObject("Boss", new Vector2(xPosition, 0))
            {
                Scale = scale
            };

            var shipTexture            = SpaceGraphics.BossAAsset.First();
            var enemySprite            = new SpriteComponent(shipTexture);
            var enemyMovement          = new MovementComponent(0.1f, FaceDirection.Down, new Vector2(0, 1));
            var enemyBullet            = new BulletComponent(TopDown.EnemyBulletName, SpaceGraphics.BulletAsset[0], enemyMovement);
            var enemyBoundary          = new BoundaryComponent(SpaceGraphics.BoundaryAsset.First(), shipTexture.Width, shipTexture.Height);
            var enemyTimed             = new TimedActionComponent(ObjectEvent.Fire, enemyBulletDelay);
            var enemyOutOfBounds       = new OutOfBoundsComponent(ObjectEvent.RemoveEntity);
            var healthCounterComponent = new CounterIncrementComponent(ObjectEvent.CollisionEnter, ObjectEvent.HealthRemoved, ObjectEvent.HealthEmpty, ObjectEvent.HealthReset, 5, 0);
            var healthBarComponent     = new SpriteRepeaterComponent(SpaceGraphics.HealthBarAsset[1], new Vector2(0, 25), false, ObjectEvent.HealthRemoved, healthCounterComponent);
            var deathAction            = new ObjectEventComponent(ObjectEvent.HealthEmpty, BossDeath);

            enemy.AddComponent(enemySprite);
            enemy.AddComponent(enemyMovement);
            enemy.AddComponent(enemyBullet);
            enemy.AddComponent(enemyBoundary);
            enemy.AddComponent(enemyOutOfBounds);
            enemy.AddComponent(enemyTimed);
            enemy.AddComponent(healthCounterComponent);
            enemy.AddComponent(healthBarComponent);
            enemy.AddComponent(deathAction);

            ForegroundLayer.AddGameObject(enemy);
        }
예제 #2
0
 public SpriteRepeaterComponent(Texture2D texture, Vector2 relativeLocation, bool isVertical, ObjectEvent subscribeEvent, CounterIncrementComponent counterIncrementComponent, bool isReverse = false, Color?color = null)
 {
     Texture                    = texture;
     _relativeLocation          = relativeLocation;
     _currentValue              = counterIncrementComponent.CurrentValue;
     _isVertical                = isVertical;
     _subscribeEvent            = subscribeEvent;
     _counterIncrementComponent = counterIncrementComponent;
     _isReverse                 = isReverse;
     _color = color ?? Color.White;
 }
예제 #3
0
        private void CreateScoreDisplay()
        {
            var score            = new GameObject("Score", new Vector2(10, 10));
            var counterComponent = new CounterIncrementComponent(ObjectEvent.ScoreIncrease, ObjectEvent.ScoreIncreaseDisplay, ObjectEvent.Ignore, ObjectEvent.Ignore, 0, 100, false);
            var scoreComponent   = new TextComponent(FontGraphics.PropertialFont_8X8, counterComponent);

            score.AddComponent(counterComponent);
            score.AddComponent(scoreComponent);
            DisplayLayer.AddGameObject(score);

            _scoreGameObject = score;
            GameConstants.GameInstance.ScoreEventHandler += ScoreMilestones;
        }
예제 #4
0
        public SpriteGenericComponent(Texture2D[] textures, Vector2 relativeLocation, ObjectEvent subscribeEvent, CounterIncrementComponent counterIncrementComponent, Func <int, int, IEnumerable <Vector2> > drawMethod)
        {
            Textures = textures;

            Width  = Textures.Max(t => t.Width);
            Height = Textures.Max(t => t.Height);

            _relativeLocation          = relativeLocation;
            _currentValue              = counterIncrementComponent.CurrentValue;
            _subscribeEvent            = subscribeEvent;
            _counterIncrementComponent = counterIncrementComponent;
            _drawMethod = drawMethod;
            _locations  = drawMethod.Invoke(_currentValue, 0).ToList();
        }
예제 #5
0
        private void CreatePlayer()
        {
            var xPosition = GameHelper.GetRelativeScaleX(0.5f);
            var yPosition = GameHelper.GetRelativeScaleY(0.8f);

            // PLAYER
            var player = new GameObject(TopDown.PlayerName, new Vector2(xPosition, yPosition));

            // GENERAL
            var texture  = SpaceGraphics.PlayerShipAsset.First();
            var sprite   = new SpriteComponent(texture);
            var boundary = new BoundaryComponent(SpaceGraphics.BoundaryAsset.First(), texture.Width, texture.Height);

            player.AddComponent(boundary);
            player.AddComponent(sprite);

            // MOVEMENT
            var movement      = new MovementComponent(5, FaceDirection.Up, Vector2.Zero);
            var localKeyboard = new LocalKeyboardComponent();
            var input         = new InputComponent(InputHelper.KeyboardMappedKey(), localKeyboard, movement);

            player.AddComponent(movement);
            player.AddComponent(input);

            // THRUSTER
            var thrusterLeft  = new SpriteComponent(SpaceGraphics.FlameAsset, new Vector2(2, 16), color: Color.BlueViolet);
            var thrusterRight = new SpriteComponent(SpaceGraphics.FlameAsset, new Vector2(11, 16), color: Color.BlueViolet);

            player.AddComponent(thrusterLeft);
            player.AddComponent(thrusterRight);

            // GUNS
            var gunLeft  = new SpriteComponent(SpaceGraphics.PlayerGunLeftAsset, new Vector2(-6, 8), color: Color.White);
            var gunRight = new SpriteComponent(SpaceGraphics.PlayerGunRightAsset, new Vector2(16, 8), color: Color.White);

            player.AddComponent(gunLeft);
            player.AddComponent(gunRight);

            // STATE
            var state = new StateComponent();

            state.AddComponentState(thrusterLeft, movement);
            state.AddComponentState(thrusterRight, movement);
            player.AddComponent(state);

            // HEALTH
            var healthCounter = new CounterIncrementComponent(ObjectEvent.CollisionEnter, ObjectEvent.HealthRemoved, ObjectEvent.HealthEmpty, ObjectEvent.HealthReset, 5, 0);
            var healthBar     = new SpriteRepeaterComponent(SpaceGraphics.HealthBarAsset.First(), new Vector2(0, 35), false, ObjectEvent.HealthRemoved, healthCounter, false, Color.ForestGreen);

            //healthBar.SetDynamicColors(Color.DarkRed, Color.Red, Color.Orange, Color.Yellow, Color.ForestGreen);
            healthBar.SetColorEvent(ObjectEvent.HealthRemoved, HealthColourFunc);
            player.AddComponent(healthCounter);
            player.AddComponent(healthBar);

            // TODO: Refactor into their own game objects that are attached to PlayerObject
            // FIRING - MACHINE GUN
            var machineGun   = new BulletComponent(TopDown.PlayerBulletName, SpaceGraphics.LargeBulletAsset, movement, ObjectEvent.AmmoRemoved, ObjectEvent.AmmoEmpty, ObjectEvent.AmmoReset, 20, Color.DarkOrange, 0, null, TopDown.EnemyBulletName);
            var ammoCounter  = new CounterIncrementComponent(ObjectEvent.Fire, ObjectEvent.AmmoRemoved, ObjectEvent.AmmoEmpty, ObjectEvent.AmmoReset, 50, 0);
            var ammoBar      = new SpriteRepeaterComponent(SpaceGraphics.OnePixelBarAsset.First(), new Vector2(-25, 25), true, ObjectEvent.AmmoRemoved, ammoCounter, true, Color.Red);
            var ammoMovement = new EventMovementComponent(new Vector2(0, 2), ObjectEvent.AmmoRemoved);
            var ammoSound    = new EventSoundComponent(SpaceSounds.Sound_LongFire01, ObjectEvent.AmmoRemoved);

            player.AddComponent(machineGun);
            player.AddComponent(ammoCounter);
            player.AddComponent(ammoMovement);
            player.AddComponent(ammoBar);
            player.AddComponent(ammoSound);

            // FIRING - MISSILE
            var missileKeyboard = new KeyboardEventComponent(Keys.Z, ObjectEvent.MissileFire);
            var missile         = new BulletComponent(TopDown.PlayerBulletName, SpaceGraphics.MissileAsset, movement, ObjectEvent.MissileRemoved, ObjectEvent.MissileEmpty, ObjectEvent.MissileReset, 0, Color.White, 0.5f, new Vector2(-10, 5), TopDown.EnemyBulletName);
            var missileCounter  = new CounterIncrementComponent(ObjectEvent.MissileFire, ObjectEvent.MissileRemoved, ObjectEvent.MissileEmpty, ObjectEvent.MissileReset, 50, 0);
            var missileBar      = new SpriteRepeaterComponent(SpaceGraphics.OnePixelBarAsset.First(), new Vector2(-30, 25), true, ObjectEvent.MissileRemoved, missileCounter, true, Color.DarkGray);
            var missileMovement = new EventMovementComponent(new Vector2(0, 5), ObjectEvent.MissileRemoved);
            var missileSound    = new EventSoundComponent(SpaceSounds.Sound_ShortFire01, ObjectEvent.MissileRemoved);

            missile.SetCollisionAction(MissileCollision);
            player.AddComponent(missileKeyboard);
            player.AddComponent(missile);
            player.AddComponent(missileCounter);
            player.AddComponent(missileMovement);
            player.AddComponent(missileBar);
            player.AddComponent(missileSound);

            // FIRING - LASER
            var laserKeyboard = new KeyboardEventComponent(Keys.C, ObjectEvent.LaserFire);
            var laser         = new BulletComponent(TopDown.PlayerBulletName, SpaceGraphics.LaserAsset, movement, ObjectEvent.LaserRemoved, ObjectEvent.LaserEmpty, ObjectEvent.LaserReset, 20, Color.LightBlue, 0, new Vector2(10, 5), TopDown.EnemyBulletName, TopDown.EnemyName);
            var laserCounter  = new CounterIncrementComponent(ObjectEvent.LaserFire, ObjectEvent.LaserRemoved, ObjectEvent.LaserEmpty, ObjectEvent.LaserReset, 50, 0);
            var laserBar      = new SpriteRepeaterComponent(SpaceGraphics.OnePixelBarAsset.First(), new Vector2(-20, 25), true, ObjectEvent.LaserRemoved, laserCounter, true, Color.Blue);
            var laserMovement = new EventMovementComponent(new Vector2(0, 1), ObjectEvent.LaserRemoved);
            var laserSound    = new EventSoundComponent(SpaceSounds.Sound_ShortFire01, ObjectEvent.LaserRemoved);

            player.AddComponent(laserKeyboard);
            player.AddComponent(laser);
            player.AddComponent(laserCounter);
            player.AddComponent(laserMovement);
            player.AddComponent(laserBar);
            player.AddComponent(laserSound);

            // DAMAGE
            var fireCounter = new CounterIncrementComponent(ObjectEvent.CollisionEnter, ObjectEvent.ElectricalFire, ObjectEvent.Ignore, ObjectEvent.Ignore, 0, 5, false);
            var fireSprite  = new SpriteGenericComponent(SpaceGraphics.FireAsset, Vector2.Zero, ObjectEvent.ElectricalFire, fireCounter, RandomDrawMethod);

            player.AddComponent(fireCounter);
            player.AddComponent(fireSprite);

            // DEATH
            var deathEvent = new ObjectEventComponent(ObjectEvent.HealthEmpty, PlayerDeath);

            player.AddComponent(deathEvent);

            ForegroundLayer.AddGameObject(player);
        }