add ground texture

GitOrigin-RevId: 2313a9c0387ddb62ffca2aa563f9bab3ee10cdaf
This commit is contained in:
Colin McMillen 2019-12-10 16:09:43 -05:00
parent 06620ce368
commit 1fbcacecfc
3 changed files with 18 additions and 3 deletions

View File

@ -4,7 +4,7 @@ using System.Text;
namespace Jumpy { namespace Jumpy {
class Camera { class Camera {
public const int Width = 1920 / 4; public const int Width = 1920 / 6;
public const int Height = 1080 / 4; public const int Height = 1080 / 6;
} }
} }

View File

@ -25,6 +25,7 @@ namespace Jumpy {
FpsCounter fpsCounter = new FpsCounter(); FpsCounter fpsCounter = new FpsCounter();
Player player; Player player;
Texture2D grassland;
public JumpyGame() { public JumpyGame() {
graphics = new GraphicsDeviceManager(this); graphics = new GraphicsDeviceManager(this);
@ -52,6 +53,7 @@ namespace Jumpy {
spriteBatch = new SpriteBatch(GraphicsDevice); spriteBatch = new SpriteBatch(GraphicsDevice);
font = Content.Load<SpriteFont>("font"); font = Content.Load<SpriteFont>("font");
player = new Player(Content.Load<Texture2D>("player_1x")); player = new Player(Content.Load<Texture2D>("player_1x"));
grassland = Content.Load<Texture2D>("grassland");
} }
// Called once per game. Unloads all game content. // Called once per game. Unloads all game content.
@ -91,7 +93,19 @@ namespace Jumpy {
GraphicsDevice.SetRenderTarget(renderTarget); GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(); spriteBatch.Begin();
// Draw player.
player.Draw(gameTime, spriteBatch); player.Draw(gameTime, spriteBatch);
// Draw foreground tiles.
int size = 16;
Rectangle textureSource = new Rectangle(3 * size, 0 * size, size, size);
for (int i = 0; i < Camera.Width / size; i++) {
Vector2 drawPos = new Vector2(i * size, Camera.Height - size);
spriteBatch.Draw(grassland, drawPos, textureSource, Color.White);
}
// Aaaaand we're done.
spriteBatch.End(); spriteBatch.End();
// Draw RenderTarget to screen. // Draw RenderTarget to screen.

View File

@ -12,10 +12,11 @@ namespace Jumpy {
private Texture2D texture; private Texture2D texture;
private const int spriteSize = 48; private const int spriteSize = 48;
private const int spriteWidth = 7; private const int spriteWidth = 7;
private const int bottomPadding = 5;
private const int moveSpeed = 200; private const int moveSpeed = 200;
private const int jumpSpeed = 600; private const int jumpSpeed = 600;
private const int gravity = 2000; private const int gravity = 2000;
private const int groundLevel = Camera.Height - spriteSize / 2; private const int groundLevel = Camera.Height - spriteSize / 2 + bottomPadding - 16;
private Point position = new Point(Camera.Width / 2, groundLevel); private Point position = new Point(Camera.Width / 2, groundLevel);
private Facing facing = Facing.Right; private Facing facing = Facing.Right;