Esempio n. 1
0
        public static Entity CreateDestroyer(
            DestroyerView destroyer, float x, float y,
            float animX, float animY
            )
        {
            var destroyerEntity = new Entity(Registrator.GenerateName(BaseNames.Destroyer));

            var dDisplayComponent = new DisplayComponent();

            destroyer.DestroyerShape.Origin = new SFML.System.Vector2f(
                destroyer.DestroyerShape.GetLocalBounds().Width / 2.0f,
                destroyer.DestroyerShape.GetLocalBounds().Height / 2.0f
                );
            dDisplayComponent.DisplayObject = destroyer.DestroyerShape;

            var dPositionComponent = new PositionComponent();

            dPositionComponent.X = x;
            dPositionComponent.Y = y;

            float angle = 0.0f;

            if (animX > x)
            {
                angle = 180.0f;
            }
            else if (animY < y)
            {
                angle = 90.0f;
            }
            else if (animY > y)
            {
                angle = 270.0f;
            }
            dPositionComponent.Rotation = angle;

            var dCollisionComponent = new CollisionComponent();

            dCollisionComponent.BoundingBox = new FloatRect(x, y, Layout.GemSize, Layout.GemSize);

            var dAnimationComponent = new AnimationComponent();

            dAnimationComponent.X     = animX;
            dAnimationComponent.Y     = animY;
            dAnimationComponent.Speed = Engine.GameSpeed;
            dAnimationComponent.Scale = dDisplayComponent.DisplayObject.Scale;

            var dGemComponent = new GemComponent();

            dGemComponent.GemType    = destroyer.GemType;
            dGemComponent.GemSubType = GemSub.Gem;

            destroyerEntity.AddComponent(dDisplayComponent);
            destroyerEntity.AddComponent(dPositionComponent);
            destroyerEntity.AddComponent(dCollisionComponent);
            destroyerEntity.AddComponent(dAnimationComponent);
            destroyerEntity.AddComponent(dGemComponent);

            return(destroyerEntity);
        }
Esempio n. 2
0
        public static Entity CreateGem(
            GemView gem, int x, int y
            )
        {
            var gemEntity = new Entity(Registrator.GenerateName(BaseNames.Gem));

            var gDisplayComponent = new DisplayComponent();

            gem.GemShape.Origin = new SFML.System.Vector2f(
                gem.GemShape.GetLocalBounds().Width / 2.0f,
                gem.GemShape.GetLocalBounds().Height / 2.0f
                );
            gDisplayComponent.DisplayObject = gem.GemShape;

            var gPositionComponent = new PositionComponent();

            gPositionComponent.X = x;
            gPositionComponent.Y = y;

            var gCollisionComponent = new CollisionComponent();

            gCollisionComponent.BoundingBox = new FloatRect(x, y, Layout.GemSize, Layout.GemSize);

            var gAnimationComponent = new AnimationComponent();

            gAnimationComponent.X     = x;
            gAnimationComponent.Y     = y;
            gAnimationComponent.Speed = Engine.GameSpeed;
            gAnimationComponent.Scale = gDisplayComponent.DisplayObject.Scale;

            var gGemComponent = new GemComponent();

            gGemComponent.GemType    = gem.GemType;
            gGemComponent.GemSubType = gem.GemSubType;

            gemEntity.AddComponent(gDisplayComponent);
            gemEntity.AddComponent(gPositionComponent);
            gemEntity.AddComponent(gCollisionComponent);
            gemEntity.AddComponent(gAnimationComponent);
            gemEntity.AddComponent(gGemComponent);

            return(gemEntity);
        }