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;
|
2019-12-08 23:51:23 +00:00
|
|
|
|
RenderTarget2D renderTarget;
|
2019-12-04 18:16:38 +00:00
|
|
|
|
SpriteBatch spriteBatch;
|
|
|
|
|
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
|
|
|
|
|
2019-12-08 14:38:26 +00:00
|
|
|
|
Player player;
|
|
|
|
|
|
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-08 23:51:23 +00:00
|
|
|
|
renderTarget = new RenderTarget2D(
|
|
|
|
|
GraphicsDevice, 320, 180, false /* mipmap */,
|
|
|
|
|
GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);
|
|
|
|
|
|
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-08 23:51:23 +00:00
|
|
|
|
player = new Player(Content.Load<Texture2D>("player_1x"));
|
2019-12-08 14:38:26 +00:00
|
|
|
|
|
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();
|
2019-12-08 14:38:26 +00:00
|
|
|
|
GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);
|
2019-12-04 18:16:38 +00:00
|
|
|
|
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
|
|
|
|
|
2019-12-08 14:38:26 +00:00
|
|
|
|
if (gamePadState.Buttons.Start == ButtonState.Pressed ||
|
2019-12-04 18:16:38 +00:00
|
|
|
|
keysDown.Contains(Keys.Escape)) {
|
|
|
|
|
Exit();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-08 14:38:26 +00:00
|
|
|
|
player.Update(gameTime, gamePadState);
|
|
|
|
|
|
2019-12-04 18:16:38 +00:00
|
|
|
|
base.Update(gameTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called when the game should draw itself.
|
|
|
|
|
protected override void Draw(GameTime gameTime) {
|
2019-12-08 23:51:23 +00:00
|
|
|
|
// Draw scene to RenderTarget.
|
|
|
|
|
GraphicsDevice.SetRenderTarget(renderTarget);
|
|
|
|
|
// GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true };
|
2019-12-04 18:16:38 +00:00
|
|
|
|
GraphicsDevice.Clear(Color.CornflowerBlue);
|
|
|
|
|
spriteBatch.Begin();
|
2019-12-08 14:38:26 +00:00
|
|
|
|
player.Draw(gameTime, spriteBatch);
|
2019-12-04 18:16:38 +00:00
|
|
|
|
spriteBatch.End();
|
|
|
|
|
|
2019-12-08 23:51:23 +00:00
|
|
|
|
// Draw RenderTarget to screen.
|
|
|
|
|
GraphicsDevice.SetRenderTarget(null);
|
|
|
|
|
GraphicsDevice.Clear(Color.Black);
|
|
|
|
|
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque,
|
|
|
|
|
SamplerState.PointClamp, DepthStencilState.Default,
|
|
|
|
|
RasterizerState.CullNone);
|
|
|
|
|
Rectangle drawRect = new Rectangle(
|
|
|
|
|
0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
|
|
|
|
|
spriteBatch.Draw(renderTarget, drawRect, Color.White);
|
|
|
|
|
// spriteBatch.DrawString(font, "hello world", new Vector2(10, 10), Color.Black);
|
|
|
|
|
spriteBatch.End();
|
2019-12-07 01:00:42 +00:00
|
|
|
|
|
2019-12-04 18:16:38 +00:00
|
|
|
|
base.Draw(gameTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|