Created
          January 22, 2020 18:51 
        
      - 
      
- 
        Save rdeioris/7528efc0f21c1500ae428222bb0267bb to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using Aiv.Fast2D; | |
| using OpenTK; | |
| namespace Fast2DApp | |
| { | |
| class Terminal | |
| { | |
| char[] characters; | |
| int cols; | |
| int rows; | |
| int cursorX; | |
| int cursorY; | |
| Texture fonts; | |
| Sprite tile; | |
| Vector4 color; | |
| public Terminal(int cols, int rows) | |
| { | |
| this.cols = cols; | |
| this.rows = rows; | |
| this.characters = new char[this.cols * this.rows]; | |
| this.cursorX = 0; | |
| this.cursorY = 0; | |
| this.fonts = new Texture("Assets/text.png"); | |
| this.tile = new Sprite(50, 50); | |
| this.color = new Vector4(1, 0, 1, 0); | |
| } | |
| public void Put(char character) | |
| { | |
| character = char.ToLower(character); | |
| int index = cursorY * this.cols + cursorX; | |
| if (character == ' ') | |
| { | |
| characters[index] = '\0'; | |
| } | |
| else if (character == '\n') | |
| { | |
| if (cursorY < this.rows - 1) | |
| { | |
| cursorY++; | |
| } | |
| return; | |
| } | |
| else if (character == '\r') | |
| { | |
| cursorX = 0; | |
| return; | |
| } | |
| else | |
| { | |
| characters[index] = character; | |
| } | |
| if (cursorX < this.cols - 1) | |
| cursorX++; | |
| } | |
| public void Put(string message) | |
| { | |
| foreach(char character in message) | |
| { | |
| Put(character); | |
| } | |
| } | |
| public void Draw() | |
| { | |
| for (int y = 0; y < this.rows; y++) | |
| { | |
| for (int x = 0; x < this.cols; x++) | |
| { | |
| int index = y * this.cols + x; | |
| int currentCharacterIndex = (int)this.characters[index]; | |
| // fix the character index for the texture | |
| currentCharacterIndex -= 97; | |
| // is it a valid character ? | |
| if (currentCharacterIndex < 26) | |
| { | |
| // compute the UV (in pixel space) | |
| int gridX = currentCharacterIndex % 6; | |
| int gridY = currentCharacterIndex / 6; | |
| int textureX = gridX * 100; | |
| int textureY = gridY * 100; | |
| tile.SetAdditiveTint(color); | |
| tile.position = new Vector2(x * tile.Width, y * tile.Height); | |
| tile.DrawTexture(this.fonts, textureX, textureY, 100, 100); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment