public bool AddLizard(Lizard lizard) { if (this.lizard == null) { this.lizard = lizard; lizard.tile = this; UpdatePassability(); return true; } return false; }
public static Lizard addLizard(Vector2 position) { if (Lizard.lizTex == null) { return null; } Lizard lizard = new Lizard(position); if (!lizard.tile.AddLizard(lizard)) { Console.Out.WriteLine("Failure"); } if (lizard != null) { player.lizards.Add(lizard); } return lizard; }
public static Lizard addLizard(Vector2 position) { if (Lizard.lizTex == null) { return(null); } Lizard lizard = new Lizard(position); if (!lizard.tile.AddLizard(lizard)) { Console.Out.WriteLine("Failure"); } if (lizard != null) { player.lizards.Add(lizard); } return(lizard); }
private Lizard getLizardAtMouse() { Lizard retLizard = null; float currDiff = 999f; float testDiff; Vector2 wsm = worldSpaceMouse(); foreach (Lizard lizard in this.lizards) { testDiff = (lizard.position - wsm).Length(); if (currDiff > testDiff && testDiff < TileMap.TILESIZE) { currDiff = (lizard.position - wsm).Length(); retLizard = lizard; } } return(retLizard); }
public bool RemoveLizard(Lizard lizard) { if (this.lizard != null) { this.lizard = null; UpdatePassability(); return true; } return false; }
public void Update(GameTime gameTime) { UpdateCursor(); HandleCamera(); currMouse = Mouse.GetState(); KeyboardState currKeys = Keyboard.GetState(); if (currMouse.LeftButton == ButtonState.Pressed && lastMouse.LeftButton == ButtonState.Released) { Lizard lizard = getLizardAtMouse(); if (lizard != null) { //unselect old if (selected != null) { selected.isSelected = false; } selected = lizard; selected.isSelected = true; } else if (selected != null) { selected.isSelected = false; selected = null; } } if (currMouse.RightButton == ButtonState.Pressed && lastMouse.RightButton == ButtonState.Released && !currKeys.IsKeyDown(Keys.LeftShift)) { if (selected != null) { selected.pickupBlock = null; Tile attempt = TileMap.getTileAtPos(worldSpaceMouse()); //if attempt is valid, path there if (attempt != null && attempt.lizard == null && attempt.Passable) { if ((attempt == selected.path.Last() || (selected.dropTile != null && attempt == selected.dropTile)) && selected.block != null)//clicking twice on a place when carrying a block drops { List<Tile> places = new List<Tile>(); places.Add(TileMap.getTileByIndex((int)attempt.index.X - 1, (int)attempt.index.Y)); places.Add(TileMap.getTileByIndex((int)attempt.index.X + 1, (int)attempt.index.Y)); places.Add(TileMap.getTileByIndex((int)attempt.index.X, (int)attempt.index.Y - 1)); places.Add(TileMap.getTileByIndex((int)attempt.index.X, (int)attempt.index.Y + 1)); selected.Path(places); selected.dropTile = attempt; } else { selected.Path(attempt); } } else if (attempt.block != null && this.selected.block == null)//if there is a block there, pick it up { selected.pickupBlock = attempt.block; selected.Path(attempt); } } } if (currMouse.MiddleButton == ButtonState.Pressed )//&& lastMouse.MiddleButton == ButtonState.Released) { Tile tile = TileMap.getTileAtPos(worldSpaceMouse()); if (tile != null && tile.lizard == null && tile.block == null) { //find index to add at Vector2 offset = worldSpaceMouse() - tile.position; world.AddBlock(new TreeBlock(tile.position), false); } } if (Keyboard.GetState().IsKeyDown(Keys.RightControl) && Keyboard.GetState().IsKeyDown(Keys.I)) { world.SaveLevel("new.txt"); } lastMouse = currMouse; }
public void Update(GameTime gameTime) { UpdateCursor(); HandleCamera(); currMouse = Mouse.GetState(); KeyboardState currKeys = Keyboard.GetState(); if (currMouse.LeftButton == ButtonState.Pressed && lastMouse.LeftButton == ButtonState.Released) { Lizard lizard = getLizardAtMouse(); if (lizard != null) { //unselect old if (selected != null) { selected.isSelected = false; } selected = lizard; selected.isSelected = true; } else if (selected != null) { selected.isSelected = false; selected = null; } } if (currMouse.RightButton == ButtonState.Pressed && lastMouse.RightButton == ButtonState.Released && !currKeys.IsKeyDown(Keys.LeftShift)) { if (selected != null) { selected.pickupBlock = null; Tile attempt = TileMap.getTileAtPos(worldSpaceMouse()); //if attempt is valid, path there if (attempt != null && attempt.lizard == null && attempt.Passable) { if ((attempt == selected.path.Last() || (selected.dropTile != null && attempt == selected.dropTile)) && selected.block != null)//clicking twice on a place when carrying a block drops { List <Tile> places = new List <Tile>(); places.Add(TileMap.getTileByIndex((int)attempt.index.X - 1, (int)attempt.index.Y)); places.Add(TileMap.getTileByIndex((int)attempt.index.X + 1, (int)attempt.index.Y)); places.Add(TileMap.getTileByIndex((int)attempt.index.X, (int)attempt.index.Y - 1)); places.Add(TileMap.getTileByIndex((int)attempt.index.X, (int)attempt.index.Y + 1)); selected.Path(places); selected.dropTile = attempt; } else { selected.Path(attempt); } } else if (attempt.block != null && this.selected.block == null)//if there is a block there, pick it up { selected.pickupBlock = attempt.block; selected.Path(attempt); } } } if (currMouse.MiddleButton == ButtonState.Pressed) //&& lastMouse.MiddleButton == ButtonState.Released) { Tile tile = TileMap.getTileAtPos(worldSpaceMouse()); if (tile != null && tile.lizard == null && tile.block == null) { //find index to add at Vector2 offset = worldSpaceMouse() - tile.position; world.AddBlock(new TreeBlock(tile.position), false); } } if (Keyboard.GetState().IsKeyDown(Keys.RightControl) && Keyboard.GetState().IsKeyDown(Keys.I)) { world.SaveLevel("new.txt"); } lastMouse = currMouse; }