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;
|
|
|
|
|
//}
|
|
|
|
|
|
2024-03-24 18:37:55 -03:00
|
|
|
|
class Game1 : public Game {
|
2024-04-01 11:29:32 -03:00
|
|
|
|
public:
|
|
|
|
|
Game1() {
|
2024-04-16 16:13:36 -03:00
|
|
|
|
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-01 11:29:32 -03:00
|
|
|
|
|
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
|
|
|
|
|
2024-04-16 16:13:36 -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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*if (position.X > 1280 || position.X < 0)
|
|
|
|
|
vel *= -1;
|
|
|
|
|
|
|
|
|
|
if (gameTime.ElapsedGameTime.TotalMilliseconds() > 1) {
|
|
|
|
|
|
|
|
|
|
}
|
2024-04-07 14:06:12 -03:00
|
|
|
|
|
2024-04-16 16:13:36 -03:00
|
|
|
|
position.X += 0.05 * (gameTime.ElapsedGameTime.TotalMilliseconds() * vel);*/
|
|
|
|
|
//position.X += 2 * vel;
|
2024-03-24 18:37:55 -03:00
|
|
|
|
|
|
|
|
|
Game::Update(gameTime);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-16 16:13:36 -03:00
|
|
|
|
void Draw(GameTime const& gameTime) override {
|
|
|
|
|
_graphicsDevice->Clear(Colors::CornflowerBlue);
|
2024-03-24 18:37:55 -03:00
|
|
|
|
|
2024-04-14 21:23:09 -03:00
|
|
|
|
spriteBatch->Begin();
|
2024-04-16 16:13:36 -03:00
|
|
|
|
spriteBatch->Draw(*texture, position, nullptr, Colors::White, 0, { 0,0 }, 0.5F, SpriteEffects::None, 0);
|
2024-04-14 21:23:09 -03:00
|
|
|
|
spriteBatch->End();
|
|
|
|
|
|
2024-03-24 18:37:55 -03:00
|
|
|
|
Game::Draw(gameTime);
|
|
|
|
|
}
|
2024-04-01 11:29:32 -03:00
|
|
|
|
|
|
|
|
|
private:
|
2024-04-14 21:23:09 -03:00
|
|
|
|
PGraphicsDeviceManager graphics = nullptr;
|
|
|
|
|
PSpriteBatch spriteBatch = nullptr;
|
|
|
|
|
PTexture2D texture = nullptr;
|
2024-04-16 16:13:36 -03:00
|
|
|
|
Vector2 position{};
|
|
|
|
|
float vel = 1;
|
2024-03-24 18:37:55 -03:00
|
|
|
|
};
|
|
|
|
|
|
2024-04-01 11:29:32 -03:00
|
|
|
|
int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
|
|
|
|
|
/*FileStream stream("D:/VS_EXPBSLN_x64_enu.CAB");
|
2024-03-26 17:22:00 -03:00
|
|
|
|
auto pos = stream.Position();
|
|
|
|
|
auto len = stream.Length();
|
2024-04-01 11:29:32 -03:00
|
|
|
|
pos = stream.Position();*/
|
2024-03-26 17:22:00 -03:00
|
|
|
|
|
2024-03-24 18:37:55 -03:00
|
|
|
|
Game1 game;
|
2024-03-21 16:01:47 -03:00
|
|
|
|
game.Run();
|
2024-03-18 15:41:46 -03:00
|
|
|
|
return 0;
|
|
|
|
|
}
|