1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00

Implementações em Game

This commit is contained in:
Danilo 2024-08-01 16:33:06 -03:00
parent 34d9533261
commit 2135b5859b
5 changed files with 36 additions and 20 deletions

View File

@ -28,7 +28,7 @@ namespace xna {
int Game::StartGameLoop() {
MSG msg{};
impl->_stepTimer = xna::StepTimer();
impl->_stepTimer = xna::StepTimer();
do {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
@ -42,6 +42,7 @@ namespace xna {
} while (msg.message != WM_QUIT);
EndRun();
return static_cast<int>(msg.wParam);
}
@ -58,7 +59,9 @@ namespace xna {
Update(_currentGameTime);
});
BeginDraw();
Draw(_currentGameTime);
EndDraw();
}
int Game::Run() {
@ -79,6 +82,7 @@ namespace xna {
}
isRunning = true;
BeginRun();
return StartGameLoop();
}
catch (std::exception& e) {

View File

@ -53,19 +53,29 @@ namespace xna {
void ResizeWindow(int width, int heigth);
protected:
//Starts the drawing of a frame. This method is followed by calls to Draw and EndDraw.
virtual void BeginDraw(){}
//Called after all components are initialized but before the first update in the game loop.
virtual void BeginRun() {};
//Called when the game determines it is time to draw a frame.
virtual void Draw(GameTime const& gameTime);
//Ends the drawing of a frame. This method is preceeded by calls to Draw and BeginDraw.
virtual void EndDraw() {}
//Called after the game loop has stopped running before exiting.
virtual void EndRun() {};
//Called after the Game and GraphicsDevice are created, but before LoadContent.
virtual void Initialize();
//Called when graphics resources need to be loaded.
virtual void LoadContent(){}
virtual void Update(GameTime const& gameTime);
int StartGameLoop();
public:
sptr<GraphicsDevice> graphicsDevice = nullptr;
protected:
sptr<GameServiceContainer> services = nullptr;
//Called when the game has determined that game logic needs to be processed.
virtual void Update(GameTime const& gameTime);
private:
int StartGameLoop();
private:
friend class GraphicsDeviceManager;
sptr<GameComponentCollection> _gameComponents = nullptr;
sptr<GameWindow> _gameWindow{ nullptr };
sptr<AudioEngine> _audioEngine = nullptr;
@ -77,6 +87,8 @@ namespace xna {
bool isFixedTimeStep{ true };
TimeSpan targetElapsedTime{ TimeSpan::FromTicks(166667L) };
bool isRunning{ false };
sptr<GameServiceContainer> services = nullptr;
sptr<GraphicsDevice> graphicsDevice = nullptr;
public:
struct PlatformImplementation;

View File

@ -20,14 +20,14 @@ namespace xna {
//graphics->Initialize();
graphics->ApplyChanges();
std::any device = graphicsDevice;
services->AddService(*typeof<GraphicsDevice>(), device);
std::any device = Device();
Services()->AddService(*typeof<GraphicsDevice>(), device);
Game::Initialize();
}
void LoadContent() override {
spriteBatch = snew<SpriteBatch>(graphicsDevice);
spriteBatch = snew<SpriteBatch>(Device());
Game::LoadContent();
}
@ -39,7 +39,7 @@ namespace xna {
}
void Draw(GameTime const& gameTime) override {
graphicsDevice->Clear(Colors::CornflowerBlue);
Device()->Clear(Colors::CornflowerBlue);
Game::Draw(gameTime);
}

View File

@ -24,14 +24,14 @@ namespace PlatformerStarterKit {
graphics = snew<GraphicsDeviceManager>(game->shared_from_this());
graphics->ApplyChanges();
std::any device = graphicsDevice;
services->AddService(*typeof<GraphicsDevice>(), device);
std::any device = Device();
Services()->AddService(*typeof<GraphicsDevice>(), device);
Game::Initialize();
}
void LoadContent() override {
spriteBatch = snew<SpriteBatch>(graphicsDevice);
spriteBatch = snew<SpriteBatch>(Device());
// Load fonts
hudFont = Content()->Load<PSpriteFont>("Fonts/Hud");
@ -55,7 +55,7 @@ namespace PlatformerStarterKit {
}
void Draw(GameTime const& gameTime) override {
graphicsDevice->Clear(Colors::CornflowerBlue);
Device()->Clear(Colors::CornflowerBlue);
spriteBatch->Begin();
@ -111,7 +111,7 @@ namespace PlatformerStarterKit {
levelIndex = -1;
}
level = snew<Level>(services, levelPath);
level = snew<Level>(Services(), levelPath);
level->Initialize();
}
@ -122,7 +122,7 @@ namespace PlatformerStarterKit {
void DrawHud()
{
auto titleSafeArea = graphicsDevice->Viewport().Bounds();
auto titleSafeArea = Device()->Viewport().Bounds();
auto hudLocation = Vector2(titleSafeArea.X, titleSafeArea.Y);
auto center = Vector2(titleSafeArea.X + titleSafeArea.Width / 2.0f,
titleSafeArea.Y + titleSafeArea.Height / 2.0f);

View File

@ -4,4 +4,4 @@
# Add source to this project's executable.
add_subdirectory ("01_blank")
#add_subdirectory ("02_PlatfformerStarterKit")
add_subdirectory ("02_PlatfformerStarterKit")