Commit 18577f03 authored by Maxime's avatar Maxime
Browse files

automation of area in levels

parent 4abd5efc
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.5" tiledversion="1.7.2" name="tiles" tilewidth="32" tileheight="32" tilecount="3" columns="3">
<image source="tiles.png" width="96" height="32"/>
<tile id="0">
<objectgroup draworder="index" id="4">
<object id="4" x="0" y="0" width="32" height="32"/>
</objectgroup>
</tile>
<tile id="1">
<objectgroup draworder="index" id="2">
<object id="1" x="0" y="0" width="32" height="32"/>
</objectgroup>
</tile>
<tile id="2">
<objectgroup draworder="index" id="2">
<object id="1" x="0" y="0" width="32" height="32"/>
</objectgroup>
</tile>
</tileset>
......@@ -22,11 +22,5 @@
</layer>
<objectgroup id="2" name="Calque d'Objets 1">
<object id="2" name="Spawn" x="64" y="416"/>
<object id="4" name="Area" x="32" y="32" width="704" height="416">
<properties>
<property name="X" type="int" value="0"/>
<property name="Y" type="int" value="0"/>
</properties>
</object>
</objectgroup>
</map>
......@@ -21,11 +21,5 @@
</data>
</layer>
<objectgroup id="2" name="Calque d'Objets 1">
<object id="4" name="Area" x="32" y="32" width="704" height="416">
<properties>
<property name="X" type="int" value="0"/>
<property name="Y" type="int" value="1"/>
</properties>
</object>
</objectgroup>
</map>
......@@ -21,11 +21,5 @@
</data>
</layer>
<objectgroup id="2" name="Calque d'Objets 1">
<object id="4" name="Area" x="32" y="32" width="704" height="416">
<properties>
<property name="X" type="int" value="0"/>
<property name="Y" type="int" value="2"/>
</properties>
</object>
</objectgroup>
</map>
using Urho;
using Urho.Physics;
using Urho.Urho2D;
namespace ZZZZZZ.Physics.CollisionBoxs
{
public class Area : RigidBody2D
{
public Vector2 WorldPosition { get; private set; }
public void Init(Vector2 worldPosition)
{
WorldPosition = worldPosition;
var box = Node.CreateComponent<CollisionBox2D>();
box.Size = new Vector2(736, 448) / 100;
box.Trigger = true;
box.Node.SetPosition2D(new Vector2(16, 16) / 100 + box.Size / 2);
}
}
}
......@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Text;
using Urho;
namespace ZZZZZZ.Physics.CollisionBox
namespace ZZZZZZ.Physics.CollisionBoxs
{
public class AreaTriggeredEventArgs : EventArgs
{
......
using Urho;
using Urho.Urho2D;
namespace ZZZZZZ.Physics.CollisionBox
namespace ZZZZZZ.Physics.CollisionBoxs
{
public class CollisionBox : RigidBody2D
{
public bool TypeGoto { get; private set; }
public string Goto { get => Tile.GetProperty("goto"); }
public Vector2 LevelPosition { get => new Vector2(int.Parse(Tile.GetProperty("X")), int.Parse(Tile.GetProperty("Y"))); }
private TileMapObject2D Tile { get; set; }
public void Init(TileMapObject2D tile, bool typeGoTo = true)
public void Init(TileMapObject2D tile)
{
Tile = tile;
TypeGoto = typeGoTo;
var box = Node.CreateComponent<CollisionBox2D>();
box.Size = tile.Size;
(box as CollisionBox2D).Trigger = true;
box.Trigger = true;
box.Node.SetPosition2D(tile.Position + box.Size / 2);
}
......
using System;
namespace ZZZZZZ.Physics.CollisionBox
namespace ZZZZZZ.Physics.CollisionBoxs
{
public class CollisionBoxTriggeredEventArgs : EventArgs
{
......
......@@ -3,7 +3,7 @@ using Urho;
using Urho.Urho2D;
using ZZZZZZ.Entities.Character;
using ZZZZZZ.Objects.Character;
using ZZZZZZ.Physics.CollisionBox;
using ZZZZZZ.Physics.CollisionBoxs;
namespace ZZZZZZ.Physics
{
......@@ -29,20 +29,26 @@ namespace ZZZZZZ.Physics
private void PhysicsWorld2D_PhysicsBeginContact2D(PhysicsBeginContact2DEventArgs obj)
{
CollisionBox.CollisionBox cb = null;
CollisionBox cb = null;
Area area = null;
LocalCharacter perso = null;
if (obj.BodyA.GetType() == typeof(CollisionBox.CollisionBox))
cb = obj.BodyA as CollisionBox.CollisionBox;
if (obj.BodyB.GetType() == typeof(CollisionBox.CollisionBox))
cb = obj.BodyB as CollisionBox.CollisionBox;
if (obj.BodyA.GetType() == typeof(CollisionBox))
cb = obj.BodyA as CollisionBox;
if (obj.BodyB.GetType() == typeof(CollisionBox))
cb = obj.BodyB as CollisionBox;
if (obj.BodyA.GetType() == typeof(Area))
area = obj.BodyA as Area;
if (obj.BodyB.GetType() == typeof(Area))
area = obj.BodyB as Area;
if (cb != null)
{
if (cb.TypeGoto)
CollisionBoxTriggered?.Invoke(new CollisionBoxTriggeredEventArgs(cb.Goto));
else
AreaLevelTriggered?.Invoke(new AreaTriggeredEventArgs(cb.LevelPosition));
}
CollisionBoxTriggered?.Invoke(new CollisionBoxTriggeredEventArgs(cb.Goto));
if (area != null)
AreaLevelTriggered?.Invoke(new AreaTriggeredEventArgs(area.WorldPosition));
if (obj.BodyA == (GameManager.Current.LocalPlayerManager.Character as LocalCharacter).Body)
perso = GameManager.Current.LocalPlayerManager.Character as LocalCharacter;
......
......@@ -2,7 +2,7 @@
using System.IO;
using Urho;
using Urho.Urho2D;
using ZZZZZZ.Physics.CollisionBox;
using ZZZZZZ.Physics.CollisionBoxs;
namespace ZZZZZZ.Worlds
{
......@@ -21,8 +21,8 @@ namespace ZZZZZZ.Worlds
public Level(string level, int x, int y)
{
Console.WriteLine($"ctor level {x} {y}");
WorldX=x;
WorldY=y;
WorldX = x;
WorldY = y;
Name = level;
ChildFromScene = GameManager.Current.Scene.CreateChild("Level");
......@@ -33,8 +33,9 @@ namespace ZZZZZZ.Worlds
TileMap.Node.SetPosition2D(new Vector2(y * 7.68f, x * 4.8f));
Node.CreateChild().CreateComponent<Area>().Init(new Vector2(WorldX, WorldY));
SetSpawn();
SetArea();
GenerateCollision();
GenerateTriggerBox();
......@@ -57,20 +58,6 @@ namespace ZZZZZZ.Worlds
}
}
private void SetArea()
{
var layer = TileMap.GetLayer(1);
for (uint i = 0; i < layer.NumObjects; i++)
{
if (layer.GetObject(i).Name == "Area")
{
Node node = Node.CreateChild();
node.CreateComponent<CollisionBox>().Init(layer.GetObject(i),false);
}
}
}
private void GenerateTriggerBox()
{
var layer = TileMap.GetLayer(1);
......
......@@ -6,7 +6,7 @@ using System.Text.RegularExpressions;
using Urho;
using Urho.Actions;
using ZZZZZZ.Physics;
using ZZZZZZ.Physics.CollisionBox;
using ZZZZZZ.Physics.CollisionBoxs;
using ZZZZZZ.Utils;
namespace ZZZZZZ.Worlds
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment