Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "EditorState.hpp"
- void EditorState::draw(const float dt)
- {
- mousePosition.x = GetMouseX() + 10;
- mousePosition.y = GetMouseY() + 10;
- // Draw the map
- for (int i = 0; i < 14; i++)
- {
- for (int j = 0; j < 14; j++)
- {
- position.x = i * 42;
- position.y = j * 42;
- switch (map[i][j])
- {
- case GROUND:
- DrawTextureRec(items, ground, position, WHITE);
- break;
- case WALL:
- DrawTextureRec(items, wall, position, WHITE);
- break;
- case CRATE:
- DrawTextureRec(items, crate, position, WHITE);
- break;
- case OBJECTIVE:
- DrawTextureRec(items, objective, position, WHITE);
- break;
- case PLAYER:
- DrawTextureRec(items, player, position, WHITE);
- break;
- default:
- break;
- }
- }
- }
- // Draw current object under cursor
- switch (actualObject) {
- case WALL:
- DrawTextureRec(items, wall, mousePosition, WHITE);
- break;
- case CRATE:
- DrawTextureRec(items, crate, mousePosition, WHITE);
- break;
- case OBJECTIVE:
- DrawTextureRec(items, objective, mousePosition, WHITE);
- break;
- case PLAYER:
- DrawTextureRec(items, player, mousePosition, WHITE);
- break;
- case GROUND:
- DrawTextureRec(items, ground, mousePosition, WHITE);
- break;
- default:
- break;
- }
- // Draw text for error message
- if (printError) {
- errorMessageTimer += dt;
- DrawText(errorMessage.c_str(), (GetScreenWidth() - 10) - (MeasureText(errorMessage.c_str(), 20)), GetScreenHeight() - 30, 20, RED);
- if (errorMessageTimer > 2.0f) {
- errorMessageTimer = 0.0f;
- errorMessage = "";
- printError = false;
- }
- }
- }
- void EditorState::update(const float dt)
- {
- }
- void EditorState::handleInput()
- {
- if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
- {
- if (actualObject == PLAYER && playerPlaced) {
- printError = true;
- errorMessage = "Only one player spawn is allowed";
- return;
- }
- else if (actualObject == PLAYER && !playerPlaced) playerPlaced = true;
- this->map[GetMouseX() / 42][GetMouseY() / 42] = this->actualObject;
- }
- else if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) this->map[GetMouseX() / 42][GetMouseY() / 42] = EMPTY;
- if (IsKeyPressed(KEY_ONE)) this->actualObject = GROUND;
- if (IsKeyPressed(KEY_TWO)) this->actualObject = WALL;
- if (IsKeyPressed(KEY_THREE)) this->actualObject = CRATE;
- if (IsKeyPressed(KEY_FOUR)) this->actualObject = OBJECTIVE;
- if (IsKeyPressed(KEY_FIVE)) this->actualObject = PLAYER;
- }
- EditorState::EditorState(Game * game)
- {
- this->game = game;
- items = LoadTexture("assets/items.png");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement