예제 #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);
        }
예제 #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);
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
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);
        }