Motor de sprites/animacions/surfaces i jugador centrat (v0.2.0)
This commit is contained in:
1 parent
7bb1edd08a
commit
de5a670fdb
34 files changed
+16137
-81
No files matched your search
@@ -0,0 +1,42 @@
|
||||
#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();
|
||||
}
|
||||
Reference in new issue
Block a user