Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.50 KB | None | 0 0
  1. #include "EditorState.hpp"
  2.  
  3.  
  4. void EditorState::draw(const float dt)
  5. {
  6.     mousePosition.x = GetMouseX() + 10;
  7.     mousePosition.y = GetMouseY() + 10;
  8.  
  9.  
  10.     // Draw the map
  11.     for (int i = 0; i < 14; i++)
  12.     {
  13.         for (int j = 0; j < 14; j++)
  14.         {
  15.             position.x = i * 42;
  16.             position.y = j * 42;
  17.  
  18.             switch (map[i][j])
  19.             {
  20.             case GROUND:
  21.                 DrawTextureRec(items, ground, position, WHITE);
  22.                 break;
  23.             case WALL:
  24.                 DrawTextureRec(items, wall, position, WHITE);
  25.                 break;
  26.             case CRATE:
  27.                 DrawTextureRec(items, crate, position, WHITE);
  28.                 break;
  29.             case OBJECTIVE:
  30.                 DrawTextureRec(items, objective, position, WHITE);
  31.                 break;
  32.             case PLAYER:
  33.                 DrawTextureRec(items, player, position, WHITE);
  34.                 break;
  35.             default:
  36.                 break;
  37.             }
  38.         }
  39.     }
  40.  
  41.     // Draw current object under cursor
  42.     switch (actualObject) {
  43.     case WALL:
  44.         DrawTextureRec(items, wall, mousePosition, WHITE);
  45.         break;
  46.     case CRATE:
  47.         DrawTextureRec(items, crate, mousePosition, WHITE);
  48.         break;
  49.     case OBJECTIVE:
  50.         DrawTextureRec(items, objective, mousePosition, WHITE);
  51.         break;
  52.     case PLAYER:
  53.         DrawTextureRec(items, player, mousePosition, WHITE);
  54.         break;
  55.     case GROUND:
  56.         DrawTextureRec(items, ground, mousePosition, WHITE);
  57.         break;
  58.     default:
  59.         break;
  60.     }
  61.  
  62.     // Draw text for error message
  63.     if (printError) {
  64.         errorMessageTimer += dt;
  65.         DrawText(errorMessage.c_str(), (GetScreenWidth() - 10) - (MeasureText(errorMessage.c_str(), 20)), GetScreenHeight() - 30, 20, RED);
  66.         if (errorMessageTimer > 2.0f) {
  67.             errorMessageTimer = 0.0f;
  68.             errorMessage = "";
  69.             printError = false;
  70.         }
  71.     }
  72. }
  73.  
  74. void EditorState::update(const float dt)
  75. {
  76.    
  77. }
  78.  
  79. void EditorState::handleInput()
  80. {
  81.     if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  82.     {
  83.         if (actualObject == PLAYER && playerPlaced) {
  84.             printError = true;
  85.             errorMessage = "Only one player spawn is allowed";
  86.             return;
  87.         }
  88.         else if (actualObject == PLAYER && !playerPlaced) playerPlaced = true;
  89.  
  90.         this->map[GetMouseX() / 42][GetMouseY() / 42] = this->actualObject;
  91.     }
  92.     else if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) this->map[GetMouseX() / 42][GetMouseY() / 42] = EMPTY;
  93.  
  94.     if (IsKeyPressed(KEY_ONE)) this->actualObject = GROUND;
  95.     if (IsKeyPressed(KEY_TWO)) this->actualObject = WALL;
  96.     if (IsKeyPressed(KEY_THREE)) this->actualObject = CRATE;
  97.     if (IsKeyPressed(KEY_FOUR)) this->actualObject = OBJECTIVE;
  98.     if (IsKeyPressed(KEY_FIVE)) this->actualObject = PLAYER;
  99. }
  100.  
  101. EditorState::EditorState(Game * game)
  102. {
  103.     this->game = game;
  104.     items = LoadTexture("assets/items.png");
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement