Ejemplo n.º 1
0
        public void OnGlobalPostUpdate()
        {
            BallSpawningData spawningData = GlobalEntity.Current <BallSpawningData>();

            // can we spawn?
            if (spawningData.Remaining <= 0)
            {
                // create a new ball
                IEntity spawned = spawningData.Ball.Instantiate();

                // it isn't necessary to set the position of the spawned object to zero, but it
                // demos how to initialize a newly created entity
                PositionData spawnedPosition = spawned.AddOrModify <PositionData>();
                spawnedPosition.Position = new Bound(0, 0, spawnedPosition.Position.Radius);

                // reset the ticks until the next spawn
                GlobalEntity.Modify <BallSpawningData>().Remaining =
                    GameRandom.Range(spawningData.MinTicks, spawningData.MaxTicks);
            }

            // can't spawn yet; decrement the number of ticks until we can spawn again
            else
            {
                GlobalEntity.Modify <BallSpawningData>().Remaining--;
            }
        }
Ejemplo n.º 2
0
        protected override void OnInitialize()
        {
            PositionData data = _entity.Current <PositionData>();

            float radius = data.Position.Radius.AsFloat * 2;

            transform.localScale = new Vector3(radius, radius, radius);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Moves an object to its next position according to its current velocity.
        /// </summary>
        private static void IntegratePosition(IEntity entity)
        {
            PositionData pos = entity.Current <PositionData>();
            MovementData mov = entity.Current <MovementData>();

            entity.Modify <PositionData>().Position = new Bound(
                pos.Position.X + mov.Velocity.X,
                pos.Position.Z + mov.Velocity.Z,
                pos.Position.Radius
                );
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Changes an objects velocity if it has left the map.
        /// </summary>
        private static void RespondToMapBounds(MapBoundsData mapBounds, IEntity entity)
        {
            PositionData pos = entity.Current <PositionData>();
            MovementData mov = entity.Current <MovementData>();

            if (((pos.Position.Z - pos.Position.Radius) < -mapBounds.Height && mov.Velocity.Z < 0) ||
                ((pos.Position.Z + pos.Position.Radius) > mapBounds.Height && mov.Velocity.Z > 0))
            {
                entity.Modify <MovementData>().MultVelocity(1, -1);
            }
            if (((pos.Position.X - pos.Position.Radius) < -mapBounds.Width && mov.Velocity.X < 0) ||
                ((pos.Position.X + pos.Position.Radius) > mapBounds.Width && mov.Velocity.X > 0))
            {
                entity.Modify <MovementData>().MultVelocity(-1, 1);
            }
        }