Add map god mode

This commit is contained in:
Mootfrost777 2023-08-18 01:29:21 +03:00
parent 2deaa74ede
commit b9f0740c17
3 changed files with 24 additions and 25 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="left-up" width="200" height="200" tilewidth="16" tileheight="16" infinite="1" nextlayerid="8" nextobjectid="43"> <map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="left-up" width="200" height="200" tilewidth="16" tileheight="16" infinite="1" nextlayerid="8" nextobjectid="49">
<tileset firstgid="1" source="../Documents/Github_repos/DangerousD/DangerousD/Content/map.tsx"/> <tileset firstgid="1" source="../Documents/Github_repos/DangerousD/DangerousD/Content/map.tsx"/>
<layer id="3" name="Слой тайлов 3" class="Tile" width="200" height="200"> <layer id="3" name="Слой тайлов 3" class="Tile" width="200" height="200">
<data encoding="csv"> <data encoding="csv">
@ -77,11 +77,6 @@
</chunk> </chunk>
</data> </data>
</layer> </layer>
<objectgroup id="7" name="Player" class="LivingEntities">
<object id="42" type="Player" x="236.506" y="-54.4681">
<point/>
</object>
</objectgroup>
<layer id="1" name="Collidable" class="StopTile" width="200" height="200"> <layer id="1" name="Collidable" class="StopTile" width="200" height="200">
<data encoding="csv"> <data encoding="csv">
<chunk x="-32" y="0" width="16" height="16"> <chunk x="-32" y="0" width="16" height="16">
@ -194,6 +189,11 @@
</chunk> </chunk>
</data> </data>
</layer> </layer>
<objectgroup id="7" name="Player" class="LivingEntities">
<object id="42" name="DEBUGUS" type="Player" x="236.506" y="-54.4681">
<point/>
</object>
</objectgroup>
<objectgroup id="6" name="Zombies" class="LivingEntities.Monsters.Zombie"> <objectgroup id="6" name="Zombies" class="LivingEntities.Monsters.Zombie">
<object id="17" x="568" y="130"> <object id="17" x="568" y="130">
<point/> <point/>

View file

@ -25,9 +25,10 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
public int leftBorder; public int leftBorder;
public bool isVisible = true; public bool isVisible = true;
private bool isAttacked = false; private bool isAttacked = false;
public bool isInvincible;
public GameObject objectAttack; public GameObject objectAttack;
public Player(Vector2 position) : base(position) public Player(Vector2 position, bool isInvincible = false) : base(position)
{ {
Width = 16; Width = 16;
Height = 32; Height = 32;
@ -40,6 +41,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
velocity = new Vector2(0, 0); velocity = new Vector2(0, 0);
rightBorder = (int)position.X + 100; rightBorder = (int)position.X + 100;
leftBorder = (int)position.X - 100; leftBorder = (int)position.X - 100;
this.isInvincible = isInvincible;
} }
@ -98,7 +100,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
{ {
GraphicsComponent.CameraPosition = (_pos-new Vector2(200, 350)).ToPoint(); GraphicsComponent.CameraPosition = (_pos-new Vector2(200, 350)).ToPoint();
if (!isAttacked) if (!isAttacked || isInvincible)
{ {
Move(gameTime); Move(gameTime);
} }

View file

@ -9,6 +9,7 @@ using Microsoft.Xna.Framework.Graphics;
using System.Xml.Serialization; using System.Xml.Serialization;
using DangerousD.GameCore.GameObjects; using DangerousD.GameCore.GameObjects;
using System.Globalization; using System.Globalization;
using DangerousD.GameCore.GameObjects.LivingEntities;
namespace DangerousD.GameCore.Managers namespace DangerousD.GameCore.Managers
{ {
@ -70,22 +71,8 @@ namespace DangerousD.GameCore.Managers
Rectangle sourceRect = new(new Point((tiles[i] -1) % _columns, (tiles[i] -1) / _columns) * tileSize.ToPoint(), tileSize.ToPoint()); Rectangle sourceRect = new(new Point((tiles[i] -1) % _columns, (tiles[i] -1) / _columns) * tileSize.ToPoint(), tileSize.ToPoint());
Type type = Type.GetType($"DangerousD.GameCore.GameObjects.MapObjects.{tileType}"); Type type = Type.GetType($"DangerousD.GameCore.GameObjects.MapObjects.{tileType}");
Activator.CreateInstance(type, pos, tileSize * _scale, sourceRect); Activator.CreateInstance(type, pos, tileSize * _scale, sourceRect);
/*switch (tileType)
{
case "collidable":
new StopTile(pos, tileSize * _scale, sourceRect);
break;
case "platform":
new Platform(pos, tileSize * _scale, sourceRect);
break;
case "non_collidable":
new Tile(pos, tileSize * _scale, sourceRect);
break;
}*/
}
} }
}
} }
} }
@ -105,10 +92,20 @@ namespace DangerousD.GameCore.Managers
float offsetY = group.Attributes["offsety"] is not null ? float.Parse(group.Attributes["offsety"].Value) : 0; float offsetY = group.Attributes["offsety"] is not null ? float.Parse(group.Attributes["offsety"].Value) : 0;
foreach (XmlNode entity in group.ChildNodes) foreach (XmlNode entity in group.ChildNodes)
{ {
Debug.WriteLine(entity.Attributes["type"] is not null ? "." + entity.Attributes["type"].Value : "");
string entityType = entity.Attributes["type"] is not null ? "." + entity.Attributes["type"].Value : ""; string entityType = entity.Attributes["type"] is not null ? "." + entity.Attributes["type"].Value : "";
Type type = Type.GetType($"DangerousD.GameCore.GameObjects.{entityGroup}{entityType}"); Type type = Type.GetType($"DangerousD.GameCore.GameObjects.{entityGroup}{entityType}");
Entity inst = (Entity)Activator.CreateInstance(type, new Vector2(float.Parse(entity.Attributes["x"].Value, CultureInfo.InvariantCulture) + offsetX, float.Parse(entity.Attributes["y"].Value, CultureInfo.InvariantCulture) + offsetY) * _scale); Vector2 pos =
new Vector2(float.Parse(entity.Attributes["x"].Value, CultureInfo.InvariantCulture) + offsetX,
float.Parse(entity.Attributes["y"].Value, CultureInfo.InvariantCulture) + offsetY) * _scale;
Entity inst;
if (type.Equals(typeof(Player)) && entity.Attributes["name"].Value == "DEBUGUS")
{
inst = (Entity)Activator.CreateInstance(type, pos, true);
}
else
{
inst = (Entity)Activator.CreateInstance(type, pos);
}
inst.SetPosition(new Vector2(inst.Pos.X, inst.Pos.Y - inst.Height)); inst.SetPosition(new Vector2(inst.Pos.X, inst.Pos.Y - inst.Height));
inst.Height *= _scale; inst.Height *= _scale;
inst.Width *= _scale; inst.Width *= _scale;