Exemplo n.º 1
0
        public void Fire()
        {
            var bulletTexture = _texture2D;
            var direction     = _movementComponent.FaceDirection.GetVector2();

            direction.Normalize();

            var startLocation = Owner.Centre;

            startLocation += (direction * new Vector2(Owner.Width, Owner.Height));
            startLocation += (direction * new Vector2(bulletTexture.Width + 1, bulletTexture.Height + 1));
            startLocation += _offset;

            var bullet = new GameObject(_bulletGameType, startLocation);

            if (_bulletSpeed > 0)
            {
                var movement = new MovementComponent(_bulletSpeed, _movementComponent.FaceDirection, direction);
                bullet.AddComponent(movement);
            }
            if (_bulletAcceleration > 0)
            {
                var acceleration = new AccelerateMovementComponent(new Vector2(0, -_bulletAcceleration));
                bullet.AddComponent(acceleration);
            }

            var bulletSprite   = new SpriteComponent(bulletTexture, color: _color);
            var bulletBoundary = new BoundaryComponent(SpaceGraphics.BoundaryAsset.First(), bulletTexture.Width, bulletTexture.Height, true, false, _ignoreCollisionTypes);

            if (_collisionAction != null)
            {
                var collisionAction = new ObjectEventComponent(ObjectEvent.CollisionEnter, _collisionAction);
                bullet.AddComponent(collisionAction);
            }
            else
            {
                var instanceComponent = new InstanceComponent();
                bullet.AddComponent(instanceComponent);
            }

            var bulletOutOfBounds = new OutOfBoundsComponent(ObjectEvent.RemoveEntity);

            bullet.AddComponent(bulletSprite);
            bullet.AddComponent(bulletBoundary);

            bullet.AddComponent(bulletOutOfBounds);

            Owner.GameLayer.AddGameObject(bullet);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }