Exemple #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--;
            }
        }
        /// <summary>
        /// Every update, we want to ensure that objects are inside the map and we also want to move
        /// the object according to its velocity.
        /// </summary>
        public void OnUpdate(IEntity entity)
        {
            MapBoundsData mapBounds = GlobalEntity.Current <MapBoundsData>();

            RespondToMapBounds(mapBounds, entity);
            IntegratePosition(entity);
        }