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 bool TileIsFree(WorldLocation _WorldLocation) { Obj.ObjTile ThisTile = W.chunkManager.GetTile(_WorldLocation); if (ThisTile.Entity == -1) { return(true); } return(false); }
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(); }
public void SaveChunk(int x, int y, Obj.ObjChunk _Chunk) { Debug.Logs.Write("[IO] Saving chunk " + x + "," + y, Debug.LogType.Info); List <byte> Chunk = new List <byte>(); for (int tX = 0; tX <= 15; tX++) { for (int tY = 0; tY <= 15; tY++) { // Localisation Chunk.Add((byte)(tY * 16 + tX)); Obj.ObjTile Tile = _Chunk.Tiles[tX, tY]; bool AsEntity = Tile.Entity > -1; //Contien une entité ? if (AsEntity) { Chunk.Add(1); } else { Chunk.Add(0); } byte[] TileBytes = Tile.ToBytes(); if (AsEntity) { Chunk.AddRange(_Chunk.Entities[Tile.Entity].ToBytes().ToList()); } Chunk.AddRange(TileBytes.ToList()); } } SaveData("Saves\\" + W.worldProperty.WorldName + "\\Chunk_" + x + "_" + y + ".bytes", Chunk.ToArray()); }
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); }