2019-12-04 18:16:38 +00:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
using Microsoft.Xna.Framework.Input;
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Jumpy {
|
|
|
|
|
public class JumpyGame : Game {
|
|
|
|
|
GraphicsDeviceManager graphics;
|
|
|
|
|
SpriteBatch spriteBatch;
|
2019-12-07 01:00:42 +00:00
|
|
|
|
Texture2D playerTexture;
|
2019-12-04 18:16:38 +00:00
|
|
|
|
SpriteFont font;
|
|
|
|
|
KeyboardInput keyboardInput = new KeyboardInput();
|
2019-12-04 20:32:07 +00:00
|
|
|
|
bool fullScreen = false;
|
2019-12-04 22:15:50 +00:00
|
|
|
|
IDisplay display;
|
2019-12-04 18:16:38 +00:00
|
|
|
|
|
|
|
|
|
public JumpyGame() {
|
|
|
|
|
graphics = new GraphicsDeviceManager(this);
|
2019-12-04 20:48:38 +00:00
|
|
|
|
IsMouseVisible = true;
|
2019-12-04 18:16:38 +00:00
|
|
|
|
Content.RootDirectory = "Content";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Performs initialization that's needed before starting to run.
|
|
|
|
|
protected override void Initialize() {
|
2019-12-04 22:15:50 +00:00
|
|
|
|
display = (IDisplay) Services.GetService(typeof(IDisplay));
|
2019-12-04 22:09:02 +00:00
|
|
|
|
display.Initialize(Window, graphics);
|
|
|
|
|
display.SetFullScreen(fullScreen);
|
2019-12-06 19:55:42 +00:00
|
|
|
|
|
2019-12-04 18:16:38 +00:00
|
|
|
|
base.Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called once per game. Loads all game content.
|
|
|
|
|
protected override void LoadContent() {
|
|
|
|
|
spriteBatch = new SpriteBatch(GraphicsDevice);
|
|
|
|
|
font = Content.Load<SpriteFont>("font");
|
2019-12-07 01:00:42 +00:00
|
|
|
|
playerTexture = Content.Load<Texture2D>("player");
|
2019-12-04 18:16:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called once per game. Unloads all game content.
|
|
|
|
|
protected override void UnloadContent() {
|
|
|
|
|
// TODO: Unload any non ContentManager content here.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Updates the game world.
|
|
|
|
|
protected override void Update(GameTime gameTime) {
|
|
|
|
|
keyboardInput.Update();
|
|
|
|
|
List<Keys> keysDown = keyboardInput.NewKeysDown();
|
|
|
|
|
|
2019-12-04 20:32:07 +00:00
|
|
|
|
if (keysDown.Contains(Keys.F12)) {
|
|
|
|
|
fullScreen = !fullScreen;
|
2019-12-04 22:09:02 +00:00
|
|
|
|
display.SetFullScreen(fullScreen);
|
2019-12-04 20:32:07 +00:00
|
|
|
|
}
|
2019-12-04 18:16:38 +00:00
|
|
|
|
|
|
|
|
|
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
|
|
|
|
|
keysDown.Contains(Keys.Escape)) {
|
|
|
|
|
Exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.Update(gameTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called when the game should draw itself.
|
|
|
|
|
protected override void Draw(GameTime gameTime) {
|
|
|
|
|
GraphicsDevice.Clear(Color.CornflowerBlue);
|
|
|
|
|
|
2019-12-08 13:28:17 +00:00
|
|
|
|
const int spriteSize = 144;
|
2019-12-07 01:00:42 +00:00
|
|
|
|
int frameNum = gameTime.TotalGameTime.Milliseconds / 250;
|
|
|
|
|
if (frameNum == 3) {
|
|
|
|
|
frameNum = 1;
|
|
|
|
|
}
|
2019-12-08 13:28:17 +00:00
|
|
|
|
int sourceX = spriteTileSize * frameNum + spriteTileSize * 3;
|
|
|
|
|
int sourceY = spriteTileSize * 0;
|
2019-12-07 01:00:42 +00:00
|
|
|
|
Rectangle source = new Rectangle(sourceX, sourceY, 144, 144);
|
|
|
|
|
// Vector2 position = new Vector2(0, 0);
|
|
|
|
|
Vector2 position = new Vector2(100, 100);
|
|
|
|
|
Vector2 spriteCenter = new Vector2(144 / 2, 144 / 2);
|
2019-12-04 18:16:38 +00:00
|
|
|
|
spriteBatch.Begin();
|
2019-12-07 01:00:42 +00:00
|
|
|
|
spriteBatch.Draw(playerTexture, position, source, Color.White, 0f, spriteCenter, Vector2.One, SpriteEffects.FlipHorizontally, 0f);
|
2019-12-04 18:16:38 +00:00
|
|
|
|
spriteBatch.End();
|
|
|
|
|
|
2019-12-07 01:00:42 +00:00
|
|
|
|
// spriteBatch.DrawString(font, "hello world", new Vector2(100, 100), Color.Black);
|
|
|
|
|
|
2019-12-04 18:16:38 +00:00
|
|
|
|
base.Draw(gameTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|