Example #1
0
        public virtual void DestroyEntity(Entity entity) {
            var removed = _entities.Remove(entity);
            if (!removed) {
                throw new PoolDoesNotContainEntityException(entity,
                    "Could not destroy entity!");
            }
            _entitiesCache = null;

            if (OnEntityWillBeDestroyed != null) {
                OnEntityWillBeDestroyed(this, entity);
            }

            entity.destroy();

            if (OnEntityDestroyed != null) {
                OnEntityDestroyed(this, entity);
            }

            if (entity._refCount == 1) {
                entity.OnEntityReleased -= _cachedOnEntityReleased;
                _reusableEntities.Push(entity);
            } else {
                _retainedEntities.Add(entity);
            }
            entity.Release();
        }
 //Its possible that we create a bullet and say 'destroy yourself in 4 seconds' and then the bullet collides and we say destroy yourself now,
 //then the 4 seconds expires and it tries to delete itself again.
 //So this 'if' solves that - srivello
 private void DestroyEntity(Entity entity)
 {
     if (_pool.HasEntity(entity))
     {
         _pool.DestroyEntity(entity);
     }
     else
     {
         entity.destroy();
     }
 }
        public override void process(Entity entity)
        {
            // Grab the component from the entity
            var healthComponent = entity.getComponent <HealthComponent>();

            // Tick down the health
            healthComponent.health--;

            // Destory the entity once it runs out of health
            if (healthComponent.health <= 0)
            {
                entity.destroy();
            }
        }
Example #4
0
        private void UpdateUIText()
        {
            if (_healthEntity != null)
            {
                _healthEntity.destroy();
            }
            var healthText = new Text(Graphics.instance.bitmapFont, _player.Health.ToString(), new Vector2(45, 7), Color.White);
            var dropText   = new Text(Graphics.instance.bitmapFont, "Buttons: " + _player.DropCount.ToString(), new Vector2(6, 18), Color.White);

            _healthEntity = createEntity("healthText");
            healthText.setRenderLayer(SCREEN_SPACE_RENDER_LAYER);
            dropText.setRenderLayer(SCREEN_SPACE_RENDER_LAYER);
            _healthEntity.addComponent(healthText);
            _healthEntity.addComponent(dropText);
        }
Example #5
0
        private IEnumerator <object> damageNumEntityThrowUp(Entity entity)
        {
            float timer = 0f;

            while (true)
            {
                timer += Time.deltaTime;
                if (timer > 0.5f)
                {
                    entity.destroy();
                    yield break;
                }
                entity.position -= new Vector2(0, 1);
                yield return(null);
            }
        }
        public override void process(Entity entity)
        {
            UpgradeComponent upgrade        = entity.getComponent <UpgradeComponent>();
            Collider         entityCollider = entity.getComponent <Collider>();
            var colliders = Physics.boxcastBroadphase(entityCollider.bounds, 1 << 1);

            foreach (var collider in colliders)
            {
                var upgrades = collider.getComponent <PlayerUpgradesComponent>();
                if (upgrades != null)
                {
                    upgrades.AddUpgrade(upgrade.Upgrade);
                    entity.destroy();
                    break;
                }
            }
        }
        public override void process()
        {
            if (!_enabled || _player == null)
            {
                return;
            }
            CollisionResult collisionResult;

            if (_key.getComponent <BoxCollider>()
                .collidesWith(_player.getComponent <BoxCollider>(), out collisionResult))
            {
                AudioManager.key.Play(1.0f);
                _player.getComponent <PlayerComponent>().isWithKey = true;
                _key.destroy();
                _enabled = false;
            }
        }
Example #8
0
        private void initBoss()
        {
            if ((GameEvent.homeEvent & GameHomeEvent.killShuChengCaveBoss) == 0)
            {
                var objectLayer = tiledMap.getObjectGroup("Object");
                var bossArea    = objectLayer.objectWithName("bossArea");
                var boss        = objectLayer.objectWithName("boss");

                var bigSlime = addEntity(new BigSlime());
                bigSlime.setPosition(boss.position);

                bossAreaCollider = createEntity("collision");
                Vertices verts = new Vertices(bossArea.polyPoints);
                bossAreaCollider
                .addComponent <FSRigidBody>()
                .setBodyType(BodyType.Static)
                .addComponent <FSCollisionChain>()
                .setVertices(verts)
                .setCollisionCategories(CollisionSetting.wallCategory);

                bigSlime.onDeathed += () =>
                {
                    GameEvent.homeEvent = GameEvent.homeEvent | GameHomeEvent.killShuChengCaveBoss;
                    bossAreaCollider.destroy();
                    var box = addEntity(new TreasureBox());
                    box.setPosition(boss.position);
                    box.openBox += () =>
                    {
                        player.recipes.Add(new Recipe.BombRecipe());
                        player.pickUp(new BombComponent(), 5);

                        var uiManager = Core.getGlobalManager <GameUIManager>();
                        //uiManager.createConfirmUI("获得炸弹和炸弹制作书");

                        IList <Conmunication> conmunications = new List <Conmunication>();
                        conmunications.Add(new Conmunication("Images/headIcons/Link_Sprite", "终于获得了炸弹"));
                        conmunications.Add(new Conmunication("Images/headIcons/Link_Sprite", "可以利用炸弹将地图上一些挡路的东西炸开了"));
                        conmunications.Add(new Conmunication("Images/headIcons/Link_Sprite", "而且我还在宝箱中找到了炸弹的制作书,这样子炸弹用完了可以摁Q在制作界面制作炸弹了"));
                        uiManager.createConmunication(conmunications);
                    };
                };
            }
        }
        public override void update()
        {
            if (IntroTimer.GetFinished())
            {
                TimeSystem.update();

                if (IntroCard != null)
                {
                    IntroCard.destroy();
                    IntroCard = null;
                }
            }

            base.update();

            ItemPickupSystem.Update();
            HUDPositionSystem.Update();
            BurningSystem.Update();
            MoneySystem.Update();
        }
Example #10
0
        public override void process(Entity loadEntity)
        {
            var load = loadEntity.getComponent <ConnectionLoad>();

            loadEntity.removeComponent <ConnectionLoad>();
            loadEntity.destroy();

            var distance   = Vector2.Distance(load.Start, load.End);
            var difference = load.End - load.Start;
            var theta      = (float)Math.Atan2(difference.Y, difference.X);

            for (int i = 0; i < distance; i += line.Width)
            {
                float t          = i / distance;
                float x          = load.Start.X + difference.X * t;
                float y          = load.Start.Y + difference.Y * t;
                var   lineEntity = scene.createEntity("connectionLine");
                lineEntity.position = new Vector2(x, y);
                lineEntity.rotation = theta;
                var sprite = new Sprite(line);
                lineEntity.addComponent(sprite.setRenderLayer(1));
            }
        }
Example #11
0
        protected override void lateProcess(List <Entity> entities)
        {
            if (!_enabled || _player == null)
            {
                return;
            }

            CollisionResult collisionResult;

            if (_door.getComponent <BoxCollider>()
                .collidesWith(_player.getComponent <BoxCollider>(), out collisionResult))
            {
                var playerComponent = _player.getComponent <PlayerComponent>();
                if (playerComponent.isWithKey)
                {
                    AudioManager.door.Play(1.0f);
                    playerComponent.isWithKey = false;
                    _door.destroy();
                    _enabled = false;
                    return;
                }
                _player.transform.position += collisionResult.minimumTranslationVector;
            }
        }
Example #12
0
        private void UpdateTileMap(Vector2 newPos, bool left)
        {
            //only load if actually new room and not just new part of old room
            if (_prevTileMapName != _world.activeRoom.tilemap)
            {
                if (_snowRenderer != null)
                {
                    removeRenderer(_snowRenderer);
                }

                if (_world.activeRoom.IsSnowing)
                {
                    _snowRenderer = addRenderer(new ScreenSpaceRenderer(99, 998));
                }

                if (_world.activeRoom.IsDark)
                {
                    _spriteLightPostProcessor.enabled = true;
                }
                else
                {
                    _spriteLightPostProcessor.enabled = false;
                }

                if (_tiledEntity != null)
                {
                    // transitions within the current Scene with a SquaresTransition
                    //var transition = new SquaresTransition();
                    //transition.onScreenObscured = ClearScene();
                    //Core.startSceneTransition(transition);
                    _tiledEntity.destroy();
                    ClearScene();
                }
                _tiledEntity = createEntity("tiled");
                var tiledmap = contentManager.Load <TiledMap>(_world.activeRoom.tilemap);

                _tiledEntity.transform.setScale(3f);

                try
                {
                    var shrooms = tiledmap.objectGroups[0].objectsWithName("shroom");
                    for (var i = 0; i < shrooms.Count; i++)
                    {
                        CreateShroom(new Vector2(shrooms[i].x, shrooms[i].y - 8));
                    }
                }
                catch
                {
                }

                try
                {
                    var fire = tiledmap.objectGroups[0].objectsWithName("fire");
                    for (var i = 0; i < fire.Count; i++)
                    {
                        CreateFire(new Vector2(fire[i].x, fire[i].y - 8));
                    }
                }
                catch
                {
                }

                var tiledMapComponent = _tiledEntity.addComponent(new TiledMapComponent(tiledmap, "collision"));
                tiledMapComponent.setLayersToRender(new string[] { "collision" });
                tiledMapComponent.renderLayer  = 10;
                tiledMapComponent.physicsLayer = 10;

                //fix me ;-;

                try
                {
                    var spikeComponent = _tiledEntity.addComponent(new TiledMapComponent(tiledmap, "spike"));
                    spikeComponent.renderLayer  = 1;
                    spikeComponent.physicsLayer = 501;
                    spikeComponent.setLayersToRender("spike");
                }
                catch
                {
                }

                try
                {
                    var ladderComponent = _tiledEntity.addComponent(new TiledMapComponent(tiledmap, "ladder"));
                    ladderComponent.renderLayer  = 1;
                    ladderComponent.physicsLayer = 500;
                    ladderComponent.setLayersToRender("ladder");
                    //ladderComponent.collisionLayer = null;
                }
                catch {
                }

                try
                {
                    var accentComponent = _tiledEntity.addComponent(new TiledMapComponent(tiledmap, "accent"));
                    accentComponent.renderLayer    = 0;
                    accentComponent.collisionLayer = null;
                    accentComponent.setLayersToRender("accent");
                }
                catch
                {
                }

                try
                {
                    var bgComponent = _tiledEntity.addComponent(new TiledMapComponent(tiledmap, "bg"));
                    bgComponent.setLayersToRender("bg");
                    bgComponent.renderLayer    = 1000;
                    bgComponent.collisionLayer = null;
                }
                catch
                {
                }

                try
                {
                    var waterComponent = _tiledEntity.addComponent(new TiledMapComponent(tiledmap, "water"));
                    waterComponent.setLayersToRender("water");
                    waterComponent.renderLayer    = 1000;
                    waterComponent.collisionLayer = null;
                }
                catch
                {
                }

                _tiledEntity.addComponent(new CameraBounds(new Vector2(0, 0), new Vector2(16 * (tiledmap.width), 16 * (tiledmap.height))));
                _width           = tiledmap.width * 16;
                _height          = tiledmap.height * 16;
                _prevTileMapName = _world.activeRoom.tilemap;
                _tileCollLayer   = tiledMapComponent.collisionLayer;
                //if left make sure we set pos to new width
                if (left)
                {
                    newPos.X = _width - 16;
                }
                playerEntity.transform.position = newPos;
                if (true)
                {
                    SpawnEnemies();
                }
            }
        }
 public override void onRemovedFromEntity()
 {
     xAxis.destroy();
     yAxis.destroy();
 }
Example #14
0
        public virtual void DestroyEntity(Entity entity)
        {
            var removed = _entities.Remove(entity);
            if(!removed) {
                throw new ContextDoesNotContainEntityException(
                    "'" + this + "' cannot destroy " + entity + "!",
                    "Did you call context.DestroyEntity() on a wrong context?"
                );
            }
            _entitiesCache = null;

            if(OnEntityWillBeDestroyed != null) {
                OnEntityWillBeDestroyed(this, entity);
            }

            entity.destroy();

            if(OnEntityDestroyed != null) {
                OnEntityDestroyed(this, entity);
            }

            if(entity.retainCount == 1) {
                // Can be released immediately without
                // adding to _retainedEntities
                entity.OnEntityReleased -= _cachedEntityReleased;
                _reusableEntities.Push(entity);
                entity.Release(this);
                entity.removeAllOnEntityReleasedHandlers();
            } else {
                _retainedEntities.Add(entity);
                entity.Release(this);
            }
        }
Example #15
0
 public void destoryedByKey()
 {
     colliderEntity.destroy();
     this.destroy();
 }
Example #16
0
        public override void onAddedToScene()
        {
            base.onAddedToScene();

            var texture       = scene.content.Load <Texture2D>("TileMaps/MapTextures/objects");
            var texturePacker = TexturePackerAtlas.create(texture, 32, 32);

            animationTexture[0] = texturePacker.createRegion("1", 64, 96, 32, 32);
            animationTexture[1] = texturePacker.createRegion("2", 96, 96, 32, 32);
            animationTexture[2] = texturePacker.createRegion("3", 128, 96, 32, 32);
            animationTexture[3] = texturePacker.createRegion("4", 160, 96, 32, 32);

            animation = addComponent(new Sprite <BottleAnimation>(animationTexture[0]));
            animation.setLayerDepth(LayerDepthExt.caluelateLayerDepth(this.position.Y));

            animation.addAnimation(BottleAnimation.Idle, new SpriteAnimation(animationTexture[0]));
            var spriteAnimation = new SpriteAnimation(new List <Subtexture>()
            {
                animationTexture[0],
                animationTexture[1],
                animationTexture[2],
                animationTexture[3],
            });

            spriteAnimation.loop = false;
            animation.addAnimation(BottleAnimation.Broke, spriteAnimation);
            animation.onAnimationCompletedEvent += Animation_onAnimationCompletedEvent;

            animation.currentAnimation = BottleAnimation.Idle;
            animation.play(BottleAnimation.Idle);

            var rigidBody = addComponent <FSRigidBody>()
                            .setBodyType(FarseerPhysics.Dynamics.BodyType.Dynamic);

            var shape = addComponent <SceneObjectTriggerComponent>();

            shape.setRadius(5)
            ;

            shape.setCollisionCategories(CollisionSetting.tiledObjectCategory);
            shape.setCollidesWith(CollisionSetting.allAttackCategory | CollisionSetting.allAttackTypeCategory);

            shape.onAdded = onAddedMethod;

            colliderEntity = scene.createEntity("collision");
            colliderEntity.setPosition(this.position);
            colliderEntity.addComponent <FSRigidBody>()
            .setBodyType(BodyType.Static);

            var colliderShape = colliderEntity.addComponent <FSCollisionCircle>();

            colliderShape.setRadius(4);
            colliderShape.setCollisionCategories(CollisionSetting.wallCategory);

            triggerEvent = () =>
            {
                if (!colliderEntity.isDestroyed)
                {
                    colliderEntity.destroy();
                }
            };
        }
Example #17
0
        public virtual void DestroyEntity(Entity entity) {
            var removed = _entities.Remove(entity);
            if (!removed) {
                throw new PoolDoesNotContainEntityException("'" + this + "' cannot destroy " + entity + "!",
                    "Did you call pool.DestroyEntity() on a wrong pool?");
            }
            _entitiesCache = null;

            if (OnEntityWillBeDestroyed != null) {
                OnEntityWillBeDestroyed(this, entity);
            }

            entity.destroy();

            if (OnEntityDestroyed != null) {
                OnEntityDestroyed(this, entity);
            }

            if (entity.retainCount == 1) {
                entity.OnEntityReleased -= _cachedOnEntityReleased;
                _reusableEntities.Push(entity);
            } else {
                _retainedEntities.Add(entity);
            }
            entity.Release(this);
        }
Example #18
0
 // We want to destroy last so that we don't break things.
 public override void lateProcess(Entity entity)
 {
     entity.destroy();
 }