Reformatted a bunch of files.
This commit is contained in:
@@ -83,7 +83,13 @@ local GetButton = require("Assets.Scripts.MenuScripts.MenuButton");
|
||||
local GetInactiveButton = require("Assets.Scripts.MenuScripts.InactiveMenuButton");
|
||||
|
||||
local spb = GetButton("SINGLEPLAYER", buttonContainer);
|
||||
spb.OnLMBClick:Bind(function(ev, mousedata)
|
||||
spb.OnLMBClick:Bind(function()
|
||||
print(menumanager)
|
||||
print(menumanager.CurrentPage);
|
||||
print(menumanager.Pages["singleplayermenu"]);
|
||||
|
||||
print("OK");
|
||||
|
||||
menumanager.CurrentPage = menumanager.Pages["singleplayermenu"];
|
||||
end)
|
||||
|
||||
|
@@ -1,15 +1,16 @@
|
||||
print("Load up Singleplayer Menu")
|
||||
|
||||
import ('MonoGame.Framework', 'Microsoft.Xna.Framework')
|
||||
import ('CaveGame.Client.DesktopGL', 'CaveGame.Client')
|
||||
import ('CaveGame.Client.DesktopGL', 'CaveGame.Client.UI')
|
||||
import ('CaveGame.Client.DesktopGL', 'CaveGame.Common')
|
||||
import ('CaveGame.Client.DesktopGL', 'CaveGame.Common.World')
|
||||
import ('CaveGame.Client.DesktopGL', 'CaveGame.Client.Menu')
|
||||
|
||||
local GetButton = require("Assets.Scripts.MenuScripts.MenuButton")
|
||||
|
||||
local SingleplayerMenu = UIRoot();
|
||||
|
||||
|
||||
|
||||
local title = Label(script, {
|
||||
Parent = SingleplayerMenu,
|
||||
Text = 'SINGLEPLAYER',
|
||||
@@ -76,12 +77,14 @@ local deleteWorld = toolbarButton("Delete World", 0);
|
||||
|
||||
|
||||
local function refresh()
|
||||
for obj in list(worldListing:FindChildrenWithName("Entry")) do
|
||||
|
||||
for obj in list(worldListing:FindChildrenWithName("Entry")) do
|
||||
worldListing.Children:Remove(obj);
|
||||
obj.Parent = nil;
|
||||
end
|
||||
-- TODO: Load the world listing
|
||||
|
||||
for obj in list(SavedWorldManager.GetWorldsOnFile()) do
|
||||
print(obj)
|
||||
local instance = ContextButton(script, {
|
||||
Parent = worldListing,
|
||||
Size = UICoords(0, 60, 1.0, 0),
|
||||
@@ -122,7 +125,7 @@ for obj in list(worldListing:FindChildrenWithName("Entry")) do
|
||||
end)
|
||||
instance.ContextNodes:Add(loadWorld);
|
||||
end
|
||||
|
||||
print("Finish Generating World Listing")
|
||||
end
|
||||
|
||||
deleteWorld.OnLMBClick:Bind(function()
|
||||
@@ -164,5 +167,5 @@ backbutton.OnLMBClick:Bind(function()
|
||||
menumanager.CurrentPage = menumanager.Pages["mainmenu"];
|
||||
end)
|
||||
|
||||
|
||||
print("Finished Initialization")
|
||||
return SingleplayerMenu;
|
@@ -31,9 +31,9 @@ local NewWorldMenu = require("Assets.Scripts.MenuScripts.NewWorldMenu")
|
||||
print("require NewWorldMenu Succeeded")
|
||||
|
||||
menumanager.Pages:Add("mainmenu", MainMenu);
|
||||
menumanager.Pages:Add("singleplayermenu", SingleplayerMenu);
|
||||
menumanager.Pages:Add("multiplayermenu", MultiplayerMenu);
|
||||
menumanager.Pages:Add("timeoutmenu", TimeoutMenu);
|
||||
menumanager.Pages:Add("singleplayermenu", SingleplayerMenu);
|
||||
menumanager.Pages:Add("creditsmenu", CreditsMenu);
|
||||
menumanager.Pages:Add("newworldmenu", NewWorldMenu);
|
||||
|
||||
|
@@ -1,9 +0,0 @@
|
||||
namespace CaveGame.Client.DesktopGL
|
||||
{
|
||||
public class CaveGameArguments
|
||||
{
|
||||
public string AutoLoadWorld { get; set; } = "";
|
||||
public string AutoConnectName { get; set; } = "";
|
||||
public string AutoConnectAddress { get; set; } = "";
|
||||
}
|
||||
}
|
@@ -96,7 +96,7 @@ GameVersion: {Globals.CurrentVersionFullString} <br/>
|
||||
NetworkProtocolVersion: {Globals.ProtocolVersion} <br/>
|
||||
TextureLoadSuccess: {GraphicsEngine.Instance.ContentLoaded} <br/>
|
||||
TextureCount: {GraphicsEngine.Instance.Textures.Count} <br/>
|
||||
Steam Enabled: {Game.SteamManager.Enabled}<br/>
|
||||
Steam Enabled: {Game.Steam.Enabled}<br/>
|
||||
IsOS64Bit: {Environment.Is64BitOperatingSystem} <br/>
|
||||
OperatingSystem: {Environment.OSVersion.Platform} platform. {Environment.OSVersion.VersionString} <br/>
|
||||
Architecture: {Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")} <br/>
|
||||
@@ -119,7 +119,7 @@ Window Dimensions: {Game.Window.ClientBounds.Width}x{Game.Window.ClientBounds.He
|
||||
Window Dimensions: { Game.Window.ClientBounds.Width}x{ Game.Window.ClientBounds.Height}
|
||||
Screen Dimensions: {Game.GraphicsDeviceManager.GraphicsDevice.Adapter.CurrentDisplayMode.Width}x{Game.GraphicsDeviceManager.GraphicsDevice.Adapter.CurrentDisplayMode.Height}<br/>
|
||||
Fullscreen: {Game.GraphicsDeviceManager.IsFullScreen}<br/>
|
||||
Settings.FPSLimit: {Game.Settings.FPSLimit}<br/>
|
||||
Settings.FPSLimit: {Game.Settings.FramerateLimit}<br/>
|
||||
Settings.CameraShake: {Game.Settings.CameraShake}<br/>
|
||||
Settings.ParticlesEnabled: {Game.Settings.Particles}<br/>
|
||||
Game Context: {Game.CurrentGameContext}<br/>
|
||||
|
@@ -1,63 +1,58 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using CaveGame.Client.DesktopGL;
|
||||
using CaveGame.Common;
|
||||
using CaveGame.Common.Game.Tiles;
|
||||
|
||||
|
||||
namespace CaveGame.Client.DesktopGL
|
||||
namespace CaveGame.Client.DesktopGL;
|
||||
public static class Program
|
||||
{
|
||||
public static class Program
|
||||
|
||||
|
||||
// When Debugging the game, we want direct access to the code
|
||||
private static void DebugGameloop()
|
||||
{
|
||||
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
using (var game = new CaveGameDesktopClient())
|
||||
{
|
||||
// parse command line arguments
|
||||
CaveGameArguments arguments = new CaveGameArguments();
|
||||
|
||||
for (int x = 0; x < args.Length; x++)
|
||||
{
|
||||
switch(args[x])
|
||||
{
|
||||
case "-world":
|
||||
arguments.AutoLoadWorld = args[x + 1];
|
||||
break;
|
||||
case "-connect":
|
||||
arguments.AutoConnectName = args[x + 1];
|
||||
arguments.AutoConnectAddress = args[x + 2];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Tile.AssertTileEnumeration();
|
||||
using (var game = new CaveGameDesktopClient(arguments))
|
||||
{
|
||||
#if !DEBUG
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
game.Run();
|
||||
game.Exit();
|
||||
} catch(Exception e)
|
||||
{
|
||||
CrashReport report = new CrashReport(game, e);
|
||||
report.GenerateHTMLReport();
|
||||
throw e;
|
||||
|
||||
}
|
||||
#else
|
||||
game.Run();
|
||||
game.Exit();
|
||||
#endif
|
||||
}
|
||||
|
||||
Process.GetCurrentProcess().CloseMainWindow();
|
||||
Environment.Exit(Environment.ExitCode);
|
||||
|
||||
game.Run();
|
||||
game.Exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// In "Release" We want crashes to generate a report
|
||||
// that the player can submit to us
|
||||
private static void ReleaseGameloop()
|
||||
{
|
||||
using (var game = new CaveGameDesktopClient())
|
||||
{
|
||||
try
|
||||
{
|
||||
game.Run();
|
||||
game.Exit();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
CrashReport report = new CrashReport(game, e);
|
||||
report.GenerateHTMLReport();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Logger.LogInfo("Starting Program");
|
||||
// parse command line arguments
|
||||
Tile.AssertTileEnumeration();
|
||||
|
||||
#if DEBUG
|
||||
DebugGameloop();
|
||||
#else
|
||||
ReleaseGameloop();
|
||||
#endif
|
||||
Process.GetCurrentProcess().CloseMainWindow();
|
||||
Environment.Exit(Environment.ExitCode);
|
||||
}
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ namespace CaveGame.Client.DesktopGL
|
||||
|
||||
}
|
||||
|
||||
public class SteamManager: GameComponent, ISteamManager
|
||||
public class Steam: GameComponent, ISteamManager
|
||||
{
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace CaveGame.Client.DesktopGL
|
||||
|
||||
|
||||
//
|
||||
public SteamManager Instance { get; set; }
|
||||
public Steam Instance { get; set; }
|
||||
|
||||
public string SteamUsername => SteamEnabled ? SteamFriends.GetPersonaName() : "Player1";
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace CaveGame.Client.DesktopGL
|
||||
|
||||
RepeatingIntervalTask callbackRun;
|
||||
|
||||
public SteamManager(Microsoft.Xna.Framework.Game _game) : base(_game)
|
||||
public Steam(Microsoft.Xna.Framework.Game _game) : base(_game)
|
||||
{
|
||||
if (Instance != null)
|
||||
throw new Exception("SteamManager is a singleton class, and can only be instantiated once!");
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -17,26 +17,26 @@ public enum FramerateLimiterOptions
|
||||
Cap30,
|
||||
}
|
||||
|
||||
public enum FullscreenResolutionOptions
|
||||
public enum FullscreenResolutions
|
||||
{
|
||||
// 4 by 3
|
||||
Res640x480,
|
||||
Res800x600,
|
||||
Res1024x768,
|
||||
Res1152x864,
|
||||
Res1280x960,
|
||||
Res1440x1050,
|
||||
Res1600x1200,
|
||||
Res2048x1536,
|
||||
Res640X480,
|
||||
Res800X600,
|
||||
Res1024X768,
|
||||
Res1152X864,
|
||||
Res1280X960,
|
||||
Res1440X1050,
|
||||
Res1600X1200,
|
||||
Res2048X1536,
|
||||
|
||||
// 16 by 9
|
||||
Res854x480,
|
||||
Res1280x720,
|
||||
Res1366x768,
|
||||
Res1600x900,
|
||||
Res1920x1080,
|
||||
Res2560x1440,
|
||||
Res3840x2160,
|
||||
Res854X480,
|
||||
Res1280X720,
|
||||
Res1366X768,
|
||||
Res1600X900,
|
||||
Res1920X1080,
|
||||
Res2560X1440,
|
||||
Res3840X2160,
|
||||
|
||||
UseMonitorSize
|
||||
}
|
||||
@@ -92,6 +92,8 @@ public class SettingChangedEventArgs<T> : EventArgs
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Create Wrapper Thingy to represent s
|
||||
// List<T> where T: Keys, GamepadButton, etc.
|
||||
public class InputActionWrapping
|
||||
{
|
||||
|
||||
@@ -118,7 +120,7 @@ public class GameSettings : ConfigFile
|
||||
get => _uiScale;
|
||||
set
|
||||
{
|
||||
OnUIScaleChanged?.Invoke(this, new(_uiScale, value));
|
||||
OnUiScaleChanged?.Invoke(this, new(_uiScale, value));
|
||||
_uiScale = value;
|
||||
}
|
||||
}
|
||||
@@ -131,6 +133,7 @@ public class GameSettings : ConfigFile
|
||||
_fullscreen = value;
|
||||
}
|
||||
}
|
||||
public FullscreenResolutions FullscreenResolution { get; set; }
|
||||
public bool VSync
|
||||
{
|
||||
get => _vsync;
|
||||
@@ -177,12 +180,12 @@ public class GameSettings : ConfigFile
|
||||
// AudioManager.MusicVolume = value / 100.0f;
|
||||
}
|
||||
}
|
||||
public int SFXVolume
|
||||
public int SfxVolume
|
||||
{
|
||||
get => _sfxVolume;
|
||||
set
|
||||
{
|
||||
OnSFXVolumeChanged?.Invoke(this, new(_sfxVolume, value));
|
||||
OnSfxVolumeChanged?.Invoke(this, new(_sfxVolume, value));
|
||||
_sfxVolume = value;
|
||||
}
|
||||
}
|
||||
@@ -200,13 +203,14 @@ public class GameSettings : ConfigFile
|
||||
public Keys MoveDownKey { get; set; }
|
||||
public Keys MoveUpKey { get; set; }
|
||||
public Keys JumpKey { get; set; }
|
||||
|
||||
public GameChatSize ChatSize { get; set; }
|
||||
public string TexturePackName { get; set; }
|
||||
#endregion
|
||||
|
||||
#region Internal values
|
||||
[XmlIgnore]
|
||||
private bool _fullscreen;
|
||||
private FullscreenResolutionOptions _fullscreenRes;
|
||||
private FullscreenResolutions _fullscreenRes;
|
||||
private bool _particles;
|
||||
private bool _vsync;
|
||||
private int _fpsLimit;
|
||||
@@ -225,15 +229,15 @@ public class GameSettings : ConfigFile
|
||||
public event SettingChangedEvent<int> OnMasterVolumeChanged;
|
||||
public event SettingChangedEvent<int> OnMusicVolumeChanged;
|
||||
public event SettingChangedEvent<int> OnAmbienceVolumeChanged;
|
||||
public event SettingChangedEvent<int> OnSFXVolumeChanged;
|
||||
public event SettingChangedEvent<int> OnSfxVolumeChanged;
|
||||
public event SettingChangedEvent<bool> OnVSyncEnabledChanged;
|
||||
public event SettingChangedEvent<int> OnFpsLimitChanged;
|
||||
public event SettingChangedEvent<bool> OnFullscreenStateChanged;
|
||||
public event SettingChangedEvent<FullscreenResolutionOptions> OnFullscreenResolutionChanged;
|
||||
public event SettingChangedEvent<FullscreenResolutions> OnFullscreenResolutionChanged;
|
||||
|
||||
public event SettingChangedEvent<bool> OnCameraShakeEnabledChanged;
|
||||
public event SettingChangedEvent<bool> OnParticlesEnabledChanged;
|
||||
public event SettingChangedEvent<float> OnUIScaleChanged;
|
||||
public event SettingChangedEvent<float> OnUiScaleChanged;
|
||||
|
||||
|
||||
public static SliderIndex<int>[] VolumeSliderOptions = SliderIndex<int>.GetIntArray(0, 101);
|
||||
@@ -245,23 +249,44 @@ public class GameSettings : ConfigFile
|
||||
new SliderIndex<GameChatSize>("Small", GameChatSize.Small)
|
||||
};
|
||||
|
||||
public static SliderIndex<GameChatSize>[] FPSSliderOptionSet =
|
||||
public static SliderIndex<GameChatSize>[] FpsSliderOptionSet =
|
||||
{
|
||||
new SliderIndex<GameChatSize>("Large", GameChatSize.Large),
|
||||
new SliderIndex<GameChatSize>("Normal", GameChatSize.Normal),
|
||||
new SliderIndex<GameChatSize>("Small", GameChatSize.Small)
|
||||
};
|
||||
|
||||
public static GameSettings CurrentSettings { get; set; }
|
||||
|
||||
public GameSettings()
|
||||
{
|
||||
CurrentSettings = this;
|
||||
}
|
||||
|
||||
public GameChatSize ChatSize { get; set; }
|
||||
public string TexturePackName { get; set; }
|
||||
public void Save() {}
|
||||
public void LoadGameSettings()
|
||||
{
|
||||
FillDefaults();
|
||||
// Ur Kidding Me?
|
||||
// OK Here's the issue at hand:
|
||||
// GameSettings instance must exist before loading the file
|
||||
// Because CaveGameDesktopClient connects to it's XSettingChanged
|
||||
// Lazy solution: Create a "clone" object with the data
|
||||
// and copy properties
|
||||
|
||||
// The alternative to this is to load the XML directly and that's nasty.
|
||||
|
||||
var settings = ConfigFile.Load<GameSettings>("settings.xml", true);
|
||||
this.FramerateLimit = settings.FramerateLimit;
|
||||
this.MoveDownKey = settings.MoveDownKey;
|
||||
this.MasterVolume = settings.MasterVolume;
|
||||
this.SfxVolume = settings.SfxVolume;
|
||||
this.AmbienceVolume = settings.AmbienceVolume;
|
||||
this.VSync = settings.VSync;
|
||||
this.Fullscreen = settings.Fullscreen;
|
||||
this.FullscreenResolution = settings.FullscreenResolution;
|
||||
this.UserInterfaceScale = settings.UserInterfaceScale;
|
||||
this.CameraShake = settings.CameraShake;
|
||||
|
||||
}
|
||||
|
||||
public override void FillDefaults()
|
||||
{
|
||||
@@ -275,6 +300,7 @@ public class GameSettings : ConfigFile
|
||||
ChatSize = GameChatSize.Normal;
|
||||
MasterVolume = 100;
|
||||
MusicVolume = 50;
|
||||
SFXVolume = 75;
|
||||
SfxVolume = 75;
|
||||
FullscreenResolution = FullscreenResolutions.Res1366X768;
|
||||
}
|
||||
}
|
||||
|
@@ -8,20 +8,18 @@ using System.Collections.Generic;
|
||||
using NLua;
|
||||
using System.IO;
|
||||
using CaveGame.Client.DesktopGL;
|
||||
using CaveGame.Common.Extensions;
|
||||
using CaveGame.Common.LuaInterop;
|
||||
|
||||
namespace CaveGame.Client.Menu
|
||||
{
|
||||
public static class EnumExtensions
|
||||
{
|
||||
public static int ToInt(this GameChatSize e)
|
||||
{
|
||||
return (int)e;
|
||||
}
|
||||
}
|
||||
public class MenuManager : IGameContext
|
||||
{
|
||||
|
||||
public void SetPage(string pagename)
|
||||
{
|
||||
if (this.Pages.TryGetValue(pagename, out UIRoot objeckt))
|
||||
this.CurrentPage = objeckt;
|
||||
}
|
||||
|
||||
public CaveGameDesktopClient Game { get; private set; }
|
||||
|
||||
@@ -41,7 +39,7 @@ namespace CaveGame.Client.Menu
|
||||
{
|
||||
_currentPage?.OnUnload.Invoke(null);
|
||||
_currentPage = value;
|
||||
_currentPage.OnLoad.Invoke(null);
|
||||
_currentPage?.OnLoad.Invoke(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +83,9 @@ namespace CaveGame.Client.Menu
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine(e.StackTrace);
|
||||
|
||||
}
|
||||
Console.WriteLine("PostLoad");
|
||||
}
|
||||
|
@@ -1,18 +1,12 @@
|
||||
using CaveGame.Client.UI;
|
||||
using CaveGame.Common;
|
||||
using CaveGame.Common.Game.Tiles;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using CaveGame.Client.DesktopGL;
|
||||
|
||||
namespace CaveGame.Client.Menu
|
||||
{
|
||||
|
||||
public class BindButton : TextButton
|
||||
{
|
||||
public event KeysHandler OnRebind;
|
||||
@@ -152,7 +146,7 @@ namespace CaveGame.Client.Menu
|
||||
Parent = LeftContainer,
|
||||
Size = new UICoords(0, 25, 1, 0),
|
||||
Font = GFX.Fonts.Arial14,
|
||||
Text = "FPS Cap: " + Game.Settings.FPSLimit,
|
||||
Text = "FPS Cap: " + Game.Settings.FramerateLimit,
|
||||
};
|
||||
|
||||
NumericSlider fpsCapSlider = new NumericSlider
|
||||
@@ -170,7 +164,7 @@ namespace CaveGame.Client.Menu
|
||||
void onFpsCapSliderChanged(NumericSlider slider, float value)
|
||||
{
|
||||
fpsCapText.Text = "FPS Cap:" + (int)value;
|
||||
Game.Settings.FPSLimit = (int)value;
|
||||
Game.Settings.FramerateLimit = (int)value;
|
||||
}
|
||||
fpsCapSlider.OnValueChanged += onFpsCapSliderChanged;
|
||||
|
||||
@@ -295,7 +289,7 @@ namespace CaveGame.Client.Menu
|
||||
Parent = RightContainer,
|
||||
Size = new UICoords(0, 25, 1, 0),
|
||||
Font = GFX.Fonts.Arial14,
|
||||
Text = GetSFXLabelText(GameSettings.CurrentSettings.SFXVolume),
|
||||
Text = GetSFXLabelText(GameSettings.CurrentSettings.SfxVolume),
|
||||
};
|
||||
NumericSlider sfxVolumeSlider = new NumericSlider
|
||||
{
|
||||
@@ -312,9 +306,9 @@ namespace CaveGame.Client.Menu
|
||||
string GetSFXLabelText(float value) => "SFX Volume: " + Math.Floor(value) + "%";
|
||||
void OnSFXVolumeSliderChanged(NumericSlider slider, float value)
|
||||
{
|
||||
GameSettings.CurrentSettings.SFXVolume = (int)value;
|
||||
GameSettings.CurrentSettings.SfxVolume = (int)value;
|
||||
AudioManager.EffectVolume = value / 100.0f;
|
||||
sfxVolumeLabel.Text = GetSFXLabelText(GameSettings.CurrentSettings.SFXVolume);
|
||||
sfxVolumeLabel.Text = GetSFXLabelText(GameSettings.CurrentSettings.SfxVolume);
|
||||
}
|
||||
sfxVolumeSlider.OnValueChanged += OnSFXVolumeSliderChanged;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using CaveGame.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using CaveGame.Common.World;
|
||||
@@ -13,15 +13,20 @@ namespace CaveGame.Client
|
||||
if (!System.IO.Directory.Exists(filename))
|
||||
System.IO.Directory.CreateDirectory(filename);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static List<WorldMetadata> GetWorldsOnFile()
|
||||
{
|
||||
CreateDirectoryIfNull("Worlds");
|
||||
List<WorldMetadata> results = new List<WorldMetadata>();
|
||||
foreach (var directory in Directory.EnumerateDirectories("Worlds"))
|
||||
results.Add(WorldMetadata.LoadWorldData(directory));
|
||||
foreach (var directory in Directory.EnumerateDirectories("Worlds"))
|
||||
{
|
||||
Console.WriteLine(directory);
|
||||
|
||||
var worldMetadataFilePath = Path.Combine(directory, @"WorldMetadata.xml");
|
||||
var worldMetadataFileExists = File.Exists(worldMetadataFilePath);
|
||||
if (worldMetadataFileExists)
|
||||
results.Add(WorldMetadata.LoadWorldData(directory));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,6 @@
|
||||
using CaveGame.Common;
|
||||
using CaveGame.Common.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CaveGame.Common.Extensions;
|
||||
|
||||
namespace CaveGame.Client
|
||||
@@ -16,7 +12,7 @@ namespace CaveGame.Client
|
||||
|
||||
public Splash()
|
||||
{
|
||||
SplashTimer = 7;
|
||||
SplashTimer = 4.5f;
|
||||
}
|
||||
|
||||
public void Update(GameTime gt)
|
||||
|
@@ -20,9 +20,15 @@ using CaveGame.Common.Game.Items;
|
||||
|
||||
namespace CaveGame.Common.Game.Entities
|
||||
{
|
||||
public class Humanoid : PhysicsEntity
|
||||
{
|
||||
|
||||
public interface IExplosionDamagable
|
||||
{
|
||||
void Damage(DamageType type, IDamageSource source, int amount);
|
||||
void Damage(DamageType type, IDamageSource source, int amount, Vector2 direction);
|
||||
}
|
||||
|
||||
public class Humanoid : PhysicsEntity, IExplosionDamagable
|
||||
{
|
||||
public virtual int BaseDefense { get; }
|
||||
public virtual int DefenseModifier { get; set; }
|
||||
public virtual int ArmorDefense
|
||||
@@ -189,8 +195,8 @@ namespace CaveGame.Common.Game.Entities
|
||||
spriteFrame = SP_FALL;
|
||||
}
|
||||
|
||||
DrawHealth(gfx);
|
||||
DrawName(gfx);
|
||||
//DrawHealth(gfx);
|
||||
//DrawName(gfx);
|
||||
|
||||
gfx.Sprite(gfx.Player, Position, spriteFrame, Illumination.MultiplyAgainst(Color), Rotation.Zero, new Vector2(8, 12), 1, (SpriteEffects)flipSprite, 0);
|
||||
}
|
||||
|
@@ -233,6 +233,12 @@ namespace CaveGame.Common.Game.Items
|
||||
}
|
||||
base.OnClientLMBHeld(player, client, stack, gt);
|
||||
}
|
||||
|
||||
public void DrawSwinging(GraphicsEngine GFX, Vector2 position, float scale)
|
||||
{
|
||||
GFX.Sprite(GFX.PickaxeNew, position+new Vector2(8*scale, 8*scale), null, Tint, Rotation.FromRad(swingingTimer), new Vector2(8, 8), scale* Size, SpriteEffects.None, 0);
|
||||
}
|
||||
|
||||
public override void Draw(GraphicsEngine GFX, Vector2 position, float scale)
|
||||
{
|
||||
GFX.Sprite(GFX.PickaxeNew, position+new Vector2(8*scale, 8*scale), null, Tint, Rotation.Zero, new Vector2(8, 8), scale* Size, SpriteEffects.None, 0);
|
||||
|
@@ -178,7 +178,6 @@ namespace CaveGame.Common.Game.Tiles
|
||||
else
|
||||
GFX.Sprite(GFX.TileSheet, position + new Vector2(4, 0), TR, color.MultiplyAgainst(Color));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void LocalTileUpdate(IGameWorld world, int x, int y)
|
||||
|
@@ -69,7 +69,7 @@ namespace CaveGame.Common.Game.Tiles
|
||||
|
||||
// Tile Properties
|
||||
public virtual float Friction => 1;
|
||||
public virtual byte Opacity => 24;
|
||||
public virtual byte Opacity => 32;
|
||||
public virtual Color Color => Color.White;
|
||||
public virtual Rectangle Quad => TileMap.Default;
|
||||
public virtual byte Hardness => 2;
|
||||
|
@@ -1,271 +1,262 @@
|
||||
#if CLIENT
|
||||
using CaveGame.Client;
|
||||
#endif
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using CaveGame.Common.Game.Tiles;
|
||||
using CaveGame.Common.Extensions;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace CaveGame.Common.Game.Walls
|
||||
|
||||
namespace CaveGame.Common.Game.Walls;
|
||||
|
||||
public enum WallID : short
|
||||
{
|
||||
public enum WallID : short
|
||||
{
|
||||
Void = 255,
|
||||
Air = 0,
|
||||
Stone = 1,
|
||||
Dirt,
|
||||
OakPlank,
|
||||
RedwoodPlank,
|
||||
PinePlank,
|
||||
EbonyPlank,
|
||||
StoneBrick,
|
||||
ClayBrick,
|
||||
SandstoneBrick,
|
||||
MossyStone,
|
||||
CarvedStoneBrick,
|
||||
CarvedSandstoneBrick,
|
||||
MossyStoneBrick,
|
||||
CubedStone,
|
||||
CubedSandstone,
|
||||
Sandstone
|
||||
}
|
||||
|
||||
public class Wall
|
||||
{
|
||||
public virtual byte Opacity => 12;
|
||||
public virtual Color Color => Color.Gray;
|
||||
public virtual Rectangle Quad => TileMap.Default;
|
||||
public virtual byte Hardness => 2;
|
||||
public virtual string Namespace => "CaveGame";
|
||||
public virtual string WallName => this.GetType().Name;
|
||||
|
||||
public virtual short ID => (short) Enum.Parse(typeof(WallID), GetType().Name);
|
||||
|
||||
public static Color BGDarken = new Color(92, 92, 92);
|
||||
|
||||
|
||||
public static Random RNG = new Random();
|
||||
|
||||
public byte Damage { get; set; }
|
||||
|
||||
public byte[] Serialize()
|
||||
{
|
||||
byte[] serializedTile = new byte[4];
|
||||
Encode(ref serializedTile, 0);
|
||||
return serializedTile;
|
||||
}
|
||||
|
||||
public void Serialize(ref byte[] datagram, int pushindex) => Encode(ref datagram, pushindex);
|
||||
|
||||
public virtual void Encode(ref byte[] datagram, int pushIndex)
|
||||
{
|
||||
datagram.WriteShort(pushIndex+0, ID);
|
||||
datagram[2 + pushIndex] = Damage;
|
||||
datagram[3 + pushIndex] = 0; // reserved for future uses
|
||||
}
|
||||
|
||||
public virtual void Decode(ref byte[] datagram, int pullIndex) {}
|
||||
|
||||
public static Wall Deserialize(ref byte[] datagram, int pullIndex)
|
||||
{
|
||||
Wall w = Wall.FromID(datagram.ReadShort(pullIndex));
|
||||
w.Decode(ref datagram, pullIndex);
|
||||
//w.Damage = datagram[pullIndex+1];
|
||||
return w;
|
||||
}
|
||||
|
||||
public static byte IDOf<T>()
|
||||
{
|
||||
var type = typeof(T);
|
||||
byte id = (byte)Enum.Parse(typeof(WallID), type.Name);
|
||||
return id;
|
||||
}
|
||||
|
||||
public static Wall FromID(short t)
|
||||
{
|
||||
var basetype = typeof(Wall);
|
||||
var types = basetype.Assembly.GetTypes().Where(type => type.IsSubclassOf(basetype));
|
||||
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
bool exists = Enum.TryParse(type.Name, out WallID id);
|
||||
if (exists && id == (WallID)t)
|
||||
return (Wall)type.GetConstructor(Type.EmptyTypes).Invoke(null);
|
||||
}
|
||||
throw new Exception(String.Format("WallID not valid! {0}", t));
|
||||
}
|
||||
|
||||
public virtual void Draw(GraphicsEngine GFX, int x, int y, Light3 color)
|
||||
{
|
||||
GFX.Sprite(
|
||||
GFX.TileSheet,
|
||||
new Vector2(x * Globals.TileSize, y * Globals.TileSize),
|
||||
Quad, color.MultiplyAgainst(Color)
|
||||
);
|
||||
}
|
||||
|
||||
internal static Wall FromName(string name)
|
||||
{
|
||||
var basetype = typeof(Wall);
|
||||
var types = basetype.Assembly.GetTypes().Where(type => type.IsSubclassOf(basetype));
|
||||
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (name == type.Name)
|
||||
return (Wall)type.GetConstructor(Type.EmptyTypes).Invoke(null);
|
||||
}
|
||||
throw new Exception("ID not valid!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class Void : Wall
|
||||
{
|
||||
public override void Draw(GraphicsEngine GFX, int x, int y, Light3 color) { }
|
||||
}
|
||||
public class Air : Wall, INonSolid {
|
||||
public override void Draw(GraphicsEngine GFX, int x, int y, Light3 color) { }
|
||||
}
|
||||
|
||||
public abstract class RockWall : Wall
|
||||
{
|
||||
public override byte Hardness => 5;
|
||||
public override Rectangle Quad => TileMap.Stone;
|
||||
public override void Draw(GraphicsEngine GFX, int x, int y, Light3 color)
|
||||
{
|
||||
Rectangle quad = TileMap.BGBrickTL;
|
||||
|
||||
if (x.Mod(2) == 0 && y.Mod(2) == 0)
|
||||
quad = TileMap.BGStoneTL;
|
||||
if (x.Mod(2) == 1 && y.Mod(2) == 0)
|
||||
quad = TileMap.BGStoneTR;
|
||||
if (x.Mod(2) == 0 && y.Mod(2) == 1)
|
||||
quad = TileMap.BGStoneBL;
|
||||
if (x.Mod(2) == 1 && y.Mod(2) == 1)
|
||||
quad = TileMap.BGStoneBR;
|
||||
//base.Dquad = TileMap.BGStoneBL;raw(tilesheet, sb, x, y, color);
|
||||
|
||||
GFX.Sprite(
|
||||
GFX.TileSheet,
|
||||
new Vector2(x * Globals.TileSize, y * Globals.TileSize),
|
||||
quad, color.MultiplyAgainst(Color)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public class Stone : RockWall {
|
||||
|
||||
public override Color Color => new Color(0.4f, 0.4f, 0.4f);
|
||||
}
|
||||
public class Sandstone : RockWall
|
||||
{
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.0f);
|
||||
}
|
||||
public class Dirt : Wall {
|
||||
public override Color Color => new Color(40, 20, 5);
|
||||
public override Rectangle Quad => TileMap.Soil;
|
||||
|
||||
}
|
||||
public class OakPlank : Wall {
|
||||
public override Rectangle Quad => TileMap.Plank;
|
||||
public override Color Color => new Color(0.5f, 0.3f, 0.15f);
|
||||
}
|
||||
public class RedwoodPlank : Wall
|
||||
{
|
||||
public override Rectangle Quad => TileMap.Plank;
|
||||
public override Color Color => new Color(100, 50, 25);
|
||||
}
|
||||
public class PinePlank : Wall
|
||||
{
|
||||
public override Rectangle Quad => TileMap.Plank;
|
||||
public override Color Color => new Color(90, 40, 55);
|
||||
}
|
||||
public class EbonyPlank : Wall
|
||||
{
|
||||
public override Rectangle Quad => TileMap.Plank;
|
||||
public override Color Color => new Color(30, 30, 30);
|
||||
}
|
||||
|
||||
public abstract class Brick : Wall
|
||||
{
|
||||
public override byte Hardness => 5;
|
||||
public override Rectangle Quad => TileMap.Brick;
|
||||
|
||||
|
||||
|
||||
public override void Draw(GraphicsEngine GFX, int x, int y, Light3 color)
|
||||
{
|
||||
Rectangle quad = TileMap.BGBrickTL;
|
||||
|
||||
if (x.Mod(2) == 0 && y.Mod(3) == 0)
|
||||
quad = TileMap.BGBrickTL;
|
||||
if (x.Mod(2) == 1 && y.Mod(3) == 0)
|
||||
quad = TileMap.BGBrickTR;
|
||||
if (x.Mod(2) == 0 && y.Mod(3) == 1)
|
||||
quad = TileMap.BGBrickML;
|
||||
if (x.Mod(2) == 1 && y.Mod(3) == 1)
|
||||
quad = TileMap.BGBrickMR;
|
||||
if (x.Mod(2) == 0 && y.Mod(3) == 2)
|
||||
quad = TileMap.BGBrickBL;
|
||||
if (x.Mod(2) == 1 && y.Mod(3) == 2)
|
||||
quad = TileMap.BGBrickBR;
|
||||
|
||||
//base.Draw(tilesheet, sb, x, y, color);
|
||||
|
||||
GFX.Sprite(
|
||||
GFX.TileSheet,
|
||||
new Vector2(x * Globals.TileSize, y * Globals.TileSize),
|
||||
quad, color.MultiplyAgainst(Color)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public class StoneBrick : Brick
|
||||
{
|
||||
public override Color Color => new Color(0.4f, 0.4f, 0.4f);
|
||||
}
|
||||
public class ClayBrick : Brick
|
||||
{
|
||||
public override Color Color => new Color(0.65f, 0.65f, 0.65f);
|
||||
}
|
||||
public class SandstoneBrick: Brick
|
||||
{
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.0f);
|
||||
}
|
||||
public class MossyStone : Wall
|
||||
{
|
||||
public override Rectangle Quad => TileMap.StoneMossy;
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.3f);
|
||||
}
|
||||
public class MossyStoneBrick : Wall
|
||||
{
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.3f);
|
||||
public override Rectangle Quad => TileMap.MossyBrick;
|
||||
}
|
||||
public class CarvedStoneBrick : Wall
|
||||
{
|
||||
public override Rectangle Quad => TileMap.Carved;
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.3f);
|
||||
}
|
||||
public class CarvedSandstoneBrick : Wall
|
||||
{
|
||||
public override Rectangle Quad => TileMap.Carved;
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.0f);
|
||||
}
|
||||
public class CubedStone : Wall
|
||||
{
|
||||
public override Rectangle Quad => TileMap.StoneCubes;
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.3f);
|
||||
}
|
||||
public class CubedSandstone : Wall
|
||||
{
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.0f);
|
||||
public override Rectangle Quad => TileMap.StoneCubes;
|
||||
}
|
||||
Void = 255,
|
||||
Air = 0,
|
||||
Stone = 1,
|
||||
Dirt,
|
||||
OakPlank,
|
||||
RedwoodPlank,
|
||||
PinePlank,
|
||||
EbonyPlank,
|
||||
StoneBrick,
|
||||
ClayBrick,
|
||||
SandstoneBrick,
|
||||
MossyStone,
|
||||
CarvedStoneBrick,
|
||||
CarvedSandstoneBrick,
|
||||
MossyStoneBrick,
|
||||
CubedStone,
|
||||
CubedSandstone,
|
||||
Sandstone
|
||||
}
|
||||
public class Wall
|
||||
{
|
||||
public virtual byte Opacity => 16;
|
||||
public virtual Color Color => Color.Gray;
|
||||
public virtual Rectangle Quad => TileMap.Default;
|
||||
public virtual byte Hardness => 2;
|
||||
public virtual string Namespace => "CaveGame";
|
||||
public virtual string WallName => this.GetType().Name;
|
||||
|
||||
public virtual short ID => (short)Enum.Parse(typeof(WallID), GetType().Name);
|
||||
|
||||
public static Color BGDarken = new Color(92, 92, 92);
|
||||
|
||||
|
||||
public static Random RNG = new Random();
|
||||
|
||||
public byte Damage { get; set; }
|
||||
|
||||
public byte[] Serialize()
|
||||
{
|
||||
byte[] serializedTile = new byte[4];
|
||||
Encode(ref serializedTile, 0);
|
||||
return serializedTile;
|
||||
}
|
||||
|
||||
public void Serialize(ref byte[] datagram, int pushindex) => Encode(ref datagram, pushindex);
|
||||
|
||||
public virtual void Encode(ref byte[] datagram, int pushIndex)
|
||||
{
|
||||
datagram.WriteShort(pushIndex + 0, ID);
|
||||
datagram[2 + pushIndex] = Damage;
|
||||
datagram[3 + pushIndex] = 0; // reserved for future uses
|
||||
}
|
||||
|
||||
public virtual void Decode(ref byte[] datagram, int pullIndex) { }
|
||||
|
||||
public static Wall Deserialize(ref byte[] datagram, int pullIndex)
|
||||
{
|
||||
Wall w = Wall.FromID(datagram.ReadShort(pullIndex));
|
||||
w.Decode(ref datagram, pullIndex);
|
||||
//w.Damage = datagram[pullIndex+1];
|
||||
return w;
|
||||
}
|
||||
|
||||
public static byte IDOf<T>()
|
||||
{
|
||||
var type = typeof(T);
|
||||
byte id = (byte)Enum.Parse(typeof(WallID), type.Name);
|
||||
return id;
|
||||
}
|
||||
|
||||
public static Wall FromID(short t)
|
||||
{
|
||||
var basetype = typeof(Wall);
|
||||
var types = basetype.Assembly.GetTypes().Where(type => type.IsSubclassOf(basetype));
|
||||
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
bool exists = Enum.TryParse(type.Name, out WallID id);
|
||||
if (exists && id == (WallID)t)
|
||||
return (Wall)type.GetConstructor(Type.EmptyTypes).Invoke(null);
|
||||
}
|
||||
throw new Exception(String.Format("WallID not valid! {0}", t));
|
||||
}
|
||||
|
||||
public virtual void Draw(GraphicsEngine GFX, int x, int y, Light3 color)
|
||||
{
|
||||
GFX.Sprite(
|
||||
GFX.TileSheet,
|
||||
new Vector2(x * Globals.TileSize, y * Globals.TileSize),
|
||||
Quad, color.MultiplyAgainst(Color)
|
||||
);
|
||||
}
|
||||
|
||||
internal static Wall FromName(string name)
|
||||
{
|
||||
var basetype = typeof(Wall);
|
||||
var types = basetype.Assembly.GetTypes().Where(type => type.IsSubclassOf(basetype));
|
||||
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (name == type.Name)
|
||||
return (Wall)type.GetConstructor(Type.EmptyTypes).Invoke(null);
|
||||
}
|
||||
throw new Exception("ID not valid!");
|
||||
}
|
||||
}
|
||||
public class Void : Wall
|
||||
{
|
||||
public override void Draw(GraphicsEngine GFX, int x, int y, Light3 color) { }
|
||||
}
|
||||
public class Air : Wall, INonSolid
|
||||
{
|
||||
public override void Draw(GraphicsEngine GFX, int x, int y, Light3 color) { }
|
||||
}
|
||||
public abstract class RockWall : Wall
|
||||
{
|
||||
public override byte Hardness => 5;
|
||||
public override Rectangle Quad => TileMap.Stone;
|
||||
public override void Draw(GraphicsEngine GFX, int x, int y, Light3 color)
|
||||
{
|
||||
Rectangle quad = TileMap.BGBrickTL;
|
||||
|
||||
if (x.Mod(2) == 0 && y.Mod(2) == 0)
|
||||
quad = TileMap.BGStoneTL;
|
||||
if (x.Mod(2) == 1 && y.Mod(2) == 0)
|
||||
quad = TileMap.BGStoneTR;
|
||||
if (x.Mod(2) == 0 && y.Mod(2) == 1)
|
||||
quad = TileMap.BGStoneBL;
|
||||
if (x.Mod(2) == 1 && y.Mod(2) == 1)
|
||||
quad = TileMap.BGStoneBR;
|
||||
//base.Dquad = TileMap.BGStoneBL;raw(tilesheet, sb, x, y, color);
|
||||
|
||||
GFX.Sprite(
|
||||
GFX.TileSheet,
|
||||
new Vector2(x * Globals.TileSize, y * Globals.TileSize),
|
||||
quad, color.MultiplyAgainst(Color)
|
||||
);
|
||||
}
|
||||
}
|
||||
public class Stone : RockWall
|
||||
{
|
||||
|
||||
public override Color Color => new Color(0.4f, 0.4f, 0.4f);
|
||||
}
|
||||
public class Sandstone : RockWall
|
||||
{
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.0f);
|
||||
}
|
||||
public class Dirt : Wall
|
||||
{
|
||||
public override Color Color => new Color(40, 20, 5);
|
||||
public override Rectangle Quad => TileMap.Soil;
|
||||
|
||||
}
|
||||
public class OakPlank : Wall
|
||||
{
|
||||
public override Rectangle Quad => TileMap.Plank;
|
||||
public override Color Color => new Color(0.5f, 0.3f, 0.15f);
|
||||
}
|
||||
public class RedwoodPlank : Wall
|
||||
{
|
||||
public override Rectangle Quad => TileMap.Plank;
|
||||
public override Color Color => new Color(100, 50, 25);
|
||||
}
|
||||
public class PinePlank : Wall
|
||||
{
|
||||
public override Rectangle Quad => TileMap.Plank;
|
||||
public override Color Color => new Color(90, 40, 55);
|
||||
}
|
||||
public class EbonyPlank : Wall
|
||||
{
|
||||
public override Rectangle Quad => TileMap.Plank;
|
||||
public override Color Color => new Color(30, 30, 30);
|
||||
}
|
||||
public abstract class Brick : Wall
|
||||
{
|
||||
public override byte Hardness => 5;
|
||||
public override Rectangle Quad => TileMap.Brick;
|
||||
|
||||
|
||||
|
||||
public override void Draw(GraphicsEngine GFX, int x, int y, Light3 color)
|
||||
{
|
||||
Rectangle quad = TileMap.BGBrickTL;
|
||||
|
||||
if (x.Mod(2) == 0 && y.Mod(3) == 0)
|
||||
quad = TileMap.BGBrickTL;
|
||||
if (x.Mod(2) == 1 && y.Mod(3) == 0)
|
||||
quad = TileMap.BGBrickTR;
|
||||
if (x.Mod(2) == 0 && y.Mod(3) == 1)
|
||||
quad = TileMap.BGBrickML;
|
||||
if (x.Mod(2) == 1 && y.Mod(3) == 1)
|
||||
quad = TileMap.BGBrickMR;
|
||||
if (x.Mod(2) == 0 && y.Mod(3) == 2)
|
||||
quad = TileMap.BGBrickBL;
|
||||
if (x.Mod(2) == 1 && y.Mod(3) == 2)
|
||||
quad = TileMap.BGBrickBR;
|
||||
|
||||
//base.Draw(tilesheet, sb, x, y, color);
|
||||
|
||||
GFX.Sprite(
|
||||
GFX.TileSheet,
|
||||
new Vector2(x * Globals.TileSize, y * Globals.TileSize),
|
||||
quad, color.MultiplyAgainst(Color)
|
||||
);
|
||||
}
|
||||
}
|
||||
public class StoneBrick : Brick
|
||||
{
|
||||
public override Color Color => new Color(0.4f, 0.4f, 0.4f);
|
||||
}
|
||||
public class ClayBrick : Brick
|
||||
{
|
||||
public override Color Color => new Color(0.65f, 0.65f, 0.65f);
|
||||
}
|
||||
public class SandstoneBrick : Brick
|
||||
{
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.0f);
|
||||
}
|
||||
public class MossyStone : Wall
|
||||
{
|
||||
public override Rectangle Quad => TileMap.StoneMossy;
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.3f);
|
||||
}
|
||||
public class MossyStoneBrick : Wall
|
||||
{
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.3f);
|
||||
public override Rectangle Quad => TileMap.MossyBrick;
|
||||
}
|
||||
public class CarvedStoneBrick : Wall
|
||||
{
|
||||
public override Rectangle Quad => TileMap.Carved;
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.3f);
|
||||
}
|
||||
public class CarvedSandstoneBrick : Wall
|
||||
{
|
||||
public override Rectangle Quad => TileMap.Carved;
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.0f);
|
||||
}
|
||||
public class CubedStone : Wall
|
||||
{
|
||||
public override Rectangle Quad => TileMap.StoneCubes;
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.3f);
|
||||
}
|
||||
public class CubedSandstone : Wall
|
||||
{
|
||||
public override Color Color => new Color(0.3f, 0.3f, 0.0f);
|
||||
public override Rectangle Quad => TileMap.StoneCubes;
|
||||
}
|
||||
|
@@ -1,442 +1,399 @@
|
||||
using CaveGame.Common;
|
||||
using CaveGame.Common.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CaveGame.Common.Extensions;
|
||||
|
||||
namespace CaveGame.Common
|
||||
namespace CaveGame.Common;
|
||||
|
||||
// CaveGame's Core Graphics Service
|
||||
// Provides rendering functions and utilities to the rest of the gamecode
|
||||
|
||||
|
||||
using Circle = List<Vector2>;
|
||||
using Arc = List<Vector2>;
|
||||
|
||||
public static class ShapeCache
|
||||
{
|
||||
using Circle = List<Vector2>;
|
||||
using Arc = List<Vector2>;
|
||||
private static readonly Dictionary<String, Circle> circleCache = new Dictionary<string, Circle>();
|
||||
|
||||
public static Arc GetArc(float radius, int sides, float startingAngle, float radians)
|
||||
{
|
||||
Arc points = new Arc();
|
||||
|
||||
public interface IGraphicsEngine
|
||||
{
|
||||
Vector2 WindowSize { get; set; }
|
||||
SpriteBatch SpriteBatch { get; set; }
|
||||
points.AddRange(GetCircle(radius, sides));
|
||||
points.RemoveAt(points.Count - 1);
|
||||
|
||||
SpriteSortMode SpriteSortMode { get; set; }
|
||||
BlendState BlendState { get; set; }
|
||||
SamplerState SamplerState { get; set; }
|
||||
DepthStencilState DepthStencilState { get; set; }
|
||||
RasterizerState RasterizerState { get; set; }
|
||||
Effect Shader { get; set; }
|
||||
Matrix Matrix { get; set; }
|
||||
double curAngle = 0.0;
|
||||
double anglePerSide = MathHelper.TwoPi / sides;
|
||||
|
||||
void Begin(SpriteSortMode sorting = SpriteSortMode.Deferred, BlendState blending = null,
|
||||
SamplerState sampling = null,
|
||||
DepthStencilState depthStencil = null, RasterizerState rasterizing = null, Effect effect = null,
|
||||
Matrix? transform = null);
|
||||
while ((curAngle + (anglePerSide / 2.0)) < startingAngle)
|
||||
{
|
||||
curAngle += anglePerSide;
|
||||
|
||||
void End();
|
||||
points.Add(points[0]);
|
||||
points.RemoveAt(0);
|
||||
}
|
||||
|
||||
}
|
||||
points.Add(points[0]);
|
||||
int sidesInArc = (int)((radians / anglePerSide) + 0.5);
|
||||
|
||||
public static class ShapeCache
|
||||
{
|
||||
private static readonly Dictionary<String, Circle> circleCache = new Dictionary<string, Circle>();
|
||||
points.RemoveRange(sidesInArc + 1, points.Count - sidesInArc - 1);
|
||||
|
||||
public static Arc GetArc(float radius, int sides, float startingAngle, float radians)
|
||||
{
|
||||
Arc points = new Arc();
|
||||
return points;
|
||||
}
|
||||
|
||||
points.AddRange(GetCircle(radius, sides));
|
||||
points.RemoveAt(points.Count - 1);
|
||||
public static Circle GetCircle(double radius, int sides)
|
||||
{
|
||||
String circleKey = radius + "x" + sides;
|
||||
|
||||
double curAngle = 0.0;
|
||||
double anglePerSide = MathHelper.TwoPi / sides;
|
||||
if (circleCache.ContainsKey(circleKey))
|
||||
return circleCache[circleKey];
|
||||
|
||||
while ((curAngle + (anglePerSide / 2.0)) < startingAngle)
|
||||
{
|
||||
curAngle += anglePerSide;
|
||||
Circle circleDef = new Circle();
|
||||
|
||||
points.Add(points[0]);
|
||||
points.RemoveAt(0);
|
||||
}
|
||||
const double max = 2.0 * Math.PI;
|
||||
|
||||
points.Add(points[0]);
|
||||
int sidesInArc = (int)((radians / anglePerSide) + 0.5);
|
||||
double step = max / sides;
|
||||
|
||||
points.RemoveRange(sidesInArc + 1, points.Count - sidesInArc - 1);
|
||||
for (double theta = 0.0; theta < max; theta += step)
|
||||
{
|
||||
circleDef.Add(new Vector2((float)(radius * Math.Cos(theta)), (float)(radius * Math.Sin(theta))));
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
circleDef.Add(new Vector2((float)(radius * Math.Cos(0)), (float)(radius * Math.Sin(0))));
|
||||
|
||||
public static Circle GetCircle(double radius, int sides)
|
||||
{
|
||||
String circleKey = radius + "x" + sides;
|
||||
circleCache.Add(circleKey, circleDef);
|
||||
|
||||
if (circleCache.ContainsKey(circleKey))
|
||||
return circleCache[circleKey];
|
||||
return circleDef;
|
||||
}
|
||||
}
|
||||
public class FontManager
|
||||
{
|
||||
public SpriteFont Arial8 { get; private set; }
|
||||
public SpriteFont Arial10 { get; private set; }
|
||||
public SpriteFont Arial12 { get; private set; }
|
||||
public SpriteFont Arial14 { get; private set; }
|
||||
public SpriteFont Arial16 { get; private set; }
|
||||
public SpriteFont Arial20 { get; private set; }
|
||||
public SpriteFont Arial30 { get; private set; }
|
||||
public SpriteFont Arial10Italic { get; private set; }
|
||||
public SpriteFont Consolas10 { get; private set; }
|
||||
public SpriteFont Consolas12 { get; private set; }
|
||||
public SpriteFont ComicSans10 { get; private set; }
|
||||
public void LoadAssets(ContentManager Content)
|
||||
{
|
||||
|
||||
Circle circleDef = new Circle();
|
||||
Logger.LogInfo("Loading Fonts");
|
||||
Content.RootDirectory = Path.Combine("Assets", "Fonts");
|
||||
Arial8 = Content.Load<SpriteFont>("Arial8");
|
||||
Arial10 = Content.Load<SpriteFont>("Arial10");
|
||||
Arial12 = Content.Load<SpriteFont>("Arial12");
|
||||
Arial14 = Content.Load<SpriteFont>("Arial14");
|
||||
Arial16 = Content.Load<SpriteFont>("Arial16");
|
||||
Arial20 = Content.Load<SpriteFont>("Arial20");
|
||||
Arial30 = Content.Load<SpriteFont>("Arial30");
|
||||
Arial10Italic = Content.Load<SpriteFont>("Arial10Italic");
|
||||
Consolas10 = Content.Load<SpriteFont>("Consolas10");
|
||||
Consolas12 = Content.Load<SpriteFont>("Consolas12");
|
||||
ComicSans10 = Content.Load<SpriteFont>("ComicSans10");
|
||||
}
|
||||
}
|
||||
public class GraphicsEngine
|
||||
{
|
||||
public bool LoadFonts { get; set; }
|
||||
|
||||
const double max = 2.0 * Math.PI;
|
||||
public float GlobalAnimationTimer { get; private set; }
|
||||
|
||||
double step = max / sides;
|
||||
|
||||
for (double theta = 0.0; theta < max; theta += step)
|
||||
{
|
||||
circleDef.Add(new Vector2((float)(radius * Math.Cos(theta)), (float)(radius * Math.Sin(theta))));
|
||||
}
|
||||
|
||||
circleDef.Add(new Vector2((float)(radius * Math.Cos(0)), (float)(radius * Math.Sin(0))));
|
||||
|
||||
circleCache.Add(circleKey, circleDef);
|
||||
|
||||
return circleDef;
|
||||
}
|
||||
}
|
||||
public class FontManager
|
||||
{
|
||||
public SpriteFont Arial8 { get; private set; }
|
||||
public SpriteFont Arial10 { get; private set; }
|
||||
public SpriteFont Arial12 { get; private set; }
|
||||
public SpriteFont Arial14 { get; private set; }
|
||||
public SpriteFont Arial16 { get; private set; }
|
||||
public SpriteFont Arial20 { get; private set; }
|
||||
public SpriteFont Arial30 { get; private set; }
|
||||
public SpriteFont Arial10Italic { get; private set; }
|
||||
public SpriteFont Consolas10 { get; private set; }
|
||||
public SpriteFont Consolas12 { get; private set; }
|
||||
public SpriteFont ComicSans10 { get; private set; }
|
||||
public void LoadAssets(ContentManager Content)
|
||||
{
|
||||
|
||||
Content.RootDirectory = Path.Combine("Assets", "Fonts");
|
||||
Arial8 = Content.Load<SpriteFont>("Arial8");
|
||||
Arial10 = Content.Load<SpriteFont>("Arial10");
|
||||
Arial12 = Content.Load<SpriteFont>("Arial12");
|
||||
Arial14 = Content.Load<SpriteFont>("Arial14");
|
||||
Arial16 = Content.Load<SpriteFont>("Arial16");
|
||||
Arial20 = Content.Load<SpriteFont>("Arial20");
|
||||
Arial30 = Content.Load<SpriteFont>("Arial30");
|
||||
Arial10Italic = Content.Load<SpriteFont>("Arial10Italic");
|
||||
Consolas10 = Content.Load<SpriteFont>("Consolas10");
|
||||
Consolas12 = Content.Load<SpriteFont>("Consolas12");
|
||||
ComicSans10 = Content.Load<SpriteFont>("ComicSans10");
|
||||
}
|
||||
}
|
||||
|
||||
public class GraphicsEngine : IGraphicsEngine
|
||||
{
|
||||
|
||||
|
||||
public bool LoadFonts { get; set; }
|
||||
|
||||
public float GlobalAnimationTimer { get; private set; }
|
||||
|
||||
public static GraphicsEngine Instance { get; private set; }
|
||||
public static GraphicsEngine Instance { get; private set; }
|
||||
|
||||
|
||||
|
||||
#region Texture Shortcuts
|
||||
|
||||
public Texture2D TitleScreen => Textures["TitleScreen.png"];
|
||||
public Texture2D EyeOfHorus => Textures["csoft.png"];
|
||||
public Texture2D ParticleSet => Textures["particles.png"];
|
||||
public Texture2D TileSheet => Textures["tilesheet.png"];
|
||||
public Texture2D CSoftWP => Textures["csoft_wp2.png"];
|
||||
public Texture2D BG => Textures["menu_bg.png"];
|
||||
public Texture2D Border => Textures["border.png"];
|
||||
public Texture2D Slot => Textures["slot.png"];
|
||||
public Texture2D CloudBackground => Textures["clouds.png"];
|
||||
public Texture2D Starfield => Textures["stars.png"];
|
||||
#region Texture Shortcuts
|
||||
public Texture2D TitleScreen => Textures["TitleScreen.png"];
|
||||
public Texture2D EyeOfHorus => Textures["csoft.png"];
|
||||
public Texture2D ParticleSet => Textures["particles.png"];
|
||||
public Texture2D TileSheet => Textures["tilesheet.png"];
|
||||
public Texture2D CSoftWP => Textures["csoft_wp2.png"];
|
||||
public Texture2D BG => Textures["menu_bg.png"];
|
||||
public Texture2D Border => Textures["border.png"];
|
||||
public Texture2D Slot => Textures["slot.png"];
|
||||
public Texture2D CloudBackground => Textures["clouds.png"];
|
||||
public Texture2D Starfield => Textures["stars.png"];
|
||||
|
||||
public Texture2D Nimdoc => Textures["Items:nimdoc_anim.png"];
|
||||
public Texture2D Nimdoc => Textures["Items:nimdoc.png"];
|
||||
|
||||
public Texture2D Explosion => Textures["michaelbay.png"];
|
||||
public Texture2D BowSprite => Textures["Items:bow.png"];
|
||||
public Texture2D BombSprite => Textures["Items:bomb.png"];
|
||||
public Texture2D Bong => Textures["Items:bong.png"];
|
||||
public Texture2D Arrow => Textures["Items:arrow.png"];
|
||||
public Texture2D Bucket => Textures["Items:bucket.png"];
|
||||
public Texture2D BigPickaxe => Textures["Items:bigpickaxe.png"];
|
||||
public Texture2D Helmet => Textures["Armor:helmet.png"];
|
||||
public Texture2D Chestplate => Textures["Armor:chestplate.png"];
|
||||
public Texture2D Sword => Textures["Items:sword.png"];
|
||||
public Texture2D WallScraper => Textures["Items:wallscraper.png"];
|
||||
public Texture2D PickaxeNew => Textures["Items:pickaxenew.png"];
|
||||
public Texture2D Scroll => Textures["Items:scroll.png"];
|
||||
public Texture2D Dynamite => Textures["Items:dynamite.png"];
|
||||
public Texture2D Workbench => Textures["Items:workbench.png"];
|
||||
public Texture2D Potion => Textures["Items:potion.png"];
|
||||
public Texture2D Jetpack => Textures["Items:jetpack.png"];
|
||||
public Texture2D Door => Textures["Items:door.png"];
|
||||
public Texture2D ForestPainting => Textures["Items:forestpainting.png"];
|
||||
public Texture2D Ingot => Textures["Items:ingot.png"];
|
||||
public Texture2D Leggings => Textures["Armor:leggings.png"];
|
||||
public Texture2D Furnace => Textures["Items:furnace.png"];
|
||||
public Texture2D Campfire => Textures["Items:campfire.png"];
|
||||
|
||||
public Texture2D Player => Textures["Entities:player.png"];
|
||||
public Texture2D Zombie => Textures["Entities:zombie.png"];
|
||||
public Texture2D ArrowEntity => Textures["Entities:arrow.png"];
|
||||
public Texture2D VoidMonster => Textures["Entities:wurmhole.png"];
|
||||
public Texture2D Bee => Textures["Entities:bee.png"];
|
||||
public Texture2D Goldfish => Textures["Entities:gregothy.png"];
|
||||
public Texture2D Explosion => Textures["michaelbay.png"];
|
||||
public Texture2D BowSprite => Textures["Items:bow.png"];
|
||||
public Texture2D BombSprite => Textures["Items:bomb.png"];
|
||||
public Texture2D Bong => Textures["Items:bong.png"];
|
||||
public Texture2D Arrow => Textures["Items:arrow.png"];
|
||||
public Texture2D Bucket => Textures["Items:bucket.png"];
|
||||
public Texture2D BigPickaxe => Textures["Items:bigpickaxe.png"];
|
||||
public Texture2D Helmet => Textures["Armor:helmet.png"];
|
||||
public Texture2D Chestplate => Textures["Armor:chestplate.png"];
|
||||
public Texture2D Sword => Textures["Items:sword.png"];
|
||||
public Texture2D WallScraper => Textures["Items:wallscraper.png"];
|
||||
public Texture2D PickaxeNew => Textures["Items:pickaxenew.png"];
|
||||
public Texture2D Scroll => Textures["Items:scroll.png"];
|
||||
public Texture2D Dynamite => Textures["Items:dynamite.png"];
|
||||
public Texture2D Workbench => Textures["Items:workbench.png"];
|
||||
public Texture2D Potion => Textures["Items:potion.png"];
|
||||
public Texture2D Jetpack => Textures["Items:jetpack.png"];
|
||||
public Texture2D Door => Textures["Items:door.png"];
|
||||
public Texture2D ForestPainting => Textures["Items:forestpainting.png"];
|
||||
public Texture2D Ingot => Textures["Items:ingot.png"];
|
||||
public Texture2D Leggings => Textures["Armor:leggings.png"];
|
||||
public Texture2D Furnace => Textures["Items:furnace.png"];
|
||||
public Texture2D Campfire => Textures["Items:campfire.png"];
|
||||
|
||||
//public static Texture2D Campfire => Textures["campfire.png"];
|
||||
#endregion
|
||||
public Texture2D Player => Textures["Entities:player.png"];
|
||||
public Texture2D Zombie => Textures["Entities:zombie.png"];
|
||||
public Texture2D ArrowEntity => Textures["Entities:arrow.png"];
|
||||
public Texture2D VoidMonster => Textures["Entities:wurmhole.png"];
|
||||
public Texture2D Bee => Textures["Entities:bee.png"];
|
||||
public Texture2D Goldfish => Textures["Entities:gregothy.png"];
|
||||
|
||||
public Dictionary<string, Texture2D> Textures = new Dictionary<string, Texture2D>();
|
||||
//public static Texture2D Campfire => Textures["campfire.png"];
|
||||
#endregion
|
||||
|
||||
struct TextureDef
|
||||
{
|
||||
public string Path { get; set; }
|
||||
public string Name { get; set; }
|
||||
public TextureDef(string name, string path)
|
||||
{
|
||||
Name = name;
|
||||
Path = path;
|
||||
}
|
||||
}
|
||||
public Dictionary<string, Texture2D> Textures = new Dictionary<string, Texture2D>();
|
||||
|
||||
private Queue<TextureDef> LoadingQueue = new Queue<TextureDef>();
|
||||
struct TextureDef
|
||||
{
|
||||
public string Path { get; set; }
|
||||
public string Name { get; set; }
|
||||
public TextureDef(string name, string path)
|
||||
{
|
||||
Name = name;
|
||||
Path = path;
|
||||
}
|
||||
}
|
||||
|
||||
public AssetLoader AssetLoader = new AssetLoader();
|
||||
private Texture2D pixel;
|
||||
private Queue<TextureDef> LoadingQueue = new Queue<TextureDef>();
|
||||
|
||||
private void LoadNextAsset(GraphicsDevice gdev)
|
||||
{
|
||||
TextureDef nextTex = LoadingQueue.Dequeue();
|
||||
Texture2D loaded = AssetLoader.LoadTexture(gdev, nextTex.Path);
|
||||
Textures.Add(nextTex.Name, loaded);
|
||||
Console.WriteLine("{0} => {1}", nextTex.Name, nextTex.Path);
|
||||
LoadedTextures++;
|
||||
}
|
||||
public AssetLoader AssetLoader = new AssetLoader();
|
||||
private Texture2D pixel;
|
||||
|
||||
public int TotalTextures { get; private set; }
|
||||
public int LoadedTextures { get; private set; }
|
||||
private void LoadNextAsset(GraphicsDevice gdev)
|
||||
{
|
||||
TextureDef nextTex = LoadingQueue.Dequeue();
|
||||
Texture2D loaded = AssetLoader.LoadTexture(gdev, nextTex.Path);
|
||||
Textures.Add(nextTex.Name, loaded);
|
||||
Logger.LogInfo($"Loading Texture {nextTex.Path} as {nextTex.Name}");
|
||||
LoadedTextures++;
|
||||
}
|
||||
|
||||
public bool FontsLoaded { get; set; }
|
||||
public int TotalTextures { get; private set; }
|
||||
public int LoadedTextures { get; private set; }
|
||||
|
||||
public void LoadAssets(GraphicsDevice graphicsDevice)
|
||||
{
|
||||
var texturesPath = Path.Combine("Assets", "Textures");
|
||||
if (!Directory.Exists(texturesPath))
|
||||
throw new MissingContentFolderException { MissingFilename = "texturesPath" };
|
||||
public bool FontsLoaded { get; set; }
|
||||
|
||||
foreach (var tex in Directory.GetFiles(texturesPath, "*.png", SearchOption.AllDirectories))
|
||||
{
|
||||
|
||||
var trimmedPath = tex.Replace(texturesPath + @"/", "");
|
||||
var cleanedPath = trimmedPath.Replace(@"/", ":");
|
||||
//System.Console.WriteLine($"QTexture {tex} => {cleanedPath} ");
|
||||
public void LoadAssets(GraphicsDevice graphicsDevice)
|
||||
{
|
||||
var texturesPath = Path.Combine("Assets", "Textures");
|
||||
if (!Directory.Exists(texturesPath))
|
||||
throw new MissingContentFolderException
|
||||
{
|
||||
MissingFilename = "texturesPath"
|
||||
};
|
||||
|
||||
LoadingQueue.Enqueue(new TextureDef(cleanedPath, tex));
|
||||
TotalTextures++;
|
||||
}
|
||||
foreach (var tex in Directory.GetFiles(texturesPath, "*.png", SearchOption.AllDirectories))
|
||||
{
|
||||
|
||||
var trimmedPath = tex.Replace(texturesPath + @"/", "");
|
||||
var cleanedPath = trimmedPath.Replace(@"/", ":");
|
||||
//System.Console.WriteLine($"QTexture {tex} => {cleanedPath} ");
|
||||
|
||||
LoadingQueue.Enqueue(new TextureDef(cleanedPath, tex));
|
||||
TotalTextures++;
|
||||
}
|
||||
|
||||
#if !EDITOR
|
||||
/*var entityTexturesPath = Path.Combine("Assets", "Textures", "Entities");
|
||||
foreach (var tex in Directory.GetFiles(entityTexturesPath, "*.png", SearchOption.AllDirectories))
|
||||
{
|
||||
|
||||
GameConsole.Log($"QTexture {tex} => {tex.Replace(entityTexturesPath + @"\", "")} ");
|
||||
LoadingQueue.Enqueue(new TextureDef(
|
||||
tex.Replace(entityTexturesPath + @"\", ""),
|
||||
tex
|
||||
));
|
||||
TotalTextures++;
|
||||
}
|
||||
|
||||
foreach (var tex in Directory.GetFiles("Assets/Textures/Items/", "*.png"))
|
||||
{
|
||||
//Texture2D loaded = AssetLoader.LoadTexture(graphicsDevice, tex);
|
||||
LoadingQueue.Enqueue(new TextureDef(
|
||||
tex.Replace("Assets/Textures/Items/", ""),
|
||||
tex
|
||||
));
|
||||
TotalTextures++;
|
||||
}*/
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
SpriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
if (LoadFonts)
|
||||
Fonts.LoadAssets(ContentManager);
|
||||
|
||||
// create pixel
|
||||
pixel = new Texture2D(GraphicsDevice, 1, 1);
|
||||
pixel.SetData<Color>(new Color[] { Color.White });
|
||||
|
||||
FontsLoaded = true;
|
||||
}
|
||||
|
||||
public FontManager Fonts = new FontManager();
|
||||
|
||||
public Vector2 WindowSize { get; set; }
|
||||
public SpriteSortMode SpriteSortMode { get; set; }
|
||||
public BlendState BlendState { get; set; }
|
||||
public SamplerState SamplerState { get; set; }
|
||||
public DepthStencilState DepthStencilState { get; set; }
|
||||
public RasterizerState RasterizerState { get; set; }
|
||||
public Effect Shader { get; set; }
|
||||
public Matrix Matrix { get; set; }
|
||||
|
||||
public ContentManager ContentManager { get; set; }
|
||||
public SpriteBatch SpriteBatch { get; set; }
|
||||
public GraphicsDevice GraphicsDevice { get; set; }
|
||||
public GraphicsDeviceManager GraphicsDeviceManager { get; set; }
|
||||
|
||||
public bool ContentLoaded { get; private set; }
|
||||
|
||||
public float GraphicsTimer { get; set; }
|
||||
|
||||
public float LoadingDelay { get; set; }
|
||||
|
||||
public GraphicsEngine()
|
||||
{
|
||||
Instance = this;
|
||||
LoadingDelay = 0.03f;
|
||||
FontsLoaded = false;
|
||||
LoadFonts = true;
|
||||
}
|
||||
|
||||
|
||||
public void Update(GameTime gt)
|
||||
{
|
||||
|
||||
// move asset loading to it's own class?
|
||||
if (LoadingQueue.Count > 0)
|
||||
LoadNextAsset(GraphicsDevice);
|
||||
|
||||
if (LoadingQueue.Count == 0)
|
||||
ContentLoaded = true;
|
||||
|
||||
|
||||
// increase global anim time.
|
||||
// used by items, entities, and tiles when an internal state is otherwise not ideal.
|
||||
GlobalAnimationTimer += gt.GetDelta();
|
||||
|
||||
}
|
||||
|
||||
public void Clear(Color color) => GraphicsDevice.Clear(color);
|
||||
public void End() => SpriteBatch.End();
|
||||
public void Begin(SpriteSortMode sorting = SpriteSortMode.Deferred, BlendState blending = null, SamplerState sampling = null, DepthStencilState depthStencil = null,
|
||||
RasterizerState rasterizing = null, Effect effect = null, Matrix? transform = null)
|
||||
{
|
||||
SpriteBatch.Begin(sorting, blending, sampling, depthStencil, rasterizing, effect, transform);
|
||||
}
|
||||
public void Arc(Color color, Vector2 center, float radius, int sides, Rotation startingAngle, Rotation radians, float thickness = 1)
|
||||
{
|
||||
List<Vector2> arc = ShapeCache.GetArc(radius, sides, startingAngle.Radians, radians.Radians);
|
||||
Polygon(color, center, arc, thickness);
|
||||
}
|
||||
public void Circle(Color color, Vector2 position, double radius, int sides = 12, float thickness = 1)
|
||||
{
|
||||
List<Vector2> c = ShapeCache.GetCircle(radius, sides);
|
||||
Polygon(color, position, c, thickness);
|
||||
}
|
||||
public void Line(Color color, Vector2 point, float length, Rotation angle, float thickness = 1)
|
||||
{
|
||||
Vector2 origin = new Vector2(0f, 0.5f);
|
||||
Vector2 scale = new Vector2(length, thickness);
|
||||
SpriteBatch.Draw(pixel, point, null, color, angle.Radians, origin, scale, SpriteEffects.None, 0);
|
||||
}
|
||||
public void Line(Color color, Vector2 point1, Vector2 point2, float thickness = 1)
|
||||
{
|
||||
float distance = Vector2.Distance(point1, point2);
|
||||
float angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X);
|
||||
|
||||
float expanded = (float)Math.Floor(angle * Math.PI);
|
||||
float backDown = expanded / (float)Math.PI;
|
||||
|
||||
Line(color, point1, distance, Rotation.FromRad(angle), thickness);
|
||||
}
|
||||
public void OutlineRect(Color color, Vector2 position, Vector2 size, float thickness = 2.0f)
|
||||
{
|
||||
Line(color, position, position + new Vector2(0, size.Y), thickness);
|
||||
Line(color, position, position + new Vector2(size.X, 0), thickness);
|
||||
Line(color, position + new Vector2(size.X, 0), position + size, thickness);
|
||||
Line(color, position + new Vector2(0, size.Y), position + new Vector2(size.X, size.Y), thickness);
|
||||
}
|
||||
public void Polygon(Color color, Vector2 position, List<Vector2> points, float thickness = 1)
|
||||
{
|
||||
if (points.Count < 2)
|
||||
return;
|
||||
|
||||
for (int i = 1; i < points.Count; i++)
|
||||
Line(color, points[i - 1] + position, points[i] + position, thickness);
|
||||
}
|
||||
public void Polygon(Color color, List<Vector2> points, float thickness = 1)
|
||||
{
|
||||
if (points.Count < 2)
|
||||
return;
|
||||
|
||||
for (int i = 1; i < points.Count; i++)
|
||||
Line(color, points[i - 1], points[i], thickness);
|
||||
}
|
||||
public void Rect(Color color, Vector2 position, Vector2 size) => Rect(color, position, size, Rotation.Zero);
|
||||
public void Rect(Color color, Vector2 position, Vector2 size, Rotation rotation)
|
||||
{
|
||||
SpriteBatch.Draw(
|
||||
pixel,
|
||||
new Rectangle(position.ToPoint(), size.ToPoint()),
|
||||
null,
|
||||
color, rotation.Degrees, new Vector2(0, 0), SpriteEffects.None, 0
|
||||
);
|
||||
}
|
||||
public void Sprite(Texture2D texture, Vector2 position) => Sprite(texture, position, Color.White);
|
||||
public void Sprite(Texture2D texture, Vector2 position, Color color) => SpriteBatch.Draw(texture, position, color);
|
||||
public void Sprite(Texture2D texture, Vector2 position, Rectangle? quad, Color color) => SpriteBatch.Draw(texture, position, quad, color);
|
||||
public void Sprite(Texture2D texture, Vector2 position, Rectangle? quad, Color color, Rotation rotation, Vector2 origin, Vector2 scale, SpriteEffects efx, float layer) =>
|
||||
SpriteBatch.Draw(texture,position,quad,color,rotation.Radians, origin,scale,efx,layer);
|
||||
public void Sprite(Texture2D texture, Vector2 position, Rectangle? quad, Color color, Rotation rotation, Vector2 origin, float scale, SpriteEffects efx, float layer) =>
|
||||
SpriteBatch.Draw(texture, position, quad, color, rotation.Radians, origin, scale, efx, layer);
|
||||
public void Text(string text, Vector2 position) => Text(Fonts.Arial10, text, position);
|
||||
public void Text(string text, Vector2 position, Color color) => SpriteBatch.DrawString(Fonts.Arial10, text, position, color);
|
||||
public void Text(SpriteFont font, string text, Vector2 position) => Text(font, text, position, Color.White, TextXAlignment.Left, TextYAlignment.Top);
|
||||
public void Text(SpriteFont font, string text, Vector2 position, Color color, TextXAlignment textX = TextXAlignment.Left, TextYAlignment textY = TextYAlignment.Top)
|
||||
{
|
||||
float xoffset = 0;
|
||||
float yoffset = 0;
|
||||
|
||||
Vector2 bounds = font.MeasureString(text);
|
||||
|
||||
if (textX == TextXAlignment.Center)
|
||||
xoffset = bounds.X / 2;
|
||||
if (textX == TextXAlignment.Right)
|
||||
xoffset = bounds.X;
|
||||
|
||||
if (textY == TextYAlignment.Center)
|
||||
yoffset = bounds.Y / 2;
|
||||
if (textY == TextYAlignment.Bottom)
|
||||
yoffset = bounds.Y;
|
||||
|
||||
SpriteBatch.DrawString(font, text, position-new Vector2(xoffset, yoffset), color);
|
||||
}
|
||||
/*public void Line3D(Camera camera, Vector3 pointA, Vector3 pointB, Color color)
|
||||
/*var entityTexturesPath = Path.Combine("Assets", "Textures", "Entities");
|
||||
foreach (var tex in Directory.GetFiles(entityTexturesPath, "*.png", SearchOption.AllDirectories))
|
||||
{
|
||||
Line3D(camera, pointA, pointB, color, color);
|
||||
|
||||
GameConsole.Log($"QTexture {tex} => {tex.Replace(entityTexturesPath + @"\", "")} ");
|
||||
LoadingQueue.Enqueue(new TextureDef(
|
||||
tex.Replace(entityTexturesPath + @"\", ""),
|
||||
tex
|
||||
));
|
||||
TotalTextures++;
|
||||
}
|
||||
public void Line3D(Camera camera, Vector3 pointA, Vector3 pointB, Color colorA, Color colorB)
|
||||
{
|
||||
Line3D(camera, pointA, pointB, colorA, colorB);
|
||||
}
|
||||
public void Line3D(Camera camera, Vector3 pointA, Vector3 pointB, Color color)
|
||||
{
|
||||
Line3D(camera, pointA, pointB, color, color);
|
||||
}
|
||||
public void Line3D(Camera camera, Vector3 pointA, Vector3 pointB, Color colorA, Color colorB)
|
||||
{
|
||||
_effect3D.View = camera.View;
|
||||
_effect3D.Projection = camera.Projection;
|
||||
|
||||
_effect3D.CurrentTechnique.Passes[0].Apply();
|
||||
|
||||
var vertices = new[] { new VertexPositionColor(pointA, colorA), new VertexPositionColor(pointB, colorB)};
|
||||
GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices, 0, 1);
|
||||
foreach (var tex in Directory.GetFiles("Assets/Textures/Items/", "*.png"))
|
||||
{
|
||||
//Texture2D loaded = AssetLoader.LoadTexture(graphicsDevice, tex);
|
||||
LoadingQueue.Enqueue(new TextureDef(
|
||||
tex.Replace("Assets/Textures/Items/", ""),
|
||||
tex
|
||||
));
|
||||
TotalTextures++;
|
||||
}*/
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
SpriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
if (LoadFonts)
|
||||
Fonts.LoadAssets(ContentManager);
|
||||
|
||||
// create pixel
|
||||
pixel = new Texture2D(GraphicsDevice, 1, 1);
|
||||
pixel.SetData<Color>(new Color[]
|
||||
{
|
||||
Color.White
|
||||
});
|
||||
|
||||
FontsLoaded = true;
|
||||
}
|
||||
|
||||
public FontManager Fonts = new FontManager();
|
||||
|
||||
public Vector2 WindowSize { get; set; }
|
||||
public SpriteSortMode SpriteSortMode { get; set; }
|
||||
public BlendState BlendState { get; set; }
|
||||
public SamplerState SamplerState { get; set; }
|
||||
public DepthStencilState DepthStencilState { get; set; }
|
||||
public RasterizerState RasterizerState { get; set; }
|
||||
public Effect Shader { get; set; }
|
||||
public Matrix Matrix { get; set; }
|
||||
|
||||
public ContentManager ContentManager { get; set; }
|
||||
public SpriteBatch SpriteBatch { get; set; }
|
||||
public GraphicsDevice GraphicsDevice { get; set; }
|
||||
public GraphicsDeviceManager GraphicsDeviceManager { get; set; }
|
||||
|
||||
public bool ContentLoaded { get; private set; }
|
||||
|
||||
public float GraphicsTimer { get; set; }
|
||||
|
||||
public float LoadingDelay { get; set; }
|
||||
|
||||
public GraphicsEngine()
|
||||
{
|
||||
Instance = this;
|
||||
LoadingDelay = 0.03f;
|
||||
FontsLoaded = false;
|
||||
LoadFonts = true;
|
||||
}
|
||||
|
||||
|
||||
public void Update(GameTime gt)
|
||||
{
|
||||
|
||||
// move asset loading to it's own class?
|
||||
if (LoadingQueue.Count > 0)
|
||||
LoadNextAsset(GraphicsDevice);
|
||||
|
||||
if (LoadingQueue.Count == 0)
|
||||
ContentLoaded = true;
|
||||
|
||||
|
||||
// increase global anim time.
|
||||
// used by items, entities, and tiles when an internal state is otherwise not ideal.
|
||||
GlobalAnimationTimer += gt.GetDelta();
|
||||
|
||||
}
|
||||
|
||||
public void Clear(Color color) => GraphicsDevice.Clear(color);
|
||||
public void End() => SpriteBatch.End();
|
||||
public void Begin(SpriteSortMode sorting = SpriteSortMode.Deferred, BlendState blending = null, SamplerState sampling = null, DepthStencilState depthStencil = null,
|
||||
RasterizerState rasterizing = null, Effect effect = null, Matrix? transform = null)
|
||||
{
|
||||
SpriteBatch.Begin(sorting, blending, sampling, depthStencil, rasterizing, effect, transform);
|
||||
}
|
||||
public void Arc(Color color, Vector2 center, float radius, int sides, Rotation startingAngle, Rotation radians, float thickness = 1)
|
||||
{
|
||||
List<Vector2> arc = ShapeCache.GetArc(radius, sides, startingAngle.Radians, radians.Radians);
|
||||
Polygon(color, center, arc, thickness);
|
||||
}
|
||||
public void Circle(Color color, Vector2 position, double radius, int sides = 12, float thickness = 1)
|
||||
{
|
||||
List<Vector2> c = ShapeCache.GetCircle(radius, sides);
|
||||
Polygon(color, position, c, thickness);
|
||||
}
|
||||
public void Line(Color color, Vector2 point, float length, Rotation angle, float thickness = 1)
|
||||
{
|
||||
Vector2 origin = new Vector2(0f, 0.5f);
|
||||
Vector2 scale = new Vector2(length, thickness);
|
||||
SpriteBatch.Draw(pixel, point, null, color, angle.Radians, origin, scale, SpriteEffects.None, 0);
|
||||
}
|
||||
public void Line(Color color, Vector2 point1, Vector2 point2, float thickness = 1)
|
||||
{
|
||||
float distance = Vector2.Distance(point1, point2);
|
||||
float angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X);
|
||||
|
||||
float expanded = (float)Math.Floor(angle * Math.PI);
|
||||
float backDown = expanded / (float)Math.PI;
|
||||
|
||||
Line(color, point1, distance, Rotation.FromRad(angle), thickness);
|
||||
}
|
||||
public void OutlineRect(Color color, Vector2 position, Vector2 size, float thickness = 2.0f)
|
||||
{
|
||||
Line(color, position, position + new Vector2(0, size.Y), thickness);
|
||||
Line(color, position, position + new Vector2(size.X, 0), thickness);
|
||||
Line(color, position + new Vector2(size.X, 0), position + size, thickness);
|
||||
Line(color, position + new Vector2(0, size.Y), position + new Vector2(size.X, size.Y), thickness);
|
||||
}
|
||||
public void Polygon(Color color, Vector2 position, List<Vector2> points, float thickness = 1)
|
||||
{
|
||||
if (points.Count < 2)
|
||||
return;
|
||||
|
||||
for (int i = 1; i < points.Count; i++)
|
||||
Line(color, points[i - 1] + position, points[i] + position, thickness);
|
||||
}
|
||||
public void Polygon(Color color, List<Vector2> points, float thickness = 1)
|
||||
{
|
||||
if (points.Count < 2)
|
||||
return;
|
||||
|
||||
for (int i = 1; i < points.Count; i++)
|
||||
Line(color, points[i - 1], points[i], thickness);
|
||||
}
|
||||
public void Rect(Color color, Vector2 position, Vector2 size) => Rect(color, position, size, Rotation.Zero);
|
||||
public void Rect(Color color, Vector2 position, Vector2 size, Rotation rotation)
|
||||
{
|
||||
SpriteBatch.Draw(
|
||||
pixel,
|
||||
new Rectangle(position.ToPoint(), size.ToPoint()),
|
||||
null,
|
||||
color, rotation.Degrees, new Vector2(0, 0), SpriteEffects.None, 0
|
||||
);
|
||||
}
|
||||
public void Sprite(Texture2D texture, Vector2 position) => Sprite(texture, position, Color.White);
|
||||
public void Sprite(Texture2D texture, Vector2 position, Color color) => SpriteBatch.Draw(texture, position, color);
|
||||
public void Sprite(Texture2D texture, Vector2 position, Rectangle? quad, Color color) => SpriteBatch.Draw(texture, position, quad, color);
|
||||
public void Sprite(Texture2D texture, Vector2 position, Rectangle? quad, Color color, Rotation rotation, Vector2 origin, Vector2 scale, SpriteEffects efx, float layer) =>
|
||||
SpriteBatch.Draw(texture, position, quad, color, rotation.Radians, origin, scale, efx, layer);
|
||||
public void Sprite(Texture2D texture, Vector2 position, Rectangle? quad, Color color, Rotation rotation, Vector2 origin, float scale, SpriteEffects efx, float layer) =>
|
||||
SpriteBatch.Draw(texture, position, quad, color, rotation.Radians, origin, scale, efx, layer);
|
||||
public void Text(string text, Vector2 position) => Text(Fonts.Arial10, text, position);
|
||||
public void Text(string text, Vector2 position, Color color) => SpriteBatch.DrawString(Fonts.Arial10, text, position, color);
|
||||
public void Text(SpriteFont font, string text, Vector2 position) => Text(font, text, position, Color.White, TextXAlignment.Left, TextYAlignment.Top);
|
||||
public void Text(SpriteFont font, string text, Vector2 position, Color color, TextXAlignment textX = TextXAlignment.Left, TextYAlignment textY = TextYAlignment.Top)
|
||||
{
|
||||
float xoffset = 0;
|
||||
float yoffset = 0;
|
||||
|
||||
Vector2 bounds = font.MeasureString(text);
|
||||
|
||||
if (textX == TextXAlignment.Center)
|
||||
xoffset = bounds.X / 2;
|
||||
if (textX == TextXAlignment.Right)
|
||||
xoffset = bounds.X;
|
||||
|
||||
if (textY == TextYAlignment.Center)
|
||||
yoffset = bounds.Y / 2;
|
||||
if (textY == TextYAlignment.Bottom)
|
||||
yoffset = bounds.Y;
|
||||
|
||||
SpriteBatch.DrawString(font, text, position - new Vector2(xoffset, yoffset), color);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -87,6 +87,11 @@ namespace CaveGame.Common
|
||||
return (other.X == X && other.Y == Y);
|
||||
}
|
||||
|
||||
public string ToString()
|
||||
{
|
||||
return $"{X}, {Y}";
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
var hash = 42069;
|
||||
|
@@ -18,6 +18,8 @@ namespace CaveGame.Common
|
||||
public float BlastPressure { get; set; }
|
||||
public bool Thermal { get; set; }
|
||||
|
||||
public IEntity Source { get; set; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -338,16 +340,19 @@ namespace CaveGame.Common
|
||||
|
||||
protected virtual void InflictExplosionDamageOnEntity(Explosion Blast, IEntity Entity, int Damage, Vector2 Direction, float KickBack)
|
||||
{
|
||||
if (Entity is IExplosionDamagable explosionDamagableEntity)
|
||||
explosionDamagableEntity.Damage(
|
||||
type: DamageType.Explosion,
|
||||
source: Blast,
|
||||
amount: Damage,
|
||||
direction: Direction
|
||||
);
|
||||
|
||||
if (Entity is IPhysicsEntity MovingEntity)
|
||||
{
|
||||
Entity.Damage(
|
||||
type: DamageType.Explosion,
|
||||
source: Blast,
|
||||
amount: Damage,
|
||||
direction: Direction
|
||||
);
|
||||
|
||||
MovingEntity.Velocity += Direction * KickBack;
|
||||
|
||||
Logger.LogCurrentContext($"{Direction*KickBack*10000}");
|
||||
MovingEntity.Velocity += Direction * KickBack*10000;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -356,17 +361,24 @@ namespace CaveGame.Common
|
||||
{
|
||||
foreach (var ent in Entities)
|
||||
{
|
||||
if (ent == Blast.Source)
|
||||
continue; // Skip ourselves
|
||||
|
||||
|
||||
if (ent is IPhysicsEntity physicsEntity)
|
||||
{
|
||||
var dist = physicsEntity.Position.Distance(Blast.Position);
|
||||
if (dist < MAX_BLAST_DISTANCE)
|
||||
{
|
||||
var power = Math.Min((1 / dist) * Blast.BlastPressure * 7f, 350);
|
||||
var power = Math.Min((1 / dist) * Blast.BlastPressure * 7f, 3550);
|
||||
var unitVec = (physicsEntity.Position - Blast.Position);
|
||||
unitVec.Normalize();
|
||||
int damage = (int)Math.Max(MAX_DAMAGE - dist, 1);
|
||||
|
||||
InflictExplosionDamageOnEntity(Blast, ent, damage, unitVec, power);
|
||||
|
||||
// TODO: Implement Explosion Force impact on entity velocity
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ namespace CaveGame.Common
|
||||
public static Light3 Moonlight = new Light3(128, 128, 128);
|
||||
public static Light3 Dawn = new Light3(96, 96, 40);
|
||||
public static Light3 Ambience = new Light3(128, 128, 128);
|
||||
public static Light3 Daylight = new Light3(128, 128, 128);
|
||||
public static Light3 Daylight = new Light3(192, 192, 192);
|
||||
public static Light3 Dusk = new Light3(96, 60, 40);
|
||||
|
||||
[FieldOffset(0)] public byte Red;
|
||||
|
@@ -6,6 +6,7 @@ using System.Xml;
|
||||
|
||||
namespace CaveGame.Common.World
|
||||
{
|
||||
// TODO: Candidate for refactor
|
||||
public class WorldMetadata
|
||||
{
|
||||
public int Seed { get; set; }
|
||||
|
@@ -7,18 +7,18 @@ using CaveGame.Common.LuaInterop;
|
||||
using CaveGame.Common.Network;
|
||||
using CaveGame.Common.Game.Tiles;
|
||||
using CaveGame.Common.Extensions;
|
||||
using KeraLua;
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using NLua;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlTypes;
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
@@ -182,7 +182,7 @@ namespace CaveGame.Server
|
||||
}
|
||||
private void HandshakeResponse(NetworkMessage msg)
|
||||
{
|
||||
GameConsole.Log("Handshake response!");
|
||||
Logger.LogServer("Handshake response!");
|
||||
string[] playerslist = ConnectedUsers.Select(z => z.Username).ToArray();
|
||||
NetworkServer.SendPacket(
|
||||
new HandshakeResponsePacket(
|
||||
@@ -574,7 +574,7 @@ namespace CaveGame.Server
|
||||
}
|
||||
public virtual void Shutdown()
|
||||
{
|
||||
GameConsole.Log("Shutting Down. Not Saving while testing worldgen");
|
||||
Logger.LogServer("Shutting Down. Not Saving while testing worldgen");
|
||||
World.SaveData();
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
Reference in New Issue
Block a user