Commit 4bfb4ef9 authored by Maxime POULAIN's avatar Maxime POULAIN
Browse files

add working camera, better level management (2)

parent 2e5c5dcb
<?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>
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="24" height="15" tilewidth="32" tileheight="32" infinite="0" nextlayerid="4" nextobjectid="3">
<map version="1.0" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="24" height="15" tilewidth="32" tileheight="32" infinite="0" nextlayerid="4" nextobjectid="5">
<tileset firstgid="1" source="../tiles.tsx"/>
<layer id="1" name="Calque de Tuiles 1" width="24" height="15">
<data encoding="csv">
......@@ -22,5 +22,11 @@
</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>
......@@ -20,5 +20,12 @@
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
</data>
</layer>
<objectgroup id="2" name="Calque d'Objets 1"/>
<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>
......@@ -20,5 +20,12 @@
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
</data>
</layer>
<objectgroup id="2" name="Calque d'Objets 1"/>
<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>
......@@ -13,7 +13,7 @@ namespace ZZZZZZ.Objects.Character
public int CharacterID { get; set; }
public float Speed { get; set; }
private Vector2 PrevPos { get; set; }
public bool IsGrounded {get; set;}
public bool IsGrounded { get; set; }
public (bool X, bool Y) Flip
{
get => (Sprite.FlipX, Sprite.FlipY);
......@@ -26,11 +26,13 @@ namespace ZZZZZZ.Objects.Character
public LocalCharacter(int id = -1)
{
CharacterID = id;
Node.Scale *= 10;
Speed = 15f;
Shape = Node.CreateComponent<CollisionBox2D>();
(Shape as CollisionBox2D).Size = Vector2.One / 8;
(Shape as CollisionBox2D).Density = 1000;
Node.Scale *= 2;
Node.SetPosition2D(new Vector2(1, 1));
Speed = 5f;
Shape = Node.CreateComponent<CollisionCircle2D>();
(Shape as CollisionCircle2D).Radius = 0.075f;
PrevPos = Vector2.Zero;
Body.UseFixtureMass = false;
Body.Inertia = 5;
......@@ -52,7 +54,7 @@ namespace ZZZZZZ.Objects.Character
public void Move(Movement movement)
{
//Console.WriteLine(movement);
var vect = new Vector2(0, 0);
var gravity = GameManager.Current.Scene.Gravity;
/*
......@@ -104,7 +106,7 @@ namespace ZZZZZZ.Objects.Character
}
Body.SetLinearVelocity((vect + GameManager.Current.Scene.PhysicsWorld2D.Gravity) * Speed);
this.IsGroundedQ();
PrevPos = new Vector2( Body.Node.Position.X, Body.Node.Position.Y);
PrevPos = new Vector2(Body.Node.Position.X, Body.Node.Position.Y);
}
......@@ -118,9 +120,9 @@ namespace ZZZZZZ.Objects.Character
public override void Update(UpdateEventArgs obj)
{
internalTimer = (internalTimer + obj.TimeStep) % 1000;
if(GameManager.Current.Scene.UpdateEnabled)
if (GameManager.Current.Scene.UpdateEnabled)
Sprite.Sprite = Sprites[((int)(internalTimer * 2)) % Sprites.Count];
if (Body.LinearVelocity.Length > 10f)
if (Body.LinearVelocity.Length > 5f)
{
Body.SetLinearVelocity(Body.LinearVelocity * 0.90f);
}
......
......@@ -68,8 +68,16 @@ namespace ZZZZZZ
BackgroundParticle.Start();
LevelManager = new LevelManager(Scene.CollisionHandler);
Input.KeyDown += Input_KeyDown;
}
private void Input_KeyDown(KeyDownEventArgs obj)
{
if(obj.Key == Key.P)
{
LocalPlayerManager.Character.Move(Vector2.One);
}
}
}
}
using Urho;
using Urho.Actions;
using ZZZZZZ.Objects.Character;
using ZZZZZZ.Utils;
namespace ZZZZZZ.Graphics
{
public class CameraCustom : Camera
{
private float Counter;
private bool IsRumbling;
public CameraCustom() : base()
{
GameManager.Current.Scene.CreateChild().AddComponent(this);
Orthographic = true;
Application.Current.Update += Update;
Counter = 1;
Zoom = 1f;
Node.Position = new Vector3(3.2f, 2.4f, -1f);
IsRumbling = false;
}
private void Update(UpdateEventArgs obj)
{
if (Counter <= 0 && IsRumbling == true) IsRumbling = false;
if (IsRumbling)
{
var _pos = Node.Position;
var _delta = 0.4f;
Node.Position = new Vector3(ToolBox.RandomFloat(_pos.X - _delta, _pos.Y + _delta), ToolBox.RandomFloat(_pos.Y - _delta, _pos.Y + _delta), _pos.Z);
Counter -= obj.TimeStep;
return;
}
}
public async void Reset()
{
await Node.RunActionsAsync(new EaseBackOut(new MoveTo(1.5f, new Vector3(0, 0, -10))));
}
public void Rumble()
{
IsRumbling = true;
Counter = 1;
//Zoom = 4.2f;
Node.Position = new Vector3(3.85f, 2.4f, -1f);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using Urho;
namespace ZZZZZZ.Physics.CollisionBox
{
public class AreaTriggeredEventArgs : EventArgs
{
public Vector2 CameraPosition { get; }
public AreaTriggeredEventArgs(Vector2 cameraPosition)
{
CameraPosition = cameraPosition;
}
}
}
......@@ -5,15 +5,20 @@ namespace ZZZZZZ.Physics.CollisionBox
{
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)
public void Init(TileMapObject2D tile, bool typeGoTo = true)
{
Tile = tile;
TypeGoto = typeGoTo;
var box = Node.CreateComponent<CollisionBox2D>();
box.Size = tile.Size;
(box as CollisionBox2D).Trigger = true;
box.Node.SetPosition2D(tile.Position + box.Size / 2);
}
......
......@@ -11,6 +11,7 @@ namespace ZZZZZZ.Physics
{
private PhysicsWorld2D _physicsWorld2D;
public event Action<CollisionBoxTriggeredEventArgs> CollisionBoxTriggered;
public event Action<AreaTriggeredEventArgs> AreaLevelTriggered;
public PhysicsWorld2D PhysicsWorld2D
{
......@@ -37,7 +38,10 @@ namespace ZZZZZZ.Physics
if (cb != null)
{
CollisionBoxTriggered?.Invoke(new CollisionBoxTriggeredEventArgs(cb.Goto));
if (cb.TypeGoto)
CollisionBoxTriggered?.Invoke(new CollisionBoxTriggeredEventArgs(cb.Goto));
else
AreaLevelTriggered?.Invoke(new AreaTriggeredEventArgs(cb.LevelPosition));
}
if (obj.BodyA == (GameManager.Current.LocalPlayerManager.Character as LocalCharacter).Body)
......@@ -46,10 +50,6 @@ namespace ZZZZZZ.Physics
perso = GameManager.Current.LocalPlayerManager.Character as LocalCharacter;
if (cb != null)
{
CollisionBoxTriggered?.Invoke(new CollisionBoxTriggeredEventArgs(cb.Goto));
}
if (perso != null)
{
......
......@@ -44,6 +44,7 @@ namespace ZZZZZZ.Physics
CreateComponent<DebugRenderer>();
UpdateEnabled = true;
}
......
......@@ -35,6 +35,7 @@ namespace ZZZZZZ.Player
private void Current_Update(UpdateEventArgs obj)
{
Character.Move(Input.Movement);
if ((Character as LocalCharacter).IsGrounded)
{
......
......@@ -11,23 +11,31 @@ namespace ZZZZZZ.Worlds
public TileMap2D TileMap { get; private set; }
public string Name { get; private set; }
public Vector2 Spawn { get; private set; }
public int WorldX { get; private set; }
public int WorldY { get; private set; }
private Node ChildFromScene { get; }
public Level(string level)
public Level(string level, int x, int y)
{
WorldX=x;
WorldY=y;
Name = level.Split('.')[1];
ChildFromScene = GameManager.Current.Scene.CreateChild("Level");
ChildFromScene.AddComponent(this);
TileMap = Node.CreateComponent<TileMap2D>();
TileMap.TmxFile = Application.ResourceCache.GetTmxFile2D(level);
TileMap.Node.SetPosition2D(new Vector2(-12.9f, -7.7f));
TileMap.Node.Scale *= 4.2f;
TileMap.Node.SetPosition2D(new Vector2(x * 7.65f, y * 7.65f));
SetSpawn();
SetArea();
GenerateCollision();
GenerateTriggerBox();
}
private void SetSpawn()
......@@ -47,6 +55,20 @@ 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);
......
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