//Moves the control to new location, preserves state public static void moveControlLocation(Tile toMove, TileTypes replaceWith, Zone zone, Point newLoc) { Point pos = TileOperators.getGridPosition(toMove); int posX = pos.Y; int posY = pos.X; Tile replacement = extractControlFromType(replaceWith, zone); setTileDetails(replacement, toMove.Width, posX, posY); setTileDetails(toMove, toMove.Width, newLoc.X, newLoc.Y); if (zone == Zone.Surface) { levelHandler.currentLevelSurfaceArray[posX, posY] = replacement; if (levelHandler.player.currentZone == Zone.Surface) { Program.formRef.RemoveControl(levelHandler.currentLevelSurfaceArray[newLoc.X, newLoc.Y]); Program.formRef.AddControl(replacement); replacement.Show(); } levelHandler.currentLevelSurfaceArray[newLoc.X, newLoc.Y] = toMove; } else if (zone == Zone.Cave) { levelHandler.currentLevelCaveArray[posX, posY] = replacement; if (levelHandler.player.currentZone == Zone.Cave) { Program.formRef.RemoveControl(levelHandler.currentLevelCaveArray[newLoc.X, newLoc.Y]); Program.formRef.AddControl(replacement); } levelHandler.currentLevelCaveArray[newLoc.X, newLoc.Y] = toMove; } }
//Changes the tile at a specific location, creates a new instance public static void changeTileAtLocation(Tile current, TileTypes replacement, Zone zone) { Point pos = TileOperators.getGridPosition(current); int posY = pos.X;//these must be inverted as the initial Point is inverted due to the initial inversion of the placements int posX = pos.Y; Tile newControl = extractControlFromType(replacement, zone); setTileDetails(newControl, current.Width, posX, posY); if (zone == Zone.Surface) { levelHandler.currentLevelSurfaceArray[posX, posY] = newControl; if (levelHandler.player.currentZone == Zone.Surface) { Program.formRef.RemoveControl(current); Program.formRef.AddControl(newControl); } } else if (zone == Zone.Cave) { levelHandler.currentLevelCaveArray[posX, posY] = newControl; if (levelHandler.player.currentZone == Zone.Cave) { Program.formRef.RemoveControl(current); Program.formRef.AddControl(newControl); } } }
private void uncover(Utils.MessageBox sender, bool result) { if (result && levelHandler.player.HasItem(ItemTypes.Spade)) { levelHandler.player.RemoveItem(ItemTypes.Spade); if (base.baseType == TileTypes.Grass) { TileOperators.changeTileAtLocation(this, TileTypes.Chest, Zone.Surface); } else if (base.baseType == TileTypes.Stone) { TileOperators.changeTileAtLocation(this, TileTypes.Chest, Zone.Cave); } levelHandler.player.callMove(); } else if (base.isInRange())//Player could theoretically move before pressing no { Point pos = TileOperators.getGridPosition(this); levelHandler.player.MovePlayer(pos.X, pos.Y); levelHandler.player.callMove(); } sender.Hide(); Program.formRef.Controls.Remove(sender); sender.Controls.Clear(); sender.Dispose(); }
public override void playerAction() { if (path != null) { Point curLoc = TileOperators.getGridPosition(this); //Get the reversed path location int revPathLoc = (pathLoc + (reversed ? 1 : -1)) % path.Length; if (revPathLoc < 0) { revPathLoc = path.Length - 1; } AnimalMovementHandler.Request request = new AnimalMovementHandler.Request(new Point(curLoc.Y, curLoc.X), getMovementLocation(pathLoc, false), getMovementLocation(revPathLoc, true), new AnimalMovementHandler.movementHandlerCallBack(movementCallBack), new AnimalMovementHandler.movementHandlerDeathCallBack(animalAttack), 0); AnimalMovementHandler.requestMovement(request); } }
//Default Clicked On For Tiles That Are Walkable public virtual void ClickedOn(object sender, EventArgs e) { int tileSize = base.Size.Width; if (isInRange() && isWalkable && //Can Walk On It validActions.Length == 1) // Walking is the only valid option { Point pos = TileOperators.getGridPosition(this); int posX = pos.X; int posY = pos.Y; levelHandler.player.MovePlayer(posX, posY); levelHandler.player.callMove(); } }
//Checks if the player can interact with the tile public bool isInRange() { Point curPos = TileOperators.getGridPosition(this); int curPosX = curPos.X; int curPosY = curPos.Y; Point playerPos = TileOperators.getGridPosition(levelHandler.player.hiddenControl); int playerPosX = playerPos.X; int playerPosY = playerPos.Y; if (Math.Abs(playerPosX - curPosX) > 1 || // X is more than one away Math.Abs(playerPosY - curPosY) > 1 || // Y is more than one away Math.Abs(playerPosX - curPosX) == Math.Abs(playerPosY - curPosY) // Not On a diagonal or the player's tile ) { return(false); } return(true); }
public override void ClickedOn(object sender, EventArgs e) { if (base.isInRange()) { if (levelHandler.player.HasItem(ItemTypes.Spade)) { Utils.MessageBox messageBox = new Utils.MessageBox(Program.formRef.ClientSize, global::TileGamePrototype.Properties.Resources.WoodTexture); Program.formRef.Controls.Add(messageBox); messageBox.BringToFront(); messageBox.ShowMessageBox("Do you wish to uncover the treasure?", new Utils.MessageBox.DialogResultCallBack(uncover)); } else { Point pos = TileOperators.getGridPosition(this); levelHandler.player.MovePlayer(pos.X, pos.Y); levelHandler.player.callMove(); } } }
public Point getMovementLocation(int pathLocAlt, bool reversed) { Point loc = TileOperators.getGridPosition(this); int modifier = reversed ? 2 : 0; // Switches direction when going backward through the path if ((path[pathLocAlt] + modifier - 1) % 4 + 1 == 1) //Up { loc.Y--; } else if ((path[pathLocAlt] + modifier - 1) % 4 + 1 == 2)//Right { loc.X++; } else if ((path[pathLocAlt] + modifier - 1) % 4 + 1 == 3)//Down { loc.Y++; } else if ((path[pathLocAlt] + modifier - 1) % 4 + 1 == 4)//Left { loc.X--; } return(new Point(loc.Y, loc.X));//Needs Flipped }
public void attackNeighbouringTiles() { if (base.isInRange()) { levelHandler.requestPlayersBrutallyPainfulDeath(); return; } Point curLoc = TileOperators.getGridPosition(this); for (int i = -1; i <= 2; i += 2) { if (curLoc.Y + i < 0 || curLoc.Y + i >= levelHandler.currentLevelSurfaceArray.GetLength(0)) { continue; } Tile neighbour = levelHandler.currentLevelSurfaceArray[curLoc.Y + i, curLoc.X]; if (neighbour.GetType().ToString() == (TileOperators.extractControlFromType(TileTypes.Passive, Zone.Surface)).GetType().ToString()) { PassiveAnimal animal = (PassiveAnimal)neighbour; animal.animalAttack(); } } for (int i = -1; i <= 2; i += 2) { if (curLoc.X + i < 0 || curLoc.X + i >= levelHandler.currentLevelSurfaceArray.GetLength(1)) { continue; } Tile neighbour = levelHandler.currentLevelSurfaceArray[curLoc.Y, curLoc.X + i]; if (neighbour.GetType().ToString() == (TileOperators.extractControlFromType(TileTypes.Passive, Zone.Surface)).GetType().ToString()) { PassiveAnimal animal = (PassiveAnimal)neighbour; animal.animalAttack(); } } }
//Key down event private void GameForm_KeyDown(object sender, KeyEventArgs e) { //If message box is shown this will be disabled if (disableKeyPress) { return; } //Gets players location Point loc = TileOperators.getGridPosition(levelHandler.player.hiddenControl); //Up if (e.KeyCode == Keys.Up) { if (loc.Y > 0 && move) { levelHandler.currentLevelSurfaceArray[loc.Y - 1, loc.X].ClickedOn(this, EventArgs.Empty); } move = false; } //Down else if (e.KeyCode == Keys.Down) { if (loc.Y < levelHandler.currentLevelSurfaceArray.GetLength(0) - 1 && move) { levelHandler.currentLevelSurfaceArray[loc.Y + 1, loc.X].ClickedOn(this, EventArgs.Empty); } move = false; } //Left else if (e.KeyCode == Keys.Left) { if (loc.X > 0 && move) { levelHandler.currentLevelSurfaceArray[loc.Y, loc.X - 1].ClickedOn(this, EventArgs.Empty); } move = false; } //Right else if (e.KeyCode == Keys.Right) { if (loc.X < levelHandler.currentLevelSurfaceArray.GetLength(1) - 1 && move) { levelHandler.currentLevelSurfaceArray[loc.Y, loc.X + 1].ClickedOn(this, EventArgs.Empty); } move = false; } //Inventory Shortcut else if (e.KeyCode == Keys.I) { Inventory(null, EventArgs.Empty); } //Crafting shortcut else if (e.KeyCode == Keys.C) { Combine(null, EventArgs.Empty); } //Menu shortcut else if (e.KeyCode == Keys.M || e.KeyCode == Keys.Escape) { ReturnToMenu(null, EventArgs.Empty); } //Help shortcut else if (e.KeyCode == Keys.H) { Help(null, EventArgs.Empty); } //Restart level else if (e.KeyCode == Keys.R) { levelHandler.restartLevel(); } //Developer hack /*else * { * Program.NextLevel(); * }*/ }