Beispiel #1
0
        private static void PlayerTryMoveOffsetTo(int xoffset, int yoffset)
        {
            //this is the proposed new x,y of the player if move is successful.
            int newx = ThePlayer.X + xoffset;
            int newy = ThePlayer.Y + yoffset;

            //perform boundary checking of new location, if it fails then we can't move there just because of boundary issues
            if (newx > -1 && newx < Width && newy > -1 && newy < Height)
            {
                //get the tile that is at the new location
                MapTile t = GetTileAtPos(newx, newy);

                //if the space moving upwards is a blank space then move up
                if (t.IsWalkable)
                {
                    ThePlayer.Dirty = true;
                    Tiles[ThePlayer.Y, ThePlayer.X].IsWalkable = true;  //the space we just moved from
                    ThePlayer.LastX = ThePlayer.X;
                    ThePlayer.LastY = ThePlayer.Y;
                    ThePlayer.X     = newx;
                    ThePlayer.Y     = newy;
                    Tiles[ThePlayer.Y, ThePlayer.X].IsWalkable = false; //make new tile not walkable because you are on it

                    CheckTileForAction(ThePlayer.X, ThePlayer.Y);
                }
                else
                {
                    //if we can't walk onto this space then what is in this space? a wall, door, monster, etc.?
                    //walls do nothing, doors we can check for keys, monsters we attack.
                    var type = GetTileAtPos(newx, newy).GetType();
                    if (type == typeof(MapTileWall))
                    {
                        //do nothing, its a wall
                    }
                    else if (type == typeof(MapTileSpace))
                    {
                        //so if its a space and its not walkable, probably a monster here.
                        var monster = MonsterMgr.GetMonsterAt(newx, newy);
                        if (monster.IsAlive)
                        {
                            var maxdamage = ThePlayer.CanDealDamage();
                            //lets hit the monster for damage
                            monster.TakeDamage(maxdamage);
                            MessageBrd.Add($"Monster took {maxdamage} damage.");
                            if (!monster.IsAlive)
                            {
                                MessageBrd.Add($"Monster is DEAD!");
                            }
                            MonsterMgr.PruneDeadMonsters();
                        }
                    }
                }
            } // end of map boundary check
        }