Esempio n. 1
0
 void spawnEnemy(MotherShipComponent motherShip, PositionComponent position)
 {
     getFactory().CreateEnemyByType(motherShip.droneType, position.pos.x, position.pos.y, motherShip.droneHealth, 0, 0, motherShip.droneDamage, motherShip.droneSpeed)
         .ReplaceVelocity(getRandomizedStartVelocity(motherShip.droneSpeed))
         .AddFindTarget(CollisionTypes.Player)
         .AddHomeMissile(0.5f, motherShip.droneSpeed, CollisionTypes.Player);
 }
 public Entity AddPosition(float newX, float newY, float newZ)
 {
     var component = new PositionComponent();
     component.x = newX;
     component.y = newY;
     component.z = newZ;
     return AddPosition(component);
 }
    Vector2 getDesiredPosition(VelocityComponent velocity, PositionComponent position)
    {
        Vector2 positionOffset = velocity.vel;
        positionOffset *= -1.0f;
        positionOffset.Normalize();
        positionOffset *= LEADER_BEHIND_DIST;

        return position.pos + positionOffset;
    }
 Vector2 arrivalSteeringForce(PositionComponent position, VelocityComponent velocity, float speed, Vector2 desiredPosition, float slowingRadius)
 {
     Vector2 desiredVelocity = new Vector2((desiredPosition.x - position.pos.x), (desiredPosition.y - position.pos.y));
     float distance = desiredVelocity.magnitude;
     desiredVelocity.Normalize();
     desiredVelocity *= speed;
     if (distance < slowingRadius) {
         desiredVelocity *= (distance / slowingRadius);
     }
     return desiredVelocity - velocity.vel;
 }
Esempio n. 5
0
        public static Entity Particle(Entity entity, World world, Vector2 position)
        {
            //SpriteComponent sprite = new SpriteComponent("particle");
            PositionComponent pos = new PositionComponent(position);
            //ParticleComponent particle = new ParticleComponent(pos, world, sprite);
            //sprite.Tint = Color.Yellow;
            //particle.Size = 5;

            entity.Add(pos);
            return entity;
        }
Esempio n. 6
0
        public MoveAction(float expiration, int priority, Entity entity, Vector2 goal)
            : base(expiration, priority)
        {
            _entity = entity;
            _goal = goal;

            ComponentMapper<PositionComponent> positionMapper = new ComponentMapper<PositionComponent>(Director.SharedDirector.EntityWorld);
            _position = positionMapper.Get(entity);

            ComponentMapper<VelocityComponent> velocityMapper = new ComponentMapper<VelocityComponent>(Director.SharedDirector.EntityWorld);
            _velocity = velocityMapper.Get(entity);
        }
Esempio n. 7
0
        /// <summary>
        /// Creates this system.
        /// </summary>
        /// <param name="game"></param>
        public WeaponSystem(DungeonCrawlerGame game)
        {
            _game = game;

            //To simplfy some things, I'm keeping a reference to components I often use.
            _collisionComponent = _game.CollisionComponent;
            _equipmentComponent = _game.EquipmentComponent;
            _playerInfoComponent = _game.PlayerInfoComponent;
            _weaponComponent = _game.WeaponComponent;
            _weaponSpriteComponent = _game.WeaponSpriteComponent;
            _positionComponent = _game.PositionComponent;
        }
        public void Initialize()
        {
            _entityMock = new Mock<IEntity>();
            _movement = new MovementComponent();
            _movement.Parent = _entityMock.Object;
            _container = new FakeGameplayContainer();
            _screen = new Mock<ITiledScreen>();
            _entityMock.SetupGet(e => e.Screen).Returns(_screen.Object);
            _entityMock.SetupGet(e => e.Container).Returns(_container);

            _position = new PositionComponent();
            _movement.RegisterDependencies(_position);
        }
 public Entity ReplacePosition(float newX, float newY, float newZ)
 {
     PositionComponent component;
     if (hasPosition) {
         WillRemoveComponent(CoreComponentIds.Position);
         component = position;
     } else {
         component = new PositionComponent();
     }
     component.x = newX;
     component.y = newY;
     component.z = newZ;
     return ReplaceComponent(CoreComponentIds.Position, component);
 }
 Vector2 seperationSteeringForce(Entity e, PositionComponent position, List<Entity> children)
 {
     Vector2 desiredVelocity = new Vector2();
     for (int i = 0; i < children.Count; i++) {
         Entity child = children[i];
         if (child.isLeaderFollower && child != e) {
             Vector2 diff = position.pos - child.position.pos;
             if (diff.sqrMagnitude < SEPERATION_RADIUS_POW) {
                 desiredVelocity += diff;
             }
         }
     }
     return desiredVelocity;
 }
Esempio n. 11
0
        public TestOldMan(int playerNumber = 0)
        {
            mPlayerNumber = playerNumber;

            mPosition = new PositionComponent(this, 100, 100);
            mRotation = new RotationComponent(this);
            //mRenderable = new RenderableComponent(this);
            mPhysics = new PhysicsComponent(this);
            mAnimated = new AnimatedComponent(this);
            mInput = new InputComponent(this);
            mController = new PlayerControllerComponent(this);

            mHealth = new HealthComponent(this, 100.0f);
        }
        public override void Initialize()
        {
            base.Initialize();

            _collision = new CollisionComponent();
            _collision.Parent = EntityMock.Object;
            _movement = new MovementComponent();
            _movement.Parent = EntityMock.Object;
            _position = new PositionComponent();
            _position.Parent = EntityMock.Object;
            _movement.RegisterDependencies(_position);
            _movement.RegisterDependencies(_collision);
            _collision.RegisterDependencies(_position);
            _collision.RegisterDependencies(_movement);

            _position.Start(Container);
            _movement.Start(Container);
            _collision.Start(Container);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="parent">The parent entity for this Component.</param>
        /// <note>The parent Entity MUST have a PositionComponent in order to construct this Component.</note>
        /// <note>The parent Entity MUST have an InputComponent in order to construct this Component.</note>
        public TheFinaleCameraComponent_cl(Entity_cl parent)
            : base(parent)
        {
            // Asserting here to ensure that the TheFinaleCameraComponent has all the required Components
            // These will be compiled out of the Release build
            Debug.Assert(mParentEntity.GetComponentOfType(typeof(PositionComponent)) != null, "TheFinaleCameraComponent: No PositionComponent exists on parent Entity!");
            Debug.Assert(mParentEntity.GetComponentOfType(typeof(InputComponent)) != null, "TheFinaleCameraComponent: No InputComponent exists on parent Entity!");

            mPositionComponent = (PositionComponent)mParentEntity.GetComponentOfType(typeof(PositionComponent));
            mInputComponent = (InputComponent)mParentEntity.GetComponentOfType(typeof(InputComponent));

            mInputComponent.AddKey("moveN", Keys.W);
            mInputComponent.AddKey("moveW", Keys.A);
            mInputComponent.AddKey("moveS", Keys.S);
            mInputComponent.AddKey("moveE", Keys.D);

            // Items at the same position as the camera should appear at the bottom of the screen, horizontally centered
            mScreenOffsetMatrix = Matrix.CreateTranslation(new Vector3((float)FNA.Game.BaseInstance.WindowWidth * 0.5f, (float)FNA.Game.BaseInstance.WindowHeight, 0));

            RecalculateTransformationMatrix();
        }
Esempio n. 14
0
        public TestNess(int playerNumber = 0)
        {
            mPlayerNumber = playerNumber;

            mPosition = new PositionComponent(this, 100, 100);
            mRotation = new RotationComponent(this);
            //mRenderable = new RenderableComponent(this);
            mPhysics = new PhysicsComponent(this);
            mAnimated = new AnimatedComponent(this);
            mInput = new InputComponent(this);
            mController = new PlayerControllerComponent(this);

            //switch (mPlayerNumber)
            //{
            //    case 0:
            //        // Player 0 means no human control.
            //        break;

            //    case 1:
            //        mInput.PlayerIndex = PlayerIndex.One;
            //        break;

            //    case 2:
            //        mInput.PlayerIndex = PlayerIndex.Two;
            //        break;

            //    case 3:
            //        mInput.PlayerIndex = PlayerIndex.Three;
            //        break;

            //    case 4:
            //        mInput.PlayerIndex = PlayerIndex.Four;
            //        break;
            //}

            mHealth = new HealthComponent(this, 100.0f);
        }
Esempio n. 15
0
 private void OnPositionChanged(PositionComponent component)
 {
     OnPositionChanged(component, ref _position);
 }
Esempio n. 16
0
        private Effect ParsePositionBehavior(PositionEffectAxisInfo axisInfo, Axis axis)
        {
            Effect action = e => { };

            var baseVar   = axisInfo.BaseVar;
            var offsetVar = axisInfo.OffsetVar;

            if (baseVar != null)
            {
                if (axis == Axis.X)
                {
                    action = entity => {
                        var x = CheckNumericVar(entity, baseVar);
                        if (x.HasValue)
                        {
                            PositionComponent pos = entity.GetComponent <PositionComponent>();
                            if (pos != null)
                            {
                                pos.SetX(x.Value);
                            }
                        }
                    }
                }
                ;
                else
                {
                    action = entity => {
                        var y = CheckNumericVar(entity, baseVar);
                        if (y.HasValue)
                        {
                            PositionComponent pos = entity.GetComponent <PositionComponent>();
                            if (pos != null)
                            {
                                pos.SetY(y.Value);
                            }
                        }
                    }
                };
            }
            else if (axisInfo.Base == null)
            {
                action = entity => {
                    PositionComponent pos = entity.GetComponent <PositionComponent>();
                    if (pos != null && entity.Parent != null)
                    {
                        PositionComponent parentPos = entity.Parent.GetComponent <PositionComponent>();
                        if (parentPos != null)
                        {
                            if (axis == Axis.X)
                            {
                                pos.SetX(parentPos.X);
                            }
                            else if (axis == Axis.Y)
                            {
                                pos.SetY(parentPos.Y);
                            }
                        }
                    }
                };
            }
            else
            {
                if (axis == Axis.X)
                {
                    action = entity => {
                        PositionComponent pos = entity.GetComponent <PositionComponent>();
                        if (pos != null)
                        {
                            pos.SetPosition(new PointF(axisInfo.Base.Value, pos.Position.Y));
                        }
                    }
                }
                ;
                else
                {
                    action = entity => {
                        PositionComponent pos = entity.GetComponent <PositionComponent>();
                        if (pos != null)
                        {
                            pos.SetPosition(new PointF(pos.Position.X, axisInfo.Base.Value));
                        }
                    }
                };
            }

            if (axisInfo.Offset != null || offsetVar != null)
            {
                switch (axisInfo.OffsetDirection)
                {
                case OffsetDirection.Inherit:
                    action += entity => {
                        var offset            = axisInfo.Offset ?? CheckNumericVar(entity, offsetVar) ?? 0;
                        PositionComponent pos = entity.GetComponent <PositionComponent>();
                        if (pos != null && entity.Parent != null)
                        {
                            Direction offdir = entity.Parent.Direction;
                            switch (offdir)
                            {
                            case Direction.Down: pos.Offset(0, offset); break;

                            case Direction.Up: pos.Offset(0, -offset); break;

                            case Direction.Left: pos.Offset(-offset, 0); break;

                            case Direction.Right: pos.Offset(offset, 0); break;
                            }
                        }
                    };
                    break;

                case OffsetDirection.Input:
                    action += entity => {
                        var offset              = axisInfo.Offset ?? CheckNumericVar(entity, offsetVar) ?? 0;
                        PositionComponent pos   = entity.GetComponent <PositionComponent>();
                        InputComponent    input = entity.GetComponent <InputComponent>();
                        if (input != null && pos != null)
                        {
                            if (axis == Axis.Y)
                            {
                                if (input.Down)
                                {
                                    pos.Offset(0, offset);
                                }
                                else if (input.Up)
                                {
                                    pos.Offset(0, -offset);
                                }
                            }
                            else
                            {
                                if (input.Left)
                                {
                                    pos.Offset(-offset, 0);
                                }
                                else if (input.Right || (!input.Up && !input.Down))
                                {
                                    pos.Offset(offset, 0);
                                }
                            }
                        }
                    };
                    break;

                case OffsetDirection.Left:
                    action += entity => {
                        var offset            = axisInfo.Offset ?? CheckNumericVar(entity, offsetVar) ?? 0;
                        PositionComponent pos = entity.GetComponent <PositionComponent>();
                        if (pos != null)
                        {
                            pos.Offset(-offset, 0);
                        }
                    };
                    break;

                case OffsetDirection.Right:
                    action += entity => {
                        var offset            = axisInfo.Offset ?? CheckNumericVar(entity, offsetVar) ?? 0;
                        PositionComponent pos = entity.GetComponent <PositionComponent>();
                        if (pos != null)
                        {
                            pos.Offset(offset, 0);
                        }
                    };
                    break;

                case OffsetDirection.Down:
                    action += entity => {
                        var offset            = axisInfo.Offset ?? CheckNumericVar(entity, offsetVar) ?? 0;
                        PositionComponent pos = entity.GetComponent <PositionComponent>();
                        if (pos != null)
                        {
                            pos.Offset(0, offset);
                        }
                    };
                    break;

                case OffsetDirection.Up:
                    action += entity => {
                        var offset            = axisInfo.Offset ?? CheckNumericVar(entity, offsetVar) ?? 0;
                        PositionComponent pos = entity.GetComponent <PositionComponent>();
                        if (pos != null)
                        {
                            pos.Offset(0, -offset);
                        }
                    };
                    break;
                }
            }
            return(action);
        }
 public static bool IsGameBoardPositionOpen(this Pool pool,
                                            PositionComponent position,
                                            out ICollection <Entity> entities)
 {
     return(pool.IsGameBoardPositionOpen(position.x, position.y, out entities));
 }
        private void LoadPositionComponent(GameEntity entity, PositionComponentInfo componentInfo)
        {
            var poscomp = new PositionComponent();
            entity.AddComponent(poscomp);

            if (componentInfo != null)
                poscomp.LoadInfo(componentInfo);
        }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            AggregateFactory   = new AggregateFactory(this);
            WeaponFactory      = new WeaponFactory(this);
            DoorFactory        = new DoorFactory(this);
            RoomFactory        = new RoomFactory(this);
            CollectableFactory = new CollectibleFactory(this);
            WallFactory        = new WallFactory(this);
            EnemyFactory       = new EnemyFactory(this);
            SkillEntityFactory = new SkillEntityFactory(this);
            NPCFactory         = new NPCFactory(this);

            // Initialize Components
            PlayerComponent          = new PlayerComponent();
            LocalComponent           = new LocalComponent();
            RemoteComponent          = new RemoteComponent();
            PositionComponent        = new PositionComponent();
            MovementComponent        = new MovementComponent();
            MovementSpriteComponent  = new MovementSpriteComponent();
            SpriteComponent          = new SpriteComponent();
            DoorComponent            = new DoorComponent();
            RoomComponent            = new RoomComponent();
            HUDSpriteComponent       = new HUDSpriteComponent();
            HUDComponent             = new HUDComponent();
            InventoryComponent       = new InventoryComponent();
            InventorySpriteComponent = new InventorySpriteComponent();
            ContinueNewGameScreen    = new ContinueNewGameScreen(graphics, this);
            EquipmentComponent       = new EquipmentComponent();
            WeaponComponent          = new WeaponComponent();
            BulletComponent          = new BulletComponent();
            PlayerInfoComponent      = new PlayerInfoComponent();
            WeaponSpriteComponent    = new WeaponSpriteComponent();
            StatsComponent           = new StatsComponent();
            EnemyAIComponent         = new EnemyAIComponent();
            NpcAIComponent           = new NpcAIComponent();

            CollectibleComponent = new CollectibleComponent();
            CollisionComponent   = new CollisionComponent();
            TriggerComponent     = new TriggerComponent();
            EnemyComponent       = new EnemyComponent();
            NPCComponent         = new NPCComponent();
            //QuestComponent = new QuestComponent();
            LevelManager             = new LevelManager(this);
            SpriteAnimationComponent = new SpriteAnimationComponent();
            SkillProjectileComponent = new SkillProjectileComponent();
            SkillAoEComponent        = new SkillAoEComponent();
            SkillDeployableComponent = new SkillDeployableComponent();
            SoundComponent           = new SoundComponent();
            ActorTextComponent       = new ActorTextComponent();
            TurretComponent          = new TurretComponent();
            TrapComponent            = new TrapComponent();
            ExplodingDroidComponent  = new ExplodingDroidComponent();
            HealingStationComponent  = new HealingStationComponent();
            PortableShieldComponent  = new PortableShieldComponent();
            PortableStoreComponent   = new PortableStoreComponent();
            ActiveSkillComponent     = new ActiveSkillComponent();
            PlayerSkillInfoComponent = new PlayerSkillInfoComponent();

            Quests = new List <Quest>();


            #region Initialize Effect Components
            AgroDropComponent          = new AgroDropComponent();
            AgroGainComponent          = new AgroGainComponent();
            BuffComponent              = new BuffComponent();
            ChanceToSucceedComponent   = new ChanceToSucceedComponent();
            ChangeVisibilityComponent  = new ChangeVisibilityComponent();
            CoolDownComponent          = new CoolDownComponent();
            DamageOverTimeComponent    = new DamageOverTimeComponent();
            DirectDamageComponent      = new DirectDamageComponent();
            DirectHealComponent        = new DirectHealComponent();
            FearComponent              = new FearComponent();
            HealOverTimeComponent      = new HealOverTimeComponent();
            InstantEffectComponent     = new InstantEffectComponent();
            KnockBackComponent         = new KnockBackComponent();
            TargetedKnockBackComponent = new TargetedKnockBackComponent();
            ReduceAgroRangeComponent   = new ReduceAgroRangeComponent();
            ResurrectComponent         = new ResurrectComponent();
            StunComponent              = new StunComponent();
            TimedEffectComponent       = new TimedEffectComponent();
            EnslaveComponent           = new EnslaveComponent();
            CloakComponent             = new CloakComponent();
            #endregion

            base.Initialize();
        }
Esempio n. 20
0
        protected override void OnPositionChanged(PositionComponent component, ref Vector3 position)
        {
            if (component.HasFlag(PositionComponent.X) && WrapWidth > 0) {
                position.X -= (int) Math.Floor(position.X / WrapWidth) * WrapWidth;
            }

            if (component.HasFlag(PositionComponent.Z) && WrapHeight > 0) {
                position.Z -= (int) Math.Floor(position.Z / WrapHeight) * WrapHeight;
            }

            if (component.HasFlag(PositionComponent.Y)) {
                InvalidateProjectionMatrix();
            } else {
                base.OnPositionChanged(component, ref position);
            }
        }
Esempio n. 21
0
        public void Attach()
        {
            _texture = _factory.Create <ITexture2D>();
            _texture.SetData("Assets/picture.png");

            _texture2 = _factory.Create <ITexture2D>();
            _texture2.SetData("Assets/picture2.png");

            _scene.Init();
            _physicsContainer.Gravity = new Vector3(0, -800, 0);

            var entity = _scene.CreateEntity();

            _scene.AddComponent(entity, new CameraComponent {
                Camera = _camera, Active = true
            });
            _scene.AddComponent(entity, new CameraScript(_camera));

            entity = _scene.CreateEntity();
            _scene.AddComponent(entity, new PositionComponent {
                Position = new Vector3(-100, 400, 0)
            });
            _scene.AddComponent(entity, new SizeComponent {
                Width = 300, Height = 300
            });
            _scene.AddComponent(entity, new ColorComponent {
                Color = new Vector4(0.5f, 0.5f, 0.5f, 1f)
            });

            entity = _scene.CreateEntity();
            var positionComponent = new PositionComponent {
                Position = new Vector3(400, -100, 0)
            };

            _scene.AddComponent(entity, positionComponent);
            _scene.AddComponent(entity, new SizeComponent {
                Width = 400, Height = 300
            });
            _scene.AddComponent(entity, new ColorComponent {
                Color = new Vector4(1, 0, 1, 1)
            });
            _scene.AddComponent(entity, new TextureComponent {
                Texture = _texture
            });
            _scene.AddComponent(entity, new DiceScript(positionComponent));

            entity = _scene.CreateEntity();
            _scene.AddComponent(entity, new PositionComponent {
                Position = new Vector3(-400, -100, 0)
            });
            _scene.AddComponent(entity, new SizeComponent {
                Width = 300, Height = 300
            });
            _scene.AddComponent(entity, new TextureComponent {
                Texture = _texture2
            });
            _scene.AddComponent(entity, new PhysicsComponent {
                Velocity = new Vector3(300, 500, 0)
            });

            entity = _scene.CreateEntity();
            _scene.AddComponent(entity, new PositionComponent {
                Position = new Vector3(0, -360, 0)
            });
            _scene.AddComponent(entity, new SizeComponent {
                Width = 1280, Height = 10
            });
            _scene.AddComponent(entity, new PhysicsComponent {
                Fixed = true
            });
        }
Esempio n. 22
0
        private void Shoot(Entity player)
        {
            PlayerComponent   pc   = (PlayerComponent)player.components[typeof(PlayerComponent)];
            PositionComponent posc = (PositionComponent)player.components[typeof(PositionComponent)];

            if (pc.lastFireTime > 50)
            {
                Texture2D laser = Game1.instance.laserRed;
                if (pc.laserLevel >= 1)
                {
                    laser = Game1.instance.laserGreen;
                }

                Texture2D expTexToUse = pc.laserLevel == 0 ? Game1.instance.explosionTexture : Game1.instance.explosionTextureGreen;

                if (pc.laserLevel < 2)
                {
                    Entity newLaser = new Entity();
                    newLaser.AddComponent(new RenderComponent(laser));
                    newLaser.AddComponent(new LaserComponent(expTexToUse));
                    newLaser.AddComponent(new SpeedComponent(new Vector2(0, -20)));
                    newLaser.AddComponent(new PositionComponent(new Vector2(posc.position.X, posc.position.Y - laser.Height / 2 - 40)));
                    newLaser.AddComponent(new DealsDamageComponent(pc.laserLevel + 1, DamageSystem.LASER));
                    Game1.instance.world.AddEntity(newLaser);
                }
                if (pc.laserLevel >= 2)
                {
                    Entity newLaser1 = new Entity();
                    newLaser1.AddComponent(new RenderComponent(laser));
                    newLaser1.AddComponent(new LaserComponent(expTexToUse));
                    newLaser1.AddComponent(new SpeedComponent(new Vector2(0, -20)));
                    newLaser1.AddComponent(new PositionComponent(new Vector2(posc.position.X - 10, posc.position.Y - laser.Height / 2 - 40)));
                    newLaser1.AddComponent(new DealsDamageComponent(pc.laserLevel + 1, DamageSystem.LASER));
                    Game1.instance.world.AddEntity(newLaser1);

                    Entity newLaser2 = new Entity();
                    newLaser2.AddComponent(new RenderComponent(laser));
                    newLaser2.AddComponent(new LaserComponent(expTexToUse));
                    newLaser2.AddComponent(new SpeedComponent(new Vector2(0, -20)));
                    newLaser2.AddComponent(new PositionComponent(new Vector2(posc.position.X + 10, posc.position.Y - laser.Height / 2 - 40)));
                    newLaser2.AddComponent(new DealsDamageComponent(pc.laserLevel + 1, DamageSystem.LASER));
                    Game1.instance.world.AddEntity(newLaser2);
                }
                if (pc.laserLevel >= 3)
                {
                    Entity newLaser1 = new Entity();
                    newLaser1.AddComponent(new RenderComponent(laser));
                    newLaser1.AddComponent(new LaserComponent(expTexToUse));
                    newLaser1.AddComponent(new SpeedComponent(new Vector2(-10, -20)));
                    newLaser1.AddComponent(new PositionComponent(new Vector2(posc.position.X - 10, posc.position.Y - laser.Height / 2 - 40)));
                    newLaser1.AddComponent(new DealsDamageComponent(pc.laserLevel + 1, DamageSystem.LASER));
                    Game1.instance.world.AddEntity(newLaser1);

                    Entity newLaser2 = new Entity();
                    newLaser2.AddComponent(new RenderComponent(laser));
                    newLaser2.AddComponent(new LaserComponent(expTexToUse));
                    newLaser2.AddComponent(new SpeedComponent(new Vector2(10, -20)));
                    newLaser2.AddComponent(new PositionComponent(new Vector2(posc.position.X + 10, posc.position.Y - laser.Height / 2 - 40)));
                    newLaser2.AddComponent(new DealsDamageComponent(pc.laserLevel + 1, DamageSystem.LASER));
                    Game1.instance.world.AddEntity(newLaser2);
                }
                pc.lastFireTime = 0;
            }
        }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            AggregateFactory = new AggregateFactory(this);
            WeaponFactory = new WeaponFactory(this);
            DoorFactory = new DoorFactory(this);
            RoomFactory = new RoomFactory(this);
            CollectableFactory = new CollectibleFactory(this);
            WallFactory = new WallFactory(this);
            EnemyFactory = new EnemyFactory(this);

            // Initialize Components
            PlayerComponent = new PlayerComponent();
            LocalComponent = new LocalComponent();
            RemoteComponent = new RemoteComponent();
            PositionComponent = new PositionComponent();
            MovementComponent = new MovementComponent();
            MovementSpriteComponent = new MovementSpriteComponent();
            SpriteComponent = new SpriteComponent();
            DoorComponent = new DoorComponent();
            RoomComponent = new RoomComponent();
            HUDSpriteComponent = new HUDSpriteComponent();
            HUDComponent = new HUDComponent();
            InventoryComponent = new InventoryComponent();
            InventorySpriteComponent = new InventorySpriteComponent();
            ContinueNewGameScreen = new ContinueNewGameScreen(graphics, this);
            EquipmentComponent = new EquipmentComponent();
            WeaponComponent = new WeaponComponent();
            BulletComponent = new BulletComponent();
            PlayerInfoComponent = new PlayerInfoComponent();
            WeaponSpriteComponent = new WeaponSpriteComponent();
            StatsComponent = new StatsComponent();
            EnemyAIComponent = new EnemyAIComponent();
            CollectibleComponent = new CollectibleComponent();
            CollisionComponent = new CollisionComponent();
            TriggerComponent = new TriggerComponent();
            EnemyComponent = new EnemyComponent();
            QuestComponent = new QuestComponent();
            LevelManager = new LevelManager(this);
            SpriteAnimationComponent = new SpriteAnimationComponent();
            SkillProjectileComponent = new SkillProjectileComponent();
            SkillAoEComponent = new SkillAoEComponent();
            SkillDeployableComponent = new SkillDeployableComponent();

            //TurretComponent = new TurretComponent();
            //TrapComponent = new TrapComponent();
            //PortableShopComponent = new PortableShopComponent();
            //PortableShieldComponent = new PortableShieldComponent();
            //MotivateComponent =  new MotivateComponent();
            //FallbackComponent = new FallbackComponent();
            //ChargeComponent = new ChargeComponent();
            //HealingStationComponent = new HealingStationComponent();
            //ExplodingDroidComponent = new ExplodingDroidComponent();

            base.Initialize();
        }
Esempio n. 24
0
        static void positionComponent(Entity e, PositionComponent component, int x, int y)
        {
            var pos = e.position;
            var has = e.hasPosition;

            e.AddPosition(x, y);
            e.AddPosition(component);

            e.ReplacePosition(x, y);

            e.RemovePosition();
        }
Esempio n. 25
0
        public override void Update(GameTime gameTime)
        {
            if (!Enabled)
            {
                return;
            }

            if (player == null || player.CurrentEntity == null)
            {
                return;
            }

            Entity            entity   = player.CurrentEntity;
            HeadComponent     head     = player.CurrentEntityHead;
            PositionComponent position = player.Position;

            CameraChunk = position.Position.ChunkIndex;

            CameraPosition = position.Position.LocalPosition + head.Offset;
            CameraUpVector = new Vector3(0, 0, 1f);

            float height   = (float)Math.Sin(head.Tilt);
            float distance = (float)Math.Cos(head.Tilt);

            float lookX = (float)Math.Cos(head.Angle) * distance;
            float lookY = -(float)Math.Sin(head.Angle) * distance;

            float strafeX = (float)Math.Cos(head.Angle + MathHelper.PiOver2);
            float strafeY = -(float)Math.Sin(head.Angle + MathHelper.PiOver2);

            CameraUpVector = Vector3.Cross(new Vector3(strafeX, strafeY, 0), new Vector3(lookX, lookY, height));

            View = Matrix.CreateLookAt(
                CameraPosition,
                new Vector3(
                    CameraPosition.X + lookX,
                    CameraPosition.Y + lookY,
                    CameraPosition.Z + height),
                CameraUpVector);

            MinimapView = Matrix.CreateLookAt(
                new Vector3(CameraPosition.X, CameraPosition.Y, 100),
                new Vector3(
                    position.Position.LocalPosition.X,
                    position.Position.LocalPosition.Y,
                    0f),
                new Vector3(
                    (float)Math.Cos(head.Angle),
                    (float)Math.Sin(-head.Angle), 0f));

            float centerX = GraphicsDevice.Viewport.Width / 2;
            float centerY = GraphicsDevice.Viewport.Height / 2;

            Vector3 nearPoint = GraphicsDevice.Viewport.Unproject(new Vector3(centerX, centerY, 0f), Projection, View, Matrix.Identity);
            Vector3 farPoint  = GraphicsDevice.Viewport.Unproject(new Vector3(centerX, centerY, 1f), Projection, View, Matrix.Identity);
            Vector3 direction = farPoint - nearPoint;

            direction.Normalize();
            PickRay = new Ray(nearPoint, direction);
            Frustum = new BoundingFrustum(Projection * View);
        }
Esempio n. 26
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            AggregateFactory = new AggregateFactory(this);

            // Initialize Components
            PlayerComponent = new PlayerComponent();
            LocalComponent = new LocalComponent();
            RemoteComponent = new RemoteComponent();
            PositionComponent = new PositionComponent();
            MovementComponent = new MovementComponent();
            MovementSpriteComponent = new MovementSpriteComponent();
            SpriteComponent = new SpriteComponent();
            DoorComponent = new DoorComponent();
            RoomComponent = new RoomComponent();
            HUDSpriteComponent = new HUDSpriteComponent();
            HUDComponent = new HUDComponent();

            CharacterSelectionScreen = new CharacterSelectionScreen(graphics, this);

            LevelManager = new LevelManager(this);

            base.Initialize();
        }
Esempio n. 27
0
        private void LoadEntity(XElement xml)
        {
            GameEntity entity = new GameEntity();
            string name = xml.RequireAttribute("name").Value;

            if (entities.ContainsKey(name)) throw new GameXmlException(xml, "You have defined two entities both named \"" + name + "\".");

            entity.Name = name;
            entity.MaxAlive = xml.TryAttribute<int>("limit", 50);

            SpriteComponent spritecomp = null;
            PositionComponent poscomp = null;
            StateComponent statecomp = new StateComponent();
            entity.AddComponent(statecomp);

            try
            {
                foreach (XElement xmlComp in xml.Elements())
                {
                    switch (xmlComp.Name.LocalName)
                    {
                        case "EditorData":
                            break;

                        case "Tilesheet":
                            if (spritecomp == null)
                            {
                                spritecomp = new SpriteComponent();
                                entity.AddComponent(spritecomp);
                            }
                            if (poscomp == null)
                            {
                                poscomp = new PositionComponent();
                                entity.AddComponent(poscomp);
                            }
                            spritecomp.LoadTilesheet(xmlComp);
                            break;

                        case "Trigger":
                            statecomp.LoadStateTrigger(xmlComp);
                            break;

                        case "Sprite":
                            if (spritecomp == null)
                            {
                                spritecomp = new SpriteComponent();
                                entity.AddComponent(spritecomp);
                            }
                            if (poscomp == null)
                            {
                                poscomp = new PositionComponent();
                                entity.AddComponent(poscomp);
                            }
                            spritecomp.LoadXml(xmlComp);
                            break;

                        case "Position":
                            if (poscomp == null)
                            {
                                poscomp = new PositionComponent();
                                entity.AddComponent(poscomp);
                            }
                            poscomp.LoadXml(xmlComp);
                            break;

                        case "Death":
                            entity.OnDeath += EffectParser.LoadTriggerEffect(xmlComp);
                            break;

                        case "GravityFlip":
                            entity.IsGravitySensitive = xmlComp.GetValue<bool>();
                            break;

                        default:
                            entity.GetOrCreateComponent(xmlComp.Name.LocalName).LoadXml(xmlComp);
                            break;
                    }
                }
            }
            catch (GameXmlException ex)
            {
                ex.Entity = name;
                throw;
            }

            entities.Add(name, entity);
        }
Esempio n. 28
0
        //You must have this, but it may be empty.
        //What should the entity do in order to revert to its starting state?
        public override void revertToStartingState()
        {
            PositionComponent posComp = ( PositionComponent )this.getComponent(GlobalVars.POSITION_COMPONENT_NAME);

            level.getMovementSystem().teleportToNoCollisionCheck(posComp, posComp.startingX, posComp.startingY);
        }
Esempio n. 29
0
 /// <summary>
 /// Method called when the camera's position has been modified.
 /// </summary>
 /// <param name="component">The component(s) of the camera's position
 /// that were modified</param>
 protected virtual void OnPositionChanged(PositionComponent component, ref Vector3 position)
 {
     InvalidateViewMatrix();
 }
Esempio n. 30
0
        //--------------------------------------------------------------------------------------------

        public void fireWeapon(PositionComponent posComp)
        {
            if (level.getPlayer() == null)
            {
                return;
            }

            //Do maths!
            float mouseX = level.getInputSystem().mouseX + level.sysManager.drawSystem.getMainView().x;
            float mouseY = level.getInputSystem().mouseY + level.sysManager.drawSystem.getMainView().y;

            float xDiff = mouseX - posComp.x;
            float yDiff = mouseY - posComp.y;

            double theta = Math.Atan(xDiff / yDiff);

            double xVel = Math.Sin(theta) * GlobalVars.BULLET_SPEED;
            double yVel = Math.Cos(theta) * GlobalVars.BULLET_SPEED;

            if (xDiff > 0 && xVel < 0)
            {
                xVel = -xVel;
            }
            if (xDiff < 0 && xVel > 0)
            {
                xVel = -xVel;
            }
            if (yDiff > 0 && yVel < 0)
            {
                yVel = -yVel;
            }
            if (yDiff < 0 && yVel > 0)
            {
                yVel = -yVel;
            }

            //if (level.sysManager.spSystem.speedyActive && xVel > 0) xVel += GlobalVars.SPEEDY_SPEED;
            //else if (level.sysManager.spSystem.speedyActive && xVel < 0) xVel -= GlobalVars.SPEEDY_SPEED;
            Player            player        = ( Player )level.getPlayer();
            VelocityComponent playerVelComp = ( VelocityComponent )player.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);

            //Change bullet speed depending on player's speed.
            //But - only speed the bullet up, don't slow it down.
            if ((playerVelComp.x > 0 && xVel > 0) || (playerVelComp.x < 0 && xVel < 0))
            {
                if (Math.Abs(xVel) > GlobalVars.PLAYER_HORIZ_MOVE_SPEED)
                {
                    xVel += playerVelComp.x;
                }
            }
            if ((playerVelComp.y > 0 && yVel > 0) || (playerVelComp.y < 0 && yVel < 0))
            {
                if (Math.Abs(yVel) > GlobalVars.STANDARD_GRAVITY)
                {
                    yVel += playerVelComp.y;
                }
            }

            //Make the bullet
            BulletEntity bullet = new BulletEntity(level, posComp.x, posComp.y, ( float )xVel, ( float )yVel);

            level.addEntity(bullet.randId, bullet);
            //level.sysManager.sndSystem.playSound("RunningGame.Resources.Sounds.boop.wav", false);

            //Recoil
            if (recoil && player.hasComponent(GlobalVars.VELOCITY_COMPONENT_NAME))
            {
                //Don't recoil if the player is walking in the direcion of the shot
                if (!((xVel > 0 && level.getInputSystem().myKeys[GlobalVars.KEY_RIGHT].pressed) || (xVel < 0 && level.getInputSystem().myKeys[GlobalVars.KEY_LEFT].pressed)))
                {
                    if (!level.sysManager.spSystem.playerSpeedyEnabled)
                    {
                        playerVelComp.x -= ( float )xVel * recoilMultiplier;
                    }
                }
                else
                {
                    //If the player is in the air, still recoil
                    float leftX  = (posComp.x - posComp.width / 2);
                    float rightX = (posComp.x + posComp.width / 2);
                    float lowerY = (posComp.y + posComp.height / 2 + 1);
                    if (!(level.getCollisionSystem().findObjectsBetweenPoints(leftX, lowerY, rightX, lowerY).Count > 0))
                    {
                        //Check it isn't over the cap
                        if (!((playerVelComp.x < 0 && playerVelComp.x < recoilCap) || (playerVelComp.x > 0 && playerVelComp.x > recoilCap)))
                        {
                            if (!level.sysManager.spSystem.playerSpeedyEnabled)
                            {
                                playerVelComp.x -= ( float )xVel * recoilMultiplier;
                            }
                        }
                    }
                }

                //Check it isn't over the recoil cap
                if (!((playerVelComp.y < 0 && playerVelComp.y < recoilCap) || (playerVelComp.y > 0 && playerVelComp.y > recoilCap)))
                {
                    playerVelComp.y -= ( float )yVel * recoilMultiplier;
                }
            }

            //Turn if need be
            if (player.isLookingLeft() && xVel > 0)
            {
                player.faceRight();
            }
            else if (player.isLookingRight() && xVel < 0)
            {
                player.faceLeft();
            }
            bulletFired = true;
        }
Esempio n. 31
0
        public override void Run()
        {
            // If there is no state, setup world.
            if (State == WorldState.None)
            {
                // Create a renderable text entity for "Pong".
                int pongTextID = EntityManager.CreateEntity();

                // Load font.
                SpriteFont pongFont = ContentManager.Load <SpriteFont>("Exo-2-SemiBold");

                // Create components.
                PositionComponent   pongTextPosition   = new PositionComponent(pongTextID, engine.ScreenWidth / 2 - 80, 50);
                TextRenderComponent pongTextSpriteFont = new TextRenderComponent(pongTextID, Color.Black, pongFont, "MEGA PONG");

                // Add components.
                ComponentManager
                .SetComponent(pongTextPosition)
                .SetComponent(pongTextSpriteFont);


                // Create renderable text entity for player 1 score.
                int player1ID = EntityManager.CreateEntity();

                // Load font.
                SpriteFont player1Font = ContentManager.Load <SpriteFont>("Exo-2-SemiBold");

                // Create components.
                PositionComponent   player1Position   = new PositionComponent(player1ID, 50, 50);
                TextRenderComponent player1SpriteFont = new TextRenderComponent(player1ID, Color.Black, player1Font, "0");

                // Add components.
                ComponentManager
                .SetComponent(player1Position)
                .SetComponent(player1SpriteFont);

                // Emit event.
                EventManager.Emit(new ScoreTextCreateEvent(player1ID, 1));


                // Create renderable text entity for player 2 score.
                int player2ID = EntityManager.CreateEntity();

                // Load font.
                SpriteFont player2Font = ContentManager.Load <SpriteFont>("Exo-2-SemiBold");

                // Create components.
                PositionComponent   player2Position   = new PositionComponent(player2ID, engine.ScreenWidth - 75, 50);
                TextRenderComponent player2SpriteFont = new TextRenderComponent(player2ID, Color.Black, player2Font, "0");

                // Add components.
                ComponentManager
                .SetComponent(player2Position)
                .SetComponent(player2SpriteFont);

                // Emit event.
                EventManager.Emit(new ScoreTextCreateEvent(player2ID, 2));
            }

            base.Run();
        }
Esempio n. 32
0
        public void Run()
        {
            foreach (int i in _moveEntities)
            {
                PositionComponent positionComponent = _moveEntities.Get1[i];
                MoveComponent     moveComponent     = _moveEntities.Get2[i];
                Transform         transform         = _moveEntities.Get3[i].Transform;
                EcsEntity         movingEntity      = _moveEntities.Entities[i];

                Vector3 curPosition     = transform.position;
                float   height          = curPosition.y;
                Vector3 desiredPosition = moveComponent.DesiredPosition.ToVector3(height);
                Vector3 estimatedVector = desiredPosition - curPosition;
                if (estimatedVector.magnitude > Epsilon)
                {
                    transform.position = Vector3.Lerp(
                        transform.position, desiredPosition,
                        moveComponent.Speed / estimatedVector.magnitude * Time.deltaTime);
                    continue;
                }

                Vector2Int oldPosition = positionComponent.Position;
                Vector2Int newPosition = moveComponent.DesiredPosition;
                if (!oldPosition.Equals(newPosition))
                {
                    movingEntity.Set <NewPositionComponent>().NewPosition = newPosition;
                }

                Vector2Int newDesiredPosition;
                Vector3    newDirection;
                switch (moveComponent.Heading)
                {
                case Directions.Up:
                    newDesiredPosition = new Vector2Int(newPosition.x, newPosition.y + 1);
                    newDirection       = new Vector3(0, 0, 0);
                    break;

                case Directions.Right:
                    newDesiredPosition = new Vector2Int(newPosition.x + 1, newPosition.y);
                    newDirection       = new Vector3(0, 90, 0);
                    break;

                case Directions.Down:
                    newDesiredPosition = new Vector2Int(newPosition.x, newPosition.y - 1);
                    newDirection       = new Vector3(0, 180, 0);
                    break;

                case Directions.Left:
                    newDesiredPosition = new Vector2Int(newPosition.x - 1, newPosition.y);
                    newDirection       = new Vector3(0, -90, 0);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                transform.rotation = Quaternion.Euler(newDirection);

                bool stuckToWall = false;
                foreach (EcsEntity entity in _worldService.WorldField[newDesiredPosition.x][newDesiredPosition.y])
                {
                    if (!entity.IsAlive())
                    {
                        continue;
                    }
                    if (entity.Get <WallComponent>() == null)
                    {
                        continue;
                    }

                    stuckToWall = true;
                }

                if (stuckToWall)
                {
                    movingEntity.Set <StoppedComponent>();
                }
                else
                {
                    moveComponent.DesiredPosition = newDesiredPosition;
                    movingEntity.Unset <StoppedComponent>();
                }
            }
        }
 public static bool IsGameBoardPositionOpen(this Pool pool,
                                            PositionComponent position,
                                            out ICollection<Entity> entities)
 {
     return pool.IsGameBoardPositionOpen(position.x, position.y, out entities);
 }
Esempio n. 34
0
 void setVelocity(VelocityComponent velocity, PositionComponent actual, PositionComponent desired)
 {
     //velocity.x = (desired.x - actual.x) * 2.0f;
 }
Esempio n. 35
0
    public static PositionComponent FromHexCoordinates(int hx, int hy, int hz)
    {
        PositionComponent component = new PositionComponent();

        return component;
    }
 public Entity AddPosition(PositionComponent component)
 {
     return AddComponent(CoreComponentIds.Position, component);
 }
Esempio n. 37
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            AggregateFactory = new AggregateFactory(this);

            // Initialize Components
            PlayerComponent = new PlayerComponent();
            LocalComponent = new LocalComponent();
            RemoteComponent = new RemoteComponent();
            PositionComponent = new PositionComponent();
            MovementComponent = new MovementComponent();
            MovementSpriteComponent = new MovementSpriteComponent();
            SpriteComponent = new SpriteComponent();

            base.Initialize();
        }
Esempio n. 38
0
        public override void Update(GameTime gameTime)
        {
            keyboardState = Keyboard.GetState();

            Entity        player;
            List <Entity> playerEntities = world.GetEntities(new[] { typeof(PlayerComponent) });

            if (playerEntities.Count == 0)
            {
                player = new Entity();
                PlayerComponent ppc = new PlayerComponent();
                player.AddComponent(ppc);
                player.AddComponent(new HasShieldComponent());
                player.AddComponent(new SpeedComponent(Vector2.Zero));
                player.AddComponent(new TakesDamageComponent(50, DamageSystem.ENEMY ^ DamageSystem.ENEMY_LASER ^ DamageSystem.METEOR));
                world.AddEntity(player);

                ppc.lives = ppc.maxLives;
            }
            else
            {
                player = playerEntities[0];
            }

            if (!player.HasComponent(typeof(RenderComponent)))
            {
                Game1.instance.kills = 0;

                PlayerComponent ppc = (PlayerComponent)player.components[typeof(PlayerComponent)];

                ppc.timeSinceRespawn = 0;
                ppc.laserLevel       = 0;

                //Remove shield upgrade on respawn
                //player.RemoveComponent(typeof(HasShieldComponent));

                TakesDamageComponent ptdc = (TakesDamageComponent)player.components[typeof(TakesDamageComponent)];
                ptdc.health = ptdc.maxHealth;

                RenderComponent prc = new RenderComponent(Game1.instance.shipTextures.ToArray());
                player.AddComponent(prc);
                if (!player.HasComponent(typeof(PositionComponent)))
                {
                    player.AddComponent(new PositionComponent(new Vector2(
                                                                  (world.screenRect.Width / 2) - (prc.CurrentTexture.Width / 2),
                                                                  (world.screenRect.Height / 3) * 2 + (prc.CurrentTexture.Height / 2)
                                                                  )));
                }
                else
                {
                    PositionComponent playerPositionComp = (PositionComponent)player.components[typeof(PositionComponent)];
                    playerPositionComp.position = new Vector2(
                        (world.screenRect.Width / 2) - (prc.CurrentTexture.Width / 2),
                        (world.screenRect.Height / 3) * 2 + (prc.CurrentTexture.Height / 2)
                        );
                }
            }

            PlayerComponent pc = (PlayerComponent)player.components[typeof(PlayerComponent)];
            SpeedComponent  sc = (SpeedComponent)player.components[typeof(SpeedComponent)];
            RenderComponent rc = (RenderComponent)player.components[typeof(RenderComponent)];

            if (pc.lives == 0)
            {
                Game1.instance.PopScreen();
                Game1.instance.PushScreen(new GameOverScreen());
                return;
            }

            sc.motion        = Vector2.Zero;
            pc.lastFireTime += gameTime.ElapsedGameTime.Milliseconds;

            if (player.HasComponent(typeof(HasShieldComponent)))
            {
                HasShieldComponent hasShieldComp = (HasShieldComponent)player.components[typeof(HasShieldComponent)];

                if (!player.HasComponent(typeof(ShieldedComponent)) && hasShieldComp.shieldPower < hasShieldComp.maxShieldPower)
                {
                    hasShieldComp.shieldPower += hasShieldComp.shieldRegenRate * gameTime.ElapsedGameTime.Milliseconds;
                }

                if (hasShieldComp.shieldPower >= hasShieldComp.maxShieldPower)
                {
                    hasShieldComp.shieldPower    = hasShieldComp.maxShieldPower;
                    hasShieldComp.shieldCooldown = false;
                }
                if (player.HasComponent(typeof(ShieldedComponent)))
                {
                    hasShieldComp.shieldPower -= hasShieldComp.shieldDepleteRate * gameTime.ElapsedGameTime.Milliseconds;

                    if (hasShieldComp.shieldPower <= 0)
                    {
                        player.RemoveComponent(typeof(ShieldedComponent));
                        hasShieldComp.shieldCooldown = true;
                        hasShieldComp.shieldPower    = 0;
                    }
                }

                if (!hasShieldComp.shieldCooldown)
                {
                    if (keyboardState.IsKeyDown(Keys.LeftShift) && hasShieldComp.shieldPower >= 0)
                    {
                        if (!player.HasComponent(typeof(ShieldedComponent)))
                        {
                            player.AddComponent(new ShieldedComponent());
                        }
                    }
                    else
                    {
                        player.RemoveComponent(typeof(ShieldedComponent));
                    }
                }
            }

            bool upgradedLasers = false;

            if (Game1.instance.kills > 10 && pc.laserLevel == 0)
            {
                pc.laserLevel  = 1;
                upgradedLasers = true;
            }
            if (Game1.instance.kills > 20 && pc.laserLevel == 1)
            {
                pc.laserLevel  = 2;
                upgradedLasers = true;
            }
            if (Game1.instance.kills > 40 && pc.laserLevel == 2)
            {
                pc.laserLevel  = 3;
                upgradedLasers = true;
            }

            if (upgradedLasers)
            {
                Entity e = new Entity();
                e.AddComponent(new NotificationComponent("Lasers Improved", 2000, true));
                world.AddEntity(e);
            }

            if (keyboardState.IsKeyDown(Keys.Space) && !player.HasComponent(typeof(ShieldedComponent)))
            {
                Shoot(player);
            }

            if (keyboardState.IsKeyDown(Keys.Left))
            {
                rc.currentTexture = 1;
                sc.motion.X       = -1;
            }
            if (keyboardState.IsKeyDown(Keys.Right))
            {
                rc.currentTexture = 2;
                sc.motion.X       = 1;
            }
            if (keyboardState.IsKeyDown(Keys.Up))
            {
                if (keyboardState.IsKeyUp(Keys.Left) && keyboardState.IsKeyUp(Keys.Right))
                {
                    rc.currentTexture = 0;
                }
                sc.motion.Y = -1;
            }
            if (keyboardState.IsKeyDown(Keys.Down))
            {
                if (keyboardState.IsKeyUp(Keys.Left) && keyboardState.IsKeyUp(Keys.Right))
                {
                    rc.currentTexture = 0;
                }
                sc.motion.Y = 1;
            }
            if (keyboardState.IsKeyUp(Keys.Left) && keyboardState.IsKeyUp(Keys.Right))
            {
                rc.currentTexture = 0;
            }

            sc.motion *= 5;
        }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            AggregateFactory = new AggregateFactory(this);
            WeaponFactory = new WeaponFactory(this);
            DoorFactory = new DoorFactory(this);
            RoomFactory = new RoomFactory(this);
            CollectableFactory = new CollectibleFactory(this);
            WallFactory = new WallFactory(this);
            EnemyFactory = new EnemyFactory(this);
            SkillEntityFactory = new SkillEntityFactory(this);
            NPCFactory = new NPCFactory(this);

            // Initialize Components
            PlayerComponent = new PlayerComponent();
            LocalComponent = new LocalComponent();
            RemoteComponent = new RemoteComponent();
            PositionComponent = new PositionComponent();
            MovementComponent = new MovementComponent();
            MovementSpriteComponent = new MovementSpriteComponent();
            SpriteComponent = new SpriteComponent();
            DoorComponent = new DoorComponent();
            RoomComponent = new RoomComponent();
            HUDSpriteComponent = new HUDSpriteComponent();
            HUDComponent = new HUDComponent();
            InventoryComponent = new InventoryComponent();
            InventorySpriteComponent = new InventorySpriteComponent();
            ContinueNewGameScreen = new ContinueNewGameScreen(graphics, this);
            EquipmentComponent = new EquipmentComponent();
            WeaponComponent = new WeaponComponent();
            BulletComponent = new BulletComponent();
            PlayerInfoComponent = new PlayerInfoComponent();
            WeaponSpriteComponent = new WeaponSpriteComponent();
            StatsComponent = new StatsComponent();
            EnemyAIComponent = new EnemyAIComponent();
            NpcAIComponent = new NpcAIComponent();

            CollectibleComponent = new CollectibleComponent();
            CollisionComponent = new CollisionComponent();
            TriggerComponent = new TriggerComponent();
            EnemyComponent = new EnemyComponent();
            NPCComponent = new NPCComponent();
            //QuestComponent = new QuestComponent();
            LevelManager = new LevelManager(this);
            SpriteAnimationComponent = new SpriteAnimationComponent();
            SkillProjectileComponent = new SkillProjectileComponent();
            SkillAoEComponent = new SkillAoEComponent();
            SkillDeployableComponent = new SkillDeployableComponent();
            SoundComponent = new SoundComponent();
            ActorTextComponent = new ActorTextComponent();
            TurretComponent = new TurretComponent();
            TrapComponent = new TrapComponent();
            ExplodingDroidComponent = new ExplodingDroidComponent();
            HealingStationComponent = new HealingStationComponent();
            PortableShieldComponent = new PortableShieldComponent();
            PortableStoreComponent = new PortableStoreComponent();
            ActiveSkillComponent = new ActiveSkillComponent();
            PlayerSkillInfoComponent = new PlayerSkillInfoComponent();

            Quests = new List<Quest>();

            #region Initialize Effect Components
            AgroDropComponent = new AgroDropComponent();
            AgroGainComponent = new AgroGainComponent();
            BuffComponent = new BuffComponent();
            ChanceToSucceedComponent = new ChanceToSucceedComponent();
            ChangeVisibilityComponent = new ChangeVisibilityComponent();
            CoolDownComponent = new CoolDownComponent();
            DamageOverTimeComponent = new DamageOverTimeComponent();
            DirectDamageComponent = new DirectDamageComponent();
            DirectHealComponent = new DirectHealComponent();
            FearComponent = new FearComponent();
            HealOverTimeComponent = new HealOverTimeComponent();
            InstantEffectComponent = new InstantEffectComponent();
            KnockBackComponent = new KnockBackComponent();
            TargetedKnockBackComponent = new TargetedKnockBackComponent();
            ReduceAgroRangeComponent = new ReduceAgroRangeComponent();
            ResurrectComponent = new ResurrectComponent();
            StunComponent = new StunComponent();
            TimedEffectComponent = new TimedEffectComponent();
            EnslaveComponent = new EnslaveComponent();
            CloakComponent = new CloakComponent();
            #endregion

            base.Initialize();
        }
Esempio n. 40
0
        //Run once each frame deltaTime is the amount of seconds since the last frame
        public override void Update(float deltaTime)
        {
            foreach (Entity e in getApplicableEntities())
            {
                //Don't apply gravity if the object is on top of something
                PositionComponent posComp1 = ( PositionComponent )e.getComponent(GlobalVars.POSITION_COMPONENT_NAME);
                ColliderComponent colComp1 = ( ColliderComponent )e.getComponent(GlobalVars.COLLIDER_COMPONENT_NAME);

                float sideBuffer  = -1;
                float floorBuffer = 1; //Distance it checks below object for the ground

                float e1X      = posComp1.x;
                float e1Y      = posComp1.y;
                float e1Width  = posComp1.width;
                float e1Height = posComp1.height;

                //If it has a collider, use its Width and Height instead.
                if (colComp1 != null)
                {
                    e1Width  = colComp1.width;
                    e1Height = colComp1.height;
                }

                if (e1Width != posComp1.width)
                {
                    float diff = (posComp1.width - e1Width);
                    e1X += diff / 2;
                }
                if (e1Height != posComp1.height)
                {
                    float diff = (posComp1.height - e1Height);
                    e1Y += diff / 2;
                }

                float leftX  = (e1X - e1Width / 2 - sideBuffer);
                float rightX = (e1X + e1Width / 2 + sideBuffer);
                float lowerY = (e1Y + e1Height / 2 + floorBuffer);
                //Console.WriteLine("Lower y: " + lowerY);
                //List<Entity> cols = level.getCollisionSystem().checkForCollision(e, posComp.x, lowerY, posComp.width, posComp.height);
                List <Entity> cols = level.getCollisionSystem().findObjectsBetweenPoints(leftX, lowerY, rightX, lowerY);

                bool shouldApplyGravity = true; //False if there's a solid object below

                foreach (Entity ent in cols)
                {
                    ColliderComponent colComp2 = ( ColliderComponent )ent.getComponent(GlobalVars.COLLIDER_COMPONENT_NAME);


                    //If the object is below e, and it's solid, don't apply gravity.
                    if (colComp2.colliderType == GlobalVars.BASIC_SOLID_COLLIDER_TYPE)
                    {
                        PositionComponent posComp2 = ( PositionComponent )ent.getComponent(GlobalVars.POSITION_COMPONENT_NAME);

                        //Separated out for easy changing.
                        float e2Y      = posComp2.y;
                        float e2Height = colComp2.height;

                        //Center width/height values
                        if (e2Height != posComp2.height)
                        {
                            float diff = (posComp2.height - e2Height);
                            e2Y += diff / 2;
                        }

                        float newY = e1Y - e2Height / 2 - e1Height / 2;

                        if (moveToContactWhenTouchGround && Math.Abs(e1Y - newY) > 0.1)
                        {
                            level.getMovementSystem().changePosition(posComp1, e1X, newY, false, true);
                        }

                        shouldApplyGravity = false;
                        break;
                    }
                }
                if (shouldApplyGravity)
                {
                    //Pull out all required components
                    VelocityComponent velComp  = ( VelocityComponent )e.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);
                    GravityComponent  gravComp = ( GravityComponent )e.getComponent(GlobalVars.GRAVITY_COMPONENT_NAME);

                    //Add the x and y gravity to their respective velocity components
                    velComp.incVelocity(gravComp.x * deltaTime, gravComp.y * deltaTime);

                    //Console.WriteLine("Gravity for " + e + " - X Vel : " + velComp.x + " - Y Vel - " + velComp.y);
                }
            }
        }