Beispiel #1
0
        public override void UpdateLogic(LandWorld world, IEntity owner, Time deltaTime)
        {
            this.UpdateDesiredPosition(world, owner);

            if (world.EntityManager.IsBookingStillValid(owner) == false)
            {
                switch (this.MovingState)
                {
                case MovingState.MOVE_UP:
                    this.MovingState = MovingState.IDLE_UP;
                    break;

                case MovingState.MOVE_DOWN:
                    this.MovingState = MovingState.IDLE_DOWN;
                    break;

                case MovingState.MOVE_RIGHT:
                    this.MovingState = MovingState.IDLE_RIGHT;
                    break;

                case MovingState.MOVE_LEFT:
                    this.MovingState = MovingState.IDLE_LEFT;
                    break;
                }

                if (owner.OffsetPosition.X != 0 || owner.OffsetPosition.X != 0 || owner.OffsetAltitude != 0)
                {
                    owner.SetOffsetPosition(0, 0, 0);
                }
            }
        }
Beispiel #2
0
        public override void UpdateLogic(LandWorld world, IEntity owner, Time deltaTime)
        {
            if (world.EntityManager.IsBookingStillValid(owner) == false)
            {
                WalkKinematicAbility walkKinematicAbility = owner.GetAbilityById("kinematic.walk") as WalkKinematicAbility;

                if (Keyboard.IsKeyPressed(Keyboard.Key.Z))
                {
                    walkKinematicAbility.SetSteering(world, owner, MovingDirection.ABOVE);
                }
                else if (Keyboard.IsKeyPressed(Keyboard.Key.S))
                {
                    walkKinematicAbility.SetSteering(world, owner, MovingDirection.UNDER);
                }

                if (Keyboard.IsKeyPressed(Keyboard.Key.D))
                {
                    walkKinematicAbility.SetSteering(world, owner, MovingDirection.RIGHT);
                }
                else if (Keyboard.IsKeyPressed(Keyboard.Key.Q))
                {
                    walkKinematicAbility.SetSteering(world, owner, MovingDirection.LEFT);
                }
            }
        }
Beispiel #3
0
        protected virtual bool IsPositionValid(LandWorld world, IEntity entity, Vector2i position, int altitude)
        {
            LifeAbility lifeAbility = entity.GetAbilityById("life") as LifeAbility;

            if (lifeAbility != null && lifeAbility.CurrentHP <= 0)
            {
                return(false);
            }

            if (entity.Position.Equals(position) && entity.Altitude == altitude)
            {
                return(false);
            }

            if (world.EntityManager.IsBookingStillValid(entity))
            {
                return(false);
            }

            if (world.EntityManager.GetEntitiesInCase(position.X, position.Y, altitude).Any())
            {
                return(false);
            }

            return(true);
        }
Beispiel #4
0
        public virtual bool SetSteering(LandWorld world, IEntity entity, Vector2i desiredPosition, int altitude)
        {
            this.DesiredPosition = desiredPosition;
            this.DesiredAltitude = altitude;
            this.TryToReach      = true;

            return(true);
        }
Beispiel #5
0
        public void Dispose(LandWorld landWorld)
        {
            landWorld.EntityManager.EntityAdded   -= this.entity2DManager.OnEntityAdded;
            landWorld.EntityManager.EntityRemoved -= this.entity2DManager.OnEntityRemoved;

            landWorld.ChunkAdded   -= OnChunkAdded;
            landWorld.ChunkRemoved -= OnChunkRemoved;
        }
Beispiel #6
0
 public void UpdateLogic(LandWorld world, Time deltaTime)
 {
     foreach (KeyValuePair <IEntity, ILandChunk> entries in this.entitiesToChunks)
     {
         if (world.IsChunkActive(entries.Value.Area))
         {
             entries.Key.UpdateLogic(world, deltaTime);
         }
     }
 }
Beispiel #7
0
        protected virtual bool BookPosition(LandWorld world, IEntity entity, Vector2i position, int altitude)
        {
            if (this.IsPositionValid(world, entity, position, altitude))
            {
                if (world.EntityManager.BookPositionForEntity(world, entity, position.X, position.Y, altitude))
                {
                    if (position.X != entity.Position.X &&
                        (position.Y == entity.Position.Y && altitude == entity.Altitude))
                    {
                        if (position.X > entity.Position.X)
                        {
                            this.MovingState = MovingState.MOVE_DOWN;
                        }
                        else
                        {
                            this.MovingState = MovingState.MOVE_UP;
                        }
                    }
                    else if (position.Y != entity.Position.Y &&
                             (position.X == entity.Position.X && altitude == entity.Altitude))
                    {
                        if (position.Y > entity.Position.Y)
                        {
                            this.MovingState = MovingState.MOVE_RIGHT;
                        }
                        else
                        {
                            this.MovingState = MovingState.MOVE_LEFT;
                        }
                    }
                    else if (altitude != entity.Altitude &&
                             (position.X == entity.Position.X && position.Y == entity.Position.Y))
                    {
                        if (altitude > entity.Altitude)
                        {
                            this.MovingState = MovingState.ABOVE;
                        }
                        else
                        {
                            this.MovingState = MovingState.UNDER;
                        }
                    }
                    else
                    {
                        this.MovingState = MovingState.TELEPORT;
                    }

                    this.elapsedMovingTime = 0;

                    return(true);
                }
            }
            return(false);
        }
Beispiel #8
0
        public void UpdateLogic(LandWorld world, Time deltaTime)
        {
            foreach (IAbility ability in this.idToAbilities.Values)
            {
                ability.UpdateLogic(world, this, deltaTime);
            }

            foreach (IBehavior behavior in this.idToBehaviors.Values)
            {
                behavior.UpdateLogic(world, this, deltaTime);
            }
        }
Beispiel #9
0
        public LandWorld2D(LandWorld landWorld)
        {
            this.landChunksDictionary = new Dictionary <ILandChunk, LandChunk2D>();

            this.chunkResourcesLoader = new ChunkResourcesLoader();

            this.entity2DManager = new Entity2DManager(this);
            landWorld.EntityManager.EntityAdded   += this.entity2DManager.OnEntityAdded;
            landWorld.EntityManager.EntityRemoved += this.entity2DManager.OnEntityRemoved;

            this.currentAltitude = 0;

            landWorld.ChunkAdded   += OnChunkAdded;
            landWorld.ChunkRemoved += OnChunkRemoved;
        }
Beispiel #10
0
        public override void UpdateLogic(LandWorld world, IEntity owner, Time deltaTime)
        {
            base.UpdateLogic(world, owner, deltaTime);

            if (world.EntityManager.IsBookingStillValid(owner))
            {
                BookingEntity bookEntity = world.EntityManager.GetBookingEntityFor(owner);

                Vector2i offsetPosition = bookEntity.Position - owner.Position;
                int      offsetAltitude = bookEntity.Altitude - owner.Altitude;

                this.elapsedMovingTime += deltaTime.AsMilliseconds() / 1000f;

                Vector2f elapOffsetPosition = new Vector2f(this.elapsedMovingTime * this.speed * Math.Sign(offsetPosition.X), this.elapsedMovingTime * this.speed * Math.Sign(offsetPosition.Y));
                float    elapOffsetAltitude = this.elapsedMovingTime * this.speed * Math.Sign(offsetAltitude);


                bool reachedX        = false;
                bool reachedY        = false;
                bool reachedAltitude = false;
                if (Math.Abs(elapOffsetPosition.X) > Math.Abs(offsetPosition.X))
                {
                    elapOffsetPosition.X = offsetPosition.X;
                    reachedX             = true;
                }

                if (Math.Abs(elapOffsetPosition.Y) > Math.Abs(offsetPosition.Y))
                {
                    elapOffsetPosition.Y = offsetPosition.Y;
                    reachedY             = true;
                }

                if (Math.Abs(elapOffsetAltitude) > Math.Abs(offsetAltitude))
                {
                    elapOffsetAltitude = offsetAltitude;
                    reachedAltitude    = true;
                }

                if (reachedX && reachedY && reachedAltitude)
                {
                    world.EntityManager.MoveEntity(owner, bookEntity.Position.X, bookEntity.Position.Y, bookEntity.Altitude);
                }
                else
                {
                    owner.SetOffsetPosition(elapOffsetPosition.X, elapOffsetPosition.Y, elapOffsetAltitude);
                }
            }
        }
Beispiel #11
0
        protected override bool BookPosition(LandWorld world, IEntity entity, Vector2i position, int altitude)
        {
            //while(altitude <= LandChunkLoader.ALTITUDE_RANGE && world.GetLandCaseAt(position.X, position.Y, altitude).LandWall != null)
            //{
            //    altitude++;
            //}

            altitude = world.GetAltitudeAt(position.X, position.Y);

            if (altitude <= LandChunkLoader.ALTITUDE_RANGE)
            {
                return(base.BookPosition(world, entity, position, altitude));
            }

            return(false);
        }
Beispiel #12
0
        public bool BookPositionForEntity(LandWorld world, IEntity entity, int x, int y, int z)
        {
            if (this.entitiesToBooking.ContainsKey(entity) == false)
            {
                ILandChunk landChunk = world.GetLandChunkAt(x, y);

                if (landChunk != null)
                {
                    BookingEntity bookingEntity = new BookingEntity(entity, x, y, z);

                    this.entitiesToBooking.Add(entity, bookingEntity);

                    this.AddEntity(entity, landChunk);

                    return(true);
                }
            }

            return(false);
        }
Beispiel #13
0
        public virtual bool SetSteering(LandWorld world, IEntity entity, MovingDirection direction)
        {
            Vector2i nextPosition = entity.Position;
            int      nextAltitude = entity.Altitude;

            switch (direction)
            {
            case MovingDirection.UP:
                nextPosition = new Vector2i(entity.Position.X, entity.Position.Y - 1);
                break;

            case MovingDirection.DOWN:
                nextPosition = new Vector2i(entity.Position.X, entity.Position.Y + 1);
                break;

            case MovingDirection.RIGHT:
                nextPosition = new Vector2i(entity.Position.X + 1, entity.Position.Y);
                break;

            case MovingDirection.LEFT:
                nextPosition = new Vector2i(entity.Position.X - 1, entity.Position.Y);
                break;

            case MovingDirection.ABOVE:
                nextAltitude += 1;
                break;

            case MovingDirection.UNDER:
                nextAltitude -= 1;
                break;
            }

            if (this.BookPosition(world, entity, nextPosition, nextAltitude))
            {
                return(true);
            }

            return(false);
        }
Beispiel #14
0
 public virtual void UpdateLogic(LandWorld world, IEntity owner, Time deltaTime)
 {
     // to override
 }
Beispiel #15
0
        protected virtual void UpdateDesiredPosition(LandWorld world, IEntity owner)
        {
            if (this.TryToReach)
            {
                int offsetX = this.DesiredPosition.X - owner.Position.X;
                int offsetY = this.DesiredPosition.Y - owner.Position.Y;
                int offsetZ = this.DesiredAltitude - owner.Altitude;

                Vector2i vectX = new Vector2i(owner.Position.X + offsetX, 0);
                Vector2i vectY = new Vector2i(0, owner.Position.Y + offsetY);

                if (this.IsPositionValid(world, owner, vectX, owner.Altitude))
                {
                    this.BookPosition(world, owner, vectX, owner.Altitude);
                }
                else if (this.IsPositionValid(world, owner, vectY, owner.Altitude))
                {
                    this.BookPosition(world, owner, vectY, owner.Altitude);
                }
                else if (this.IsPositionValid(world, owner, owner.Position, owner.Altitude + offsetZ))
                {
                    this.BookPosition(world, owner, owner.Position, owner.Altitude + offsetZ);
                }

                if (world.EntityManager.IsBookingStillValid(owner))
                {
                    BookingEntity bookingEntity = world.EntityManager.GetBookingEntityFor(owner);

                    if (bookingEntity.Position == this.DesiredPosition)
                    {
                        this.TryToReach = false;
                    }
                }

                //if (this.DesiredPosition.Equals(owner.Position))
                //{
                //    this.TryToReach = false;
                //}
                //else
                //{
                //    int offsetX = this.DesiredPosition.X - owner.Position.X;
                //    int offsetY = this.DesiredPosition.Y - owner.Position.Y;
                //    int offsetZ = this.DesiredAltitude - owner.Altitude;

                //    Vector2i vectX = new Vector2i(owner.Position.X + offsetX, 0);
                //    Vector2i vectY = new Vector2i(0, owner.Position.Y + offsetY);

                //    if (this.IsPositionValid(world, owner, vectX, owner.Altitude))
                //    {
                //        this.BookPosition(world, owner, vectX, owner.Altitude);
                //    }
                //    else if(this.IsPositionValid(world, owner, vectY, owner.Altitude))
                //    {
                //        this.BookPosition(world, owner, vectY, owner.Altitude);
                //    }
                //    else if (this.IsPositionValid(world, owner, owner.Position, owner.Altitude + offsetZ))
                //    {
                //        this.BookPosition(world, owner, owner.Position, owner.Altitude + offsetZ);
                //    }
                //}
            }
        }
Beispiel #16
0
 public void OnAllChunksUpdated(LandWorld world)
 {
     this.area = world.CurrentChunksArea;
 }
Beispiel #17
0
 public abstract void UpdateLogic(LandWorld world, IEntity owner, Time deltaTime);
Beispiel #18
0
        public MainWindow()
        {
            this.landWorld = new LandWorld();

            this.landWorld2D = new LandWorld2D(this.landWorld);
        }