コード例 #1
0
        protected override void afterLoadBody(string name, Body body, CustomProperties customProperties, XElement bodyData)
        {
            bool activatesObstacle = false;
            bool fallOnActivate = false;
            bool ignoreCeilingCollision = false;
            bool isDestructibleObstacle = false;
            int entityId = EntityFactory.afterLoadBody(name, body, customProperties, bodyData);

            customProperties.tryGetBool("activatesObstacle", out activatesObstacle);
            customProperties.tryGetBool("fallOnActivate", out fallOnActivate);
            customProperties.tryGetBool("ignoreCeilingCollision", out ignoreCeilingCollision);
            customProperties.tryGetBool("isDestructibleObstacle", out isDestructibleObstacle);

            // ActivatesObstacle components
            if (activatesObstacle)
            {
                _bodyThatSendsActivateObstacle = body;
            }

            // Fall on activate
            if (fallOnActivate)
            {
                _bodiesThatReceiveActivateObstacleFall.Add(body);
            }

            // Ignore ceiling collision
            if (ignoreCeilingCollision)
            {
                // TODO -- Do something tons of fun.
            }

            base.afterLoadBody(name, body, customProperties, bodyData);
        }
コード例 #2
0
ファイル: EntityFactory.cs プロジェクト: klutch/Loderpit
        // afterLoadBody -- Called from terrain module loader
        public static int afterLoadBody(string name, Body body, CustomProperties customProperties, XElement bodyData)
        {
            bool activatesObstacle = false;
            bool ignoresRopeRaycast = false;
            bool ignoresBridgeRaycast = false;
            bool isDestructibleObstacle = false;
            bool isGround = false;
            bool isCeiling = false;
            bool isLevelEnd = false;
            int entityId = EntityManager.createEntity();

            body.UserData = entityId;

            customProperties.tryGetBool("isGround", out isGround);
            customProperties.tryGetBool("isDestructibleObstacle", out isDestructibleObstacle);
            customProperties.tryGetBool("activatesObstacle", out activatesObstacle);
            customProperties.tryGetBool("ignoresRopeRaycast", out ignoresRopeRaycast);
            customProperties.tryGetBool("ignoresBridgeRaycast", out ignoresBridgeRaycast);
            customProperties.tryGetBool("isCeiling", out isCeiling);
            customProperties.tryGetBool("isLevelEnd", out isLevelEnd);

            EntityManager.addComponent(entityId, new PositionComponent(entityId, body));

            // GroundBody component
            if (isGround)
            {
                body.CollisionCategories = (ushort)CollisionCategory.Terrain;
                EntityManager.addComponent(entityId, new GroundBodyComponent(entityId, body));
                EntityManager.addComponent(entityId, createColorPrimitiveRenderComponent(entityId, body, new Color(130, 130, 130, 255)));
            }

            // Ceiling component
            if (isCeiling)
            {
                body.CollisionCategories = (ushort)CollisionCategory.Terrain;
                EntityManager.addComponent(entityId, new CeilingComponent(entityId, body));
                EntityManager.addComponent(entityId, createColorPrimitiveRenderComponent(entityId, body, new Color(130, 130, 130, 255)));
            }

            // DestructibleObstacle (with Vitals) components
            if (isDestructibleObstacle)
            {
                EntityManager.addComponent(entityId, new DestructibleObstacleComponent(entityId, body, new List<Faction>(new [] { Faction.Enemy, Faction.Player })));
                EntityManager.addComponent(entityId, new StatsComponent(entityId, 10, 10, 0, 0, 0, 100));
                EntityManager.addComponent(entityId, new FactionComponent(entityId, Faction.Neutral, Faction.None));
                EntityManager.addComponent(entityId, new AffectedBySpellEntitiesComponent(entityId));
                EntityManager.addComponent(entityId, createColorPrimitiveRenderComponent(entityId, body, Color.Red));
            }

            // IgnoresRopeRaycast and IgnoresBridgeRaycast components
            if (ignoresRopeRaycast)
            {
                EntityManager.addComponent(entityId, new IgnoreRopeRaycastComponent(entityId));
            }
            if (ignoresBridgeRaycast)
            {
                EntityManager.addComponent(entityId, new IgnoreBridgeRaycastComponent(entityId));
            }

            // Level end
            if (isLevelEnd)
            {
                body.CollidesWith = (ushort)CollisionCategory.Characters;
                body.OnCollision += new OnCollisionEventHandler(levelEndOnCollision);
                body.OnSeparation += new OnSeparationEventHandler(levelEndOnSeparation);
            }

            return entityId;
        }
コード例 #3
0
        protected override void beforeLoadBodies(World world, CustomProperties customWorldProperties)
        {
            int moduleEndPointsCount = _map.moduleEndPointsCount;
            Vector2 size = _map.moduleEndPoints[moduleEndPointsCount - 1] - _map.moduleEndPoints[moduleEndPointsCount - 2];
            Vector2 randomFactor = new Vector2(Helpers.randomBetween(_rng, 0f, 1f), Helpers.randomBetween(_rng, 0f, 1f));
            bool attachToCeiling = false;

            _offset = _map.moduleEndPoints[_map.moduleEndPoints.Count - 2] + size * randomFactor;

            if (customWorldProperties.tryGetBool("attachToCeiling", out attachToCeiling) && attachToCeiling)
            {
                Vector2 point = Vector2.Zero;

                // Raycast for a ceiling using the random position
                world.RayCast(
                    (f, p, n, fr) =>
                        {
                            if (f.Body.UserData == null)
                            {
                                return -1;
                            }

                            if (EntityManager.getCeilingComponent((int)f.Body.UserData) != null)
                            {
                                _offset = p;
                                return fr;
                            }
                            else
                            {
                                return -1;
                            }
                        },
                    _offset + new Vector2(0f, 1000f),
                    _offset + new Vector2(0f, -1000f));
            }

            base.beforeLoadBodies(world, customWorldProperties);
        }