Commit 3b826913 authored by Sapln's avatar Sapln
Browse files

Merge branch 'respawn-Spikes'

parents 9085b832 9c6af811
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.5" tiledversion="1.7.2" name="interaction" tilewidth="16" tileheight="16" tilecount="6" columns="6">
<transformations hflip="0" vflip="0" rotate="0" preferuntransformed="1"/>
<image source="interaction.png" width="96" height="16"/>
<tile id="0">
<properties>
<property name="Spike" value="East"/>
</properties>
</tile>
<tile id="1">
<properties>
<property name="Spike" value="South"/>
</properties>
</tile>
<tile id="2">
<properties>
<property name="Spike" value="West"/>
</properties>
</tile>
<tile id="3">
<properties>
<property name="Spike" value="North"/>
</properties>
</tile>
</tileset>
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="48" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="3" nextobjectid="2">
<map version="1.0" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="48" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="49">
<tileset firstgid="1" source="tiles16x16.tsx"/>
<tileset firstgid="5" source="interaction.tsx"/>
<tileset firstgid="4" source="interaction.tsx"/>
<layer id="1" name="Calque de Tuiles 1" width="48" height="30">
<data encoding="csv">
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,0,0,0,0,0,0,0,0,0,6,6,6,6,6,0,0,0,0,0,0,0,0,0,0,6,6,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,
1,1,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,1,1,
1,1,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,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
</data>
</layer>
<objectgroup id="2" name="Calque d'Objets 1">
<object id="1" name="Spawn" x="128" y="400">
<objectgroup id="3" name="Objects">
<object id="19" name="Spike" gid="4" x="32" y="208" width="16" height="16"/>
<object id="20" name="Spike" gid="4" x="32" y="192" width="16" height="16"/>
<object id="21" name="Spike" gid="4" x="32" y="176" width="16" height="16"/>
<object id="22" name="Spike" gid="4" x="32" y="144" width="16" height="16"/>
<object id="23" name="Spike" gid="4" x="32" y="160" width="16" height="16"/>
<object id="24" name="Spike" gid="5" x="288" y="336" width="16" height="16"/>
<object id="25" name="Spike" gid="5" x="304" y="336" width="16" height="16"/>
<object id="26" name="Spike" gid="5" x="320" y="336" width="16" height="16"/>
<object id="27" name="Spike" gid="5" x="336" y="336" width="16" height="16"/>
<object id="28" name="Spike" gid="6" x="224" y="224" width="16" height="16"/>
<object id="29" name="Spike" gid="6" x="224" y="240" width="16" height="16"/>
<object id="30" name="Spike" gid="7" x="336" y="176" width="16" height="16"/>
<object id="31" name="Spike" gid="7" x="352" y="176" width="16" height="16"/>
<object id="32" name="Spike" gid="7" x="224" y="160" width="16" height="16"/>
<object id="39" name="Spike" gid="7" x="400" y="176" width="16" height="16"/>
<object id="43" name="Spike" gid="7" x="416" y="176" width="16" height="16"/>
<object id="46" name="Checkpoint" gid="9" x="272" y="176" width="16" height="16"/>
<object id="47" name="Checkpoint" gid="9" x="144" y="448" width="16" height="16"/>
<object id="48" name="Spawn" x="64" y="416">
<point/>
</object>
</objectgroup>
......
......@@ -54,6 +54,8 @@
<Content Include="Data\Levels\World1\tiles_16x16.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Data\Sprites\Checkpoint\checkpointOff.png" />
<Content Include="Data\Sprites\Checkpoint\checkpointOn.png" />
<Content Include="Data\Sprites\Worlds\Teleporters\portal_in_1.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
......
......@@ -4,6 +4,7 @@ using Urho.Urho2D;
using ZZZZZZ.Entities;
using ZZZZZZ.Entities.Character;
using ZZZZZZ.Physics;
using ZZZZZZ.Physics.CollisionBoxs;
using ZZZZZZ.Utils;
namespace ZZZZZZ.Objects.Character
......@@ -12,8 +13,8 @@ namespace ZZZZZZ.Objects.Character
{
public int CharacterID { get; set; }
public float Speed { get; set; }
private Vector2 Spawn { get; set; }
public bool IsGrounded {get; set;}
public Checkpoint LastCheckpoint { get; set; }
public bool IsGrounded { get; set; }
public (bool X, bool Y) Flip
{
get => (Sprite.FlipX, Sprite.FlipY);
......@@ -25,6 +26,7 @@ namespace ZZZZZZ.Objects.Character
public LocalCharacter(int id = -1)
{
LastCheckpoint = null;
CharacterID = id;
Node.Scale *= 2;
Node.SetPosition2D(new Vector2(1, 1));
......@@ -131,18 +133,27 @@ namespace ZZZZZZ.Objects.Character
{
var gravity = GameManager.Current.Scene.Gravity;
IsGrounded =((gravity == GravityDirection.Droite || gravity == GravityDirection.Gauche) && 0 == Body.LinearVelocity.X)
IsGrounded = ((gravity == GravityDirection.Droite || gravity == GravityDirection.Gauche) && 0 == Body.LinearVelocity.X)
|| ((gravity == GravityDirection.Haut || gravity == GravityDirection.Bas) && 0 == Body.LinearVelocity.Y);
return IsGrounded;
}
public void Respawn()
{
Body.Node.Position = new Vector3(Spawn.X, Spawn.Y,Body.Node.Position.Z);
IsGrounded = false;
if (LastCheckpoint != null)
{
GameManager.Current.Scene.Gravity = LastCheckpoint.SpawnGravity;
Body.Node.Position = new Vector3(LastCheckpoint.Position.X, LastCheckpoint.Position.Y, Body.Node.Position.Z);
}
}
public void setSpawn(Vector2 v)
public void setSpawn(Checkpoint cp)
{
LastCheckpoint = cp;
}
public void Dies()
{
Spawn = v;
Respawn();
}
}
}
......
......@@ -20,7 +20,7 @@ namespace ZZZZZZ.GUI
switch (obj.Key)
{
case Key.L:
//System.Console.WriteLine((GameManager.Current.LocalPlayerManager.Character as LocalCharacter).Body.Node.Position.ToString());
System.Console.WriteLine((GameManager.Current.LocalPlayerManager.Character as LocalCharacter).Body.Node.Position.ToString());
break;
case Key.F3:
AppConfig.Current.DrawDebug = !AppConfig.Current.DrawDebug;
......
......@@ -21,7 +21,7 @@ namespace ZZZZZZ.Inputs
else if ((obj.Key == Key.Q || obj.Key == Key.Z) && MovementCount == -1) MovementCount = 0;
if (MovementCount == 0) Movement = Movement.None;
System.Console.WriteLine(MovementCount);
//System.Console.WriteLine(MovementCount);
}
......@@ -34,7 +34,7 @@ namespace ZZZZZZ.Inputs
if (MovementCount > 0) Movement = Movement.Right;
else if (MovementCount == 0) Movement = Movement.None;
else Movement = Movement.Left;
System.Console.WriteLine(MovementCount);
//System.Console.WriteLine(MovementCount);
if (obj.Key == Key.Up) Gravity = Physics.GravityDirection.Haut;
......
using System;
using System.Collections.Generic;
using System.Text;
using Urho;
using Urho.Urho2D;
namespace ZZZZZZ.Physics.Checkpoint
{
internal class Checkpoint : RigidBody2D
{
}
}
using System;
using System.Collections.Generic;
using System.Text;
using Urho;
using Urho.Urho2D;
using ZZZZZZ.Utils;
namespace ZZZZZZ.Physics.CollisionBoxs
{
public class Checkpoint : RigidBody2D
{
public Vector2 Position { get; private set; }
public bool Status { get; private set; }
public GravityDirection SpawnGravity { get; private set; }
public Sprite2D OnSprite { get; private set; }
public Checkpoint Init(Vector2 position)
{
SpawnGravity = GravityDirection.Bas;
var box = Node.CreateComponent<CollisionCircle2D>();
box.Radius = 8f/100;
box.Trigger = true;
box.Node.SetPosition2D(position + new Vector2(8, 8) / 100);
Position = box.Node.Position2D;
Status = false;
//OnSprite = Application.ResourceCache.GetSprite2D(Assets.Sprites.Checkpoint.CheckpointOn);
return this;
}
public void On()
{
Status = true;
}
public void Off()
{
Status = false;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using Urho;
using Urho.Urho2D;
namespace ZZZZZZ.Physics.CollisionBoxs
{
public class Spike : RigidBody2D
{
public Vector2 Position { get; private set; }
public Spike Init(Vector2 position)
{
var box = Node.CreateComponent<CollisionBox2D> ();
box.Size = new Vector2(16f, 16f) / 100;
box.Trigger = true;
box.Node.SetPosition2D(position + new Vector2(8, 8) / 100);
Position = box.Center;
return this;
}
}
}
......@@ -34,9 +34,11 @@ namespace ZZZZZZ.Physics
{
LocalCharacter perso = null;
var cb = GetSender<CollisionBox>(obj);
var area = GetSender<Area>(obj);
var portal = GetSender<Portal>(obj);
var cb = GetSenderBegin<CollisionBox>(obj);
var area = GetSenderBegin<Area>(obj);
var portal = GetSenderBegin<Portal>(obj);
var spike = GetSenderBegin<Spike>(obj);
var cp = GetSenderBegin<Checkpoint>(obj);
if (cb != null)
CollisionBoxTriggered?.Invoke(new CollisionBoxTriggeredEventArgs(cb.Goto));
......@@ -54,14 +56,29 @@ namespace ZZZZZZ.Physics
if (perso != null)
{
if (spike !=null)
perso.Dies();
if(cp != null && cp.Status ==false)
{
//cp.On //animation quand on est dessus
cp.On();
perso.setSpawn(cp);
}
}
}
private T GetSender<T>(PhysicsBeginContact2DEventArgs obj) where T : class
private T GetSenderBegin<T>(PhysicsBeginContact2DEventArgs obj) where T : class
{
T sender = null;
if (obj.BodyA.GetType() == typeof(T)) sender = obj.BodyA as T;
if (obj.BodyB?.GetType() == typeof(T)) sender = obj.BodyB as T;
return sender;
}
private T GetSenderEnd<T>(PhysicsEndContact2DEventArgs obj) where T : class
{
T sender = null;
if (obj.BodyA.GetType() == typeof(T)) sender = obj.BodyA as T;
......@@ -71,6 +88,12 @@ namespace ZZZZZZ.Physics
private void PhysicsWorld2D_PhysicsEndContact2D(PhysicsEndContact2DEventArgs obj)
{
var cp = GetSenderEnd<Checkpoint>(obj);
if(cp != null)
{
cp.Off();
}
/*
LocalCharacter perso = null;
......
using System;
using System.Collections.Generic;
using System.Text;
using Urho;
using Urho.Urho2D;
namespace ZZZZZZ.Physics.Spikes
{
internal class Spikes : RigidBody2D
{
}
}
......@@ -66,6 +66,11 @@
public const string CharacterRemote_2 = "Sprites/Characters/character_remote_2.png";
}
public static class Checkpoint
{
public const string CheckpointOn = "Sprites/Checkpoint/checkpointOn.png";
}
public static class Worlds
{
public static class Teleporter
......
......@@ -15,16 +15,20 @@ namespace ZZZZZZ.Worlds
public string Name { get; private set; }
public Vector2? Spawn { get; private set; }
public List<Portal> Portals { get; private set; }
public List<Spike> Spikes { get; private set; }
public List<Checkpoint> Checkpoints { get; private set; }
public Area Area { get; private set; }
public int WorldX { get; private set; }
public int WorldY { get; private set; }
private Node ChildFromScene { get; }
public Level(string level, int x, int y)
{
Portals = new List<Portal>();
Spikes = new List<Spike>();
Checkpoints = new List<Checkpoint>();
WorldX = x;
WorldY = y;
......@@ -38,39 +42,63 @@ namespace ZZZZZZ.Worlds
Area = Node.CreateChild().CreateComponent<Area>().Init(new Vector2(WorldX, WorldY));
SetSpawn();
GenerateCollision();
GenerateTriggerBox();
GeneratePortals();
GenerateCollision();
GenerateObjects();
}
private void GeneratePortals()
private void GenerateObjects()
{
var layer = TileMap.GetLayer(1);
if (layer == null) return;
for (uint i = 0; i < layer.NumObjects; i++)
{
if (layer.GetObject(i).Name == "Portal")
switch (layer.GetObject(i).Name)
{
var obj = layer.GetObject(i);
var id = int.Parse(obj.GetProperty("id"));
var _in = bool.Parse(obj.GetProperty("in"));
Node node = Node.CreateChild("Portal");
var portal = node.CreateComponent<Portal>().Init(obj.Position, id, _in);
Portals.Add(portal);
portal.PortalTriggered += Portal_PortalTriggered;
case "Checkpoint":
Node nodeCp = Node.CreateChild("Checkpoint");
var cp = nodeCp.CreateComponent<Checkpoint>().Init(layer.GetObject(i).Position);
Checkpoints.Add(cp);
break;
case "Spike":
Node nodeSpike = Node.CreateChild("Spike");
var spike = nodeSpike.CreateComponent<Spike>().Init(layer.GetObject(i).Position);
Spikes.Add(spike);
break;
case "Portal":
var objPortal = layer.GetObject(i);
var id = int.Parse(objPortal.GetProperty("id"));
var _in = bool.Parse(objPortal.GetProperty("in"));
Node nodePortal = Node.CreateChild("Portal");
var portal = nodePortal.CreateComponent<Portal>().Init(objPortal.Position, id, _in);
Portals.Add(portal);
portal.PortalTriggered += Portal_PortalTriggered;
break;
case "Spawn":
var obj = layer.GetObject(i);
Node nodeSpawn = Node.CreateChild("tmp");
nodeSpawn.SetPosition2D(obj.Position);
Spawn = nodeSpawn.WorldPosition2D;
nodeSpawn.Dispose();
break;
default:
break;
}
}
}
private void Portal_PortalTriggered(PortalTriggeredEventArgs obj)
{
var portalIn = Portals.Find(x => x.PortalID == obj.Id && x.In == obj.In);
if (portalIn != null && portalIn.In)
{
var portalOut = Portals.Find(x => x.PortalID == obj.Id && x.In != obj.In);
if(portalOut != null)
if (portalOut != null)
{
Console.WriteLine($"teleport player to {portalOut.Position}");
GameManager.Current.LocalPlayerManager.Character.Move(portalOut.Position);
......@@ -78,25 +106,6 @@ namespace ZZZZZZ.Worlds
}
}
private void SetSpawn()
{
Spawn = null;
var layer = TileMap.GetLayer(1);
if (layer == null) return;
for (uint i = 0; i < layer.NumObjects; i++)
{
if (layer.GetObject(i).Name == "Spawn")
{
var obj = layer.GetObject(i);
Node node = Node.CreateChild("tmp");
node.SetPosition2D(obj.Position);
Spawn = node.WorldPosition2D;
node.Dispose();
}
}
}
private void GenerateTriggerBox()
{
......@@ -140,7 +149,7 @@ namespace ZZZZZZ.Worlds
{
foreach (var portal in Portals)
portal.Dispose();
GameManager.Current.Scene.RemoveChild(ChildFromScene);
base.Dispose(disposing);
}
......@@ -149,9 +158,9 @@ namespace ZZZZZZ.Worlds
private Vector2 CalculateBoxSize(int width)
{
if(width == 24)
if (width == 24)
return Vector2.One * 32 / 100;
return Vector2.One * 16/100;
return Vector2.One * 16 / 100;
}
}
}
......@@ -11,4 +11,9 @@
<PackageReference Include="UrhoSharp" Version="1.9.67" />
</ItemGroup>
<ItemGroup>
<Folder Include="Physics\Checkpoint\" />
<Folder Include="Physics\Spikes\" />
</ItemGroup>
</Project>
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