예제 #1
0
        public void Recenter(bool forced = false)
        {
            if (PlayerCharacter.Instance.Floor != this)
            {
                return;
            }

            // Center the viewpoint such that the player in the middle
            // of the rendering area.
            Rect area = Game.Instance.LevelRenderArea;

            // Viewport's center spot
            int cX = area.Width / 2 + area.Left;
            int cY = area.Height / 2 + area.Top;

            // How far from this is the player's current rendered position?
            int dX = cX - PlayerCharacter.Instance.X - ViewOffsetX;
            int dY = cY - PlayerCharacter.Instance.Y - ViewOffsetY;

            if (forced == false)
            {
                if (Math.Abs(dX) < centerThresholdX && Math.Abs(dY) < centerThresholdY)
                {
                    return;
                }
            }

            // Update offset so player is in the center!
            ViewOffsetX += dX;
            ViewOffsetY += dY;
            RedrawRequests.FullRedraw();
        }
예제 #2
0
 static void Update_Keyboard_SimpleScreen(ConsoleKeyInfo cki)
 {
     if (cki.Key == ConsoleKey.Escape)
     {
         Game.Instance.InputMode = InputMode.Normal;
         FrameBuffer.Instance.Clear();
         RedrawRequests.FullRedraw();
     }
 }
예제 #3
0
        public void RedrawRequestedArea()
        {
            foreach (Rect r in RedrawRequests.Rects)
            {
                for (int x = r.Left; x < r.Left + r.Width; x++)
                {
                    for (int y = r.Top; y < r.Top + r.Height; y++)
                    {
                        int tX = x - ViewOffsetX;
                        int tY = y - ViewOffsetY;

                        if (tX > 0 && tX < Width && tY > 0 && tY < Height)
                        {
                            tiles[tX, tY].Draw(ViewOffsetX, ViewOffsetY);
                        }
                    }
                }
            }

            RedrawRequests.Clear();
        }
예제 #4
0
        static void Update_Keyboard_Fabricator(ConsoleKeyInfo cki)
        {
            FrameBuffer.Instance.Clear();
            if (cki.Key == ConsoleKey.Escape)
            {
                Game.Instance.InputMode = InputMode.Normal;
                RedrawRequests.FullRedraw();
            }
            else
            {
                // Try to map to an inventory item
                int i = (int)cki.KeyChar - 'a';

                if (i < 0 || i >= Game.Instance.FabricatorUpgrades.Length)
                {
                    // Out of bounds for upgrades.
                    return;
                }

                FabricatorUpgrade fu = Game.Instance.FabricatorUpgrades[i];
                PlayerCharacter   pc = PlayerCharacter.Instance;

                if (fu.NextUpgradeCost > pc.Money)
                {
                    Game.Instance.Message("Insufficient metal scraps for upgrade.");
                    return;
                }

                Game.Instance.Message("PURCHASED: " + fu.Name);
                Console.Beep();

                pc.Money -= fu.NextUpgradeCost;

                fu.OnPurchase(pc);

                fu.NextUpgradeCost = (int)(fu.NextUpgradeCost * 2);
            }
        }
예제 #5
0
        static void Update_Keyboard_Inventory(ConsoleKeyInfo cki)
        {
            FrameBuffer.Instance.Clear();
            if (cki.Key == ConsoleKey.Escape)
            {
                Game.Instance.InputMode = InputMode.Normal;
                RedrawRequests.FullRedraw();
                inventoryExamineMode  = false;
                inventoryEquippedMode = false;
                inventoryDeleteMode   = false;
            }
            else if (cki.KeyChar == '/' || cki.KeyChar == '?')
            {
                inventoryExamineMode = !inventoryExamineMode;
            }
            else if (cki.Key == ConsoleKey.Tab)
            {
                inventoryEquippedMode = !inventoryEquippedMode;
            }
            else if (cki.Key == ConsoleKey.Delete)
            {
                inventoryDeleteMode = !inventoryDeleteMode;
            }
            else
            {
                // Try to map to an inventory item
                int i = (int)cki.KeyChar - 'a';

                if (i < 0 || (inventoryEquippedMode && i >= PlayerCharacter.Instance.EquippedItems.Length) ||
                    (!inventoryEquippedMode && i >= PlayerCharacter.Instance.Items.Length))
                {
                    i = (int)cki.KeyChar - 'A';
                    if (i < 0 || (inventoryEquippedMode && i >= PlayerCharacter.Instance.EquippedItems.Length) ||
                        (!inventoryEquippedMode && i >= PlayerCharacter.Instance.Items.Length))
                    {
                        return;
                    }
                }

                if (inventoryExamineMode)
                {
                    if (inventoryEquippedMode)
                    {
                        if (PlayerCharacter.Instance.EquippedItems[i] != null)
                        {
                            Game.Instance.Message(PlayerCharacter.Instance.EquippedItems[i].FullDescription);
                        }
                    }
                    else
                    {
                        if (PlayerCharacter.Instance.Items[i] != null)
                        {
                            Game.Instance.Message(PlayerCharacter.Instance.Items[i].FullDescription);
                        }
                    }
                }
                else
                {
                    if (inventoryEquippedMode)
                    {
                        PlayerCharacter.Instance.Unequip(i);
                    }
                    else
                    {
                        if (inventoryDeleteMode)
                        {
                            if (PlayerCharacter.Instance.Items[i] != null)
                            {
                                Game.Instance.Message(PlayerCharacter.Instance.Items[i].Name + " has been scrapped for $10");
                                PlayerCharacter.Instance.RemoveItem(i);
                                PlayerCharacter.Instance.Money += 10;
                            }
                        }
                        else
                        {
                            PlayerCharacter.Instance.UseItem(i);
                        }
                    }
                }
            }
        }