improved snow removal collisions
This commit is contained in:
parent
a881cf0bdc
commit
fcf10c89ae
5 changed files with 52 additions and 12 deletions
|
@ -30,16 +30,25 @@
|
||||||
<properties>
|
<properties>
|
||||||
<property name="Snow" type="bool" value="true"/>
|
<property name="Snow" type="bool" value="true"/>
|
||||||
</properties>
|
</properties>
|
||||||
|
<objectgroup draworder="index" id="3">
|
||||||
|
<object id="2" x="0" y="14" width="16" height="2"/>
|
||||||
|
</objectgroup>
|
||||||
</tile>
|
</tile>
|
||||||
<tile id="6">
|
<tile id="6">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="Snow" type="bool" value="true"/>
|
<property name="Snow" type="bool" value="true"/>
|
||||||
</properties>
|
</properties>
|
||||||
|
<objectgroup draworder="index" id="3">
|
||||||
|
<object id="2" x="0" y="14" width="16" height="2"/>
|
||||||
|
</objectgroup>
|
||||||
</tile>
|
</tile>
|
||||||
<tile id="7">
|
<tile id="7">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="Snow" type="bool" value="true"/>
|
<property name="Snow" type="bool" value="true"/>
|
||||||
</properties>
|
</properties>
|
||||||
|
<objectgroup draworder="index" id="4">
|
||||||
|
<object id="3" x="0" y="14" width="16" height="2"/>
|
||||||
|
</objectgroup>
|
||||||
</tile>
|
</tile>
|
||||||
<tile id="8">
|
<tile id="8">
|
||||||
<objectgroup draworder="index" id="2">
|
<objectgroup draworder="index" id="2">
|
||||||
|
@ -84,17 +93,29 @@
|
||||||
<tile id="21">
|
<tile id="21">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="Snow" type="bool" value="true"/>
|
<property name="Snow" type="bool" value="true"/>
|
||||||
|
<property name="SnowBottom" type="bool" value="true"/>
|
||||||
</properties>
|
</properties>
|
||||||
|
<objectgroup draworder="index" id="2">
|
||||||
|
<object id="1" x="0" y="0" width="16" height="5"/>
|
||||||
|
</objectgroup>
|
||||||
</tile>
|
</tile>
|
||||||
<tile id="22">
|
<tile id="22">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="Snow" type="bool" value="true"/>
|
<property name="Snow" type="bool" value="true"/>
|
||||||
|
<property name="SnowBottom" type="bool" value="true"/>
|
||||||
</properties>
|
</properties>
|
||||||
|
<objectgroup draworder="index" id="3">
|
||||||
|
<object id="2" x="0" y="0" width="16" height="5"/>
|
||||||
|
</objectgroup>
|
||||||
</tile>
|
</tile>
|
||||||
<tile id="23">
|
<tile id="23">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="Snow" type="bool" value="true"/>
|
<property name="Snow" type="bool" value="true"/>
|
||||||
|
<property name="SnowBottom" type="bool" value="true"/>
|
||||||
</properties>
|
</properties>
|
||||||
|
<objectgroup draworder="index" id="2">
|
||||||
|
<object id="1" x="0" y="0" width="16" height="5"/>
|
||||||
|
</objectgroup>
|
||||||
</tile>
|
</tile>
|
||||||
<tile id="32">
|
<tile id="32">
|
||||||
<objectgroup draworder="index" id="2">
|
<objectgroup draworder="index" id="2">
|
||||||
|
|
|
@ -78,7 +78,7 @@ namespace GreatSpringGameJam {
|
||||||
}
|
}
|
||||||
|
|
||||||
// display end of level info
|
// display end of level info
|
||||||
var snowRemoved = this.Map.TotalSnow - this.Map.GetTotalTiles("Snow");
|
var snowRemoved = this.Map.TotalSnow - this.Map.GetTotalTiles("Snow") / 2;
|
||||||
var plantsGrown = this.Map.TotalSeeds - this.Map.GetTotalTiles("Seed");
|
var plantsGrown = this.Map.TotalSeeds - this.Map.GetTotalTiles("Seed");
|
||||||
var gnomesCollected = this.Map.TotalGnomes - this.Map.GetEntities<Gnome>().Count();
|
var gnomesCollected = this.Map.TotalGnomes - this.Map.GetEntities<Gnome>().Count();
|
||||||
// snow removal is less important, gnomes are more important
|
// snow removal is less important, gnomes are more important
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Contentless" Version="3.0.5" />
|
<PackageReference Include="Contentless" Version="3.0.5" />
|
||||||
<PackageReference Include="MLEM" Version="5.0.0-69" />
|
<PackageReference Include="MLEM" Version="5.0.0-71" />
|
||||||
<PackageReference Include="MLEM.Extended" Version="5.0.0-69" />
|
<PackageReference Include="MLEM.Extended" Version="5.0.0-71" />
|
||||||
<PackageReference Include="MLEM.Startup" Version="5.0.0-69" />
|
<PackageReference Include="MLEM.Startup" Version="5.0.0-71" />
|
||||||
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.0.1641" />
|
<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.Content.Pipeline" Version="3.8.0" />
|
||||||
<PackageReference Include="MonoGame.Extended.Tiled" Version="3.8.0" />
|
<PackageReference Include="MonoGame.Extended.Tiled" Version="3.8.0" />
|
||||||
|
|
|
@ -11,6 +11,7 @@ using MLEM.Startup;
|
||||||
using MLEM.Textures;
|
using MLEM.Textures;
|
||||||
using MonoGame.Extended;
|
using MonoGame.Extended;
|
||||||
using MonoGame.Extended.Tiled;
|
using MonoGame.Extended.Tiled;
|
||||||
|
using RectangleF = MLEM.Misc.RectangleF;
|
||||||
|
|
||||||
namespace GreatSpringGameJam {
|
namespace GreatSpringGameJam {
|
||||||
public class Map {
|
public class Map {
|
||||||
|
@ -32,8 +33,12 @@ namespace GreatSpringGameJam {
|
||||||
public Map(TiledMap map) {
|
public Map(TiledMap map) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.renderer = new IndividualTiledMapRenderer(this.map);
|
this.renderer = new IndividualTiledMapRenderer(this.map);
|
||||||
this.Collisions = new TiledMapCollisions(this.map);
|
this.Collisions = new TiledMapCollisions(this.map, (collisions, info) => {
|
||||||
this.TotalSnow = this.GetTotalTiles("Snow");
|
// snow should only "collide" with the snow blower wind
|
||||||
|
if (info.Layer.Name != "Snow")
|
||||||
|
TiledMapCollisions.DefaultCollectCollisions(collisions, info);
|
||||||
|
});
|
||||||
|
this.TotalSnow = this.GetTotalTiles("Snow") / 2;
|
||||||
this.TotalSeeds = this.GetTotalTiles("Seed");
|
this.TotalSeeds = this.GetTotalTiles("Seed");
|
||||||
|
|
||||||
foreach (var (pos, _) in this.EnumerateTiles("Gnome")) {
|
foreach (var (pos, _) in this.EnumerateTiles("Gnome")) {
|
||||||
|
@ -84,6 +89,10 @@ namespace GreatSpringGameJam {
|
||||||
return tile.GetTileset(this.map);
|
return tile.GetTileset(this.map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RectangleF GetArea(TiledMapObject obj, Vector2? pos = null) {
|
||||||
|
return obj.GetArea(this.map, pos).ToMlem();
|
||||||
|
}
|
||||||
|
|
||||||
public void Draw(GameTime time, SpriteBatch batch, Camera camera) {
|
public void Draw(GameTime time, SpriteBatch batch, Camera camera) {
|
||||||
batch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, transformMatrix: camera.ViewMatrix);
|
batch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, transformMatrix: camera.ViewMatrix);
|
||||||
// render background
|
// render background
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using MLEM.Extended.Tiled;
|
using MLEM.Extended.Tiled;
|
||||||
using MLEM.Extensions;
|
using MLEM.Extensions;
|
||||||
|
using MLEM.Misc;
|
||||||
using MLEM.Textures;
|
using MLEM.Textures;
|
||||||
|
|
||||||
namespace GreatSpringGameJam {
|
namespace GreatSpringGameJam {
|
||||||
|
@ -26,16 +28,24 @@ namespace GreatSpringGameJam {
|
||||||
var (x, y) = this.Position.ToPoint();
|
var (x, y) = this.Position.ToPoint();
|
||||||
var tile = this.Map.GetTile("Snow", x, y);
|
var tile = this.Map.GetTile("Snow", x, y);
|
||||||
if (!tile.IsBlank) {
|
if (!tile.IsBlank) {
|
||||||
this.Map.SetTile("Snow", x, y, 0);
|
var tilesetTile = this.Map.GetTilesetTile(tile, this.Map.GetTileset(tile));
|
||||||
var hidden = this.Map.GetTile("SnowHidden", x, y);
|
// check if the wind actually intersects with the snow's collision box
|
||||||
|
if (tilesetTile.Objects.Any(o => this.Map.GetArea(o, new Vector2(x, y)).Contains(this.Position))) {
|
||||||
|
if (tilesetTile.Properties.GetBool("SnowBottom"))
|
||||||
|
y--;
|
||||||
|
for (var yOff = 0; yOff <= 1; yOff++) {
|
||||||
|
this.Map.SetTile("Snow", x, y + yOff, 0);
|
||||||
|
var hidden = this.Map.GetTile("SnowHidden", x, y + yOff);
|
||||||
if (!hidden.IsBlank) {
|
if (!hidden.IsBlank) {
|
||||||
this.Map.SetTile("Ground", x, y, hidden.GlobalIdentifier);
|
this.Map.SetTile("Ground", x, y + yOff, hidden.GlobalIdentifier);
|
||||||
this.Map.SetTile("SnowHidden", x, y, 0);
|
this.Map.SetTile("SnowHidden", x, y + yOff, 0);
|
||||||
}
|
}
|
||||||
this.Map.RemoveEntity(this);
|
this.Map.RemoveEntity(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void Draw(GameTime time, SpriteBatch batch) {
|
public override void Draw(GameTime time, SpriteBatch batch) {
|
||||||
base.Draw(time, batch);
|
base.Draw(time, batch);
|
||||||
|
|
Loading…
Reference in a new issue