public bool MoveEntity(WorldLocation _FromLocation, WorldLocation _ToLocation)
        {
            Obj.ObjTile Tile = W.chunkManager.GetTile(_FromLocation);

            //on verifie si il y a une entitée
            if (Tile.Entity == -1)
            {
                return(false);
            }


            //on verifie si le tile est libre
            if (!(TileIsFree(_ToLocation)))
            {
                return(false);
            }

            //et enfin on le deplace
            Obj.ObjEntity EntityToMove = W.chunkManager.GetChunk(_FromLocation).Entities[Tile.Entity];

            RemoveEntity(_FromLocation);
            AddEntity(EntityToMove, _ToLocation);

            EntityToMove.Location = _ToLocation;
            return(true);
        }
        public void AddEntity(Obj.ObjEntity _Entity, WorldLocation _WorldLocation)
        {
            Obj.ObjChunk Chunk    = W.chunkManager.GetChunk(_WorldLocation.chunk);
            int          EntityID = _WorldLocation.tile.X + _WorldLocation.tile.Y * 16;

            Chunk.Entities.Add(EntityID, _Entity);
            Chunk.Tiles[_WorldLocation.tile.X, _WorldLocation.tile.Y].Entity = EntityID;
        }
        public void Draw(GameTime gameTime, bool Blur)
        {
            if (Blur)
            {
                TileSpriteBatch.Begin();
                EntitySpriteBatch.Begin();
            }
            else
            {
                TileSpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone);
                EntitySpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone);
            }

            for (int Ty = W.Camera.StartTile.Y; Ty <= W.Camera.EndTile.Y; Ty++)
            {
                for (int Tx = W.Camera.StartTile.X; Tx <= W.Camera.EndTile.X; Tx++)
                {
                    if (Tx >= 0 && Ty >= 0 && Tx < W.worldProperty.Size * 16 - 1 && Ty < W.worldProperty.Size * 16 - 1)
                    {
                        //Calcule des emplacements
                        CurrentLocation  = new Point(Tx, Ty);
                        OnScreenLocation = new Point(
                            (Tx - W.Camera.StartTile.X) * W.Camera.Zoom + W.Camera.ScreenOrigine.X,
                            (Ty - W.Camera.StartTile.Y) * W.Camera.Zoom + W.Camera.ScreenOrigine.Y);

                        //Recuperation des arguments
                        GameObject.Event.GameObjectEventArgs e = W.eventsManager.GetEventArgs(CurrentLocation.ToWorldLocation(), OnScreenLocation);

                        //recuperation des objets
                        Obj.ObjTile T = W.chunkManager.GetTile(CurrentLocation);


                        //desin des objets


                        GameObjectsManager.Tiles[T.ID].OnDraw(e, TileSpriteBatch, gameTime);



                        if (!(T.Entity == -1))
                        {
                            Obj.ObjEntity E = W.chunkManager.GetEntity(CurrentLocation);
                            GameObjectsManager.Entities[E.ID].OnDraw(e, EntitySpriteBatch, gameTime);
                        }
                    }
                }
            }
            TileSpriteBatch.End();
            EntitySpriteBatch.End();
        }
Esempio n. 4
0
        public override void Update(MouseState Mouse, KeyboardState KeyBoard, GameTime gameTime)
        {
            for (int Tx = W.Camera.StartTile.X; Tx <= W.Camera.EndTile.X; Tx++)
            {
                for (int Ty = W.Camera.StartTile.Y; Ty <= W.Camera.EndTile.Y; Ty++)
                {
                    if (Tx >= 0 && Ty >= 0 && Tx < W.worldProperty.Size * 16 - 1 && Ty < W.worldProperty.Size * 16 - 1)
                    {
                        //Calcule des emplacements
                        CurrentLocation  = new Point(Tx, Ty);
                        OnScreenLocation = new Point(
                            (Tx - W.Camera.StartTile.X) * W.Camera.Zoom + W.Camera.ScreenOrigine.X,
                            (Ty - W.Camera.StartTile.Y) * W.Camera.Zoom + W.Camera.ScreenOrigine.Y);

                        //recuperation des arguments
                        GameObject.Event.GameObjectEventArgs e = W.eventsManager.GetEventArgs(CurrentLocation.ToWorldLocation(), OnScreenLocation);

                        //recuperation des objets
                        Obj.ObjTile T = W.chunkManager.GetTile(CurrentLocation);

                        GameObjectsManager.Tiles[T.ID].OnTick(e, gameTime);
                        GameObjectsManager.Tiles[T.ID].OnUpdate(e, KeyBoard, Mouse, gameTime);

                        if (!(T.Entity == -1))
                        {
                            //On recuper l'entitée
                            Obj.ObjEntity E = W.chunkManager.GetEntity(CurrentLocation);
                            E.Location = CurrentLocation.ToWorldLocation();

                            GameObjectsManager.Entities[E.ID].OnTick(e, gameTime);
                            GameObjectsManager.Entities[E.ID].OnUpdate(e, KeyBoard, Mouse, gameTime);
                        }
                    }
                }
            }

            base.Update(Mouse, KeyBoard, gameTime);
        }