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

71 lines
1.5 KiB
C++
Raw Normal View History

2024-03-18 15:41:46 -03:00
// xna.cpp : Defines the entry point for the application.
//
#include "xna.hpp"
2024-03-18 15:41:46 -03:00
using namespace std;
using namespace xna;
2024-04-22 16:14:55 -03:00
namespace xna {
class Game1 : public Game {
public:
2024-05-06 10:32:17 -03:00
Game1() : Game() {
2024-04-22 16:14:55 -03:00
auto _game = reinterpret_cast<Game*>(this);
graphics = New<GraphicsDeviceManager>(_game);
2024-05-06 14:54:13 -03:00
Content()->RootDirectory("Content");
2024-04-22 16:14:55 -03:00
}
void Initialize() override {
graphics->Initialize();
2024-05-06 11:35:27 -03:00
2024-05-06 14:54:13 -03:00
std::any device = graphicsDevice;
services->AddService(*typeof<GraphicsDevice>(), device);
2024-05-06 11:35:27 -03:00
2024-04-22 16:14:55 -03:00
Game::Initialize();
}
void LoadContent() override {
2024-05-18 19:58:38 -03:00
spriteBatch = New<SpriteBatch>(*graphicsDevice);
texture = Content()->Load<sptr<Texture2D>>("idle");
2024-05-08 10:51:49 -03:00
2024-04-22 16:14:55 -03:00
Game::LoadContent();
}
void Update(GameTime const& gameTime) override {
2024-05-21 09:40:59 -03:00
if (Keyboard::GetState().IsKeyDown(Keys::Escape) || GamePad::GetState(PlayerIndex::One).IsButtonDown(Buttons::Back))
2024-04-22 16:14:55 -03:00
Exit();
Game::Update(gameTime);
}
void Draw(GameTime const& gameTime) override {
2024-05-08 10:51:49 -03:00
graphicsDevice->Clear(Colors::CornflowerBlue);
2024-04-22 16:14:55 -03:00
2024-05-18 19:58:38 -03:00
spriteBatch->Begin();
2024-05-20 09:32:34 -03:00
if(texture)
spriteBatch->Draw(*texture, Vector2(), Colors::White);
2024-05-18 19:58:38 -03:00
spriteBatch->End();
2024-04-22 16:14:55 -03:00
Game::Draw(gameTime);
}
private:
2024-04-26 11:35:59 -03:00
sptr<GraphicsDeviceManager> graphics = nullptr;
sptr<SpriteBatch> spriteBatch = nullptr;
2024-05-18 19:58:38 -03:00
sptr<Texture2D> texture = nullptr;
2024-04-22 16:14:55 -03:00
};
}
2024-03-18 15:41:46 -03:00
int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
xna::InitPlatform::Init();
2024-04-22 16:14:55 -03:00
auto game = xna::Game1();
2024-04-16 19:27:05 -03:00
const auto result = game.Run();
return result;
2024-03-18 15:41:46 -03:00
}