Example #1
0
        public void SpawnEgg()
        {
            const float SPAWN_DISTANCE = 10f;

            _eggSpawned = true;

            Vector2 direction = -1f * DirectionHelper.GetFacingFromDirection(_animDirection);

            if (_animDirection == AnimationDirection.Left ||
                _animDirection == AnimationDirection.Right)
            {
                direction.Y += (float)GameScreen.RandomNum.NextDouble() - 0.5f;
            }
            else if (_animDirection == AnimationDirection.Up ||
                     _animDirection == AnimationDirection.Down)
            {
                direction.X += (float)GameScreen.RandomNum.NextDouble() - 0.5f;
            }
            direction.Normalize();

            Vector2 spawn = Position + (SPAWN_DISTANCE * direction) + PHYSICS_OFFSET;

            EggEntity egg = GameScreen.AddEgg(spawn);

            egg.DynamicBody.ApplyLinearImpulse(direction);
        }
Example #2
0
        private void CleanupDeletedEntities()
        {
            if (QueuedForDisposal.Count > 0)
            {
                foreach (CharacterEntity entity in QueuedForDisposal)
                {
                    entity.DynamicBody.Enabled = false;
                    entity.DynamicBody.Dispose();
                    ActiveEntities.Remove(entity);

                    EnemyEntity enemy = entity as EnemyEntity;
                    if (enemy != null)
                    {
                        Enemies.Remove(enemy);
                    }
                    else
                    {
                        EggEntity egg = entity as EggEntity;
                        if (egg != null)
                        {
                            Eggs.Remove(egg);
                        }
                    }
                }
                QueuedForDisposal.Clear();
            }
        }
Example #3
0
        public EggEntity AddEgg(Vector2 pos)
        {
            _eggCounterCurrent++;

            EggEntity egg =
                new EggEntity(this, Clips["egg"], pos);

            egg.DynamicBody.LinearDamping = 5f;
            Eggs.Add(egg);
            QueuedForCreation.Add(egg);
            return(egg);
        }
Example #4
0
        private bool CollisionWithEgg(Fixture f1, Fixture f2,
                                      Contact contact, EggEntity egg)
        {
            if (CurrentState == State.BeingSuckedIn)
            {
                return(false);
            }

            HitEgg = true;
            egg.SwitchToDeathState();
            return(true);
        }
Example #5
0
        private bool CollisionHandler(Fixture f1, Fixture f2, Contact contact)
        {
            PlayerEntity player = f2.Body.UserData as PlayerEntity;
            EggEntity    egg    = f2.Body.UserData as EggEntity;

            if (player != null)
            {
                return(CollisionWithPlayer(f1, f2, contact, player));
            }
            else if (egg != null)
            {
                return(CollisionWithEgg(f1, f2, contact, egg));
            }
            return(true);
        }
Example #6
0
        public void DestroyEgg(EggEntity egg)
        {
            egg.IsValid = false;

            QueuedForDisposal.Add(egg);
        }
Example #7
0
        public EggEntity AddEgg(Vector2 pos)
        {
            _eggCounterCurrent++;

            EggEntity egg =
                new EggEntity(this, Clips["egg"], pos);
            egg.DynamicBody.LinearDamping = 5f;
            Eggs.Add(egg);
            QueuedForCreation.Add(egg);
            return egg;
        }
Example #8
0
        public void DestroyEgg(EggEntity egg)
        {
            egg.IsValid = false;

            QueuedForDisposal.Add(egg);
        }
Example #9
0
        private bool CollisionWithEgg(Fixture f1, Fixture f2,
            Contact contact, EggEntity egg)
        {
            if (CurrentState == State.BeingSuckedIn)
                return false;

            HitEgg = true;
            egg.SwitchToDeathState();
            return true;
        }