1 | #include "game-screen.hpp"
|
---|
2 |
|
---|
3 | #include <iostream>
|
---|
4 |
|
---|
5 | #include <SDL2/SDL_ttf.h>
|
---|
6 |
|
---|
7 | #include "../vulkan-game.hpp"
|
---|
8 |
|
---|
9 | #include "button.hpp"
|
---|
10 | #include "panel.hpp"
|
---|
11 | #include "ui-value.hpp"
|
---|
12 |
|
---|
13 | using namespace std;
|
---|
14 |
|
---|
15 | // TODO: Figure out a good way to return errors instead of just printing them
|
---|
16 | // Probably throw an exception in the constructor
|
---|
17 | // Make sure to cleanup anythign that was initialized correctly before the error
|
---|
18 | // since throwing an exception in the constructor means the destructor won't get called
|
---|
19 |
|
---|
20 | GameScreen::GameScreen(SDL_Renderer& renderer, VulkanGame& gameInfo) :
|
---|
21 | Screen(renderer, gameInfo) {
|
---|
22 | Panel *statsPanel = new Panel(10, 50, 95, 46, 0x161616FF, this->renderer);
|
---|
23 |
|
---|
24 | statsPanel->addUIElement(new UIValue(0, 0, "Score: ", this->gameInfo.score,
|
---|
25 | this->gameInfo.proggyFont, 0xFFFFFFFF, this->renderer));
|
---|
26 | statsPanel->addUIElement(new UIValue(14, 19, "FPS: ", this->gameInfo.fps,
|
---|
27 | this->gameInfo.proggyFont, 0xFFFFFFFF, this->renderer));
|
---|
28 |
|
---|
29 | // TODO: Add the button to the panel it's in, not directly to the window
|
---|
30 | addUIElement(statsPanel);
|
---|
31 | addUIElement(new Panel(540, 10, 250, 35, 0x161616FF, this->renderer));
|
---|
32 | addUIElement(new Panel(590, 60, 200, 200, 0x161616FF, this->renderer));
|
---|
33 | addUIElement(new Button("Main Menu", 708, 17, 8, 0x222299FF, 0xFFFFFFFF, this->gameInfo,
|
---|
34 | this->renderer, mainMenu_onMouseClick, nullptr, nullptr));
|
---|
35 | }
|
---|
36 |
|
---|
37 | GameScreen::~GameScreen() {
|
---|
38 | }
|
---|
39 |
|
---|
40 | void GameScreen::createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage) {
|
---|
41 | gameInfo.modelPipeline.createRenderCommands(commandBuffer, currentImage);
|
---|
42 | gameInfo.shipPipeline.createRenderCommands(commandBuffer, currentImage);
|
---|
43 | gameInfo.asteroidPipeline.createRenderCommands(commandBuffer, currentImage);
|
---|
44 | gameInfo.laserPipeline.createRenderCommands(commandBuffer, currentImage);
|
---|
45 | gameInfo.explosionPipeline.createRenderCommands(commandBuffer, currentImage);
|
---|
46 |
|
---|
47 | // Always render this pipeline last
|
---|
48 | gameInfo.overlayPipeline.createRenderCommands(commandBuffer, currentImage);
|
---|
49 | }
|
---|
50 |
|
---|
51 | void GameScreen::handleEvent(UIEvent& e) {
|
---|
52 | Screen::handleEvent(e);
|
---|
53 | }
|
---|
54 |
|
---|
55 | void mainMenu_onMouseClick(VulkanGame& gameInfo) {
|
---|
56 | gameInfo.goToScreen(gameInfo.screens[SCREEN_MAIN]);
|
---|
57 | }
|
---|