public List <Rectangle>[] walls_of_ground(PlatformObject po) { BlockObject bo = new BlockObject(0, 0, po.state); bo.Position = new Vector2(po.x, po.y); return(walls_of_ground(bo)); }
public MapEditorInstance(ChooseMap.Maps Maps, GameManager gameManager) { this.gameManager = gameManager; map = new Map(Load.BackgroundSun, Load.MapTextureNature, Maps); focus = true; mouseBlock = new BlockObject(Map.numberTileX / 2, Map.numberTileY / 2, BlockObject.Ground.MiddleGround); }
public void Update(GameTime gameTime) { KeyboardState state = Keyboard.GetState(); MouseState mouse = Mouse.GetState(); float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; last_time_change += elapsed; mouseBlock.x = (int)(mouse.X * TimGame.general_scale / mouseBlock.w); mouseBlock.y = (int)(mouse.Y * TimGame.general_scale / mouseBlock.h); // we can change if (last_time_change >= time_before_rechange) { if (state.IsKeyDown(Keys.N)) { var s = mouseBlock.Sprite.NowState(); if (s == mouseBlock.Sprite.NumberOfState() - 1) { s = -1; } mouseBlock.ChangeSpriteState(s + 1); mouseBlock.h = mouseBlock.Sprite.RectOfSprite().Height; mouseBlock.w = mouseBlock.Sprite.RectOfSprite().Width; last_time_change = 0f; } else if (state.IsKeyDown(Keys.P)) { var s = mouseBlock.Sprite.NowState(); if (s == 0) { s = mouseBlock.Sprite.NumberOfState(); } mouseBlock.ChangeSpriteState(s - 1); mouseBlock.h = mouseBlock.Sprite.RectOfSprite().Height; mouseBlock.w = mouseBlock.Sprite.RectOfSprite().Width; last_time_change = 0f; } } if (mouse.LeftButton == ButtonState.Pressed || state.IsKeyDown(Keys.Space)) { map.AddBlock(mouseBlock); mouseBlock = new BlockObject(mouseBlock.x, mouseBlock.y, mouseBlock.state); } else if (mouse.RightButton == ButtonState.Pressed || state.IsKeyDown(Keys.Delete) || state.IsKeyDown(Keys.Back)) { map.RemoveBlock(mouseBlock.x, mouseBlock.y, false); } }
/// <summary> /// Convert a graphical block into a physical wall /// </summary> /// <param name="bl">A block object</param> /// <returns>List of walls</returns> public List <Rectangle>[] walls_of_ground(BlockObject bl) { BlockObject.Ground ground = bl.state; List <Rectangle>[] walls = new List <Rectangle> [4]; for (int i = 0; i < 4; i++) { walls[i] = new List <Rectangle>(); } List <BlockObject.Ground> rightsG = new List <BlockObject.Ground> { BlockObject.Ground.LeftGround, BlockObject.Ground.LeftDurt, BlockObject.Ground.BottomLeft2Durt, BlockObject.Ground.LeftPlatform }; List <BlockObject.Ground> leftsG = new List <BlockObject.Ground> { BlockObject.Ground.RightGround, BlockObject.Ground.RightDurt, BlockObject.Ground.BottomRight2Durt, BlockObject.Ground.RightPlatform }; List <BlockObject.Ground> bottomsG = new List <BlockObject.Ground> { BlockObject.Ground.LeftGround, BlockObject.Ground.MiddleGround, BlockObject.Ground.RightGround, BlockObject.Ground.RightEGround, BlockObject.Ground.LeftEGround, BlockObject.Ground.LeftPlatform, BlockObject.Ground.RightPlatform, BlockObject.Ground.MiddlePlatform }; List <BlockObject.Ground> roofsG = new List <BlockObject.Ground> { BlockObject.Ground.BottomDurt, BlockObject.Ground.BottomLeft2Durt, BlockObject.Ground.BottomRight2Durt, BlockObject.Ground.LeftPlatform, BlockObject.Ground.RightPlatform, BlockObject.Ground.MiddlePlatform }; const int pixelOffset = 20; const int magicBorder = 10; if (leftsG.Exists(e => e == ground)) { walls[(int)Wall.left].Add(new Rectangle((int)(bl.Position.X + 3 * bl.w / 4), (int)bl.Position.Y + pixelOffset, (int)(bl.w / 4), (int)(bl.h - pixelOffset * 2))); } if (rightsG.Exists(e => e == ground)) { walls[(int)Wall.right].Add(new Rectangle((int)bl.Position.X, (int)bl.Position.Y + pixelOffset, (int)(bl.w / 4), (int)(bl.h - pixelOffset * 2))); } if (roofsG.Exists(e => e == ground)) { walls[(int)Wall.roof].Add(new Rectangle((int)bl.Position.X + magicBorder, (int)(bl.Position.Y + (bl.h / 2)), (int)(bl.w - 2 * magicBorder), (int)bl.h / 2)); } if (bottomsG.Exists(e => e == ground)) { walls[(int)Wall.bottom].Add(new Rectangle((int)bl.Position.X + magicBorder, (int)(bl.Position.Y), (int)(bl.w - 2 * magicBorder), (int)bl.h / 2)); } return(walls); }
public void AddBlock(BlockObject bl) { RemoveBlock(bl.x, bl.y, true); tileMap.Add(bl); }