From 00240a79be4905b5c6ac253593c319f8c41baf2c Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 9 Mar 2021 02:37:44 +0100 Subject: [PATCH] added a nice parallax background --- GreatSpringGameJam/Content/Content.mgcb | 5 +++++ GreatSpringGameJam/Content/Maps/Level1.tmx | 8 ++++++-- .../Content/Textures/Backgrounds.aseprite | Bin 0 -> 1321 bytes .../Content/Textures/Backgrounds.png | Bin 0 -> 1516 bytes GreatSpringGameJam/GameImpl.cs | 7 +++---- GreatSpringGameJam/GreatSpringGameJam.csproj | 7 +++---- GreatSpringGameJam/Map.cs | 15 +++++++++++++++ GreatSpringGameJam/Player.cs | 1 + 8 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 GreatSpringGameJam/Content/Textures/Backgrounds.aseprite create mode 100644 GreatSpringGameJam/Content/Textures/Backgrounds.png diff --git a/GreatSpringGameJam/Content/Content.mgcb b/GreatSpringGameJam/Content/Content.mgcb index ae90384..d4a4b5b 100644 --- a/GreatSpringGameJam/Content/Content.mgcb +++ b/GreatSpringGameJam/Content/Content.mgcb @@ -55,3 +55,8 @@ /processor:TiledMapTilesetProcessor /build:Tilesets/World.tsx +#begin Textures/Backgrounds.png +/importer:TextureImporter +/processor:TextureProcessor +/build:Textures/Backgrounds.png + diff --git a/GreatSpringGameJam/Content/Maps/Level1.tmx b/GreatSpringGameJam/Content/Maps/Level1.tmx index b84632f..f9f7467 100644 --- a/GreatSpringGameJam/Content/Maps/Level1.tmx +++ b/GreatSpringGameJam/Content/Maps/Level1.tmx @@ -1,5 +1,9 @@ + + + + @@ -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,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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,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,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,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, 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,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, diff --git a/GreatSpringGameJam/Content/Textures/Backgrounds.aseprite b/GreatSpringGameJam/Content/Textures/Backgrounds.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..96e97eb59e50b1648c9d333c22192c51b6c350d0 GIT binary patch literal 1321 zcmcJL|5MU;9LGO|40q}9{J~qzKG0EKp11}?nF`v~G-tD4QqvmRun(9vR&L8AzmQf= z3C22Sk~=lj{DMGhMe0ngso6Bdi`iyO^$+a*zW3wv`Mh8EdOTnE z3B*CrcpU~R0GkA1AP7nW=fC9xVceIH57__5YV?4hrFq=DR4@wU2M(U}F7my&9Pqw@ z^zQ_O_bL!1f+;Qta)}VY=lj9|`;LSFKILx#oNS{3ZkC1t7T#t68ucB3$O8jl$hkQ{ z#_sEY6_?#iisJ(YZHxu<#C_xn1z8^M|Kj7$5g{M}=z$xEffXo$56FNCXn+F*We61&*6Dj;`h{p>2xoWrs!U)b#q^{ibNnyvqgO$$Z=@EST%%&oz zV{IzJT$me!d>J-z-J&w^3E@%xrr0}9K0&d`(={t($dMH5G^&{u;(zpWO%qjB@V3Qb zxIz1%xwpG@(yZD}w4>j{aEN)m=^0bbUT;eNV`AWLpKInt*IYL_d3ketfbs5x$f7cP zH=nKU$zu@q8&JokvhX2JX9<4BuCVXP;D?+m7^sThTeNC|L+H0AQ|`?Tg3k|^MRu~T zy&TQ{LW@g;A2!uo%&lLNMqW*_MhHmF7s)326G_n|&PbZ4qKY}tBBC@tpabCVq=sVZ6f~q zSJtNJo6+d5pjE^I(aKR4+<))JF(x;`@e3UJ`X;+CF`R7B?8qFvR@QL=PZ<>~NQTwB z_z4a&Y)Rd2?~=ZG>5&~U@m67C!0NBf{Z;*IO?MQgt*|;xqU59_saoaW11wv1*s2}K zLkQU!v>?IBmzll31m5To=N{Szh0Nr?^^DBkV*C!-z6I`Y=JWzvH!|=9cU&fACd+Ly z!|9^2Z7vEknb-aL3cK z$yGbG>SjK8mZ zf@@KYo~vtfQ_}dERXm`TZTSj`@D)F#QAa9`aVRd_coxErQ0@6)Y^vd>bGyj zofoF-o{6oR=h3zH!9Q8|7lv=AueSQ?R+3-~qMDE7AKkw8;@SSZgI6n78>XekQHH=O zv38BEcxmOb?8Ssf{qzbWOO_w7Gs!79J1#!;B$UJJR|;n_`y_)ADLLv+LGD(9Vn{Nz rnzv9z57y>%WX09fe~MQQU%@R$>rUuxX`NZ(=cY5sY8QUX8=mtY-)KSd literal 0 HcmV?d00001 diff --git a/GreatSpringGameJam/Content/Textures/Backgrounds.png b/GreatSpringGameJam/Content/Textures/Backgrounds.png new file mode 100644 index 0000000000000000000000000000000000000000..0ff2821e6ecfe5d48dd170347e9ecedb9171c783 GIT binary patch literal 1516 zcmb`H`#;kQ7{_Ogq}-w`6h}fQWR=8ebLlIFCZo>iGDKl+F_*T?BF@%`QBD|ho1Kor z4v|Vjxs;01TsA|9TxN|^lVL~y!+Bn>=lT5dygu*GPao=Ol#8m0t_lbQQboD~=nW2v*6vdu6UvO>{RQDAJf z)jVyNl4X;|0X!1?E(qy>f9b9Uffo4MWw&Ij-VTaJdw5vN{p0AVgyF*j@C(8VLf&C1 zA}7vN9G=WOXMF~4-~u5l$=BC9O+_$Jne)Tj7n_OvUBgfVqh59aXxoYM6Obo9nq&#- zH+-`HdcP0?giwv&s?(+6*bfB&q0j)~E3zer(n9c*J<@8A?Go)aT-xH>y4QY3M@mItri zS)*~j`=u5_N2ZSQ<71wp!X@Ut#{(V0PdgVK0)*}bzF2Yr`h{NfnuV`E(|oLFb~ zK^?n5q1dI0^JG1n&oiYX(pU_(cTQb^o)EoX8Q1lzRwGC^Eyusz!%ap4NiPIt9PAf= zGm8|=gnR!g5UNA<(^kNle*HfGkNDfB`0ga>xM?a?ci+8R)9RsDhev3Rj5j1Rs7!Y4DWk>V|s%|tHMab*9trS&bf9qDsqjs9(Vk-t&CfCRECQPT9>8Rv z&vn4S58+WfBKR%nnA}BMt!H1g2zS~YQpwaBctJ-~wQanPoQx>_m^*R^#R>`xsljR` z!*0ed - - - + + + @@ -31,7 +31,6 @@ - \ No newline at end of file diff --git a/GreatSpringGameJam/Map.cs b/GreatSpringGameJam/Map.cs index ca15107..d65bd9b 100644 --- a/GreatSpringGameJam/Map.cs +++ b/GreatSpringGameJam/Map.cs @@ -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("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); diff --git a/GreatSpringGameJam/Player.cs b/GreatSpringGameJam/Player.cs index 4221a6f..1e8e977 100644 --- a/GreatSpringGameJam/Player.cs +++ b/GreatSpringGameJam/Player.cs @@ -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) {