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

94 lines
2.3 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.h"
using namespace std;
using namespace xna;
//int main()
//{
// cout << "Hello CMake." << endl;
// return 0;
//}
class Game1 : public Game {
public:
Game1() {
auto _game = reinterpret_cast<Game*>(this);
graphics = New<GraphicsDeviceManager>(_game);
}
void Initialize() override {
graphics->Initialize();
Game::Initialize();
}
void LoadContent() override {
spriteBatch = New<SpriteBatch>(*_graphicsDevice);
2024-04-07 14:06:12 -03:00
XnaErrorCode err;
2024-04-14 21:23:09 -03:00
texture = Texture2D::FromStream(*_graphicsDevice, "D:\\sprite.jpg", &err);
2024-04-07 14:06:12 -03:00
Game::LoadContent();
}
void Update(GameTime const& gameTime) override {
const auto state = Keyboard::GetState();
if (state.IsKeyDown(Keys::Right)) {
position.X += 1 * gameTime.ElapsedGameTime.TotalMilliseconds();
}
if (state.IsKeyDown(Keys::Left)) {
position.X -= 1 * gameTime.ElapsedGameTime.TotalMilliseconds();
}
if (state.IsKeyDown(Keys::Up)) {
position.Y -= 1 * gameTime.ElapsedGameTime.TotalMilliseconds();
}
if (state.IsKeyDown(Keys::Down)) {
position.Y += 1 * gameTime.ElapsedGameTime.TotalMilliseconds();
2024-04-16 19:27:05 -03:00
}
2024-04-16 19:27:05 -03:00
oldState = currentState;
const auto currentState = Mouse::GetState();
2024-04-16 19:27:05 -03:00
if (currentState.LeftButton == ButtonState::Pressed && oldState.LeftButton == ButtonState::Released) {
points.push_back(Vector2(currentState.X, currentState.Y));
}
2024-04-07 14:06:12 -03:00
Game::Update(gameTime);
}
void Draw(GameTime const& gameTime) override {
_graphicsDevice->Clear(Colors::CornflowerBlue);
2024-04-14 21:23:09 -03:00
spriteBatch->Begin();
2024-04-16 19:27:05 -03:00
// spriteBatch->Draw(*texture, position, nullptr, Colors::White, 0, { 0,0 }, 0.5F, SpriteEffects::None, 0);
for (size_t i = 0; i < points.size(); ++i) {
spriteBatch->Draw(*texture, points[i], nullptr, Colors::White, 0, {0,0}, 0.5F, SpriteEffects::None, 0);
}
2024-04-14 21:23:09 -03:00
spriteBatch->End();
Game::Draw(gameTime);
}
private:
2024-04-14 21:23:09 -03:00
PGraphicsDeviceManager graphics = nullptr;
PSpriteBatch spriteBatch = nullptr;
PTexture2D texture = nullptr;
Vector2 position{};
2024-04-16 19:27:05 -03:00
std::vector<Vector2> points;
MouseState currentState;
MouseState oldState;
float vel = 1;
};
int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
2024-04-16 19:27:05 -03:00
auto game = Game1();
const auto result = game.Run();
return result;
2024-03-18 15:41:46 -03:00
}