pull out world viewport size into a Camera class

GitOrigin-RevId: 92cd946afeaee9ba1503e55be239e3384100cc9a
This commit is contained in:
Colin McMillen 2019-12-08 20:04:22 -05:00
parent 05a779e1fb
commit 83709e9a61
4 changed files with 17 additions and 8 deletions

10
Jumpy.Shared/Camera.cs Normal file
View File

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Jumpy {
class Camera {
public const int Width = (int) (320 * 1.5);
public const int Height = (int) (180 * 1.5);
}
}

View File

@ -9,6 +9,7 @@
<Import_RootNamespace>Jumpy.Shared</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Camera.cs" />
<Compile Include="$(MSBuildThisFileDirectory)IDisplay.cs" />
<Compile Include="$(MSBuildThisFileDirectory)KeyboardInput.cs" />
<Compile Include="$(MSBuildThisFileDirectory)JumpyGame.cs" />

View File

@ -29,7 +29,7 @@ namespace Jumpy {
display.SetFullScreen(fullScreen);
renderTarget = new RenderTarget2D(
GraphicsDevice, 320, 180, false /* mipmap */,
GraphicsDevice, Camera.Width, Camera.Height, false /* mipmap */,
GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);
base.Initialize();
@ -40,7 +40,6 @@ namespace Jumpy {
spriteBatch = new SpriteBatch(GraphicsDevice);
font = Content.Load<SpriteFont>("font");
player = new Player(Content.Load<Texture2D>("player_1x"));
}
// Called once per game. Unloads all game content.

View File

@ -9,16 +9,15 @@ namespace Jumpy {
enum Pose { Walking, Standing, Crouching, Stretching, SwordSwing, Jumping };
enum AirState { Jumping, Ground };
private Texture2D texture;
private const int spriteSize = 48;
private const int spriteWidth = 8;
private const int spriteWidth = 7;
private const int moveSpeed = 200;
private const int jumpSpeed = 600;
private const int gravity = 2000;
private Texture2D texture;
private const int groundLevel = Camera.Height - spriteSize / 2;
// TODO: stop assuming 1920x1080.
private const int groundLevel = 180 - spriteSize / 2 - 10;
private Point position = new Point(200, groundLevel);
private Point position = new Point(Camera.Width / 2, groundLevel);
private Facing facing = Facing.Right;
private Pose pose = Pose.Standing;
private AirState airState = AirState.Ground;
@ -82,7 +81,7 @@ namespace Jumpy {
pose = Pose.Jumping;
}
position.X = (int) Math.Min(Math.Max(position.X, 0 + spriteWidth), 320 - spriteWidth);
position.X = Math.Min(Math.Max(position.X, 0 + spriteWidth), Camera.Width - spriteWidth);
}
private Point spritePosition(Pose pose, GameTime time) {