protected override void OnInitialize()
        {
            MapBoundsData data = _entity.Current <MapBoundsData>();

            transform.localScale = new Vector3(data.Width * 2, 1, data.Height * 2);
            transform.position   = new Vector3(0, -2, 0);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
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);
            }
        }
Esempio 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);
            }
        }