Create EndingState
This commit is contained in:
parent
6ecbda7b44
commit
cc96b2aa1b
@ -22,6 +22,8 @@ add_executable(Obstacle
|
|||||||
src/entities/Player.h
|
src/entities/Player.h
|
||||||
src/entities/Opponent.cpp
|
src/entities/Opponent.cpp
|
||||||
src/entities/Opponent.h
|
src/entities/Opponent.h
|
||||||
|
src/states/EndingState.cpp
|
||||||
|
src/states/EndingState.h
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(Obstacle SDL2::SDL2 SDL2_image::SDL2_image SDL2_ttf::SDL2_ttf)
|
target_link_libraries(Obstacle SDL2::SDL2 SDL2_image::SDL2_image SDL2_ttf::SDL2_ttf)
|
37
src/states/EndingState.cpp
Normal file
37
src/states/EndingState.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include "EndingState.h"
|
||||||
|
#include "../Renderer.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <SDL_image.h>
|
||||||
|
|
||||||
|
void EndingState::init() {
|
||||||
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
|
std::cout << "Ending state initialized\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndingState::handleEvents(SDL_Event& event) {
|
||||||
|
if (event.type == SDL_KEYDOWN) {
|
||||||
|
switch (event.key.keysym.sym) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
std::cout << "Exiting game\n";
|
||||||
|
this->changeRoom("exit");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndingState::update() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndingState::render(SDL_Renderer* renderer, double deltaTime) {
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
|
TTF_Font *font = TTF_OpenFont("./res/font.ttf", 24);
|
||||||
|
drawText(renderer, font, "GAME OVER",
|
||||||
|
WINDOW_WIDTH / 2 - 100, WINDOW_HEIGHT / 2 - 50, {255, 0, 0, SDL_ALPHA_OPAQUE});
|
||||||
|
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
}
|
11
src/states/EndingState.h
Normal file
11
src/states/EndingState.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "GameState.h"
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <SDL2/SDL_ttf.h>
|
||||||
|
|
||||||
|
class EndingState final : public GameState {
|
||||||
|
public:
|
||||||
|
void init() override;
|
||||||
|
void handleEvents(SDL_Event& event) override;
|
||||||
|
void update() override;
|
||||||
|
void render(SDL_Renderer* renderer, double deltaTime) override;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user