Browse Source

pull out world viewport size into a Camera class

GitOrigin-RevId: 92cd946afe
master
Colin McMillen 4 years ago
parent
commit
83709e9a61
  1. 10
      Jumpy.Shared/Camera.cs
  2. 1
      Jumpy.Shared/Jumpy.Shared.projitems
  3. 3
      Jumpy.Shared/JumpyGame.cs
  4. 11
      Jumpy.Shared/Player.cs

10
Jumpy.Shared/Camera.cs

@ -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);
}
}

1
Jumpy.Shared/Jumpy.Shared.projitems

@ -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" />

3
Jumpy.Shared/JumpyGame.cs

@ -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.

11
Jumpy.Shared/Player.cs

@ -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) {

Loading…
Cancel
Save