-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from adamhutchings/inventory
Add hotbar
- Loading branch information
Showing
9 changed files
with
115 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "hotbar_renderer.h" | ||
|
||
InventoryFrame::InventoryFrame(MWindow& window, int x, int y) | ||
: | ||
// Initialize the rects | ||
b(sf::Vector2f(FRAME_SIZE, FRAME_THICKNESS)), | ||
t(sf::Vector2f(FRAME_SIZE, FRAME_THICKNESS)), | ||
l(sf::Vector2f(FRAME_THICKNESS, FRAME_SIZE)), | ||
r(sf::Vector2f(FRAME_THICKNESS, FRAME_SIZE)) { | ||
// Giving positions to the various elements | ||
b.setPosition(sf::Vector2f(x - (FRAME_SIZE / 2), y + (FRAME_SIZE / 2) - FRAME_THICKNESS)); | ||
t.setPosition(sf::Vector2f(x - (FRAME_SIZE / 2), y - (FRAME_SIZE / 2))); | ||
l.setPosition(sf::Vector2f(x - (FRAME_SIZE / 2), y - (FRAME_SIZE / 2))); | ||
r.setPosition(sf::Vector2f(x + (FRAME_SIZE / 2) - (FRAME_THICKNESS / 2), y - FRAME_SIZE / 2)); | ||
} | ||
|
||
void InventoryFrame::render(MWindow& window) { | ||
// Just draw all the rectangles | ||
window.draw(b); | ||
window.draw(t); | ||
window.draw(l); | ||
window.draw(r); | ||
} | ||
|
||
void renderHotbar(MWindow& window, InventorySection* section) { | ||
int centerX; | ||
sf::Text text; // For later | ||
for (int i = 0; i < section->size; i++) { | ||
centerX = WN_WIDTH / 2 - (section->size * FRAME_SIZE / 2) + (i * FRAME_SIZE); | ||
InventoryFrame(window, centerX, HOTBAR_DISPLAY_HEIGHT).render(window); | ||
section->contents[i]->spr.setPosition( | ||
centerX - (200 * 0.4 / 2), HOTBAR_DISPLAY_HEIGHT - (200 * 0.4 / 2) | ||
); | ||
if (section->contents[i]->name != "empty") { | ||
window.draw(section->contents[i]->spr); | ||
if (section->contents[i]->count > 1) { | ||
// The item counter display | ||
text.setCharacterSize(INVENTORY_FONT_SIZE); | ||
text.setFont(INVENTORY_FONT); | ||
text.setPosition( | ||
centerX - 100 + FONT_X_OFFSET, | ||
HOTBAR_DISPLAY_HEIGHT - 100 + FONT_Y_OFFSET | ||
); | ||
text.setString(std::to_string(section->contents[i]->count)); | ||
window.draw(text); | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef M_HB_RENDERER_H | ||
#define M_HB_RENDERER_H | ||
|
||
#include <SFML/Graphics.hpp> | ||
#include <string> | ||
#include "../render/m_window.h" | ||
#include "../item/inventory.h" | ||
#include "../render/renderable.h" | ||
#include "../main.h" | ||
|
||
#define FRAME_THICKNESS 20 | ||
#define FRAME_SIZE 160 | ||
|
||
#define HOTBAR_DISPLAY_HEIGHT 1400 | ||
|
||
#define INVENTORY_FONT_SIZE 30 | ||
|
||
#define FONT_X_OFFSET 130 | ||
#define FONT_Y_OFFSET 130 | ||
|
||
inline sf::Font INVENTORY_FONT; | ||
|
||
class InventorySection; | ||
|
||
class InventoryFrame { | ||
public: | ||
sf::RectangleShape b, t, l, r; // The four sides | ||
InventoryFrame(MWindow& window, int xPos, int yPos); | ||
void render(MWindow& window); | ||
}; | ||
|
||
// This provides a method to render an inventory section in a straight line | ||
// at the bottom of the screen. | ||
void renderHotbar(MWindow& window, InventorySection* section); | ||
|
||
#endif // M_HB_RENDERER_H |
This file contains 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
This file contains 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
This file contains 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
This file contains 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