예제 #1
0
        // explodeDynamite -- Creates an explosion entity and kills the dynamite entity
        public void explodeDynamite(string levelUid, int entityId, DynamiteComponent dynamiteComponent)
        {
            //WorldPositionComponent worldPositionComponent = (WorldPositionComponent)_entityManager.getComponent(entityId, ComponentType.WorldPosition);
            PhysicsComponent physicsComponent = _entityManager.getComponent(levelUid, entityId, ComponentType.Physics) as PhysicsComponent;
            Vector2          position         = physicsComponent.body.Position;

            physicsComponent.body.World.RemoveBody(physicsComponent.body);
            _entityManager.killEntity(levelUid, entityId);
            _entityManager.factory.createExplosion(levelUid, position, dynamiteComponent.strength, dynamiteComponent.radius);
        }
예제 #2
0
        // explodeDynamite -- Creates an explosion entity and kills the dynamite entity
        public void explodeDynamite(string levelUid, int entityId, DynamiteComponent dynamiteComponent)
        {
            //WorldPositionComponent worldPositionComponent = (WorldPositionComponent)_entityManager.getComponent(entityId, ComponentType.WorldPosition);
            PhysicsComponent physicsComponent = _entityManager.getComponent(levelUid, entityId, ComponentType.Physics) as PhysicsComponent;
            Vector2 position = physicsComponent.body.Position;

            physicsComponent.body.World.RemoveBody(physicsComponent.body);
            _entityManager.killEntity(levelUid, entityId);
            _entityManager.factory.createExplosion(levelUid, position, dynamiteComponent.strength, dynamiteComponent.radius);
        }
예제 #3
0
        public void update(GameTime gameTime)
        {
            if (!_paused || _singleStep)
            {
                LevelSystem levelSystem = _systemManager.getSystem(SystemType.Level) as LevelSystem;

                if (levelSystem.finalized)
                {
                    string     levelUid          = LevelSystem.currentLevelUid;
                    List <int> dynamiteEntities  = _entityManager.getEntitiesPosessing(levelUid, ComponentType.Dynamite);
                    List <int> explosionEntities = _entityManager.getEntitiesPosessing(levelUid, ComponentType.Explosion);
                    List <int> debrisEntities    = _entityManager.getEntitiesPosessing(levelUid, ComponentType.Debris);

                    // Dynamite entities
                    for (int i = 0; i < dynamiteEntities.Count; i++)
                    {
                        DynamiteComponent dynamiteComponent = (DynamiteComponent)_entityManager.getComponent(levelUid, dynamiteEntities[i], ComponentType.Dynamite);

                        if (dynamiteComponent.timeToLive > 0)
                        {
                            dynamiteComponent.timeToLive--;
                        }
                        else
                        {
                            explodeDynamite(levelUid, dynamiteEntities[i], dynamiteComponent);
                        }
                    }

                    // Explosion entities -- Explosion contact logic is handled by the PhysicsSystem's contact listeners. This just removes them, since they only should exist for 1 frame
                    for (int i = 0; i < explosionEntities.Count; i++)
                    {
                        PhysicsComponent physicsComponent = (PhysicsComponent)_entityManager.getComponent(levelUid, explosionEntities[i], ComponentType.Physics);

                        physicsComponent.body.World.RemoveBody(physicsComponent.body);
                        _entityManager.killEntity(levelUid, explosionEntities[i]);
                    }

                    // Break fixtures and create debris
                    for (int i = 0; i < _debrisToCreate.Count; i++)
                    {
                        Fixture fixture = _debrisToCreate[i].fixture;

                        if (fixture.Shape != null)
                        {
                            int entityId = (int)fixture.Body.UserData;
                            PrimitivesRenderComponent primitiveRenderComponent = (PrimitivesRenderComponent)_entityManager.getComponent(levelUid, entityId, ComponentType.PrimitivesRender);
                            PrimitiveRenderObject     primitiveRenderObject    = primitiveRenderComponent.primitiveRenderObjects[0];
                            RenderableTriangle        triangleToRemove         = null;

                            for (int j = 0; j < primitiveRenderObject.renderableTriangles.Count; j++)
                            {
                                if (primitiveRenderObject.renderableTriangles[j].fixture == fixture)
                                {
                                    triangleToRemove = primitiveRenderObject.renderableTriangles[j];
                                    break;
                                }
                            }
                            if (triangleToRemove != null)
                            {
                                primitiveRenderObject.renderableTriangles.Remove(triangleToRemove);
                            }

                            _entityManager.factory.createDebris(levelUid, fixture, _debrisToCreate[i].force, _debrisToCreate[i].timeToLive, triangleToRemove, primitiveRenderObject.texture, primitiveRenderObject.layerDepth);
                            fixture.Body.DestroyFixture(fixture);
                        }
                    }
                    _debrisToCreate.Clear();

                    // Debris
                    for (int i = 0; i < debrisEntities.Count; i++)
                    {
                        DebrisComponent debrisComponent = (DebrisComponent)_entityManager.getComponent(levelUid, debrisEntities[i], ComponentType.Debris);
                        debrisComponent.timeToLive--;

                        if (debrisComponent.restitutionCount < DebrisComponent.RESTITUTION_RESTORE_COUNT)
                        {
                            debrisComponent.fixture.Restitution = debrisComponent.fixture.Restitution + debrisComponent.restitutionIncrement;
                        }

                        if (debrisComponent.timeToLive < 0)
                        {
                            killDebris(levelUid, debrisEntities[i]);
                        }
                    }
                }
            }
            _singleStep = false;
        }