added a nice parallax background

This commit is contained in:
Ell 2021-03-09 02:37:44 +01:00
parent bf330df988
commit 00240a79be
8 changed files with 33 additions and 10 deletions

View file

@ -55,3 +55,8 @@
/processor:TiledMapTilesetProcessor
/build:Tilesets/World.tsx
#begin Textures/Backgrounds.png
/importer:TextureImporter
/processor:TextureProcessor
/build:Textures/Backgrounds.png

View file

@ -1,5 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="83" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="1">
<properties>
<property name="StartX" type="int" value="1"/>
<property name="StartY" type="int" value="24"/>
</properties>
<tileset firstgid="1" source="../Tilesets/World.tsx"/>
<layer id="1" name="Ground" width="83" height="30">
<data encoding="csv">
@ -95,8 +99,8 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,7,7,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,15,16,0,6,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,8,6,8,0,0,0,0,0,0,0,0,0,0,14,15,15,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,16,14,16,0,6,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,7,7,8,0,0,0,0,0,0,0,0,0,0,0,0,0,6,8,0,6,7,7,7,8,0,0,0,0,0,0,0,0,0,0,0,0,0,
7,8,6,7,8,0,6,7,8,0,0,0,0,0,0,0,0,0,0,0,0,0,14,16,0,0,0,0,0,6,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -35,11 +35,10 @@ namespace GreatSpringGameJam {
this.Camera = new Camera(this.GraphicsDevice) {
AutoScaleWithScreen = true,
Scale = 4,
Position = new Vector2(0, float.MaxValue)
Scale = 4
};
this.Map = new Map("Level1");
this.Player = new Player(this.Map, new Vector2(70, 20));
this.Player = new Player(this.Map, this.Map.SpawnPoint.ToVector2());
this.Map.AddEntity(this.Player);
}
@ -88,7 +87,7 @@ namespace GreatSpringGameJam {
while (completionCounter < completion * 100) {
completionCounter++;
score.Text = string.Format(scoreText, completionCounter);
yield return new Wait(0.05F);
yield return new Wait(0.03F);
}
}

View file

@ -9,9 +9,9 @@
<ItemGroup>
<PackageReference Include="Contentless" Version="3.0.5" />
<PackageReference Include="MLEM" Version="5.0.0-66" />
<PackageReference Include="MLEM.Extended" Version="5.0.0-66" />
<PackageReference Include="MLEM.Startup" Version="5.0.0-66" />
<PackageReference Include="MLEM" Version="5.0.0-67" />
<PackageReference Include="MLEM.Extended" Version="5.0.0-67" />
<PackageReference Include="MLEM.Startup" Version="5.0.0-67" />
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.0.1641" />
<PackageReference Include="MonoGame.Extended.Content.Pipeline" Version="3.8.0" />
<PackageReference Include="MonoGame.Extended.Tiled" Version="3.8.0" />
@ -31,7 +31,6 @@
<ItemGroup>
<Folder Include="Content\Palettes" />
<Folder Include="Content\Textures" />
<Folder Include="Content\Tilesets" />
</ItemGroup>
</Project>

View file

@ -4,14 +4,19 @@ using Microsoft.Xna.Framework.Graphics;
using MLEM.Cameras;
using MLEM.Extended.Extensions;
using MLEM.Extended.Tiled;
using MLEM.Extensions;
using MLEM.Misc;
using MLEM.Startup;
using MLEM.Textures;
using MonoGame.Extended;
using MonoGame.Extended.Tiled;
namespace GreatSpringGameJam {
public class Map {
private static readonly UniformTextureAtlas BackgroundTexture = new(MlemGame.LoadContent<Texture2D>("Textures/Backgrounds"), 8, 8);
public Point SizeInPixels => new(this.map.WidthInPixels, this.map.HeightInPixels);
public Point SpawnPoint => new(this.map.Properties.GetInt("StartX"), this.map.Properties.GetInt("StartY"));
public Vector2 TileSize => this.map.GetTileSize();
public readonly TiledMapCollisions Collisions;
public readonly int TotalSnow;
@ -60,6 +65,16 @@ namespace GreatSpringGameJam {
public void Draw(GameTime time, SpriteBatch batch, Camera camera) {
batch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, transformMatrix: camera.ViewMatrix);
// render background
const float parallaxFactor = 0.5F;
var parallax = camera.Position * parallaxFactor;
var (parW, parH) = this.SizeInPixels.ToVector2() * (1 - parallaxFactor) + camera.ScaledViewport * parallaxFactor;
var mountains = BackgroundTexture[0, 0, 8, 4];
for (var x = 0; x < parW; x += mountains.Width * 2) {
batch.Draw(mountains, parallax + new Vector2(x, parH - mountains.Height * 2), Color.White * 0.5F, 0, Vector2.Zero, 2, SpriteEffects.None, 0);
}
// render map etc.
this.DrawLayer(batch, "Ground", camera);
foreach (var entity in this.entities)
entity.Draw(time, batch);

View file

@ -34,6 +34,7 @@ namespace GreatSpringGameJam {
this.animations = new SpriteAnimationGroup();
this.animations.Add(new SpriteAnimation(0.15F, PlayerTexture[1], PlayerTexture[2], PlayerTexture[3], PlayerTexture[0]), () => this.walking);
this.animations.Add(new SpriteAnimation(1, PlayerTexture[0]), () => !this.walking);
this.facingRight = true;
}
public override void Update(GameTime time) {