Commit 2e5c5dcb authored by Maxime POULAIN's avatar Maxime POULAIN
Browse files

add working camera, better level management

parent 6f1deae4
......@@ -39,6 +39,9 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Content Include="Data\Levels\World0\tiles.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Data\UI\inner_joystick.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
......@@ -130,6 +133,15 @@
<None Include="Data\Levels\world0.tmx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Data\Levels\World0\world0_0-0.tmx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Data\Levels\World0\world0_0-1.tmx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Data\Levels\World0\world0_0-2.tmx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Data\Particles\background.pex">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
......@@ -209,7 +221,11 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="Data\Levels\World0\tiles.tsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\UrhoSharp.1.9.67\build\net45\UrhoSharp.targets" Condition="Exists('..\packages\UrhoSharp.1.9.67\build\net45\UrhoSharp.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
......
......@@ -7,7 +7,7 @@ namespace ZZZZZZ.GUI.Navigations
public void SingleplayerWorld0()
{
ButtonSound();
GameManager.Current.LevelManager.Load(Assets.Levels.World0);
GameManager.Current.LevelManager.Load(Assets.Levels.World0Start);
Load(Assets.UI.Menus.Ingame);
GameManager.Current.SpawnPlayer();
GameManager.Current.Navigation.Toast.Show("Welcome to ZZZZZZ");
......
......@@ -25,6 +25,9 @@
{
public const string BasePath = "Levels/";
public const string World0 = "Levels/world0.tmx";
public const string World0Path = "Levels/World0/";
public const string World0Start = "Levels/World0/world0_0-0.tmx";
}
public static class UI
......
......@@ -76,7 +76,7 @@ namespace ZZZZZZ.WebAPIs
var content = post.Result.Content.ReadAsStringAsync();
content.Wait();
return post.Result.StatusCode == HttpStatusCode.OK;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
......
using System;
using System.Collections.Generic;
using System.IO;
using Urho;
using Urho.Actions;
using ZZZZZZ.Physics;
using ZZZZZZ.Physics.CollisionBox;
using ZZZZZZ.Utils;
......@@ -19,35 +23,68 @@ namespace ZZZZZZ.Worlds
}
}
public List<Level> Loaded { get; }
public event Action<LevelChangedEventArgs> LevelChanged;
public LevelManager(CollisionHandler collisionHandler)
{
collisionHandler.CollisionBoxTriggered += CollisionHandler_CollisionBoxTriggered;
collisionHandler.AreaLevelTriggered += CollisionHandler_AreaLevelTriggered;
Loaded = new List<Level>();
}
private void CollisionHandler_AreaLevelTriggered(AreaTriggeredEventArgs obj)
{
Console.WriteLine($"entering area {obj.CameraPosition}");
GameManager.Current.Camera.Node.Position = new Vector3(obj.CameraPosition.Y * 7.68f + 3.84f, obj.CameraPosition.X * 4.8f + 2.4f, 0);
}
public void Unload()
{
if (Current != null)
{
Current.Dispose();
var i = Current.IsDeleted;
}
foreach (var level in Loaded)
level.Dispose();
}
public void Load(string level)
{
Unload();
Current = new Level(level);
var filename = Path.GetFileNameWithoutExtension(level);
var path = Path.GetDirectoryName(level);
var splitted = filename.Split('_');
var splitted2 = splitted[1].Split('-');
var levelX = int.Parse(splitted2[0]);
var levelY = int.Parse(splitted2[1]);
for (int i = levelX - 1; i <= levelX + 1; i++)
{
for (int j = levelY - 1; j <= levelY + 1; j++)
{
var filePathToLoad = Path.Combine(path, $"{splitted[0]}_{i}-{j}.tmx");
var tmxLevel = Application.Current.ResourceCache.GetTmxFile2D(filePathToLoad, false);
if (tmxLevel != null)
{
var _level = new Level(filePathToLoad, j, i);
Loaded.Add(_level);
if (i == levelX && j == levelY)
Current = _level;
}
}
}
}
private void CollisionHandler_CollisionBoxTriggered(CollisionBoxTriggeredEventArgs obj)
{
if (Current != null)
/*if (Current != null)
Current.Dispose();
Current = new Level(Assets.Levels.BasePath + obj.Goto);
*/
}
}
}
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