Ejemplo n.º 1
0
 private void UpdatePosition(DrawComponent component)
 {
     if (component.BoundPos != null)
     {
         component.DrawRec.Center = component.BoundPos + component.Offset;
     }
 }
Ejemplo n.º 2
0
 private void RemoveFromBatch(DrawComponent component)
 {
     if (_sortedDrawComponents.ContainsKey(component.Texture))
     {
         _sortedDrawComponents[component.Texture].Remove(component);
     }
 }
Ejemplo n.º 3
0
 private void InsertIntoBatch(DrawComponent component)
 {
     if (!_sortedDrawComponents.ContainsKey(component.Texture))
     {
         _sortedDrawComponents.Add(component.Texture, new HashSet <DrawComponent>());
     }
     _sortedDrawComponents[component.Texture].Add(component);
 }
Ejemplo n.º 4
0
 private static void FlashDrawComponentColor(HealthComponent health)
 {
     if (health.Bindings.TryGetValue(typeof(DrawComponent), out var binding))
     {
         DrawComponent draw = binding as DrawComponent;
         draw.Tint = Color.Red;
     }
 }
Ejemplo n.º 5
0
 public ButtonWithText(Vector2 position, DrawComponent drawComponent, Rectangle buttonRec, String buttonHandle, String text, SpriteFont font, Vector2 textOffset, Color?color = null, bool centeredText = true) : base(position, drawComponent, buttonRec, buttonHandle)
 {
     Text         = text;
     Font         = font;
     CenteredText = centeredText;
     SetLocation(font, text);
     TextOffset = textOffset;
     TextColor  = color ?? Color.White;
 }
Ejemplo n.º 6
0
        private void SimpleCameraMovement(GameTime gameTime)
        {
            if (InputReader.IsKeyTriggered(Keys.Space))
            {
                _camera.FollowingHero = !_camera.FollowingHero;
            }
            if (!_camera.FollowingHero)
            {
                if (InputReader.IsKeyPressed(Keys.Up))
                {
                    _camera.TargetPosition.Y -= 500 * (float)gameTime.ElapsedGameTime.TotalSeconds * 1 / _camera.CurrentZoom;
                }
                if (InputReader.IsKeyPressed(Keys.Down))
                {
                    _camera.TargetPosition.Y += 500 * (float)gameTime.ElapsedGameTime.TotalSeconds * 1 / _camera.CurrentZoom;
                }
                if (InputReader.IsKeyPressed(Keys.Left))
                {
                    _camera.TargetPosition.X -= 500 * (float)gameTime.ElapsedGameTime.TotalSeconds * 1 / _camera.CurrentZoom;
                }
                if (InputReader.IsKeyPressed(Keys.Right))
                {
                    _camera.TargetPosition.X += 500 * (float)gameTime.ElapsedGameTime.TotalSeconds * 1 / _camera.CurrentZoom;
                }
            }
            else
            {
                if (_hero != null && _hero.Components.TryGetValue(typeof(DrawComponent), out var component))
                {
                    DrawComponent heroMovement = component as DrawComponent;
                    _camera.TargetPosition.X = heroMovement.DrawRec.Center.X;
                    _camera.TargetPosition.Y = heroMovement.DrawRec.Center.Y;
                }
            }



            if (InputReader.IsScrollingUp())
            {
                _camera.TargetZoom += 1;
            }
            if (InputReader.IsScrollingDown())
            {
                _camera.TargetZoom -= 1;
            }

            if (_camera.TargetZoom < 0.1)
            {
                _camera.TargetZoom = 0.3f;
            }
            else if (_camera.TargetZoom > 1)
            {
                _camera.TargetZoom = (int)_camera.TargetZoom;
            }
        }
Ejemplo n.º 7
0
 public override void Activate()
 {
     if (Bindings.TryGetValue(typeof(DrawComponent), out var binding))
     {
         DrawComponent drawComponent = binding as DrawComponent;
         BoundDrawComponent       = drawComponent;
         drawComponent.IsAnimated = true;
     }
     CurrentAnimation = Animations.Find(a => a.Trigger == EntityState.Idle);
     base.Activate();
 }
Ejemplo n.º 8
0
 private static void ResetDrawComponentColor(HealthComponent health)
 {
     if (health.Bindings.TryGetValue(typeof(DrawComponent), out var binding)) //TODO think of a way to prevent this shit being called all the time
     {
         DrawComponent draw = binding as DrawComponent;
         if (draw.Tint == Color.Red)
         {
             draw.Tint = Color.White;
         }
     }
 }
Ejemplo n.º 9
0
 private static void RotateFromMovementVector(DrawComponent component)
 {
     if (component.Bindings.TryGetValue(typeof(MovementComponent), out var binding))
     {
         MovementComponent movement = binding as MovementComponent;
         if (!movement.IsMoving)
         {
             return;
         }
         component.Rotation = (float)movement.Speed.Polar.Angle;
     }
 }
Ejemplo n.º 10
0
 public static void Draw(DrawComponent sprite)
 {
     _spriteBatch.Draw(
         sprite.Texture,
         position: sprite.DrawRec.Center,
         sourceRectangle: sprite.SourceRec,
         scale: sprite.Scale,
         rotation: sprite.Rotation,
         origin: sprite.Origin,
         color: sprite.Tint * 1,
         layerDepth: sprite.LayerDepth - 0.000000001f * sprite.DrawRec.Bottom,
         effects: sprite.FlipHorizontally ? SpriteEffects.FlipHorizontally : SpriteEffects.None);
 }
Ejemplo n.º 11
0
        private void DrawComponent(DrawComponent component)
        {
            if (component.Inactive)
            {
                return;
            }

            UpdatePosition(component);
            if (component.DrawRec.Intersects(_camera.CullRec)) //TODO can confirm, this causes the pop ins
            {
                if (component.GetRotationFromMovementVector)
                {
                    RotateFromMovementVector(component);
                }
                Functions_Draw.Draw(component);
            }
        }
Ejemplo n.º 12
0
 private static void ExitMovementBlink(BlinkComponent blink, MovementComponent movement)
 {
     movement.Speed = blink.MovementExitSpeed;
     if (blink.Bindings.TryGetValue(typeof(CollisionComponent), out var collisionBinding))
     {
         CollisionComponent collision = collisionBinding as CollisionComponent;
         collision.IsPhasing = false;
     }
     if (blink.Bindings.TryGetValue(typeof(DrawComponent), out var drawBinding))
     {
         DrawComponent draw = drawBinding as DrawComponent;
         if (draw.Tint == Color.Cyan)
         {
             draw.Tint = Color.White;
         }
     }
     blink.CurrentEntityState.Blinking = false;
 }
Ejemplo n.º 13
0
        public override void RegisterComponents(ICollection <Entity> entities)
        {
            foreach (var entity in entities)
            {
                if (entity.Components.TryGetValue(typeof(DrawComponent), out var component))
                {
                    DrawComponent drawComponent = component as DrawComponent;

                    if (drawComponent.Bindings.TryGetValue(typeof(AnimationComponent), out var animationComponent))
                    {
                        drawComponent.IsAnimated = true;
                        _animatedDrawComponents.Add(drawComponent);
                    }
                    else
                    {
                        InsertIntoBatch(drawComponent);
                    }
                    component.Activate();
                }
            }
        }
Ejemplo n.º 14
0
        private static void SetMovementVariablesForBindings(BlinkComponent blink)
        {
            if (blink.InvulnerableOnMovementBlink)
            {
                if (blink.Bindings.TryGetValue(typeof(HealthComponent), out var healthBinding))
                {
                    HealthComponent health = healthBinding as HealthComponent;
                    //TODO make this shit invincible, use blink duration
                }
            }

            if (blink.Bindings.TryGetValue(typeof(CollisionComponent), out var collisionBinding))
            {
                CollisionComponent collision = collisionBinding as CollisionComponent;
                collision.IsPhasing = true;
            }

            if (blink.Bindings.TryGetValue(typeof(DrawComponent), out var drawBinding)) //TODO Breunig talk about Coupling
            {
                DrawComponent draw = drawBinding as DrawComponent;
                draw.Tint = Color.Cyan;
            }
        }
Ejemplo n.º 15
0
 public Button(Vector2 position, DrawComponent drawComponent, Rectangle buttonRec, String buttonHandle) : base(position, drawComponent)
 {
     ButtonRec    = buttonRec;
     ButtonHandle = buttonHandle;
 }
Ejemplo n.º 16
0
        public static Entity CreateEntity(EntityType type, Vector2Ref position = null, Coord2?speed = null, GameTime gameTime = null, Allegiance allegiance = Allegiance.Neutral)
        {
            Vector2Ref safePosition = position ?? new Vector2Ref();
            Coord2     safeSpeed    = speed ?? new Coord2();

            Entity entity = new Entity(type);

            switch (type)
            {
                #region Actors

            case EntityType.Hero:
            {
                entity.SetAllegiance(Allegiance.Friendly);
                entity.SetStateComponent();
                entity.AddComponent(new MovementComponent(accelerationBase: 1250, maxSpeed: 175, friction: 800, position: safePosition));
                entity.AddComponent(new AttackBehaviorComponent(new List <AttackComponent>()
                    {
                        new AttackComponent(EntityType.HeroKnightSlashWeak, AttackType.Primary, entity.GetComponent <MovementComponent>().Position, new Vector2(0, 20), posOffsetInDirection: 35, startSpeed: 200, attackState: 0, attackDelayMilliseconds: 100, attackCooldownMilliseconds: 500, blockInputDurationMilliseconds: 250, selfKnockback: -150),
                        new AttackComponent(EntityType.HeroKnightThrowingDagger, AttackType.Secondary, entity.GetComponent <MovementComponent>().Position, new Vector2(0, 20), posOffsetInDirection: 25, startSpeed: 1100, attackState: 0, attackCooldownMilliseconds: 250, blockInputDurationMilliseconds: 100)
                    }, entity.GetComponent <MovementComponent>().Position));
                entity.AddComponent(new IntelligenceNode(EntityType.Hero, entity.GetComponent <MovementComponent>().Position));
                entity.AddComponent(new DrawComponent(Assets.GetTexture("heroIdle"), drawRec: new AABB(0, 0, 100, 100), boundPos: entity.GetComponent <MovementComponent>().Position, offset: new Vector2(0, -8)), typeof(MovementComponent));
                entity.AddComponent(new AnimationComponent(AnimationStructures.GetAnimationList(type)), typeof(DrawComponent));
                entity.AddComponent(new HealthComponent(20), typeof(MovementComponent));
                entity.AddComponent(new CollisionComponent(collisionRectangle: new AABB(safePosition, new Vector2(16, 16)), offset: new Vector2(20, 40), isPhysical: true), new List <Type> {
                        typeof(MovementComponent), typeof(HealthComponent)
                    });
                entity.AddComponent(new BlinkComponent(3, 2000, 1000, 125), new List <Type> {
                        typeof(InputComponent), typeof(MovementComponent), typeof(AttackBehaviorComponent), typeof(CollisionComponent), typeof(HealthComponent), typeof(DrawComponent)
                    });
                entity.AddComponent(new InputComponent(true), new List <Type> {
                        typeof(MovementComponent), typeof(AttackBehaviorComponent), typeof(BlinkComponent)
                    });
                break;
            }

            case EntityType.ForestKnight:
            {
                entity.SetAllegiance(Allegiance.Enemy);
                entity.SetStateComponent();
                entity.AddComponent(new MovementComponent(accelerationBase: 250, maxSpeed: 100, friction: 300, position: safePosition));
                entity.AddComponent(new AttackBehaviorComponent(new List <AttackComponent>()
                    {
                        new AttackComponent(EntityType.HeroKnightSlashWeak, AttackType.Primary, entity.GetComponent <MovementComponent>().Position, new Vector2(0, 20), posOffsetInDirection: 20, startSpeed: 300, attackState: 0, attackDelayMilliseconds: 500, attackCooldownMilliseconds: 1500, cursorType: CursorType.Relative)
                    }, entity.GetComponent <MovementComponent>().Position));
                entity.AddComponent(new DrawComponent(Assets.GetTexture("forestknightIdle"), drawRec: new AABB(0, 0, 128, 64), scale: new Vector2(1, 1), boundPos: entity.GetComponent <MovementComponent>().Position, offset: new Vector2(0, -16)), typeof(MovementComponent));
                entity.AddComponent(new HealthComponent(20, invincibilityTimeMilliseconds: 200), new List <Type> {
                        typeof(MovementComponent), typeof(DrawComponent)
                    });
                entity.AddComponent(new AnimationComponent(AnimationStructures.GetAnimationList(type)), typeof(DrawComponent));
                entity.AddComponent(new CollisionComponent(collisionRectangle: new AABB(safePosition, new Vector2(16, 16)), isPhysical: true), new List <Type> {
                        typeof(MovementComponent), typeof(HealthComponent)
                    });
                entity.AddComponent(new InputComponent(false), new List <Type> {
                        typeof(MovementComponent), typeof(AttackBehaviorComponent)
                    });
                List <IntelligenceOrder> orders = new List <IntelligenceOrder>();
                orders.Add(new IntelligenceOrder(EntityType.Hero, 100, OrderType.AttackPrimary, 1, 750, true));
                orders.Add(new IntelligenceOrder(EntityType.Hero, 300, OrderType.Move, 0, 250, true));
                entity.AddComponent(new IntelligenceComponent(orders, entity.GetComponent <MovementComponent>().Position), typeof(InputComponent));
                break;
            }

            case EntityType.ForestWolf:
            {
                entity.SetAllegiance(Allegiance.Enemy);
                entity.SetStateComponent();
                entity.AddComponent(new MovementComponent(accelerationBase: 1200, maxSpeed: 150, friction: 400, position: safePosition));
                entity.AddComponent(new AttackBehaviorComponent(new List <AttackComponent>()
                    {
                        new AttackComponent(EntityType.ForestWolfBite, AttackType.Primary, entity.GetComponent <MovementComponent>().Position, new Vector2(0, 20), posOffsetInDirection: 20, startSpeed: 75, attackState: 0, attackDelayMilliseconds: 500, attackCooldownMilliseconds: 1000, cursorType: CursorType.Relative)
                    }, entity.GetComponent <MovementComponent>().Position));
                entity.AddComponent(new DrawComponent(Assets.GetTexture("forestWolfIdle"), drawRec: new AABB(0, 0, 64, 48), boundPos: entity.GetComponent <MovementComponent>().Position, offset: new Vector2(0, 0)), typeof(MovementComponent));
                entity.AddComponent(new HealthComponent(15, invincibilityTimeMilliseconds: 200), new List <Type> {
                        typeof(MovementComponent), typeof(DrawComponent)
                    });
                entity.AddComponent(new AnimationComponent(AnimationStructures.GetAnimationList(type)), typeof(DrawComponent));
                entity.AddComponent(new CollisionComponent(collisionRectangle: new AABB(safePosition, new Vector2(16, 16)), isPhysical: true), new List <Type> {
                        typeof(MovementComponent), typeof(HealthComponent)
                    });
                entity.AddComponent(new InputComponent(false), new List <Type> {
                        typeof(MovementComponent), typeof(AttackBehaviorComponent)
                    });
                List <IntelligenceOrder> orders = new List <IntelligenceOrder>();
                orders.Add(new IntelligenceOrder(EntityType.Hero, 75, OrderType.AttackPrimary, 1, 250, true));
                orders.Add(new IntelligenceOrder(EntityType.Hero, 300, OrderType.Move, 0, 250, true));
                entity.AddComponent(new IntelligenceComponent(orders, entity.GetComponent <MovementComponent>().Position), typeof(InputComponent));
                break;
            }

            case EntityType.ForestArcher:
            {
                entity.SetAllegiance(Allegiance.Enemy);
                entity.SetStateComponent();
                entity.AddComponent(new MovementComponent(accelerationBase: 200, maxSpeed: 80, friction: 300, position: safePosition));
                entity.AddComponent(new AttackBehaviorComponent(new List <AttackComponent>()
                    {
                        new AttackComponent(EntityType.HeroKnightThrowingDagger, AttackType.Primary, entity.GetComponent <MovementComponent>().Position, new Vector2(0, 0), posOffsetInDirection: 20, startSpeed: 300, attackState: 0, attackDelayMilliseconds: 2000, attackCooldownMilliseconds: 500, cursorType: CursorType.Relative)
                    }, entity.GetComponent <MovementComponent>().Position));
                entity.AddComponent(new DrawComponent(Assets.GetTexture("forestArcherAttack"), drawRec: new AABB(0, 0, 96, 64), boundPos: entity.GetComponent <MovementComponent>().Position, offset: new Vector2(0, -10)), typeof(MovementComponent));
                entity.AddComponent(new HealthComponent(10, invincibilityTimeMilliseconds: 200), new List <Type> {
                        typeof(MovementComponent), typeof(DrawComponent)
                    });
                entity.AddComponent(new AnimationComponent(AnimationStructures.GetAnimationList(type)), typeof(DrawComponent));
                entity.AddComponent(new CollisionComponent(collisionRectangle: new AABB(safePosition, new Vector2(16, 16)), isPhysical: true), new List <Type> {
                        typeof(MovementComponent), typeof(HealthComponent)
                    });
                entity.AddComponent(new InputComponent(false), new List <Type> {
                        typeof(MovementComponent), typeof(AttackBehaviorComponent)
                    });
                List <IntelligenceOrder> orders = new List <IntelligenceOrder>();
                orders.Add(new IntelligenceOrder(EntityType.Hero, 150, OrderType.AttackPrimary, 1, 500, true));
                orders.Add(new IntelligenceOrder(EntityType.Hero, 300, OrderType.Move, 0, 250, true));
                entity.AddComponent(new IntelligenceComponent(orders, entity.GetComponent <MovementComponent>().Position), typeof(InputComponent));
                break;
            }

            case EntityType.ForestBoss:
            {
                entity.SetAllegiance(Allegiance.Enemy);
                entity.SetStateComponent();
                entity.AddComponent(new MovementComponent(accelerationBase: 200, maxSpeed: 80, friction: 300, position: safePosition));
                entity.AddComponent(new AttackBehaviorComponent(new List <AttackComponent>()
                    {
                        new AttackComponent(EntityType.HeroKnightSlashWeak, AttackType.Primary, entity.GetComponent <MovementComponent>().Position, new Vector2(0, 20), posOffsetInDirection: 20, startSpeed: 300, attackState: 0, attackDelayMilliseconds: 900, attackCooldownMilliseconds: 1500, cursorType: CursorType.Relative)
                    }, entity.GetComponent <MovementComponent>().Position));
                entity.AddComponent(new DrawComponent(Assets.GetTexture("forestBossDying"), drawRec: new AABB(0, 0, 128, 64), scale: new Vector2(1, 1), boundPos: entity.GetComponent <MovementComponent>().Position, offset: new Vector2(0, -32)), typeof(MovementComponent));
                entity.AddComponent(new HealthComponent(40, invincibilityTimeMilliseconds: 200), new List <Type> {
                        typeof(MovementComponent), typeof(DrawComponent)
                    });
                entity.AddComponent(new AnimationComponent(AnimationStructures.GetAnimationList(type)), typeof(DrawComponent));
                entity.AddComponent(new CollisionComponent(collisionRectangle: new AABB(safePosition, new Vector2(16, 16)), isPhysical: true), new List <Type> {
                        typeof(MovementComponent), typeof(HealthComponent)
                    });
                entity.AddComponent(new InputComponent(false), new List <Type> {
                        typeof(MovementComponent), typeof(AttackBehaviorComponent)
                    });
                List <IntelligenceOrder> orders = new List <IntelligenceOrder>();
                orders.Add(new IntelligenceOrder(EntityType.Hero, 100, OrderType.AttackPrimary, 1, 750, true));
                orders.Add(new IntelligenceOrder(EntityType.Hero, 300, OrderType.Move, 0, 250, true));
                entity.AddComponent(new IntelligenceComponent(orders, entity.GetComponent <MovementComponent>().Position), typeof(InputComponent));
                break;
            }

                #endregion

                #region Objects

            case EntityType.Wall:
            {
                DrawComponent drawComponent;

                Texture2D texture;
                int       rnd = _random.Next(0, 100);
                if (rnd <= 20)
                {
                    texture = Assets.GetTexture("tree1");
                }
                else if (rnd <= 40)
                {
                    texture = Assets.GetTexture("tree2");
                }
                else
                {
                    texture = Assets.GetTexture("tree3");
                }

                drawComponent = new DrawComponent(texture, new AABB(safePosition.X, safePosition.Y, 32, 64), offset: new Vector2(0, -32));
                entity.AddComponent(drawComponent);
                entity.AddComponent(new CollisionComponent(behavior: CollisionBehavior.Block, collisionRectangle: new AABB(safePosition.X, safePosition.Y, 32, 32), isWall: true, isPhysical: true));
                break;
            }

            case EntityType.Floor:
            {
                DrawComponent drawComponent;

                Texture2D texture;
                int       rnd = _random.Next(0, 100);
                if (rnd <= 75)
                {
                    texture = Assets.GetTexture("floor1");
                }
                else if (rnd <= 80)
                {
                    texture = Assets.GetTexture("floor2");
                }
                else if (rnd <= 85)
                {
                    texture = Assets.GetTexture("floor3");
                }
                else if (rnd <= 90)
                {
                    texture = Assets.GetTexture("floor4");
                }
                else
                {
                    texture = Assets.GetTexture("floor5");
                }

                drawComponent = new DrawComponent(texture, new AABB(safePosition.X, safePosition.Y, 32, 32), layerDepth: 0.5f);
                entity.AddComponent(drawComponent);

                rnd = _random.Next(0, 1000);
                if (rnd <= 5)
                {
                    _ecs.AddEntity(CreateEntity(EntityType.Mushroom, safePosition));
                }

                break;
            }

            case EntityType.Mushroom:
            {
                DrawComponent drawComponent;

                Texture2D texture;
                int       rnd = _random.Next(0, 100);
                if (rnd <= 50)
                {
                    texture = Assets.GetTexture("mushroom1");
                }
                else
                {
                    texture = Assets.GetTexture("mushroom2");
                }

                drawComponent = new DrawComponent(texture, new AABB((int)safePosition.X, (int)safePosition.Y, 32, 32), layerDepth: 0.45f);
                entity.AddComponent(drawComponent);
                break;
            }

            case EntityType.Treestump:
            {
                DrawComponent drawComponent;

                Texture2D texture;
                int       rnd = _random.Next(0, 100);
                if (rnd <= 50)
                {
                    texture = Assets.GetTexture("treestump1");
                }
                else
                {
                    texture = Assets.GetTexture("treestump1");
                }

                drawComponent = new DrawComponent(texture, new AABB((int)safePosition.X, (int)safePosition.Y, 32, 32), layerDepth: 0.4f);
                entity.AddComponent(drawComponent);
                break;
            }

                #endregion

                #region Projectiles

            case EntityType.HeroKnightSlashWeak:
            {
                entity.SetAllegiance(allegiance);
                entity.SetStateComponent();
                entity.AddComponent(new MovementComponent(maxSpeed: 100, friction: 200, position: safePosition, speed: safeSpeed));
                entity.AddComponent(new TimerComponent(TimerType.Death, currentTime: gameTime, targetLifespanInMilliseconds: 500));
                entity.AddComponent(new DrawComponent(Assets.GetTexture("heroslashweak"), drawRec: new AABB((int)safePosition.X, (int)safePosition.Y, 64, 64), boundPos: entity.GetComponent <MovementComponent>().Position, getRotationFromMovementVector: true), typeof(MovementComponent));
                entity.AddComponent(new AnimationComponent(AnimationStructures.GetAnimationList(type)), typeof(DrawComponent));
                entity.AddComponent(new ProjectileComponent(power: 10, damage: 5, knockback: 200, isPhasing: true, hitCooldownMilliseconds: 200), typeof(MovementComponent));
                entity.AddComponent(new CollisionComponent(behavior: CollisionBehavior.Pass, collisionRectangle: new AABB(safePosition, new Vector2(16, 16))), new List <Type> {
                        typeof(MovementComponent), typeof(ProjectileComponent)
                    });
                break;
            }

            case EntityType.HeroKnightSlashStrong:
            {
                entity.SetAllegiance(allegiance);
                entity.SetStateComponent();
                entity.AddComponent(new MovementComponent(maxSpeed: 800, friction: 2000, position: safePosition, speed: safeSpeed));
                entity.AddComponent(new TimerComponent(TimerType.Death, currentTime: gameTime, targetLifespanInMilliseconds: 500));
                entity.AddComponent(new DrawComponent(Assets.GetTexture("heroslashweak"), drawRec: new AABB((int)safePosition.X, (int)safePosition.Y, 32, 32), boundPos: entity.GetComponent <MovementComponent>().Position, getRotationFromMovementVector: true, tint: Color.Blue), typeof(MovementComponent));
                entity.AddComponent(new ProjectileComponent(power: 20, damage: 10, knockback: 400, isPhasing: true, hitCooldownMilliseconds: 200), typeof(MovementComponent));
                entity.AddComponent(new CollisionComponent(behavior: CollisionBehavior.Pass, collisionRectangle: new AABB(safePosition, new Vector2(16, 16))), new List <Type> {
                        typeof(MovementComponent), typeof(ProjectileComponent)
                    });
                break;
            }

            case EntityType.HeroKnightThrowingDagger:
            {
                entity.SetAllegiance(allegiance);
                entity.SetStateComponent();
                entity.AddComponent(new MovementComponent(maxSpeed: 1500, friction: 0, position: safePosition, speed: safeSpeed));
                entity.AddComponent(new TimerComponent(TimerType.Death, currentTime: gameTime, targetLifespanInMilliseconds: 350));
                entity.AddComponent(new DrawComponent(Assets.GetTexture("herothrowingdagger"), drawRec: new AABB((int)safePosition.X, (int)safePosition.Y, 16, 16), boundPos: entity.GetComponent <MovementComponent>().Position, getRotationFromMovementVector: true), typeof(MovementComponent));
                //entity.AddComponent(new AnimationComponent(AnimationStructures.GetAnimationList(type)), typeof(DrawComponent));
                entity.AddComponent(new ProjectileComponent(power: 4, damage: 2, knockback: 50, isPhasing: false, hitCooldownMilliseconds: 0), typeof(MovementComponent));
                entity.AddComponent(new CollisionComponent(behavior: CollisionBehavior.Pass, collisionRectangle: new AABB(safePosition, new Vector2(8, 8))), new List <Type> {
                        typeof(MovementComponent), typeof(ProjectileComponent)
                    });
                break;
            }


            case EntityType.ForestKnightSlash:
            {
                Color tint = allegiance == Allegiance.Enemy ? Color.Red : Color.White;
                entity.SetAllegiance(allegiance);
                entity.SetStateComponent();
                entity.AddComponent(new MovementComponent(maxSpeed: 100, friction: 200, position: safePosition, speed: safeSpeed));
                entity.AddComponent(new TimerComponent(TimerType.Death, currentTime: gameTime, targetLifespanInMilliseconds: 500));
                entity.AddComponent(new DrawComponent(Assets.GetTexture("heroslashweak"), drawRec: new AABB((int)safePosition.X, (int)safePosition.Y, 64, 64), boundPos: entity.GetComponent <MovementComponent>().Position, tint: tint, getRotationFromMovementVector: true), typeof(MovementComponent));
                entity.AddComponent(new AnimationComponent(AnimationStructures.GetAnimationList(type)), typeof(DrawComponent));
                entity.AddComponent(new ProjectileComponent(power: 10, damage: 5, knockback: 200, isPhasing: true, hitCooldownMilliseconds: 200), typeof(MovementComponent));
                entity.AddComponent(new CollisionComponent(behavior: CollisionBehavior.Pass, collisionRectangle: new AABB(safePosition, new Vector2(16, 16))), new List <Type> {
                        typeof(MovementComponent), typeof(ProjectileComponent)
                    });
                break;
            }

            case EntityType.ForestArcherArrow:
            {
                entity.SetAllegiance(allegiance);
                entity.SetStateComponent();
                entity.AddComponent(new MovementComponent(maxSpeed: 800, friction: 0, position: safePosition, speed: safeSpeed));
                entity.AddComponent(new TimerComponent(TimerType.Death, currentTime: gameTime, targetLifespanInMilliseconds: 1000));
                entity.AddComponent(new DrawComponent(Assets.GetTexture("herothrowingdagger"), drawRec: new AABB((int)safePosition.X, (int)safePosition.Y, 16, 16), boundPos: entity.GetComponent <MovementComponent>().Position, getRotationFromMovementVector: true), typeof(MovementComponent));
                entity.AddComponent(new AnimationComponent(AnimationStructures.GetAnimationList(type)), typeof(DrawComponent));
                entity.AddComponent(new ProjectileComponent(power: 5, damage: 5, knockback: 50, isPhasing: false, hitCooldownMilliseconds: 0), typeof(MovementComponent));
                entity.AddComponent(new CollisionComponent(behavior: CollisionBehavior.Pass, collisionRectangle: new AABB(safePosition, new Vector2(8, 8))), new List <Type> {
                        typeof(MovementComponent), typeof(ProjectileComponent)
                    });
                break;
            }

            case EntityType.ForestWolfBite:
            {
                entity.SetAllegiance(allegiance);
                entity.SetStateComponent();
                entity.AddComponent(new MovementComponent(maxSpeed: 75, friction: 200, position: safePosition, speed: safeSpeed));
                entity.AddComponent(new TimerComponent(TimerType.Death, currentTime: gameTime, targetLifespanInMilliseconds: 500));
                entity.AddComponent(new DrawComponent(Assets.GetTexture("forestWolfBite"), drawRec: new AABB((int)safePosition.X, (int)safePosition.Y, 32, 48), boundPos: entity.GetComponent <MovementComponent>().Position, getRotationFromMovementVector: true), typeof(MovementComponent));
                entity.AddComponent(new AnimationComponent(AnimationStructures.GetAnimationList(type)), typeof(DrawComponent));
                entity.AddComponent(new ProjectileComponent(power: 10, damage: 5, knockback: 200, isPhasing: true, hitCooldownMilliseconds: 200), typeof(MovementComponent));
                entity.AddComponent(new CollisionComponent(behavior: CollisionBehavior.Pass, collisionRectangle: new AABB(safePosition, new Vector2(16, 16))), new List <Type> {
                        typeof(MovementComponent), typeof(ProjectileComponent)
                    });
                break;
            }

                #endregion


                #region DEBUG

            case EntityType.DebugRectangle:
            {
                entity.SetAllegiance(Allegiance.Neutral);
                entity.AddComponent(new DrawComponent(Assets.GetTexture("DummyTexture"), drawRec: new AABB((int)safePosition.X, (int)safePosition.Y, 16, 16), tint: Color.Pink, layerDepth: 0.01f));
                break;
            }

                #endregion
            }

            entity.FinalizeCreation();
            return(entity);
        }
Ejemplo n.º 17
0
 private void ReorganizeIntoBatch(DrawComponent component)
 {
     RemoveFromBatch(component);
     InsertIntoBatch(component);
 }
Ejemplo n.º 18
0
 public MenuObject(Vector2 position, DrawComponent drawComponent, Origin drawOrigin = Origin.Center)
 {
     Position      = position;
     DrawComponent = drawComponent;
     DrawOrigin    = drawOrigin;
 }