public override void KeyPressed(TCODKey keyData)
 {
     if (keyData.KeyCode == TCODKeyCode.Up)
     {
         CharacterList.SelectedIndex -= 1;
     }
     else if (keyData.KeyCode == TCODKeyCode.Down)
     {
         CharacterList.SelectedIndex += 1;
     }
     else if (keyData.KeyCode == TCODKeyCode.Escape)
     {
         Game.ChangeScene(PreviousScene);
     }
     else if (keyData.KeyCode == TCODKeyCode.Tab)
     {
         if (!keyData.Shift)
         {
             Game.ChangeScene(new PersonnelWoundsScene(Game, PreviousScene, Characters, CharacterList.SelectedIndex));
         }
         else
         {
             Game.ChangeScene(new PersonnelBioticsScene(Game, PreviousScene, Characters, CharacterList.SelectedIndex));
         }
     }
 }
        public override void KeyPressed(TCODKey keyData)
        {
            switch(char.ToUpper(keyData.Character)) {
                case 'N':
                    Game.ChangeScene(new NewGameScene(Game));
                    break;

                case 'L':
                    new BlockingMessageModal(Game.Settings.UiForeground,
                        Game.Settings.UiBackground, "This feature is not yet implemented.").Show();
                    Game.ChangeScene(new MapGenTestScene(Game));
                    break;

                case 'O':
                    new BlockingMessageModal(Game.Settings.UiForeground,
                        Game.Settings.UiBackground, "This feature is not yet implemented.").Show();
                    break;

                case 'C':
                    Game.ChangeScene(new CreditsScene(Game));
                    break;

                case 'Q':
                    var confirmQuit = new BlockingConfirmationModal() {
                        Foreground = Game.Settings.UiForeground,
                        Background = Game.Settings.UiBackground,
                        Message = "Are you sure you want to quit?"
                    }.Show();
                    if(confirmQuit) {
                        Game.ChangeScene(null);
                    }
                    break;
            }
        }
        public string Show()
        {
            LongestLine = Math.Max(Message.Length, Options.Max(line => line.Length));
            X           = (TCODConsole.root.getWidth() / 2) - (Message.Length / 2 + 2);
            Width       = Math.Max(13, LongestLine + 4); // Two for padding and two for the border
            Y           = (TCODConsole.root.getHeight() / 2) - 3;
            Height      = Options.Length + 6;            // 2 for border, 2 for padding, 2 for title w/ padding

            TCODKey key = null;

            Render();
            do
            {
                key = TCODConsole.waitForKeypress(true);
                if (key.KeyCode == TCODKeyCode.Up)
                {
                    SelectedIndex -= 1;
                    if (SelectedIndex < 0)
                    {
                        SelectedIndex = Options.Length - 1;
                    }
                }
                else if (key.KeyCode == TCODKeyCode.Down)
                {
                    SelectedIndex += 1;
                    if (SelectedIndex >= Options.Length)
                    {
                        SelectedIndex = 0;
                    }
                }
                Render();
            } while(key.KeyCode != TCODKeyCode.Enter && key.KeyCode != TCODKeyCode.Escape);

            return(key.KeyCode == TCODKeyCode.Enter ? Options[SelectedIndex] : null);
        }
Beispiel #4
0
 public override void KeyPressed(TCODKey keyData)
 {
     if (keyData.KeyCode == TCODKeyCode.Escape)
     {
         Game.ChangeScene(new MainMenuScene(Game));
     }
 }
Beispiel #5
0
 public override void Update(TCODKey k, TCODMouseData m)
 {
     foreach (Button b in Buttons)
     {
         b.Update(m);
     }
 }
Beispiel #6
0
        public bool Show()
        {
            var x      = (TCODConsole.root.getWidth() / 2) - (Message.Length / 2 + 2);
            var width  = Math.Max(13, Message.Length + 4);            // Two for padding and two for the border
            var y      = (TCODConsole.root.getHeight() / 2) - 3;
            var height = 6;

            TCODConsole.root.setForegroundColor(Foreground);
            TCODConsole.root.setBackgroundColor(Background);
            TCODConsole.root.printFrame(x, y, width, height, true, TCODBackgroundFlag.Set);
            TCODConsole.root.print(x + 2, y + 2, Message);
            TCODConsole.root.print(x + (width / 2) - 4, y + 3, "[Y] / [N]");
            TCODConsole.flush();

            TCODKey key       = null;
            var     character = 'N';

            do
            {
                key       = TCODConsole.waitForKeypress(true);
                character = char.ToUpper(key.Character);
            } while(character != 'Y' && character != 'N');

            return(character == 'Y');
        }
Beispiel #7
0
        public void Update()
        {
            bool endturn;

            do
            {
                TCODKey key = TCODConsole.waitForKeypress(true);
                endturn = HandleKeyPress(key);
                Draw();
            } while (!endturn && !Exit);
            if (!Exit)
            {
                Map.Update();
                Draw();
                if (Map.IntensityAt(_player.PosX, _player.PosY) == 0)
                {
                    if (_turnInDark == 3)
                    {
                        Exit = true;
                    }
                    else
                    {
                        _turnInDark++;
                    }
                }
            }
        }
Beispiel #8
0
 public override void KeyPressed(TCODKey keyData)
 {
     if (keyData.KeyCode == TCODKeyCode.Space)
     {
         Map.Generate(Game.Settings.ScreenWidth, Game.Settings.ScreenHeight);
     }
 }
Beispiel #9
0
        public void Update(TCODKey k, TCODMouseData m)
        {
            this.Current.Update(k, m);

            //Should exit?
            this.Run = this.Run && !TCODConsole.isWindowClosed();
            this.Run = this.Run && !(k.KeyCode == TCODKeyCode.Escape);
        }
Beispiel #10
0
        public void SetActionSecondary(T action, TCODKey key)
        {
            if (!_inputs.ContainsKey(action))
            {
                _inputs[action] = new Pair <TCODKey, TCODKey>();
            }

            _inputs[action].Second = key;
        }
Beispiel #11
0
        public void SetActionPrimary(T action, TCODKey key)
        {
            if (!_inputs.ContainsKey(action))
            {
                _inputs[action] = new Pair <TCODKey, TCODKey>();
            }

            _inputs[action].First = key;
        }
Beispiel #12
0
        public void initialize(bool restarting)
        {
            Console.WriteLine("Initializing...");
            gameStatus = GameStatus.LOADING;
            TCODConsole.initRoot(screenWidth, screenHeight, "Janus Roguelike", false);

            TCODMouse.showCursor(true);

            menuGui = new GUI.MenuGui(screenWidth, screenHeight);

            levels = new Dictionary <int, Level>();

            gui        = new GUI.Gui();
            loadingGui = new GUI.LoadingGui();
            messageGui = new GUI.MessageGui();
            defeatGui  = new GUI.DefeatGui();
            debugCommands.initialize(this);

            levels.Add(FIRST_LEVEL, new Level());

            levelnr = FIRST_LEVEL;
            //currentLevel = new Level();
            if (FIRST_LEVEL == int.MaxValue)
            {
                currentLevel.initialize(restarting, FIRST_LEVEL, typeof(Generators.TestLevelGenerator));
            }
            else
            {
                currentLevel.initialize(restarting, FIRST_LEVEL);
            }

            changeLevel(FIRST_LEVEL);

            player = new Player();
            player.getDestructible().ressurect();

            player.x = map.startx; //assign player position
            player.y = map.starty;

            player.fov.update();
            if (actorHandler.getActor(0) != null)
            {
                actorHandler.actors.Remove(actorHandler.getActor(0));
            }
            actorHandler.addActor(player);

            Saver.load();

            Console.WriteLine("Initializing Complete");


            render();

            lastKey    = new TCODKey();
            gameStatus = GameStatus.STARTUP;
        }
 public override void KeyPressed(TCODKey keyData)
 {
     if(keyData.KeyCode == TCODKeyCode.Up) {
         TaskList.SelectedIndex -= 1;
     } else if(keyData.KeyCode == TCODKeyCode.Down) {
         TaskList.SelectedIndex += 1;
     } else if(keyData.KeyCode == TCODKeyCode.Escape) {
         Game.ChangeScene(PreviousScene);
     }
 }
Beispiel #14
0
        // Handle the main menu keypresses
        public char HandleMainMenu()
        {
            // Wait for a keypress
            TCODKey key = new TCODKey();

            do
            {
                // Get the keypress
                TCODConsole.flush();
                key = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);

                if (key.Character == 'S' || key.Character == 's' ||
                    key.Character == 'C' || key.Character == 'c' ||
                    key.Character == 'Q' || key.Character == 'q')
                {
                    string characterPressed = key.Character.ToString().ToUpper();
                    return(characterPressed[0]);
                }
                else if (key.KeyCode == TCODKeyCode.Up || key.KeyCode == TCODKeyCode.KeypadEight)
                {
                    if (currentMenuOption != MenuOption.Start)
                    {
                        currentMenuOption--;
                        return(' ');
                    }
                    else
                    {
                        currentMenuOption = MenuOption.Quit;
                        return(' ');
                    }
                }
                else if (key.KeyCode == TCODKeyCode.Down || key.KeyCode == TCODKeyCode.KeypadTwo)
                {
                    if (currentMenuOption != MenuOption.Quit)
                    {
                        currentMenuOption++;
                        return(' ');
                    }
                    else
                    {
                        currentMenuOption = MenuOption.Start;
                        return(' ');
                    }
                }
                else if (key.KeyCode == TCODKeyCode.KeypadEnter || key.KeyCode == TCODKeyCode.Enter)
                {
                    string KeyCodes = "SCQ";
                    return(KeyCodes[(int)currentMenuOption]);
                }

                PrintMainMenu();
            }while (!TCODConsole.isWindowClosed());
            return(' ');
        }
Beispiel #15
0
 public void Update()
 {
     do
     {
         TCODConsole.flush();
         _currentInput = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);
         if (TCODConsole.isWindowClosed())
         {
             Environment.Exit(0);
         }
     } while (_currentInput.KeyCode == TCODKeyCode.NoKey);
 }
Beispiel #16
0
 public void RegisterKeyStatus(TCODKey key, TCODKeyStatus status)
 {
     if (key.KeyCode == TCODKeyCode.Char)
     {
         int it = Enum.GetValues(typeof(TCODKeyCode)).Length + (int)key.Character;
         ksMap[it] = new KeyStatus(key.Character, key.KeyCode, status);
     }
     else
     {
         ksMap[(int)key.KeyCode] = new KeyStatus(key.Character, key.KeyCode, status);
     }
 }
Beispiel #17
0
        public void update(bool validate)
        {
            this.validate = validate;
            if (validate == true)
            {
                currentLevel.actorHandler.update(true);
            }
            mousedata = TCODMouse.getStatus();

            key = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);
            debugCommands.update();


            if (gameStatus == GameStatus.LOADING)
            {
                loadingGui.update();
            }
            else if (gameStatus == GameStatus.DEFEAT)
            {
                if (key.Pressed)
                {
                    Console.WriteLine("Restarting game...");
                    initialize(true);
                }
            }
            else if (gameStatus == GameStatus.MENU)
            {
                menuGui.focused = true;
                menuGui.update();

                if (key.KeyCode == (TCODKeyCode.Escape))
                {
                    menuGui.focused = false;
                    gameStatus      = GameStatus.IDLE;
                }
            }
            else
            {
                gameStatus = GameStatus.IDLE;

                player.update();
                gui.update();
                messageGui.update();
                if (gameStatus == GameStatus.NEW_TURN)
                {
                    currentLevel.update();
                    //Message.flush();
                }

                Message.update();
            }
            lastKey = key;
        }
Beispiel #18
0
        /// <summary>
        /// Starts the game simulation and set off the normal update life cycle
        /// </summary>
        /// <returns> A code corresponding to how the game exited: 0 = normal quit </returns>
        public int Run()
        {
            if (mainConsole == null || isRunning)
            {
                return(APPLICATION_EXIT_ERROR);
            }

            isRunning = true;
            internalTimer.Start();

            // Main update loop
            while (!TCODConsole.isWindowClosed() && isRunning)
            {
                long current   = internalTimer.ElapsedMilliseconds;
                long frameTime = current - previousUpdateTime;
                previousUpdateTime = current;

                frameLag += frameTime;

                // Actual update / console drawing runs on an inner catchup loop that is also interuptable
                // will run catchup frames or delay so that it closely matches desired FRAME_RATE, that
                // is also synced with the TCODConsoles own render frame rate
                while (frameLag >= MS_PER_UPDATE &&
                       !TCODConsole.isWindowClosed() && isRunning)
                {
                    // TCOD must be flushed immedietly before polling the input channels
                    TCODConsole.flush();
                    lastKey   = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);
                    mouseData = TCODMouse.getStatus();

                    // Handle transitions between states
                    if (gotoNewState)
                    {
                        EnteredNewState(nextState);
                        gotoNewState = false;
                    }

                    Update();
                    Render();

                    // always allow for core update interrupt
                    if (lastKey.KeyCode == TCODKeyCode.F4)
                    {
                        isRunning = false;
                    }
                }
            }

            internalTimer.Stop();
            return(APPLICATION_EXIT_NORMAL);
        }
Beispiel #19
0
        private bool Check(TCODKey key, bool noChars)
        {
            if (_currentInput.KeyCode != key.KeyCode)
            {
                return(false);
            }

            if (key.KeyCode == TCODKeyCode.Char)
            {
                return(_currentInput.Character == key.Character && !noChars);
            }

            return(true);
        }
Beispiel #20
0
 public override void KeyPressed(TCODKey keyData)
 {
     if (keyData.KeyCode == TCODKeyCode.Up)
     {
         TaskList.SelectedIndex -= 1;
     }
     else if (keyData.KeyCode == TCODKeyCode.Down)
     {
         TaskList.SelectedIndex += 1;
     }
     else if (keyData.KeyCode == TCODKeyCode.Escape)
     {
         Game.ChangeScene(PreviousScene);
     }
 }
 public override void KeyPressed(TCODKey keyData)
 {
     if(keyData.KeyCode == TCODKeyCode.Up) {
         CharacterList.SelectedIndex -= 1;
     } else if(keyData.KeyCode == TCODKeyCode.Down) {
         CharacterList.SelectedIndex += 1;
     } else if(keyData.KeyCode == TCODKeyCode.Escape) {
         Game.ChangeScene(PreviousScene);
     } else if(keyData.KeyCode == TCODKeyCode.Tab) {
         if(!keyData.Shift) {
             Game.ChangeScene(new PersonnelBioticsScene(Game, PreviousScene, Characters, CharacterList.SelectedIndex));
         } else {
             Game.ChangeScene(new PersonnelSkillsScene(Game, PreviousScene, Characters, CharacterList.SelectedIndex));
         }
     }
 }
Beispiel #22
0
        public static bool IsKeypad(TCODKey key)
        {
            bool result = false;

            result |= key.KeyCode == TCODKeyCode.KeypadOne;
            result |= key.KeyCode == TCODKeyCode.KeypadTwo;
            result |= key.KeyCode == TCODKeyCode.KeypadThree;
            result |= key.KeyCode == TCODKeyCode.KeypadFour;
            result |= key.KeyCode == TCODKeyCode.KeypadFive;
            result |= key.KeyCode == TCODKeyCode.KeypadSix;
            result |= key.KeyCode == TCODKeyCode.KeypadSeven;
            result |= key.KeyCode == TCODKeyCode.KeypadEight;
            result |= key.KeyCode == TCODKeyCode.KeypadNine;

            return(result);
        }
Beispiel #23
0
        private void PollKeyboard()
        {
            TCODKey key = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed
                                                       | (int)TCODKeyStatus.KeyReleased);

            if (key.KeyCode != TCODKeyCode.NoKey)
            {
                if (key.Pressed)
                {
                    _attachedComponent.OnKeyPressed(new KeyboardData(key));
                }
                else
                {
                    _attachedComponent.OnKeyReleased(new KeyboardData(key));
                }
            }
        }
Beispiel #24
0
        private void AddKeyPressToBuffer(TCODKey keyPress)
        {
            switch (keyPress.KeyCode)
            {
            case TCODKeyCode.Up:
            case TCODKeyCode.Left:
            case TCODKeyCode.Right:
            case TCODKeyCode.Down:
            case TCODKeyCode.Enter:
            case TCODKeyCode.KeypadOne:
            case TCODKeyCode.KeypadTwo:
            case TCODKeyCode.KeypadThree:
            case TCODKeyCode.KeypadFour:
            case TCODKeyCode.KeypadFive:
            case TCODKeyCode.KeypadSix:
            case TCODKeyCode.KeypadSeven:
            case TCODKeyCode.KeypadEight:
            case TCODKeyCode.KeypadNine:
                keyBuffer.Enqueue(keyPress);
                break;

            case TCODKeyCode.Char:

                //switch (keyPress.Character)
                //{
                //    case 101:
                //    case 113:
                //    case 119:
                //    case 100:
                //    case 97:
                //    case 115:
                //    case 99:
                //    case 120:
                //    case 122:
                //        keyBuffer.Enqueue(keyPress);
                //        break;
                //    default:
                //        break;
                //}

                break;

            default:
                break;
            }
        }
Beispiel #25
0
 public override void KeyPressed(TCODKey keyData)
 {
     if (keyData.KeyCode == TCODKeyCode.Enter)
     {
         if (new BlockingConfirmationModal()
         {
             Foreground = Game.Settings.UiForeground,
             Background = Game.Settings.UiBackground,
             Message = "Are you sure you want to start with these characters?"
         }.Show())
         {
             Game.ChangeScene(new HomeBaseScene(Game));
         }
     }
     else if (char.ToUpper(keyData.Character) == 'R')
     {
         GenerateCharacters();
     }
 }
Beispiel #26
0
        /// <summary>
        /// Update the button based on the input mouse state
        /// </summary>
        public void Update(TCODMouseData mState, TCODKey kState)
        {
            if (mState.CellX >= origin.X && mState.CellX < origin.X + size.X &&
                mState.CellY >= origin.Y && mState.CellY < origin.Y + size.Y)
            {
                if (mState.LeftButtonPressed)
                {
                    isInFocus = true;
                }
            }
            else if (mState.LeftButtonPressed)
            {
                isInFocus = false;
            }

            if (isInFocus)
            {
                char ch = kState.Character;

                // append the character, unless it would be longer than the size of the box
                if ((ch >= 'A' && ch <= 'z' || ch == ' ') && text.Length + 1 < size.X)
                {
                    text += ch;
                }

                // do backspace to remove char
                if (kState.KeyCode == TCODKeyCode.Backspace && text.Length >= 1)
                {
                    text = text.Remove(text.Length - 1, 1);
                }
            }

            if (kState.KeyCode == TCODKeyCode.Enter)
            {
                isInFocus = false;
                enterHandler();
            }
        }
Beispiel #27
0
        public override void KeyPressed(TCODKey keyData)
        {
            switch (char.ToUpper(keyData.Character))
            {
            case 'N':
                Game.ChangeScene(new NewGameScene(Game));
                break;

            case 'L':
                new BlockingMessageModal(Game.Settings.UiForeground,
                                         Game.Settings.UiBackground, "This feature is not yet implemented.").Show();
                Game.ChangeScene(new MapGenTestScene(Game));
                break;

            case 'O':
                new BlockingMessageModal(Game.Settings.UiForeground,
                                         Game.Settings.UiBackground, "This feature is not yet implemented.").Show();
                break;

            case 'C':
                Game.ChangeScene(new CreditsScene(Game));
                break;

            case 'Q':
                var confirmQuit = new BlockingConfirmationModal()
                {
                    Foreground = Game.Settings.UiForeground,
                    Background = Game.Settings.UiBackground,
                    Message    = "Are you sure you want to quit?"
                }.Show();
                if (confirmQuit)
                {
                    Game.ChangeScene(null);
                }
                break;
            }
        }
Beispiel #28
0
        // /////////////////////////////////////////////////////////////////////////////////

        // /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Constructs a KeyboardData from specified TCODKey object
        /// </summary>
        /// <param name="tcodKeys"></param>
        public KeyboardData(TCODKey tcodKeys)
        {
            if (tcodKeys == null)
            {
                throw new ArgumentNullException("tcodKeys");
            }

            this.character  = tcodKeys.Character;
            this.keyCode    = tcodKeys.KeyCode;
            this.isKeyPress = tcodKeys.Pressed;

            int f = 0;

            if (tcodKeys.LeftAlt)
            {
                f |= (int)ControlKeys.LeftAlt;
            }
            if (tcodKeys.RightAlt)
            {
                f |= (int)ControlKeys.RightAlt;
            }
            if (tcodKeys.LeftControl)
            {
                f |= (int)ControlKeys.LeftControl;
            }
            if (tcodKeys.RightControl)
            {
                f |= (int)ControlKeys.RightControl;
            }
            if (tcodKeys.Shift)
            {
                f |= (int)ControlKeys.Shift;
            }

            this.controlKeys = (ControlKeys)f;
        }
Beispiel #29
0
        public void run(Screen tempscreen)
        {
            screen    = tempscreen;
            kbHistory = new List <KeyHistory>();

            TimeSpan startTime = DateTime.Now.TimeOfDay;
            double   timectrl  = startTime.TotalMilliseconds;
            double   timespent = 0;

            while (running && !TCODConsole.isWindowClosed())
            {
                screen.update();
                screen.printDebug();
                terminalManager.drawTerminals(debug);

                TCODConsole.flush();

                KeyHistory temp = new KeyHistory(DateTime.Now.TimeOfDay - startTime);

                TCODKey key = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);

                temp.RegisterKeyStatus(key, TCODKeyStatus.KeyPressed);

                kbHistory.Add(temp);
                screen = screen.respondToUserInput(kbHistory);

                timespent = DateTime.Now.TimeOfDay.TotalMilliseconds - timectrl;


                if (timespent > 250)
                {
                    adjustFPS();
                    timectrl = DateTime.Now.TimeOfDay.TotalMilliseconds;
                }
            }
        }
Beispiel #30
0
        void render_image(bool first, TCODKey key)
        {
            sampleConsole.clear();

            if (img == null)
            {
                img = new TCODImage("skull.png");
                circle = new TCODImage("circle.png");
            }

            if (first)
                TCODSystem.setFps(30);  /* limited to 30 fps */

            sampleConsole.setBackgroundColor(TCODColor.black);
            sampleConsole.clear();

            float x = SAMPLE_SCREEN_WIDTH / 2 + (float)Math.Cos(TCODSystem.getElapsedSeconds()) * 10.0f;
            float y = (float)(SAMPLE_SCREEN_HEIGHT / 2);
            float scalex = 0.2f + 1.8f * (1.0f + (float)Math.Cos(TCODSystem.getElapsedSeconds() / 2)) / 2.0f;
            float scaley = scalex;
            float angle = TCODSystem.getElapsedSeconds();
            uint elapsed = TCODSystem.getElapsedMilli() / 2000;

            if (elapsed > lastSwitch)
            {
                lastSwitch = elapsed;
                swap = !swap;
            }

            if (swap)
            {
                /* split the color channels of circle.png */
                /* the red channel */
                sampleConsole.setBackgroundColor(TCODColor.red);
                sampleConsole.rect(0, 3, 15, 15, false, TCODBackgroundFlag.Set);
                circle.blitRect(sampleConsole, 0, 3, -1, -1, TCODBackgroundFlag.Multiply);
                /* the green channel */
                sampleConsole.setBackgroundColor(green);
                sampleConsole.rect(15, 3, 15, 15, false, TCODBackgroundFlag.Set);
                circle.blitRect(sampleConsole, 15, 3, -1, -1, TCODBackgroundFlag.Multiply);
                /* the blue channel */
                sampleConsole.setBackgroundColor(blue);
                sampleConsole.rect(30, 3, 15, 15, false, TCODBackgroundFlag.Set);
                circle.blitRect(sampleConsole, 30, 3, -1, -1, TCODBackgroundFlag.Multiply);
            }
            else
            {
                /* render circle.png with normal blitting */
                circle.blitRect(sampleConsole, 0, 3, -1, -1, TCODBackgroundFlag.Set);
                circle.blitRect(sampleConsole, 15, 3, -1, -1, TCODBackgroundFlag.Set);
                circle.blitRect(sampleConsole, 30, 3, -1, -1, TCODBackgroundFlag.Set);
            }
            img.blit(sampleConsole, x, y, TCODCBackgroundHelpers.CreateAddAlphaBackground((float).6), scalex, scaley, angle);
        }
Beispiel #31
0
 public bool Event_Tick(TCODKey k, TCODMouseData m)
 {
     if (this == GameLoop.Game.Player)
     {
         //Player move
         Directions dir;
         if (Screens.World.PlayerDirections.TryGetValue(k.Character, out dir))
         {
             Walk(dir);
         }
         else
         {
             return false;
         }
     }
     else
     {
         this.Sleep = 10;
     }
     return true;
 }
Beispiel #32
0
        void render_bsp(bool first, TCODKey key)
        {
            int x, y;

            if (generate || refresh)
            {
                // dungeon generation
                if (bsp == null)
                {
                    // create the bsp
                    bsp = new TCODBsp(0, 0, SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT);
                }
                else
                {
                    // restore the nodes size
                    bsp.resize(0, 0, SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT);
                }

                for (int x1 = 0; x1 < SAMPLE_SCREEN_WIDTH; x1++)
                    for (int y1 = 0; y1 < SAMPLE_SCREEN_HEIGHT; y1++)
                        bsp_map[x1, y1] = '#';

                if (generate)
                {
                    // build a new random bsp tree
                    bsp.removeSons();
                    bsp.splitRecursive(null, bspDepth, minRoomSize + (roomWalls ? 1 : 0), minRoomSize + (roomWalls ? 1 : 0), 1.5f, 1.5f);
                }
                // create the dungeon from the bsp
                bsp.traverseInvertedLevelOrder(new TraverseNode());
                generate = false;
                refresh = false;
            }

            sampleConsole.clear();
            sampleConsole.setForegroundColor(TCODColor.white);
            sampleConsole.printEx(1, 1, TCODBackgroundFlag.None, TCODAlignment.LeftAlignment, "ENTER : rebuild bsp\nSPACE : rebuild dungeon\n+-: bsp depth " + bspDepth + "\n*/: room size " + minRoomSize + "\n1 : random room size " + (randomRoom ? "ON" : "OFF"));

            if (randomRoom)
                sampleConsole.printEx(1, 6, TCODBackgroundFlag.None, TCODAlignment.LeftAlignment, "2 : room walls " + (roomWalls ? "ON" : "OFF"));

            // render the level
            for (y = 0; y < SAMPLE_SCREEN_HEIGHT; y++)
            {
                for (x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
                {
                    bool wall = (bsp_map[x,y] == '#');
                    sampleConsole.setCharBackground(x, y, (wall ? darkWall : darkGround), TCODBackgroundFlag.Set);
                }
            }

            if (key.KeyCode == TCODKeyCode.Enter || key.KeyCode == TCODKeyCode.KeypadEnter)
            {
                generate = true;
            }
            else if (key.Character == ' ')
            {
                refresh = true;
            }
            else if (key.Character == '+')
            {
                bspDepth++;
                generate = true;
            }
            else if (key.Character == '-' && bspDepth > 1)
            {
                bspDepth--;
                generate = true;
            }
            else if (key.Character == '*')
            {
                minRoomSize++;
                generate = true;
            }
            else if (key.Character == '/' && minRoomSize > 2)
            {
                minRoomSize--;
                generate = true;
            }
            else if (key.Character == '1' || key.KeyCode == TCODKeyCode.One || key.KeyCode == TCODKeyCode.KeypadOne)
            {
                randomRoom = !randomRoom;
                if (!randomRoom) roomWalls = true;
                refresh = true;
            }
            else if (key.Character == '2' || key.KeyCode == TCODKeyCode.Two || key.KeyCode == TCODKeyCode.KeypadTwo)
            {
                roomWalls = !roomWalls;
                refresh = true;
            }
        }
Beispiel #33
0
 public override void Update(TCODKey k, TCODMouseData m)
 {
     //GameLogic stuff here
     GameLoop.Game.world.Update(k, m);
 }
Beispiel #34
0
        public void KeyPress(TCODKey key)
        {
            Game game = Game.GetSingleton();
            if (key.KeyCode == TCODKeyCode.Char)
            {
                if (key.Character != '`')
                {
                    if (consoleActive == true)
                    {
                        AddToInput(key.Character);
                    }
                }
                else
                {
                    consoleActive = !consoleActive;
                    game.lua["native.console"] = consoleActive;
                }
            }
            else if (key.KeyCode == TCODKeyCode.Space)
            {
                if (consoleActive == true)
                {
                    AddToInput(' ');
                }
            }
            else if (key.KeyCode == TCODKeyCode.Backspace)
            {
                if (consoleActive == true)
                {
                    if (ConsoleInput.Length > 0)
                    {
                        string stemp = ConsoleInput.Substring(0, Position - 1);
                        if (Position < ConsoleInput.Length)
                        {
                            ConsoleInput = stemp + ConsoleInput.Substring(Position, ConsoleInput.Length - Position);
                        }
                        else
                        {
                            ConsoleInput = stemp;
                        }
                        Position--;
                    }
                }
            }
            else if (key.KeyCode == TCODKeyCode.Delete)
            {
                if (consoleActive == true)
                {
                    if (ConsoleInput.Length > 0 && Position < ConsoleInput.Length)
                    {
                        ConsoleInput = ConsoleInput.Remove(Position, 1);
                    }
                }
            }
            else if (key.KeyCode == TCODKeyCode.Enter & key.Shift == false)
            {
                if (consoleActive == true)
                {
                    try
                    {
                        if (TotalInput == "")
                        {
                            WriteLine('>' + ConsoleInput, TCODColor.lightGrey);
                            game.lua.DoString(ConsoleInput);
                        }
                        else
                        {
                            TotalInput += ConsoleInput + Environment.NewLine;
                            WriteLine("<->" + ConsoleInput, TCODColor.lightestPurple);
                            game.lua.DoString(TotalInput);
                            TotalInput = "";
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLine(ex.Message, TCODColor.red);
                    }
                    if (lastLines.Count > 0)
                    {
                        if (lastLines[lastLines.Count - 1] != ConsoleInput)
                        {
                            lastLines.Add(ConsoleInput);
                        }
                    }
                    else
                    {
                        lastLines.Add(ConsoleInput);
                    }
                    CurrentLine = lastLines.Count;
                    ConsoleInput = "";
                    Position = 0;
                }
            }
            else if (key.KeyCode == TCODKeyCode.Down)
            {
                if (CurrentLine < lastLines.Count - 1)
                {
                    CurrentLine++;
                    ConsoleInput = lastLines[CurrentLine];
                    Position = ConsoleInput.Length;
                }
            }
            else if (key.KeyCode == TCODKeyCode.Up)
            {
                if (CurrentLine > 0)
                {
                    CurrentLine--;
                    ConsoleInput = lastLines[CurrentLine];
                    Position = ConsoleInput.Length;
                }
            }
            else if (key.KeyCode == TCODKeyCode.Left)
            {
                if (Position > 0)
                {
                    Position--;
                }
            }
            else if (key.KeyCode == TCODKeyCode.Right)
            {
                if (Position < ConsoleInput.Length)
                {
                    Position++;
                }
            }
            else if (key.KeyCode == TCODKeyCode.Home)
            {
                Position = 0;
            }
            else if (key.KeyCode == TCODKeyCode.End)
            {
                Position = ConsoleInput.Length;
            }
            else
            {
                if (consoleActive)
                {
                    if (key.Shift)
                    {
                        switch (key.KeyCode)
                        {
                            case TCODKeyCode.One:
                                AddToInput('!');
                                break;
                            case TCODKeyCode.Two:
                                AddToInput('@');
                                break;
                            case TCODKeyCode.Three:
                                AddToInput('#');
                                break;
                            case TCODKeyCode.Four:
                                AddToInput('$');
                                break;
                            case TCODKeyCode.Six:
                                AddToInput('^');
                                break;
                            case TCODKeyCode.Seven:
                                AddToInput('&');
                                break;
                            case TCODKeyCode.Eight:
                                AddToInput('*');
                                break;
                            case TCODKeyCode.Nine:
                                AddToInput('(');
                                break;
                            case TCODKeyCode.Zero:
                                AddToInput(')');
                                break;
                            default:
                                break;
                        }
                    }
                    else
                    {
                        switch (key.KeyCode)
                        {
                            case TCODKeyCode.One:
                                AddToInput('1');
                                break;
                            case TCODKeyCode.Two:
                                AddToInput('2');
                                break;
                            case TCODKeyCode.Three:
                                AddToInput('3');
                                break;
                            case TCODKeyCode.Four:
                                AddToInput('4');
                                break;
                            case TCODKeyCode.Five:
                                AddToInput('5');
                                break;
                            case TCODKeyCode.Six:
                                AddToInput('6');
                                break;
                            case TCODKeyCode.Seven:
                                AddToInput('7');
                                break;
                            case TCODKeyCode.Eight:
                                AddToInput('8');
                                break;
                            case TCODKeyCode.Nine:
                                AddToInput('9');
                                break;
                            case TCODKeyCode.Zero:
                                AddToInput('0');
                                break;
                            default:
                                break;
                        }
                    }
                }
            }

            if (key.Shift && key.KeyCode == TCODKeyCode.Enter)
            {
                if (consoleActive && ConsoleInput.Length > 0)
                {
                    TotalInput += ConsoleInput + Environment.NewLine;
                    WriteLine("<->" + ConsoleInput, TCODColor.lightestPurple);
                    ConsoleInput = "";
                    Position = 0;
                }
            }
        }
Beispiel #35
0
        void render_name(bool first, TCODKey key)
        {
            if (names.Count == 0)
            {
                foreach (string filename in System.IO.Directory.GetFiles("Names"))
                {
                    TCODNameGenerator.parse(filename);
                }
                sets = TCODNameGenerator.getSets().ToList();
                nbSets = sets.Count;
            }
            if (first)
                TCODSystem.setFps(30);

            while (names.Count >= 15)
            {
                string nameToRemove = names[0];
                names.RemoveAt(0);
            }
            sampleConsole.clear();
            sampleConsole.setForegroundColor(TCODColor.white);
            sampleConsole.printEx(1, 1, TCODBackgroundFlag.None, TCODAlignment.LeftAlignment, string.Format("{0}\n\n+ : next generator\n- : prev generator", sets[curSet]));

            for (int i = 0; i < names.Count; ++i)
            {
                string name = names[i];
                if (name.Length < SAMPLE_SCREEN_WIDTH)
                    sampleConsole.printEx(SAMPLE_SCREEN_WIDTH - 2, 2 + i, TCODBackgroundFlag.None, TCODAlignment.RightAlignment, name);
            }

            delay += TCODSystem.getLastFrameLength();
            if (delay >= .5f)
            {
                delay -= .5f;
                names.Add(TCODNameGenerator.generate(sets[curSet]));
            }
            if (key.Character == '+')
            {
                curSet++;
                if (curSet == nbSets)
                    curSet = 0;
                names.Add("======");
            }
            if (key.Character == '-')
            {
                curSet--;
                if (curSet < 0)
                    curSet = nbSets-1;
                names.Add("======");
            }
        }
Beispiel #36
0
        public void Update(TCODKey k, TCODMouseData m)
        {
            List<Position> unload = new List<Position>();
            SortedList<long, Entitys.Entity> entitys = new SortedList<long,Entitys.Entity>();
            long sleep_lowest = 1;
            bool tick_unlocked = true;

            //Update loaded chunks
            foreach (KeyValuePair<Position, Chunk> kv in LoadedChunks)
            {
                kv.Value.Update();

                //If timed out add to unload list
                if (kv.Value.Idle > Chunk.Timeout)
                {
                    unload.Add(kv.Key);
                }
            }

            //Unload chunks
            foreach (Position p in unload)
            {
                LoadedChunks[p].SaveToFile();
                LoadedChunks.Remove(p);
            }

            //Tick next entity
            foreach (KeyValuePair<Position, Chunk> kv in LoadedChunks)
            {
                foreach (Entitys.Entity e in kv.Value.Entitys)
                {
                    entitys.Add(e.Sleep, e);
                }
            }
            if (entitys.Count > 0)
            {
                sleep_lowest = entitys.Values[0].Sleep;
                tick_unlocked = entitys.Values[0].Event_Tick(k, m);
            }
            if (tick_unlocked)
            {
                foreach (KeyValuePair<long, Entitys.Entity> kv in entitys)
                {
                    kv.Value.Sleep -= sleep_lowest;
                }
                Turns_Total += sleep_lowest;
            }
        }
Beispiel #37
0
 public virtual void KeyPressed(TCODKey keyData)
 {
 }
Beispiel #38
0
 private void HandleCharacterInTextbox(TCODKey key)
 {
     if (m_cursorPosition == -1)
     {
         if (m_fileInput.Length < TextEntryLength)
         {
             bool validCharacter = !(((char)key.Character).ToString().IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) != -1);
             if (validCharacter)
                 m_fileInput = m_fileInput + (char)key.Character;
         }
     }
 }
Beispiel #39
0
        public int Run(string[] args)
        {
            fillSampleList();

            int curSample = 0; // index of the current sample
            bool first = true; // first time we render a sample
            TCODKey key = new TCODKey();
            string font = "celtic_garamond_10x10_gs_tc.png";
            int numberCharsHorz = 32;
            int numberCharsVert = 8;
            int fullscreenWidth = 0;
            int fullscreenHeight = 0;
            bool fullscreen = false;
            bool credits = false;
            TCODFontFlags flags = TCODFontFlags.Grayscale | TCODFontFlags.LayoutTCOD;
            TCODFontFlags newFlags = 0;

            for (int i = 1; i < args.Length; i++)
            {
                if (args[i] == "-font" && ArgsRemaining(args, i, 1))
                {
                    i++;
                    font = args[i];
                }
                else if (args[i] == "-font-char-numberRows" && ArgsRemaining(args, i, 2))
                {
                    i++;
                    numberCharsHorz = System.Convert.ToInt32(args[i]);
                    i++;
                    numberCharsVert = System.Convert.ToInt32(args[i]);
                }
                else if (args[i] == "-fullscreen-resolution" && ArgsRemaining(args, i, 2))
                {
                    i++;
                    fullscreenWidth = System.Convert.ToInt32(args[i]);
                    i++;
                    fullscreenHeight = System.Convert.ToInt32(args[i]);
                }
                else if (args[i] == "-fullscreen")
                {
                    fullscreen = true;
                }
                else if (args[i] == "-font-in-row")
                {
                    flags = 0;
                    newFlags |= TCODFontFlags.LayoutAsciiInRow;
                }
                else if (args[i] == "-font-greyscale")
                {
                    flags = 0;
                    newFlags |= TCODFontFlags.Grayscale;
                }
                else if (args[i] == "-font-tcod")
                {
                    flags = 0;
                    newFlags |= TCODFontFlags.LayoutTCOD;
                }
                else if (args[i] == "-help")
                {
                    System.Console.Out.WriteLine("options : \n");
                    System.Console.Out.WriteLine("-font <filename> : use a custom font\n");
                    System.Console.Out.WriteLine("-font-char-size <char_width> <char_height> : size of the custom font's characters\n");
                    System.Console.Out.WriteLine("-font-in-row : the font layout is in row instead of columns\n");
                    System.Console.Out.WriteLine("-font-tcod : the font uses TCOD layout instead of ASCII\n");
                    System.Console.Out.WriteLine("-font-greyscale : antialiased font using greyscale bitmap\n");
                    System.Console.Out.WriteLine("-fullscreen : start in fullscreen\n");
                    System.Console.Out.WriteLine("-fullscreen-resolution <screen_width> <screen_height> : force fullscreen resolution\n");
                    return 0;
                }
            }
            if (flags == 0)
                flags = newFlags;

            if (fullscreenWidth > 0)
                TCODSystem.forceFullscreenResolution(fullscreenWidth, fullscreenHeight);

            TCODConsole.setCustomFont(font, (int)flags, numberCharsHorz, numberCharsVert);
            TCODConsole.initRoot(80, 50, "tcodlib C# sample", fullscreen, TCODRendererType.SDL);
            rootConsole = TCODConsole.root;
            sampleConsole = new TCODConsole(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT);

            setupStaticData();
            rootConsole.setBackgroundFlag(TCODBackgroundFlag.Set);
            rootConsole.setAlignment(TCODAlignment.LeftAlignment);
            do
            {
                rootConsole.clear();
                if (!credits)
                    credits = TCODConsole.renderCredits(60, 42, false);
                for (int i = 0; i < sampleList.Length; i++)
                {
                    if (i == curSample)
                    {
                        // set colors for currently selected sample
                        rootConsole.setForegroundColor(TCODColor.white);
                        rootConsole.setBackgroundColor(TCODColor.blue);
                    }
                    else
                    {
                        // set colors for other samples
                        rootConsole.setForegroundColor(TCODColor.grey);
                        rootConsole.setBackgroundColor(TCODColor.black);
                    }
                    rootConsole.print(2, 45 - sampleList.Length + i, sampleList[i].name);
                }
                rootConsole.setForegroundColor(TCODColor.grey);
                rootConsole.setBackgroundColor(TCODColor.black);
                rootConsole.printEx(79, 46, TCODBackgroundFlag.Set, TCODAlignment.RightAlignment, "last frame : " + ((int)(TCODSystem.getLastFrameLength() * 1000)).ToString() + " ms ( " + TCODSystem.getFps() + "fps)");
                rootConsole.printEx(79, 47, TCODBackgroundFlag.Set, TCODAlignment.RightAlignment, "elapsed : " + TCODSystem.getElapsedMilli() + "ms " + (TCODSystem.getElapsedSeconds().ToString("0.00")) + "s");
                rootConsole.putChar(2, 47, (char)TCODSpecialCharacter.ArrowNorth);
                rootConsole.putChar(3, 47, (char)TCODSpecialCharacter.ArrowSouth);
                rootConsole.print(4, 47, " : select a sample");
                rootConsole.print(2, 48, "ALT-ENTER : switch to " + (TCODConsole.isFullscreen() ? "windowed mode  " : "fullscreen mode"));

                sampleList[curSample].render(first, key);
                first = false;

                TCODConsole.blit(sampleConsole, 0, 0, SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT, rootConsole, SAMPLE_SCREEN_X, SAMPLE_SCREEN_Y);

                TCODConsole.flush();
                key = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);

                if (key.KeyCode == TCODKeyCode.Down)
                {
                    // down arrow : next sample
                    curSample = (curSample + 1) % sampleList.Length;
                    first = true;
                }
                else if (key.KeyCode == TCODKeyCode.Up)
                {
                    // up arrow : previous sample
                    curSample--;
                    if (curSample < 0)
                        curSample = sampleList.Length - 1;
                    first = true;
                }
                else if (key.KeyCode == TCODKeyCode.Enter && (key.LeftAlt || key.RightAlt))
                {
                    // ALT-ENTER : switch fullscreen
                    TCODConsole.setFullscreen(!TCODConsole.isFullscreen());
                }
                else if (key.KeyCode == TCODKeyCode.F1)
                {
                    System.Console.Out.WriteLine("key.pressed" + " " +
                        key.LeftAlt + " " + key.LeftControl + " " + key.RightAlt +
                        " " + key.RightControl + " " + key.Shift);
                }

            }
            while (!TCODConsole.isWindowClosed());
            return 0;
        }
Beispiel #40
0
 private static bool IsKeyCodeOfCharacter(TCODKey k)
 {
     return k.KeyCode == TCODKeyCode.Char || k.KeyCode == TCODKeyCode.Zero || k.KeyCode == TCODKeyCode.One
         || k.KeyCode == TCODKeyCode.Two || k.KeyCode == TCODKeyCode.Three || k.KeyCode == TCODKeyCode.Four
         || k.KeyCode == TCODKeyCode.Five || k.KeyCode == TCODKeyCode.Six || k.KeyCode == TCODKeyCode.Seven
         || k.KeyCode == TCODKeyCode.Eight || k.KeyCode == TCODKeyCode.Nine;
 }
Beispiel #41
0
        public bool HandleKeyPress(TCODKey key)
        {
            bool endTurn = false;
            #region switch (key.KeyCode)
            switch (key.KeyCode)
            {
                case TCODKeyCode.KeypadZero:
                    break;
                case TCODKeyCode.KeypadOne:
                    _player.Move(-1, 1);
                    endTurn = true;
                    break;
                case TCODKeyCode.KeypadTwo:
                    _player.Move(0, 1);
                    endTurn = true;
                    break;
                case TCODKeyCode.KeypadThree:
                    _player.Move(1, 1);
                    endTurn = true;
                    break;
                case TCODKeyCode.KeypadFour:
                    _player.Move(-1, 0);
                    endTurn = true;
                    break;
                case TCODKeyCode.KeypadFive:
                    endTurn = true;
                    break;
                case TCODKeyCode.KeypadSix:
                    _player.Move(1, 0);
                    endTurn = true;
                    break;
                case TCODKeyCode.KeypadSeven:
                    _player.Move(-1, -1);
                    endTurn = true;
                    break;
                case TCODKeyCode.KeypadEight:
                    _player.Move(0, -1);
                    endTurn = true;
                    break;
                case TCODKeyCode.KeypadNine:
                    _player.Move(1, -1);
                    endTurn = true;
                    break;
                case TCODKeyCode.KeypadAdd:
                    break;
                case TCODKeyCode.KeypadSubtract:
                    break;
                case TCODKeyCode.KeypadMultiply:
                    break;
                case TCODKeyCode.KeypadDivide:
                    break;
                case TCODKeyCode.KeypadEnter:
                    break;
                case TCODKeyCode.KeypadDecimal:
                    endTurn = true;
                    break;
                case TCODKeyCode.Left:
                    _player.Move(-1, 0);
                    endTurn = true;
                    break;
                case TCODKeyCode.Right:
                    _player.Move(1, 0);
                    endTurn = true;
                    break;
                case TCODKeyCode.Up:
                    _player.Move(0, -1);
                    endTurn = true;
                    break;
                case TCODKeyCode.Down:
                    _player.Move(0, 1);
                    endTurn = true;
                    break;
                case TCODKeyCode.Alt:
                    break;
                case TCODKeyCode.Apps:
                    break;
                case TCODKeyCode.Backspace:
                    break;
                case TCODKeyCode.Capslock:
                    break;
                case TCODKeyCode.Char:
                    break;
                case TCODKeyCode.Control:
                    break;
                case TCODKeyCode.Delete:
                    break;
                case TCODKeyCode.Eight:
                    break;
                case TCODKeyCode.End:
                    break;
                case TCODKeyCode.Enter:
                    break;
                case TCODKeyCode.Escape:
                    Exit = true;
                    break;
                case TCODKeyCode.F1:
                    break;
                case TCODKeyCode.F2:
                    break;
                case TCODKeyCode.F3:
                    break;
                case TCODKeyCode.F4:
                    break;
                case TCODKeyCode.F5:
                    break;
                case TCODKeyCode.F6:
                    break;
                case TCODKeyCode.F7:
                    break;
                case TCODKeyCode.F8:
                    break;
                case TCODKeyCode.F9:
                    break;
                case TCODKeyCode.F10:
                    break;
                case TCODKeyCode.F11:
                    break;
                case TCODKeyCode.F12:
                    break;
                case TCODKeyCode.Five:
                    break;
                case TCODKeyCode.Four:
                    break;
                case TCODKeyCode.Home:
                    break;
                case TCODKeyCode.Insert:
                    break;
                case TCODKeyCode.Lwin:
                    break;
                case TCODKeyCode.Nine:
                    break;
                case TCODKeyCode.NoKey:
                    break;
                case TCODKeyCode.Numlock:
                    break;
                case TCODKeyCode.One:
                    break;
                case TCODKeyCode.Pagedown:
                    break;
                case TCODKeyCode.Pageup:
                    break;
                case TCODKeyCode.Pause:
                    break;
                case TCODKeyCode.Printscreen:
                    break;
                case TCODKeyCode.Rwin:
                    break;
                case TCODKeyCode.Scrolllock:
                    break;
                case TCODKeyCode.Seven:
                    break;
                case TCODKeyCode.Shift:
                    break;
                case TCODKeyCode.Six:
                    break;
                case TCODKeyCode.Space:
                    break;
                case TCODKeyCode.Tab:
                    break;
                case TCODKeyCode.Three:
                    break;
                case TCODKeyCode.Two:
                    break;
                case TCODKeyCode.Zero:
                    break;
            }
            #endregion

            #region switch (key.Character)
            switch (key.Character)
            {
                #region Movement
                case 'h':
                    _player.Move(-1, 0);
                    endTurn = true;
                    break;
                case 'j':
                    _player.Move(0, 1);
                    endTurn = true;
                    break;
                case 'k':
                    _player.Move(0, -1);
                    endTurn = true;
                    break;
                case 'l':
                    _player.Move(1, 0);
                    endTurn = true;
                    break;
                case 'y':
                    _player.Move(-1, -1);
                    endTurn = true;
                    break;
                case 'u':
                    _player.Move(1, -1);
                    endTurn = true;
                    break;
                case 'b':
                    _player.Move(-1, 1);
                    endTurn = true;
                    break;
                case 'n':
                    _player.Move(1, 1);
                    endTurn = true;
                    break;
                case '.':
                    endTurn = true;
                    break;
                #endregion
                case 'd':
                    _player.Inventory.Draw(_root);
                    TCODConsole.flush();
                    key = TCODConsole.waitForKeypress(true);
                    Item i = _player.Inventory.GetAtLetter(key.Character);
                    _player.Inventory.RemoveAtLetter(key.Character, 1);
                    if (i != null)
                    {
                        i.Drop(_player.PosX, _player.PosY, Map);
                    }
                    break;
                case 'g':
                    foreach (Item item in Map.GetItemsAt(_player.PosX, _player.PosY))
                    {
                        item.Get();
                        _player.Inventory.Add(item);
                    }
                    endTurn = true;
                    break;
                case 'i':
                    _player.Inventory.Draw(_root);
                    TCODConsole.flush();
                    TCODConsole.waitForKeypress(true);
                    break;
                case 'e':
                    _player.Inventory.Draw(_root);
                    TCODConsole.flush();
                    key = TCODConsole.waitForKeypress(true);
                    i = _player.Inventory.GetAtLetter(key.Character);
                    if (i != null)
                    {
                        _player.Equip(i);
                    }
                    endTurn = true;
                    break;
                case 'r':
                    _player.Inventory.Draw(_root);
                    TCODConsole.flush();
                    key = TCODConsole.waitForKeypress(true);
                    i = _player.Inventory.GetAtLetter(key.Character);
                    if (i != null)
                    {
                        i.Use();
                        _player.Inventory.RemoveAllAtLetter(key.Character);
                        endTurn = true;
                    }
                    break;
                case '>':
                    if (_player.PosX == Map.Stair.PosX && _player.PosY == Map.Stair.PosY)
                    {
                        _dungeon.GoToMap(_dungeon.CurrentDepth + 1, _player);
                        for (int n = Map.CurrentMonsterNum; n < Map.MaxMonster; n++)
                        {
                            AddMonster(Map);
                        }
                    }
                    break;
                case '<':
                    if (_player.PosX == Map.StartPosX && _player.PosY == Map.StartPosY)
                    {
                        if (_dungeon.CurrentDepth != 1)
                            _dungeon.GoToMap(_dungeon.CurrentDepth - 1, _player);
                        else
                        {
                            Messages.AddMessage("If you go up, you'll exit the Dungeon. Are you sure?");
                            key = TCODConsole.waitForKeypress(true);
                            if (key.Character == 'Y')
                                Exit = true;
                            else if (key.Character != 'N')
                                Messages.AddMessage("Y or N only");
                        }
                    }
                    break;
                #region Debug
                case 'w':
                    ShowWall = !ShowWall;
                    break;
                case 'a':
                    MonsterAI = !MonsterAI;
                    break;
                case 'z':
                    MonsterDamage = !MonsterDamage;
                    break;
                case 'q':
                    InfiniteTorch = !InfiniteTorch;
                    break;

                    #endregion
            }
            #endregion
            return endTurn;
        }
 // Name: doAction
 // Description: If this is an AI controlled monster, invoke the AI. If
 //              it is a player controlled monster, allow the player to
 //              make his action
 public void doAction()
 {
     if ( !isFlagSet(AttributeFlags.isPlayer) )
     {
     }
     else
     {
         // This is temp code for keyboard input on the player's turn.
         // It most certainly does not belong here in its entirety, and
         // should probably be delegated to a dedicated class
         // ALSO THIS IMPLEMENTATION IS DISGUSTING JUST SAYING
         key = TCODConsole.waitForKeypress(true);
         if (key.KeyCode == TCODKeyCode.Down)
         {
             yCoord =
                 isWalkable(
                 monsterLayer.dungeonLevel.dungeonLayer.getTile(
                 xCoord, (short)(yCoord + 1) ) ) ? (short)(yCoord + 1) :
                 yCoord;
         }
         else if (key.KeyCode == TCODKeyCode.Up)
         {
             yCoord =
                 isWalkable(
                 monsterLayer.dungeonLevel.dungeonLayer.getTile(
                 xCoord, (short)(yCoord - 1))) ? (short)(yCoord - 1) :
                 yCoord;
         }
         else if (key.KeyCode == TCODKeyCode.Right)
         {
             xCoord =
                 isWalkable(
                 monsterLayer.dungeonLevel.dungeonLayer.getTile(
                 (short)(xCoord + 1), yCoord)) ? (short)(xCoord + 1) :
                 xCoord;
         }
         else if (key.KeyCode == TCODKeyCode.Left)
         {
             xCoord =
                 isWalkable(
                 monsterLayer.dungeonLevel.dungeonLayer.getTile(
                 (short)(xCoord - 1), yCoord )) ? (short)(xCoord - 1) :
                 xCoord;
         }
     }
 }
Beispiel #43
0
        public bool HandleInput(TCODKey key)
        {
            #region "Player Input"
            //tar_y = player.Y;
            //tar_x = player.X;
            //tar_z = player.Z;
            tar_x = 0;
            tar_y = 0;
            tar_z = 0;

            switch (key.KeyCode)
            {
                //MOVEMENT
                case TCODKeyCode.KeypadEight:
                    tar_y = - 1;
                    return true;
                case TCODKeyCode.KeypadSix:
                    tar_x =  1;
                    return true;
                case TCODKeyCode.KeypadTwo:
                    tar_y = 1;
                    return true;
                case TCODKeyCode.KeypadFour:
                    tar_x = - 1;
                    return true;
                case TCODKeyCode.KeypadNine:
                    tar_y =  - 1;
                    tar_x =  + 1;
                    return true;
                case TCODKeyCode.KeypadThree:
                    tar_y =  + 1;
                    tar_x =  + 1;
                    return true;
                case TCODKeyCode.KeypadOne:
                    tar_y =  + 1;
                    tar_x =  - 1;
                    return true;
                case TCODKeyCode.KeypadSeven:
                    tar_y =  - 1;
                    tar_x =  - 1;
                    return true;
                case TCODKeyCode.KeypadFive:
                    return true;

                //SELECTION
                case TCODKeyCode.KeypadAdd:
                    menu_selection++;
                    return true;
                case TCODKeyCode.KeypadSubtract:
                    menu_selection--;
                    return true;
                case TCODKeyCode.KeypadEnter:
                    lock_cursor = true;
                    return true;

            }

            switch (key.Character)
            {
                case '<':
                    tar_z = player.Z - 1;
                    return true;
                case '>':
                    tar_z = player.Z + 1;
                    return true;

                case 't':
                    player_pickup = true;
                    return true;
                case 'e':
                    if (mdm == MainDisplayMode.Inventory)
                    {
                        player_equip = true;
                        return true;
                    }
                    return false;
                case 'u':
                    if (mdm == MainDisplayMode.Inventory)
                    {
                        player_unequip = true;
                        return true;
                    }
                    return false;
                case 'a':
                    if (mdm == MainDisplayMode.Game)
                    {
                        player_attack_ranged = true;
                    }
                    return true;
            }

            #endregion

            if (key.Character == 'i')
            {
                mdm = MainDisplayMode.Inventory;
                menu_selection = 0;
                return true;
            }

            if (key.Character == 'c')
            {
                Item i = (Item)Select(SelectionMode.Item);
                //Creature c = (Creature)Select(SelectionMode.Creature);
                return false;
            }

            if (key.Character == 'q')
            {
                mdm = MainDisplayMode.Game;
                CancelDialog();
            }

            if (key.KeyCode == TCODKeyCode.F1)
            {
                tar_x = 1300;
                tar_y = 1300;
                tar_z = map.DropObject(1300, 1300, 49);
                return true;
            }

            if (key.KeyCode == TCODKeyCode.F2)
            {
                tar_x = 1300;
                tar_y = 1300;
                tar_z = map.DropObject(1300, 1300, 31);
                return true;
            }

            if (key.KeyCode == TCODKeyCode.F4)
            {
                map.AddItem((Item)player.Body.SeverRandomBodyPart());
            }

            if (key.KeyCode == TCODKeyCode.F5)
            {
                //DisplayDialog("This is a test message.Dabei wird in Deutschland die Maßeinheit cm zugrunde gelegt, während in Amerika und England die Maßeinheit inch (1 inch = 2,54 cm) für die Hemdgrößen von Herren verwendet wird. Zusätzlich wird die Ärmellänge im Handel gegebenenfalls mit Kurzarm oder Langarm angegeben, jedoch kann dabei die genaue Länge je nach Hersteller unterschiedlich ausfallen. Meist haben dann bei den Herrenhemden zwei aufeinander folgende Hemdgrößen (z.B. 39/40) den gleichen Schnitt des Oberkörpers.");
                SortedDictionary<char, string> test = new SortedDictionary<char, string>();
                test.Add('a', "Test item A");
                test.Add('b', "Test item B");
                test.Add('c', "Test item C");
                Out.SendDebugMessage("Response: " + DisplayInputDialog("Choose one test item. Press q to abort.", test));
            }

            if (key.KeyCode == TCODKeyCode.F6)
            {
                DisplayDialog(player.Body.MakeDescription());
            }

            if (key.KeyCode == TCODKeyCode.F9)
            {
                DisplayDialog(map.ComposeLookAt(player.X, player.Y, player.Z));
            }

            if (key.Character == 'l')
            {
                map.TEST_CIE = map.TEST_CIE ? false : true;
            }

            if (key.KeyCode == TCODKeyCode.F11)
            {
                List<LightSource> templ = new List<LightSource>();

                foreach (Item i in map.ItemList.GetValues())
                {
                    if (i.GetType() == typeof(LightSource))
                    {
                        LightSource l = (LightSource)i;
                        //l.SetPosition(l.X, l.Y, l.Z);
                        //l.SetLevel((byte)(l.LightRadius - 1));
                        l.SetRecalculate(true);
                        templ.Add(l);
                    }

                }

                foreach (LightSource ls in templ)
                {
                    map.ItemList.Remove(ls.GUID);
                    map.ItemList.Add(ls);
                }
            }

            if (key.KeyCode == TCODKeyCode.F12)
            {
                GC.Collect();
                return true;
            }

            if (key.KeyCode == TCODKeyCode.Escape)
            {
                endGame = true;
                return true;
            }
            if (key.KeyCode != TCODKeyCode.NoKey)
            {
                TCODConsole.root.print(0, 0, key.Character.ToString());
                TCODConsole.root.print(0, 1, key.KeyCode.ToString());
                return false;
            }

            return false;
        }
Beispiel #44
0
 public void EvaluateKeyPress(TCODKey keyStroke)
 {
     AddKeyPressToBuffer(keyStroke);
     ProcessKeyPressBuffer();
 }
Beispiel #45
0
        void render_offscreen(bool first, TCODKey key)
        {
            if (!off_init)
            {
                off_init = true;
                off_secondary.printFrame(0, 0, SAMPLE_SCREEN_WIDTH / 2, SAMPLE_SCREEN_HEIGHT / 2, false, TCODBackgroundFlag.Set, "Offscreen console");
                off_secondary.printRectEx(SAMPLE_SCREEN_WIDTH / 4, 2, SAMPLE_SCREEN_WIDTH / 2 - 2, SAMPLE_SCREEN_HEIGHT / 2, TCODBackgroundFlag.None, TCODAlignment.CenterAlignment, "You can render to an offscreen console and blit in on another one, simulating alpha transparency.");

            }
            if (first)
            {
                TCODSystem.setFps(30); // fps limited to 30
                // get a "screenshot" of the current sample screen
                TCODConsole.blit(sampleConsole, 0, 0, SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT, off_screenshot, 0, 0);
            }
            off_counter++;
            if (off_counter % 20 == 0)
            {
                // move the secondary screen every 2 seconds
                off_x += off_xdir;
                off_y += off_ydir;
                if (off_x == (SAMPLE_SCREEN_WIDTH / 2) + 5)
                    off_xdir = -1;
                else if (off_x == -5)
                    off_xdir = 1;
                if (off_y == (SAMPLE_SCREEN_HEIGHT / 2) + 5)
                    off_ydir = -1;
                else if (off_y == -5)
                    off_ydir = 1;
            }

            // restore the initial screen
            TCODConsole.blit(off_screenshot, 0, 0, SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT, sampleConsole, 0, 0);

            // blit the overlapping screen
            TCODConsole.blit(off_secondary, 0, 0, SAMPLE_SCREEN_WIDTH / 2, SAMPLE_SCREEN_HEIGHT / 2, sampleConsole, off_x, off_y, 1.0f, .75f);
        }
Beispiel #46
0
 public virtual void KeyReleased(TCODKey keyData)
 {
 }
Beispiel #47
0
 public virtual void KeyReleased(TCODKey keyData)
 {
 }
Beispiel #48
0
 public override void KeyPressed(TCODKey keyData)
 {
     currentDelay = 0.0f;
 }
Beispiel #49
0
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (CurrentDomain_UnhandledException);
            TCODColor fogOfWarColour = new TCODColor(80, 80, 80);

            int horizontalPixels, verticalPixels;

            TCODSystem.getCurrentResolution(out horizontalPixels, out verticalPixels);

            //string font = "celtic_garamond_10x10_gs_tc.png";
            string font = "arial12x12.png";

            TCODConsole.setCustomFont(
                font,
                (int)(TCODFontFlags.Grayscale | TCODFontFlags.LayoutTCOD),
                32,
                8);

            int fontWidth, fontHeight;

            TCODSystem.getCharSize(out fontWidth, out fontHeight);

            int screenWidth  = horizontalPixels / fontWidth;
            int screenHeight = verticalPixels / fontHeight;



            var screenBounds = new Rectangle(0, 0, screenWidth,
                                             screenHeight);

            int infoPanelWidth = 42;
            var playBounds     = new Rectangle(0, 0, screenBounds.Width - infoPanelWidth, screenBounds.Height);
            var playerBounds   = new Rectangle(playBounds.Right, 0, infoPanelWidth, 6);
            //var threatBounds = new Rectangle(playBounds.Right, playerBounds.Bottom, infoPanelWidth, 10);
            var competitorBounds = new Rectangle(playBounds.Right, playerBounds.Bottom, infoPanelWidth, 27);
            var eventBounds      = new Rectangle(playBounds.Right, competitorBounds.Bottom, infoPanelWidth,
                                                 screenBounds.Height -
                                                 (playerBounds.Height + competitorBounds.Height));

            Game game = CreateGame();

            Logger.Info("Initializing RootConsole...");

            TCODConsole.initRoot(screenBounds.Width, screenBounds.Height, "Last Man Standing v1.0", true, TCODRendererType.SDL);

            TCODSystem.setFps(30);
            var rootConsole = TCODConsole.root;

            rootConsole.setForegroundColor(ColorPresets.White);
            rootConsole.setAlignment(TCODAlignment.LeftAlignment);
            rootConsole.setBackgroundFlag(TCODBackgroundFlag.Set);

            Logger.Info("Initializing playConsole...");
            TCODConsole playConsole = new TCODConsole(playBounds.Width, playBounds.Height);

            //Logger.Info("Initializing threatConsole...");
            //Console threatConsole = RootConsole.GetNewConsole(threatBounds.Width, threatBounds.Height);
            Logger.Info("Initializing playerConsole...");
            TCODConsole playerConsole = new TCODConsole(playerBounds.Width, playerBounds.Height);

            Logger.Info("Initializing competitorConsole...");
            TCODConsole competitorConsole = new TCODConsole(competitorBounds.Width, competitorBounds.Height);

            Logger.Info("Initializing eventsConsole...");
            TCODConsole eventsConsole = new TCODConsole(eventBounds.Width, eventBounds.Height);

            Logger.Info("Starting Game Loop...");
            do
            {
                TCODKey keyStroke = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed);

                if (game.IsActive)
                {
                    game.ProcessTurn();

                    if (keyStroke.KeyCode != TCODKeyCode.NoKey)
                    {
                        ((PlayerAI)game.Player.Intellect).EvaluateKeyPress(keyStroke);
                    }
                }

                RenderAllConsoles(game, rootConsole, playConsole, fogOfWarColour, playerConsole,
                                  competitorConsole, eventsConsole, playBounds, playerBounds,
                                  competitorBounds, eventBounds);

                if (!game.IsActive)
                {
                    rootConsole.printEx((screenBounds.Width - 30) / 2, (screenBounds.Height - 10) / 2, TCODBackgroundFlag.Set,
                                        TCODAlignment.LeftAlignment, "Press SPACE to start a new game. Press ESC to quit.");
                    if (keyStroke.KeyCode == TCODKeyCode.Space)
                    {
                        rootConsole.print(1, 1, "Creating new game...");
                        TCODConsole.flush();
                        game = CreateGame();
                    }
                }

                TCODConsole.flush();

                if (keyStroke.KeyCode == TCODKeyCode.Escape)
                {
                    return;
                }
            } while (!TCODConsole.isWindowClosed());
        }
Beispiel #50
0
        void render_mouse(bool first, TCODKey key)
        {
            if (first)
            {
                sampleConsole.setBackgroundColor(TCODColor.grey);
                sampleConsole.setForegroundColor(TCODColor.yellow);
                TCODMouse.moveMouse(320, 200);
                TCODMouse.showCursor(true);
            }

            sampleConsole.clear();
            TCODMouseData mouse = TCODMouse.getStatus();

            if (mouse.LeftButtonPressed)
                mouse_lbut = !mouse_lbut;
            if (mouse.RightButtonPressed)
                mouse_rbut = !mouse_rbut;
            if (mouse.MiddleButtonPressed)
                mouse_mbut = !mouse_mbut;

            string s1 = "Mouse position : " + mouse.PixelX.ToString("000") + " x " + mouse.PixelY.ToString("000") + "\n";
            string s2 = "Mouse cell     : " + mouse.CellX.ToString("000") + " x " + mouse.CellY.ToString("000") + "\n";
            string s3 = "Mouse movement : " + mouse.PixelVelocityX.ToString("000") + " x " + mouse.PixelVelocityY.ToString("000") + "\n";
            string s4 = "Left button    : " + (mouse.LeftButton ? " ON" : "OFF") + " (toggle " + (mouse_lbut ? " ON" : "OFF") + ")\n";
            string s5 = "Right button   : " + (mouse.RightButton ? " ON" : "OFF") + " (toggle " + (mouse_rbut ? " ON" : "OFF") + ")\n";
            string s6 = "Middle button  : " + (mouse.MiddleButton ? " ON" : "OFF") + " (toggle " + (mouse_mbut ? " ON" : "OFF") + ")\n";

            sampleConsole.print(1, 1, s1 + s2 + s3 + s4 + s5 + s6);

            sampleConsole.print(1, 10, "1 : Hide cursor\n2 : Show cursor");
            if (key.Character == '1')
                TCODMouse.showCursor(false);
            else if (key.Character == '2')
                TCODMouse.showCursor(true);
        }
Beispiel #51
0
        void render_fov(bool first, TCODKey key)
        {
            if (map == null)
            {
                // initialize the map for the fov toolkit
                map = new TCODMap(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT);
                for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++)
                {
                    for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
                    {
                        if (smap[y][x] == ' ')
                            map.setProperties(x, y, true, true);// ground
                        else if (smap[y][x] == '=')
                            map.setProperties(x, y, true, false); // window
                    }
                }
                // 1d noise used for the torch flickering
                map_noise = new TCODNoise(1);
            }

            if (first)
            {
                TCODSystem.setFps(30); // fps limited to 30
                // we draw the foreground only the first time.
                // during the player movement, only the @ is redrawn.
                // the rest impacts only the background color
                // draw the help text & player @
                sampleConsole.clear();
                sampleConsole.setForegroundColor(TCODColor.white);
                string prompt = "IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[(int)algonum];
                sampleConsole.print(1, 1, prompt);
                sampleConsole.setForegroundColor(TCODColor.black);
                sampleConsole.putChar(px, py, '@');
                // draw windows
                for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++)
                {
                    for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
                    {
                        if (smap[y][x] == '=')
                        {
                            sampleConsole.putChar(x, y, '=');
                        }
                    }
                }
            }

            if (recomputeFov)
            {
                // calculate the field of view from the player position
                recomputeFov = false;
                map.computeFov(px, py, torch ? (int)TORCH_RADIUS : 0, light_walls, algonum);
            }
            // torch position & intensity variation
            float dx = 0.0f, dy = 0.0f, di = 0.0f;
            if (torch)
            {
                // slightly change the perlin noise parameter
                torchx += 0.2f;
                // randomize the light position between -1.5 and 1.5
                float[] tdx = { torchx + 20.0f };
                dx = map_noise.getPerlinNoise(tdx) * 1.5f;
                tdx[0] += 30.0f;
                dy = map_noise.getPerlinNoise(tdx) * 1.5f;
                // randomize the light intensity between -0.2 and 0.2
                float[] torchxArray = { torchx };
                di = 0.2f * map_noise.getPerlinNoise(torchxArray);
            }

            // draw the dungeon
            for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++)
            {
                for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
                {
                    bool visible = map.isInFov(x, y);
                    bool wall = (smap[y][x] == '#');
                    if (!visible)
                    {
                        sampleConsole.setCharBackground(x, y, (wall ? darkWall : darkGround), TCODBackgroundFlag.Set);
                    }
                    else
                    {
                        if (!torch)
                        {
                            sampleConsole.setCharBackground(x, y, wall ? lightWall : lightGround, TCODBackgroundFlag.Set);
                        }
                        else
                        {
                            // torch flickering fx
                            TCODColor baseColor = wall ? darkWall : darkGround;
                            TCODColor light = wall ? lightWall : lightGround;
                            // cell distance to torch (squared)
                            float r = (float)((x - px + dx) * (x - px + dx) + (y - py + dy) * (y - py + dy));
                            if (r < SQUARED_TORCH_RADIUS)
                            {
                                // l = 1.0 at player position, 0.0 at a radius of 10 cells
                                float l = (SQUARED_TORCH_RADIUS - r) / SQUARED_TORCH_RADIUS + di;
                                // clamp between 0 and 1
                                if (l < 0.0f)
                                    l = 0.0f;
                                else if (l > 1.0f)
                                    l = 1.0f;
                                // interpolate the color
                                baseColor = new TCODColor((byte)(baseColor.Red + (light.Red - baseColor.Red) * l),
                                                    (byte)(baseColor.Green + (light.Green - baseColor.Green) * l),
                                                    (byte)(baseColor.Blue + (light.Blue - baseColor.Blue) * l));
                            }
                            sampleConsole.setCharBackground(x, y, baseColor, TCODBackgroundFlag.Set);
                        }
                    }
                }
            }

            if (key.Character == 'I' || key.Character == 'i')
            {
                // player move north
                if (smap[py - 1][px] == ' ')
                {
                    sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None);
                    py--;
                    sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None);
                    recomputeFov = true;
                }
            }
            else if (key.Character == 'K' || key.Character == 'k')
            {
                // player move south
                if (smap[py + 1][px] == ' ')
                {
                    sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None);
                    py++;
                    sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None);
                    recomputeFov = true;
                }
            }
            else if (key.Character == 'J' || key.Character == 'j')
            {
                // player move west
                if (smap[py][px - 1] == ' ')
                {
                    sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None);
                    px--;
                    sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None);
                    recomputeFov = true;
                }
            }
            else if (key.Character == 'L' || key.Character == 'l')
            {
                // player move east
                if (smap[py][px + 1] == ' ')
                {
                    sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None);
                    px++;
                    sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None);
                    recomputeFov = true;
                }
            }
            else if (key.Character == 'T' || key.Character == 't')
            {
                // enable/disable the torch fx
                torch = !torch;
                sampleConsole.setForegroundColor(TCODColor.white);
                string prompt = "IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[(int)algonum];
                sampleConsole.print(1, 1, prompt);
                sampleConsole.setForegroundColor(TCODColor.black);
            }
            else if (key.Character == 'W' || key.Character == 'W')
            {
                light_walls = !light_walls;
                sampleConsole.setForegroundColor(TCODColor.white);
                string prompt = "IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[(int)algonum];
                sampleConsole.print(1, 1, prompt);
                sampleConsole.setForegroundColor(TCODColor.black);
                recomputeFov = true;
            }
            else if (key.Character == '+' || key.Character == '-')
            {
                algonum += key.Character == '+' ? 1 : -1;

                if (algonum >= TCODFOVTypes.RestrictiveFov)
                    algonum = TCODFOVTypes.RestrictiveFov;
                else if (algonum < 0)
                    algonum = TCODFOVTypes.BasicFov;

                sampleConsole.setForegroundColor(TCODColor.white);
                string prompt = "IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[(int)algonum];
                sampleConsole.print(1, 1, prompt);
                sampleConsole.setForegroundColor(TCODColor.black);
                recomputeFov = true;
            }
        }
Beispiel #52
0
        // /////////////////////////////////////////////////////////////////////////////////
        // /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Constructs a KeyboardData from specified TCODKey object
        /// </summary>
        /// <param name="tcodKeys"></param>
        public KeyboardData(TCODKey tcodKeys)
        {
            if (tcodKeys == null)
            {
                throw new ArgumentNullException("tcodKeys");
            }

            this.character = tcodKeys.Character;
            this.keyCode = tcodKeys.KeyCode;
            this.isKeyPress = tcodKeys.Pressed;

            int f = 0;
            if (tcodKeys.LeftAlt)
                f |= (int)ControlKeys.LeftAlt;
            if (tcodKeys.RightAlt)
                f |= (int)ControlKeys.RightAlt;
            if (tcodKeys.LeftControl)
                f |= (int)ControlKeys.LeftControl;
            if (tcodKeys.RightControl)
                f |= (int)ControlKeys.RightControl;
            if (tcodKeys.Shift)
                f |= (int)ControlKeys.Shift;

            this.controlKeys = (ControlKeys)f;
        }
Beispiel #53
0
        void render_noise(bool first, TCODKey key)
        {
            if (first)
            {
                TCODSystem.setFps(30); /* limited to 30 fps */
            }
            sampleConsole.clear();

            /* texture animation */
            noise_dx += 0.01f;
            noise_dy += 0.01f;

            /* render the 2d noise function */
            for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++)
            {
                for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
                {
                    float[] f = new float[2];
                    float value = 0.0f;
                    byte c;
                    TCODColor col = new TCODColor();
                    f[0] = noise_zoom * x / SAMPLE_SCREEN_WIDTH + noise_dx;
                    f[1] = noise_zoom * y / SAMPLE_SCREEN_HEIGHT + noise_dy;

                    switch (noise_func)
                    {
                        case noiseFunctions.Perlin:
                            value = noise.getPerlinNoise(f);
                            break;
                        case noiseFunctions.PerlinFBM:
                            value = noise.getPerlinBrownianMotion(f, noise_octaves);
                            break;
                        case noiseFunctions.PerlinTurbulence:
                            value = noise.getPerlinTurbulence(f, noise_octaves);
                            break;
                        case noiseFunctions.Simplex:
                            value = noise.getSimplexNoise(f);
                            break;
                        case noiseFunctions.SimplexFBM:
                            value = noise.getSimplexBrownianMotion(f, noise_octaves);
                            break;
                        case noiseFunctions.SimplexTurbulence:
                            value = noise.getSimplexTurbulence(f, noise_octaves);
                            break;
                        case noiseFunctions.Wavelet:
                            value = noise.getWaveletNoise(f);
                            break;
                        case noiseFunctions.WaveletFBM:
                            value = noise.getWaveletBrownianMotion(f, noise_octaves);
                            break;
                        case noiseFunctions.WaveletTurbulence:
                            value = noise.getWaveletTurbulence(f, noise_octaves);
                            break;
                    }

                    c = (byte)((value + 1.0f) / 2.0f * 255);
                    /* use a bluish color */
                    col = new TCODColor((byte)(c / 2), (byte)(c / 2), c);
                    sampleConsole.setCharBackground(x, y, col, TCODBackgroundFlag.Set);
                }
            }

            /* draw a transparent rectangle */
            sampleConsole.setBackgroundColor(TCODColor.grey);
            sampleConsole.rect(2, 2, (noise_func <= noiseFunctions.Wavelet ? 16 : 24), (noise_func <= noiseFunctions.Wavelet ? 4 : 7), false, TCODBackgroundFlag.Multiply);

            /* draw the text */
            for (noiseFunctions curfunc = noiseFunctions.Perlin; curfunc <= noiseFunctions.WaveletTurbulence; curfunc++)
            {
                if (curfunc == noise_func)
                {
                    sampleConsole.setForegroundColor(TCODColor.white);
                    sampleConsole.setBackgroundColor(TCODColor.blue);
                    sampleConsole.print(2, 2 + (int)(curfunc), noise_funcName[(int)curfunc]);
                }
                else
                {
                    sampleConsole.setForegroundColor(TCODColor.grey);
                    sampleConsole.print(2, 2 + (int)(curfunc), noise_funcName[(int)curfunc]);
                }
            }
            /* draw parameters */
            sampleConsole.setForegroundColor(TCODColor.white);
            sampleConsole.print(2, 11, "Y/H : zome (" + noise_zoom.ToString("0.0") + ")");

            if (noise_func > noiseFunctions.Wavelet)
            {
                sampleConsole.print(2, 12, "E/D : hurst (" + noise_hurst.ToString("0.0") + ")");
                sampleConsole.print(2, 13, "R/F : lacunarity (" + noise_lacunarity.ToString("0.0") + ")");
                sampleConsole.print(2, 14, "T/G : octaves (" + noise_octaves.ToString("0.0") + ")");
            }

            /* handle keypress */
            if (key.KeyCode == TCODKeyCode.NoKey)
                return;

            if (key.Character >= '1' && key.Character <= '9')
            {
                noise_func = (noiseFunctions)(key.Character - '1');
            }
            else if (key.Character == 'E' || key.Character == 'e')
            {
                /* increase hurst */
                noise_hurst += 0.1f;
                noise.Dispose();
                noise = new TCODNoise(2, noise_hurst, noise_lacunarity);
            }
            else if (key.Character == 'D' || key.Character == 'd')
            {
                /* decrease hurst */
                noise_hurst -= 0.1f;
                noise.Dispose();
                noise = new TCODNoise(2, noise_hurst, noise_lacunarity);
            }
            else if (key.Character == 'R' || key.Character == 'r')
            {
                /* increase lacunarity */
                noise_lacunarity += 0.5f;
                noise.Dispose();
                noise = new TCODNoise(2, noise_hurst, noise_lacunarity);
            }
            else if (key.Character == 'F' || key.Character == 'f')
            {
                /* decrease lacunarity */
                noise_lacunarity -= 0.5f;
                noise.Dispose();
                noise = new TCODNoise(2, noise_hurst, noise_lacunarity);
            }
            else if (key.Character == 'T' || key.Character == 't')
            {
                /* increase octaves */
                noise_octaves += 0.5f;
            }
            else if (key.Character == 'G' || key.Character == 'g')
            {
                /* decrease octaves */
                noise_octaves -= 0.5f;
            }
            else if (key.Character == 'Y' || key.Character == 'y')
            {
                /* increase zoom */
                noise_zoom += 0.2f;
            }
            else if (key.Character == 'H' || key.Character == 'h')
            {
                /* decrease zoom */
                noise_zoom -= 0.2f;
            }
        }
Beispiel #54
0
        void render_lines(bool first, TCODKey key)
        {
            sampleConsole.clear();
            if (key.KeyCode == TCODKeyCode.Enter || key.KeyCode == TCODKeyCode.KeypadEnter)
            {
                // switch to the next blending mode
                if (libtcod.libtcod.TCODBackgroundAlphaMask(line_bkFlag) == TCODBackgroundFlag.Alpha)
                    line_bkFlag = TCODBackgroundFlag.None;
                else
                    line_bkFlag++;
            }
            if (libtcod.libtcod.TCODBackgroundAlphaMask(line_bkFlag) == TCODBackgroundFlag.Alpha)
            {
                // for the alpha mode, update alpha every frame
                double alpha = (1.0f + Math.Cos(TCODSystem.getElapsedSeconds() * 2)) / 2.0f;
                line_bkFlag = TCODCBackgroundHelpers.CreateAlphaBackground((float)alpha);
            }
            else if (libtcod.libtcod.TCODBackgroundAlphaMask(line_bkFlag) == TCODBackgroundFlag.AddAlpha)
            {
                // for the add alpha mode, update alpha every frame
                double alpha = (1.0f + Math.Cos(TCODSystem.getElapsedSeconds() * 2)) / 2.0f;
                line_bkFlag = TCODCBackgroundHelpers.CreateAddAlphaBackground((float)alpha);
            }

            if (!line_init)
            {
                // initialize the colored background
                for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
                {
                    for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++)
                    {
                        TCODColor col = new TCODColor((byte)(x * 255 / (SAMPLE_SCREEN_WIDTH - 1)),
                                        (byte)((x + y) * 255 / (SAMPLE_SCREEN_WIDTH - 1 + SAMPLE_SCREEN_HEIGHT - 1)),
                                        (byte)(y * 255 / (SAMPLE_SCREEN_HEIGHT - 1)));

                        line_bk.setCharBackground(x, y, col, TCODBackgroundFlag.Set);
                    }
                }
                line_init = true;
            }
            if (first)
            {
                TCODSystem.setFps(30); // fps limited to 30
                sampleConsole.setForegroundColor(TCODColor.white);
            }

            // blit the background
            TCODConsole.blit(line_bk, 0, 0, SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT, sampleConsole, 0, 0);

            // render the gradient
            int recty = (int)((SAMPLE_SCREEN_HEIGHT - 2) * ((1.0f + Math.Cos(TCODSystem.getElapsedSeconds())) / 2.0f));
            for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
            {
                TCODColor col = new TCODColor((byte)(x * 255 / SAMPLE_SCREEN_WIDTH),
                                    (byte)(x * 255 / SAMPLE_SCREEN_WIDTH),
                                    (byte)(x * 255 / SAMPLE_SCREEN_WIDTH));
                sampleConsole.setCharBackground(x, recty, col, line_bkFlag);
                sampleConsole.setCharBackground(x, recty + 1, col, line_bkFlag);
                sampleConsole.setCharBackground(x, recty + 2, col, line_bkFlag);
            }

            // calculate the segment ends
            float angle = TCODSystem.getElapsedSeconds() * 2.0f;
            float cosAngle = (float)Math.Cos(angle);
            float sinAngle = (float)Math.Sin(angle);
            int xo = (int)(SAMPLE_SCREEN_WIDTH / 2 * (1 + cosAngle));
            int yo = (int)(SAMPLE_SCREEN_HEIGHT / 2 + sinAngle * SAMPLE_SCREEN_WIDTH / 2);
            int xd = (int)(SAMPLE_SCREEN_WIDTH / 2 * (1 - cosAngle));
            int yd = (int)(SAMPLE_SCREEN_HEIGHT / 2 - sinAngle * SAMPLE_SCREEN_WIDTH / 2);

            // render the line
            int xx = xo, yy = yo;
            TCODLine.init(xx, yy, xd, yd);
            do
            {
                if (xx >= 0 && yy >= 0 && xx < SAMPLE_SCREEN_WIDTH && yy < SAMPLE_SCREEN_HEIGHT)
                {
                    sampleConsole.setCharBackground(xx, yy, TCODColor.blue, line_bkFlag);
                }
            }
            while (!TCODLine.step(ref xx, ref yy));

            // print the current flag
            sampleConsole.print(2, 2, libtcod.libtcod.TCODBackgroundAlphaMask(line_bkFlag).ToString() + " (ENTER to change)");
        }
 public override void KeyPressed(TCODKey keyData)
 {
     if(keyData.KeyCode == TCODKeyCode.Space) {
         Map.Generate(Game.Settings.ScreenWidth, Game.Settings.ScreenHeight);
     }
 }
Beispiel #56
0
        void render_path(bool first, TCODKey key)
        {
            if (map == null)
            {
                // initialize the map
                map = new TCODMap(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT);
                for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++)
                {
                    for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
                    {
                        if (smap[y][x] == ' ')
                            map.setProperties(x, y, true, true);// ground
                        else if (smap[y][x] == '=')
                            map.setProperties(x, y, true, false); // window
                    }
                }
            }

            if (first)
            {
                TCODSystem.setFps(30); // fps limited to 30
                // we draw the foreground only the first time.
                // during the player movement, only the @ is redrawn.
                // the rest impacts only the background color
                // draw the help text & player @
                sampleConsole.clear();
                sampleConsole.setForegroundColor(TCODColor.white);
                sampleConsole.print(1, 1, "IJKL / mouse :\nmove destination\nTAB : A*/dijkstra");
                sampleConsole.print(1, 4, "Using : A*");
                sampleConsole.setForegroundColor(TCODColor.black);
                sampleConsole.putChar(px, py, '@');
                // draw windows
                for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++)
                {
                    for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
                    {
                        if (smap[y][x] == '=')
                        {
                            sampleConsole.putChar(x, y, '=');
                        }
                    }
                }
                recalculatePath = true;
            }

            if (recalculatePath)
            {
                if (usingAstar)
                {
                    if (AStrPath == null)
                        AStrPath = new TCODPath(map, 1.41f);

                    AStrPath.compute(px, py, dx, dy);
                }
                else
                {
                    if (DijkstraPath == null)
                        DijkstraPath = new TCODDijkstra(map, 1.41f);

                    dijkstraDist = 0.0f;
                    /* compute the distance grid */
                    DijkstraPath.compute(px, py);
                    /* get the maximum distance (needed for ground shading only) */
                    for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++)
                    {
                        for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
                        {
                            float d = DijkstraPath.getDistance(x, y);
                            if (d > dijkstraDist)
                                dijkstraDist = d;
                        }
                    }
                    // compute the path
                    DijkstraPath.setPath(dx, dy);
                }
                recalculatePath = false;
                busy = .2f;
            }

            // draw the dungeon
            for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++)
            {
                for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
                {
                    bool wall = smap[y][x] == '#';
                    sampleConsole.setCharBackground(x, y, (wall ? darkWall : darkGround), TCODBackgroundFlag.Set);
                }
            }

            // draw the path
            if (usingAstar)
            {
                for (int i = 0; i < AStrPath.size(); i++)
                {
                    int x, y;
                    AStrPath.get(i, out x, out y);
                    sampleConsole.setCharBackground(x, y, lightGround, TCODBackgroundFlag.Set);
                }
            }
            else
            {
                for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++)
                {
                    for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
                    {
                        bool wall = smap[y][x] == '#';
                        if (!wall)
                        {
                            float d = DijkstraPath.getDistance(x, y);
                            sampleConsole.setCharBackground(x, y, TCODColor.Interpolate(lightGround, darkGround, (float)0.9 * d / dijkstraDist), TCODBackgroundFlag.Set);
                        }
                    }
                }
                for (int i = 0; i < DijkstraPath.size(); i++)
                {
                    int x, y;
                    DijkstraPath.get(i, out x, out y);
                    sampleConsole.setCharBackground(x, y, lightGround, TCODBackgroundFlag.Set);
                }
            }

            // move the creature
            busy -= TCODSystem.getLastFrameLength();
            if (busy <= 0.0f)
            {
                busy += 0.2f;
                if (usingAstar)
                {
                    if (!AStrPath.isEmpty())
                    {
                        sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None);
                        AStrPath.walk(ref px, ref py, true);
                        sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None);
                    }
                }
                else
                {
                    if (!DijkstraPath.isEmpty())
                    {
                        sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None);
                        DijkstraPath.walk(ref px, ref py);
                        sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None);
                        recalculatePath = true;
                    }
                }
            }

            if ((key.Character == 'I' || key.Character == 'i') && dy > 0)
            {
                // destination move north
                sampleConsole.putChar(dx, dy, oldChar, TCODBackgroundFlag.None);
                dy--;
                oldChar = sampleConsole.getChar(dx, dy);
                sampleConsole.putChar(dx, dy, '+', TCODBackgroundFlag.None);
                if (smap[dy][dx] == ' ')
                {
                    recalculatePath = true;
                }
            }
            else if ((key.Character == 'K' || key.Character == 'k') && dy < SAMPLE_SCREEN_HEIGHT - 1)
            {
                // destination move south
                sampleConsole.putChar(dx, dy, oldChar, TCODBackgroundFlag.None);
                dy++;
                oldChar = sampleConsole.getChar(dx, dy);
                sampleConsole.putChar(dx, dy, '+', TCODBackgroundFlag.None);
                if (smap[dy][dx] == ' ')
                {
                    recalculatePath = true;
                }
            }
            else if ((key.Character == 'J' || key.Character == 'j') && dx > 0)
            {
                // destination move west
                sampleConsole.putChar(dx, dy, oldChar, TCODBackgroundFlag.None);
                dx--;
                oldChar = sampleConsole.getChar(dx, dy);
                sampleConsole.putChar(dx, dy, '+', TCODBackgroundFlag.None);
                if (smap[dy][dx] == ' ')
                {
                    recalculatePath = true;
                }
            }
            else if ((key.Character == 'L' || key.Character == 'l') && dx < SAMPLE_SCREEN_WIDTH - 1)
            {
                // destination move east
                sampleConsole.putChar(dx, dy, oldChar, TCODBackgroundFlag.None);
                dx++;
                oldChar = sampleConsole.getChar(dx, dy);
                sampleConsole.putChar(dx, dy, '+', TCODBackgroundFlag.None);
                if (smap[dy][dx] == ' ')
                {
                    recalculatePath = true;
                }
            }
            else if (key.KeyCode ==  TCODKeyCode.Tab)
            {
                usingAstar = !usingAstar;
                sampleConsole.setForegroundColor(TCODColor.white);
                if (usingAstar)
                    sampleConsole.print(1, 4, "Using : A*      ");
                else
                    sampleConsole.print(1, 4, "Using : Dijkstra");
                sampleConsole.setForegroundColor(TCODColor.black);
                recalculatePath = true;
            }

            TCODMouseData mouse = TCODMouse.getStatus();
            int mx = mouse.CellX - SAMPLE_SCREEN_X;
            int my = mouse.CellY - SAMPLE_SCREEN_Y;

            if (mx >= 0 && mx < SAMPLE_SCREEN_WIDTH && my >= 0 && my < SAMPLE_SCREEN_HEIGHT && (dx != mx || dy != my))
            {
                sampleConsole.putChar(dx, dy, oldChar, TCODBackgroundFlag.None);
                dx = mx; dy = my;
                oldChar = sampleConsole.getChar(dx, dy);
                sampleConsole.putChar(dx, dy, '+', TCODBackgroundFlag.None);
                if (smap[dy][dx] == ' ')
                {
                    recalculatePath = true;
                }
            }
        }
Beispiel #57
0
 private void Set(Actions action, TCODKey primary)
 {
     Set(action, primary, primary);
 }
Beispiel #58
0
        void render_colors(bool first, TCODKey key)
        {
            int TOPLEFT = 0;
            int TOPRIGHT = 1;
            int BOTTOMLEFT = 2;
            int BOTTOMRIGHT = 3;

            TCODColor textColor = new TCODColor();

            /* ==== slighty modify the corner colors ==== */
            if (first)
            {
                TCODSystem.setFps(0);
                sampleConsole.clear();
            }
            /* ==== slighty modify the corner colors ==== */
            for (int c = 0; c < 4; c++)
            {
                /* move each corner color */
                int component = random.getInt(0, 2);
                switch (component)
                {
                    case 0:
                        render_cols[c] = new TCODColor((byte)(render_cols[c].Red + (byte)(5 * render_dirr[c])),
                                render_cols[c].Green, render_cols[c].Blue);
                        if (render_cols[c].Red == 255)
                            render_dirr[c] = -1;
                        else if (render_cols[c].Red == 0)
                            render_dirr[c] = 1;
                        break;
                    case 1:
                        render_cols[c] = new TCODColor(render_cols[c].Red,
                                (byte)(render_cols[c].Green + (byte)(5 * render_dirg[c])), render_cols[c].Blue);
                        if (render_cols[c].Green == 255)
                            render_dirg[c] = -1;
                        else if (render_cols[c].Green == 0)
                            render_dirg[c] = 1;
                        break;
                    case 2:
                        render_cols[c] = new TCODColor(render_cols[c].Red,
                                render_cols[c].Green, (byte)(render_cols[c].Blue + (byte)(5 * render_dirb[c])));
                        if (render_cols[c].Blue == 255)
                            render_dirb[c] = -1;
                        else if (render_cols[c].Blue == 0)
                            render_dirb[c] = 1;
                        break;
                }
            }

            /* ==== scan the whole screen, interpolating corner colors ==== */
            for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
            {
                float xcoef = (float)(x) / (SAMPLE_SCREEN_WIDTH - 1);
                /* get the current column top and bottom colors */
                TCODColor top = TCODColor.Interpolate(render_cols[TOPLEFT], render_cols[TOPRIGHT], xcoef);
                TCODColor bottom = TCODColor.Interpolate(render_cols[BOTTOMLEFT], render_cols[BOTTOMRIGHT], xcoef);
                for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++)
                {
                    float ycoef = (float)(y) / (SAMPLE_SCREEN_HEIGHT - 1);
                    /* get the current cell color */
                    TCODColor curColor = TCODColor.Interpolate(top, bottom, ycoef);
                    sampleConsole.setCharBackground(x, y, curColor, TCODBackgroundFlag.Set);
                }
            }

            /* ==== print the text ==== */
            /* get the background color at the text position */
            textColor = sampleConsole.getCharBackground(SAMPLE_SCREEN_WIDTH / 2, 5);
            /* and invert it */
            textColor = new TCODColor((byte)(255 - textColor.Red),
                (byte)(255 - textColor.Green), (byte)(255 - textColor.Blue));
            sampleConsole.setForegroundColor(textColor);

            /* put random text (for performance tests) */
            for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
            {
                for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++)
                {
                    TCODColor col = sampleConsole.getCharForeground(x, y);
                    col = TCODColor.Interpolate(col, TCODColor.black, 0.5f);
                    int c = random.getInt(System.Convert.ToByte('a'), System.Convert.ToByte('z'));
                    sampleConsole.setForegroundColor(col);
                    sampleConsole.putChar(x, y, (char)c, TCODBackgroundFlag.None);
                }
            }

            /* the background behind the text is slightly darkened using the BKGND_MULTIPLY flag */
            sampleConsole.setBackgroundColor(TCODColor.grey);
            sampleConsole.printRectEx(SAMPLE_SCREEN_WIDTH / 2, 5, SAMPLE_SCREEN_WIDTH - 2, SAMPLE_SCREEN_HEIGHT - 1,
                TCODBackgroundFlag.Multiply, TCODAlignment.CenterAlignment, "The Doryen library uses 24 bits colors, for both background and foreground.");
        }
Beispiel #59
0
        protected ConsoleKey GetConsoleKey(TCODKey key)
        {
            ConsoleKey consoleKey = default(ConsoleKey);
            bool found = true;
            switch (key.KeyCode)
            {
                case TCODKeyCode.Space:
                    consoleKey = ConsoleKey.Spacebar; break;
                case TCODKeyCode.Right:
                    consoleKey = ConsoleKey.RightArrow; break;
                case TCODKeyCode.Left:
                    consoleKey = ConsoleKey.LeftArrow; break;
                case TCODKeyCode.Up:
                    consoleKey = ConsoleKey.UpArrow; break;
                case TCODKeyCode.Down:
                    consoleKey = ConsoleKey.DownArrow; break;
                default: found = false; break;
            }

            if (found)
            {
                return consoleKey;
            }
            else
            {
                string keyCodeString;
                if (key.KeyCode == TCODKeyCode.Char)
                {
                    keyCodeString = string.Format("{0}", key.Character);
                    Enum.TryParse(keyCodeString, true, out consoleKey);
                    return consoleKey;
                }
                else
                {
                    keyCodeString = string.Format("{0}", key.KeyCode);
                    Enum.TryParse(keyCodeString, true, out consoleKey);
                    return consoleKey;
                }

            }
        }
Beispiel #60
0
 private void Set(Actions action, TCODKey primary, TCODKey secondary)
 {
     SetActionPrimary(action, primary);
     SetActionSecondary(action, secondary);
 }