43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
#include "game/scenes/game_scene.hpp"
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include "core/rendering/screen.hpp"
|
|
#include "core/resources/resource_cache.hpp"
|
|
#include "core/system/event_buffer.hpp"
|
|
#include "game/entities/player.hpp"
|
|
#include "utils/defines.hpp"
|
|
|
|
namespace {
|
|
constexpr float PLAYER_FRAME_W = 12.0F;
|
|
constexpr float PLAYER_FRAME_H = 24.0F;
|
|
} // namespace
|
|
|
|
GameScene::GameScene() {
|
|
Resource::Cache::get().loadSurface("player.gif", "data/player/player.gif");
|
|
Resource::Cache::get().loadAnimation("player.yaml", "data/player/player.yaml");
|
|
|
|
const float X = static_cast<float>(GameCanvas::CENTER_X) - (PLAYER_FRAME_W / 2.0F);
|
|
const float Y = static_cast<float>(GameCanvas::CENTER_Y) - (PLAYER_FRAME_H / 2.0F);
|
|
player_ = std::make_unique<Player>(X, Y);
|
|
}
|
|
|
|
GameScene::~GameScene() = default;
|
|
|
|
void GameScene::update(int delta_ms) {
|
|
for (const auto& event : EventBuffer::events) {
|
|
if (event.type == SDL_EVENT_KEY_DOWN && event.key.scancode == SDL_SCANCODE_ESCAPE) {
|
|
wants_quit_ = true;
|
|
}
|
|
}
|
|
|
|
const float DT = static_cast<float>(delta_ms) / 1000.0F;
|
|
player_->update(DT);
|
|
}
|
|
|
|
void GameScene::render() {
|
|
Screen::get().clear(0x00, 0x00, 0x00);
|
|
player_->render();
|
|
Screen::get().present();
|
|
}
|