Beispiel #1
0
        // abstract graphics from the physics
        // 2D array of integers, representing the tile
        // 0, 1 wall, etc
        // check element array next to it
        // scale by a constant, tile at row, 4, col 2, multiple by pixel size
        // tutorials, scale up without blurry

        protected override void LoadForeground()
        {
            var player       = new GameObject("PlayerOne", new Vector2(0, 0));
            var sprites      = new SpriteMappingComponent(RpgGraphics.GameboySpriteMapping, "Player1");
            var nextItem     = new KeyboardEventComponent(Keys.X, ObjectEvent.NextItem);
            var previousItem = new KeyboardEventComponent(Keys.Z, ObjectEvent.PreviousItem);
            var useItem      = new KeyboardActionComponent(Keys.Enter, UseItem);
            var useAction    = new KeyboardActionComponent(Keys.Space, UseAction);
            // TODO: Could be refactored into single class.
            // Need to apply movement constraints based off grid
            var moveUp       = new KeyboardEventComponent(Keys.Up, ObjectEvent.MoveUp);
            var moveDown     = new KeyboardEventComponent(Keys.Down, ObjectEvent.MoveDown);
            var moveLeft     = new KeyboardEventComponent(Keys.Left, ObjectEvent.MoveLeft);
            var moveRight    = new KeyboardEventComponent(Keys.Right, ObjectEvent.MoveRight);
            var gridMovement = new GridMovementComponent(16);

            player.AddComponent(sprites);
            player.AddComponent(nextItem);
            player.AddComponent(previousItem);
            player.AddComponent(useItem);
            player.AddComponent(useAction);
            player.AddComponent(moveUp);
            player.AddComponent(moveDown);
            player.AddComponent(moveLeft);
            player.AddComponent(moveRight);
            player.AddComponent(gridMovement);
            ForegroundLayer.AddGameObject(player);
        }
Beispiel #2
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);
        }
        public void SpawnEnnemy(Animation animation, GameTime gameTime)
        {
            var ennemy2 = new Ennemy("Ennemy1", 1000);

            ennemy2.SetScene(this);
            ennemy2.SetColor(Color.Red);
            ennemy2.SetSize(24, 24);
            ennemy2.SetSpeedMax(100);
            ennemy2.SetPosition(100, 100);
            ForegroundLayer.AddSprite(ennemy2.Sprite);

            var animation21 = new MoveAnimation(new Vector2(100, 100), new Vector2(100, 600));
            var animation22 = new MoveAnimation(new Vector2(100, 600), new Vector2(600, 600));
            var animation23 = new MoveAnimation(new Vector2(600, 600), new Vector2(600, 100));
            var animation24 = new MoveAnimation(new Vector2(600, 100), new Vector2(900, 100));
            var animation25 = new MoveAnimation(new Vector2(900, 100), new Vector2(900, 600));

            var animSequence2 = new AnimationSequence();

            animSequence2.AddAnimation(animation21);
            animSequence2.AddAnimation(animation22);
            animSequence2.AddAnimation(animation23);
            animSequence2.AddAnimation(animation24);
            animSequence2.AddAnimation(animation25);

            ennemy2.AttachAnimation(animSequence2);

            this.AnimationManager.AddAnimation(animSequence2);

            _ennemies.Add(ennemy2);
        }
Beispiel #4
0
 public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
 {
     if (Visible)
     {
         BackgroundLayer.Draw(gameTime, spriteBatch);
         ForegroundLayer.Draw(gameTime, spriteBatch);
         UILayer.Draw(gameTime, spriteBatch);
     }
 }
Beispiel #5
0
        private void BossDeath(GameObject gameObject)
        {
            gameObject.RemoveGameObject();
            var death          = new GameObject("BossDeath", gameObject.Centre);
            var deathAnimation = new ScaleAnimationComponent(SpaceGraphics.PlanetAsset[3], 0, 10, 500, animationCompleteEvent: ObjectEvent.RemoveEntity);

            death.AddComponent(deathAnimation);
            ForegroundLayer.AddGameObject(death);
        }
Beispiel #6
0
        public virtual void Update(GameTime gameTime)
        {
            if (Visible)
            {
                BackgroundLayer.Update(gameTime);
                ForegroundLayer.Update(gameTime);
                UILayer.Update(gameTime);

                AnimationManager.Update(gameTime);
            }
        }
Beispiel #7
0
        public GameScene(CCWindow window) : base(window)
        {
            var backgroundLayer = new BackgroundLayer();
            var hudLayer        = new HudLayer();
            var gameplayLayer   = new GameplayLayer(hudLayer.ScoreBox);
            var foregraundLayer = new ForegroundLayer();

            AddChild(backgroundLayer);
            AddChild(gameplayLayer);
            AddChild(foregraundLayer);
            AddChild(hudLayer);
        }
Beispiel #8
0
        private GameObject CreatePlayer(int playerNumber, Color color)
        {
            // MonoGame works in Radians
            // http://msdn.microsoft.com/en-us/library/system.math.sin%28v=vs.110%29.aspx
            var startX        = GameHelper.GetRelativeScaleX(0.1f);
            var startLocation = new Vector2(startX, _waveTopY) + new Vector2(playerNumber * startX, 0);
            var startRotation = (float)(90 * (Math.PI / 180));

            var texture            = SurfingGraphics.Surfboard_Large_White_Asset;
            var player             = new GameObject("Player", startLocation, startRotation);
            var airGravityMovement = new AccelerateMovementComponent(new Vector2(0, 0.05f));
            var outOfBoundary      = new OutOfBoundsComponent(ObjectEvent.ResetEntity);
            var boundary           = new BoundaryComponent(texture, texture.Width, texture.Height);
            var rotationMovement   = new RotationMovementComponent(2, Vector2.Zero);
            var rotation           = new RotationComponent(Vector2.Zero);
            var sprite             = new SpriteComponent(texture, rotationOrigin: texture.Centre(), color: color);

            player.AddComponent(airGravityMovement);
            player.AddComponent(sprite);
            player.AddComponent(rotationMovement);
            player.AddComponent(boundary);
            player.AddComponent(outOfBoundary);
            player.AddComponent(rotation);

            var onWave = "OnWave";
            var inAir  = "InAir";

            var state = new StateStringComponent();

            state.AddComponentState(rotationMovement, onWave, inAir);
            state.AddComponentState(rotation, inAir, onWave);
            state.AddComponentState(airGravityMovement, inAir, onWave);

            player.AddComponent(state);

            var boundaryState = new BoundaryStateComponent(new Rectangle(0, _waveTopY, GameHelper.GetRelativeScaleX(1f), (int)(_waveHeight * 1.3f)), onWave, inAir);

            player.AddComponent(boundaryState);

            ForegroundLayer.AddGameObject(player);

            return(player);
        }
Beispiel #9
0
        private GameObject CreatePlayer(string playerCharacter, int xStartPosition, int yStartPosition, Keys key)
        {
            var player = new GameObject(playerCharacter, new Vector2(xStartPosition, yStartPosition));
            // TODO: Pass in the actual player selected character through constructor
            var sprites          = new SpriteMappingComponent(RpgGraphics.GameboySpriteMapping, playerCharacter);
            var bounday          = new BoundaryComponent(null, 16, 16);
            var constantMovement = new AccelerateMovementComponent(GetMovement);
            var collisionEvent   = new ObjectEventComponent(ObjectEvent.CollisionEnter, CollisionEnter);
            var collisionExit    = new ObjectEventComponent(ObjectEvent.CollisionExit, CollisionExit);
            var keyAction        = new KeyboardActionComponent(key, PlayerAttacked);

            player.AddComponent(sprites);
            player.AddComponent(bounday);
            player.AddComponent(constantMovement);
            player.AddComponent(collisionEvent);
            player.AddComponent(collisionExit);
            player.AddComponent(keyAction);
            ForegroundLayer.AddGameObject(player);
            return(player);
        }
        private void LoadForegroundLayer()
        {
            var tower1 = new Tower("Tower1", 10, 200);

            tower1.SetScene(this);
            tower1.SetColor(Color.Orange);
            tower1.SetSize(64, 64);
            tower1.SetPosition((int)(ForegroundLayer.Width * 0.5), (int)(ForegroundLayer.Height * 0.5));
            ForegroundLayer.AddSprite(tower1.Sprite);

            _towers.Add(tower1);

            var tower2 = new Tower("Tower1", 20, 300);

            tower2.SetScene(this);
            tower2.SetColor(Color.Orange);
            tower2.SetSize(64, 64);
            tower2.SetPosition((int)(ForegroundLayer.Width * 0.7), (int)(ForegroundLayer.Height * 0.7));
            ForegroundLayer.AddSprite(tower2.Sprite);

            _towers.Add(tower2);

            var tower3 = new FreezeTower("Tower1", 15, 300);

            tower3.SetScene(this);
            tower3.SetColor(Color.Cyan);
            tower3.SetSize(64, 64);
            tower3.SetPosition((int)(ForegroundLayer.Width * 0.3), (int)(ForegroundLayer.Height * 0.3));
            ForegroundLayer.AddSprite(tower3.Sprite);

            _towers.Add(tower3);

            //=======================

            //var ennemy1 = new Ennemy("Ennemy1", 1000);
            //ennemy1.SetScene(this);
            //ennemy1.SetColor(Color.Red);
            //ennemy1.SetSize(24, 24);
            //ennemy1.SetSpeedMax(100);
            //ennemy1.SetPosition(100, 100);
            //ForegroundLayer.AddSprite(ennemy1.Sprite);

            //var animation1 = new MoveAnimation(new Vector2(100, 100), new Vector2(100, 600));
            //var animation2 = new MoveAnimation(new Vector2(100, 600), new Vector2(600, 600));
            //var animation3 = new MoveAnimation(new Vector2(600, 600), new Vector2(600, 100));
            //var animation4 = new MoveAnimation(new Vector2(600, 100), new Vector2(900, 100));
            //var animation5 = new MoveAnimation(new Vector2(900, 100), new Vector2(900, 600));

            //var animSequence = new AnimationSequence();
            //animSequence.AddAnimation(animation1);
            //animSequence.AddAnimation(animation2);
            //animSequence.AddAnimation(animation3);
            //animSequence.AddAnimation(animation4);
            //animSequence.AddAnimation(animation5);

            //ennemy1.AttachAnimation(animSequence);

            //this.AnimationManager.AddAnimation(animSequence);

            //_ennemies.Add(ennemy1);

            //var test = (AnimationSequence)animSequence.Clone();

            ////=====

            //var ennemy2 = new Ennemy("Ennemy1", 1000);
            //ennemy2.SetScene(this);
            //ennemy2.SetColor(Color.Red);
            //ennemy2.SetSize(24, 24);
            //ennemy2.SetSpeedMax(100);
            //ennemy2.SetPosition(100, 90);
            //ForegroundLayer.AddSprite(ennemy2.Sprite);

            //var animation21 = new MoveAnimation(new Vector2(100, 100), new Vector2(100, 600));
            //var animation22 = new MoveAnimation(new Vector2(100, 600), new Vector2(600, 600));
            //var animation23 = new MoveAnimation(new Vector2(600, 600), new Vector2(600, 100));
            //var animation24 = new MoveAnimation(new Vector2(600, 100), new Vector2(900, 100));
            //var animation25 = new MoveAnimation(new Vector2(900, 100), new Vector2(900, 600));

            //var animSequence2 = new AnimationSequence();
            //animSequence2.AddAnimation(animation21);
            //animSequence2.AddAnimation(animation22);
            //animSequence2.AddAnimation(animation23);
            //animSequence2.AddAnimation(animation24);
            //animSequence2.AddAnimation(animation25);

            //ennemy2.AttachAnimation(animSequence2);

            //this.AnimationManager.AddAnimation(animSequence2);

            //_ennemies.Add(ennemy2);


            var spawn = new Animation();

            spawn.SetCallback(SpawnEnnemy);
            spawn.SetRepeat(true);
            spawn.SetTimeAnimation(2);

            this.AnimationManager.AddAnimation(spawn);
        }
Beispiel #11
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);
        }