// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Constructs MouseData from TCODMouseData /// </summary> /// <param name="tcodMouseData"></param> public MouseData(TCODMouseData tcodMouseData) { if (tcodMouseData == null) { throw new ArgumentNullException("tcodMouseData"); } this.position = new Point(tcodMouseData.CellX, tcodMouseData.CellY); this.pixelPosition = new Point(tcodMouseData.PixelX, tcodMouseData.PixelY); mouseButton = MouseButton.None; if (tcodMouseData.LeftButton) { mouseButton = MouseButton.LeftButton; } if (tcodMouseData.MiddleButton) { mouseButton = MouseButton.MiddleButton; } if (tcodMouseData.RightButton) { mouseButton = MouseButton.RightButton; } }
private void CheckForMouseEvents() { var mouseData = TCODMouse.getStatus(); if (mouseData.CellVelocityX != 0 || mouseData.CellVelocityY != 0) { CurrentScene.MouseMoved(mouseData); } if (mouseData.WheelDown || mouseData.WheelUp) { CurrentScene.MouseWheel(mouseData); } if (mouseData.LeftButton != previousMouseData.LeftButton) { CurrentScene.MouseLeftButton(mouseData); } if (mouseData.MiddleButton != previousMouseData.MiddleButton) { CurrentScene.MouseMiddleButton(mouseData); } if (mouseData.RightButton != previousMouseData.RightButton) { CurrentScene.MouseRightButton(mouseData); } previousMouseData = mouseData; }
public override void Update(TCODKey k, TCODMouseData m) { foreach (Button b in Buttons) { b.Update(m); } }
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); }
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; }
/// <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); }
/// <summary> /// Update the button based on the input mouse state /// </summary> public void Update(TCODMouseData mState) { if (mState.CellX >= origin.X && mState.CellX < origin.X + size.X && mState.CellY >= origin.Y && mState.CellY < origin.Y + size.Y) { isHovered = true; if (mState.LeftButtonPressed) { clickHandler(this); } } else { isHovered = false; } }
public void Initialize(BaseScene initialScene = null) { Logger.Initialize(); windowTitle = "Emergence"; Settings = LoadSettings("Assets/config.json"); if (Settings == null) { throw new Exception("Error loading config file."); } TCODConsole.setCustomFont($"Assets/Fonts/{Settings.Font}", (int)TCODFontFlags.LayoutAsciiInRow); TCODSystem.setFps(Settings.Fps); TCODConsole.initRoot(Settings.ScreenWidth, Settings.ScreenHeight, windowTitle, false, Settings.GetRendererType()); previousMouseData = TCODMouse.getStatus(); CurrentScene = initialScene; }
/// <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(); } }
public virtual void MouseMiddleButton(TCODMouseData mouseData) { }
public virtual void MouseLeftButton(TCODMouseData mouseData) { }
public override void Update(TCODKey k, TCODMouseData m) { //GameLogic stuff here GameLoop.Game.world.Update(k, m); }
private void CheckForMouseEvents() { var mouseData = TCODMouse.getStatus(); if(mouseData.CellVelocityX != 0 || mouseData.CellVelocityY != 0) { CurrentScene.MouseMoved(mouseData); } if(mouseData.WheelDown || mouseData.WheelUp) { CurrentScene.MouseWheel(mouseData); } if(mouseData.LeftButton != previousMouseData.LeftButton) { CurrentScene.MouseLeftButton(mouseData); } if(mouseData.MiddleButton != previousMouseData.MiddleButton) { CurrentScene.MouseMiddleButton(mouseData); } if(mouseData.RightButton != previousMouseData.RightButton) { CurrentScene.MouseRightButton(mouseData); } previousMouseData = mouseData; }
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; } }
public virtual void MouseWheel(TCODMouseData mouseData) { }
protected void SetMouse(Mouse newMouse, TCODMouseData mouse) { newMouse.X = mouse.CellX; newMouse.Y = mouse.CellY; newMouse.LeftButton = mouse.LeftButton; }
public void Initialize(BaseScene initialScene = null) { Logger.Initialize(); windowTitle = "Emergence"; Settings = LoadSettings("Assets/config.json"); if(Settings == null) { throw new Exception("Error loading config file."); } TCODConsole.setCustomFont($"Assets/Fonts/{Settings.Font}", (int)TCODFontFlags.LayoutAsciiInRow); TCODSystem.setFps(Settings.Fps); TCODConsole.initRoot(Settings.ScreenWidth, Settings.ScreenHeight, windowTitle, false, Settings.GetRendererType()); previousMouseData = TCODMouse.getStatus(); CurrentScene = initialScene; }
public virtual void MouseWheel(TCODMouseData mouseData) { }
public virtual void MouseMoved(TCODMouseData mouseData) { }
public bool Intersects(TCODMouseData m) { return ((m.CellX >= X && m.CellX <= X + W) && (m.CellY >= Y && m.CellY < Y + H)); }
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; }
public virtual void MouseMoved(TCODMouseData mouseData) { }
public virtual void MouseRightButton(TCODMouseData mouseData) { }
public void Update(TCODMouseData m) { bool intersects = r.Intersects(m); hover = intersects; if (intersects && m.LeftButton && A != null) { A(); } }
public virtual void MouseLeftButton(TCODMouseData mouseData) { }
// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Constructs MouseData from TCODMouseData /// </summary> /// <param name="tcodMouseData"></param> public MouseData(TCODMouseData tcodMouseData) { if (tcodMouseData == null) { throw new ArgumentNullException("tcodMouseData"); } this.position = new Point(tcodMouseData.CellX, tcodMouseData.CellY); this.pixelPosition = new Point(tcodMouseData.PixelX, tcodMouseData.PixelY); mouseButton = MouseButton.None; if (tcodMouseData.LeftButton) mouseButton = MouseButton.LeftButton; if (tcodMouseData.MiddleButton) mouseButton = MouseButton.MiddleButton; if (tcodMouseData.RightButton) mouseButton = MouseButton.RightButton; }
public virtual void MouseMiddleButton(TCODMouseData mouseData) { }
public virtual void MouseRightButton(TCODMouseData mouseData) { }
public bool pickATile(out int x, out int y, float maxRange) { int pickX = Program.engine.player.x - map.offsetX, pickY = Program.engine.player.y - map.offsetY; for (int cx = map.renderX; cx < map.renderWidth; cx++) { for (int cy = map.renderY; cy < map.renderHeight; cy++) { if (Program.engine.player.fov.isInFov(cx + map.offsetX, cy + map.offsetY) && (maxRange == 0 || Program.engine.player.getDistance(cx + map.offsetX, cy + map.offsetY) <= maxRange)) { TCODColor col = TCODConsole.root.getCharBackground(cx, cy); col = col.Multiply(1.2f); TCODConsole.root.setCharBackground(cx, cy, col); } } } int oldX = pickX, oldY = pickY; TCODColor oldC = TCODConsole.root.getCharBackground(pickX, pickY); while (!TCODConsole.isWindowClosed()) { render(); mousedata = TCODMouse.getStatus(); Program.engine.key = TCODConsole.checkForKeypress((int)TCODKeyStatus.KeyPressed); if (Engine.useMouse) { if (Program.engine.player.fov.isInFov(mousedata.CellX + map.offsetX, mousedata.CellY + map.offsetY)) { if ((maxRange == 0 || Program.engine.player.getDistance(mousedata.CellX + map.offsetX, mousedata.CellY + map.offsetY) <= maxRange)) { pickX = mousedata.CellX; pickY = mousedata.CellY; if (mousedata.LeftButtonPressed) { x = mousedata.CellX + map.offsetX; y = mousedata.CellY + map.offsetY; return(true); } } } if (mousedata.RightButtonPressed) { x = 0; y = 0; return(false); } } if (pickX != oldX || pickY != oldY) { TCODConsole.root.setCharBackground(oldX, oldY, oldC); oldC = TCODConsole.root.getCharBackground(pickX, pickY); TCODConsole.root.setCharBackground(pickX, pickY, TCODColor.white); oldX = pickX; oldY = pickY; } if (Program.engine.player.fov.isInFov(pickX + map.offsetX, pickY + map.offsetY)) { if ((maxRange == 0 || Program.engine.player.getDistance(pickX + map.offsetX, pickY + map.offsetY) <= maxRange)) { switch (Program.engine.key.KeyCode) { case TCODKeyCode.Enter: { x = pickX + map.offsetX; y = pickY + map.offsetY; return(true); } case TCODKeyCode.Up: { if (Program.engine.player.fov.isInFov(pickX + map.offsetX, pickY - 1 + map.offsetY)) { if (Program.engine.player.getDistance(pickX + map.offsetX, pickY - 1 + map.offsetY) <= maxRange) { pickY--; } } break; } case TCODKeyCode.Down: if (Program.engine.player.fov.isInFov(pickX + map.offsetX, pickY + 1 + map.offsetY)) { if (Program.engine.player.getDistance(pickX + map.offsetX, pickY + 1 + map.offsetY) <= maxRange) { pickY++; } } break; case TCODKeyCode.Left: if (Program.engine.player.fov.isInFov(pickX - 1 + map.offsetX, pickY + map.offsetY)) { if (Program.engine.player.getDistance(pickX - 1 + map.offsetX, pickY + map.offsetY) <= maxRange) { pickX--; } } break; case TCODKeyCode.Right: if (Program.engine.player.fov.isInFov(pickX + 1 + map.offsetX, pickY + map.offsetY)) { if (Program.engine.player.getDistance(pickX + 1 + map.offsetX, pickY + map.offsetY) <= maxRange) { pickX++; } } break; } } } TCODConsole.flush(); Program.engine.lastKey = Program.engine.key; } x = 0; y = 0; return(false); }
public abstract void Update(TCODKey k, TCODMouseData m);