Skip to content

Commit

Permalink
Merge pull request #8 from SneakyTactician/TileBasedDev
Browse files Browse the repository at this point in the history
Tile based dev
  • Loading branch information
TBye101 committed Jan 15, 2018
2 parents 166f507 + acdbeb6 commit dfdaedd
Show file tree
Hide file tree
Showing 26 changed files with 275 additions and 49 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
SneakyTactician <SneakyTactician@outlook.com>

[Version 0.0.0.2]
### Features
*Living creatures are now rendered

#### API
*Living creatures are now supported

### Tweaks
*

### Bugs
*

[Version 0.0.0.1]

### Features
Expand Down
43 changes: 43 additions & 0 deletions MagicalLifeAPI/Entities/Entity Factory/HumanFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using MagicalLifeAPI.Entities.Humanoid;
using MagicalLifeAPI.Util;

namespace MagicalLifeAPI.Entities.Entity_Factory
{
/// <summary>
/// Used to initialize a new human properly.
/// </summary>
public class HumanFactory
{
/// <summary>
/// The maximum number of hitpoints that a human could get per level.
/// </summary>
private readonly int MaxHumanHealthPerLevel = 10;

/// <summary>
/// The minimum number of hitpoints that a human could get per level.
/// </summary>
private readonly int MinHumanHealthPerLevel = 2;

/// <summary>
/// The fastest a human could possibly be without starting down a class path.
/// </summary>
private readonly int MaxHumanMovement = 50;

/// <summary>
/// The slowest a human could possibly be without some significant injuries.
/// </summary>
private readonly int MinHumanMovement = 25;

/// <summary>
/// Returns a fully generated human character.
/// </summary>
/// <returns></returns>
public Human GenerateHuman()
{
int health = StaticRandom.Rand(this.MinHumanHealthPerLevel, this.MaxHumanHealthPerLevel + 1);
int movement = StaticRandom.Rand(this.MinHumanMovement, this.MaxHumanMovement + 1);

return new Human(health, movement);
}
}
}
17 changes: 17 additions & 0 deletions MagicalLifeAPI/Entities/Humanoid/Human.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace MagicalLifeAPI.Entities.Humanoid
{
/// <summary>
/// A class that holds logic for control of regular humans.
/// </summary>
public class Human : Living
{
public Human(int health, int movementSpeed) : base(health, movementSpeed)
{
}

public override string GetTextureName()
{
return "Basic Human.png";
}
}
}
38 changes: 38 additions & 0 deletions MagicalLifeAPI/Entities/Living.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using MagicalLifeAPI.Entities.Util;
using MagicalLifeAPI.Universal;

namespace MagicalLifeAPI.Entities
{
/// <summary>
/// All living things inherit from this, and utilize it.
/// </summary>
public abstract class Living : Unique
{
/// <summary>
/// How many hit points this creature has.
/// </summary>
public Attribute Health { get; set; }

/// <summary>
/// How fast this creature can move.
/// </summary>
public Attribute MovementSpeed { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="Living"/> base class.
/// </summary>
/// <param name="health"></param>
/// <param name="movementSpeed"></param>
public Living(int health, int movementSpeed)
{
this.Health = new Attribute(health);
this.MovementSpeed = new Attribute(movementSpeed);
}

/// <summary>
/// Returns the name of the texture.
/// </summary>
/// <returns></returns>
public abstract string GetTextureName();
}
}
62 changes: 62 additions & 0 deletions MagicalLifeAPI/Entities/Util/Attribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using MagicalLifeAPI.Entities.Util.IModifierRemoveConditions;
using MagicalLifeAPI.Universal;
using System;
using System.Collections.Generic;

namespace MagicalLifeAPI.Entities.Util
{
public class Attribute
{
public Attribute()
{
MajorEvents.TurnEnd += this.MajorEvents_TurnEnd;
}

public Attribute(int value) : this()
{
this.AddModifier(new Tuple<long, IModifierRemoveCondition, string>(value, new NeverRemoveCondition(), "Base value"));
}

private void MajorEvents_TurnEnd(object sender, EventArgs e)
{
List<Tuple<Int64, IModifierRemoveCondition, string>> remove = new List<Tuple<Int64, IModifierRemoveCondition, string>>();
foreach (Tuple<Int64, IModifierRemoveCondition, string> item in this.Modifiers)
{
if (item.Item2.WearOff())
{
remove.Add(item);
}
}

foreach (Tuple<Int64, IModifierRemoveCondition, string> item in remove)
{
this.Modifiers.Remove(item);
}
}

public Int64 GetValue()
{
Int64 ret = 0;
foreach (Tuple<Int64, IModifierRemoveCondition, string> item in this.Modifiers)
{
ret += item.Item1;
}
return ret;
}

/// <summary>
/// The int value is applied to the value of this attribute, while the <see cref="IModifierRemoveCondition"/> is used to determine if the modifier will wear off.
/// The string value is a display message/reason as to why the modifier was applied.
/// </summary>
public List<Tuple<Int64, IModifierRemoveCondition, string>> Modifiers { get; private set; } = new List<Tuple<Int64, IModifierRemoveCondition, string>>();

/// <summary>
/// Adds a modifier to the modifiers list.
/// </summary>
/// <param name="modifier"></param>
public void AddModifier(Tuple<Int64, IModifierRemoveCondition, string> modifier)
{
this.Modifiers.Add(modifier);
}
}
}
14 changes: 14 additions & 0 deletions MagicalLifeAPI/Entities/Util/IModifierRemoveCondition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace MagicalLifeAPI.Entities.Util
{
/// <summary>
/// Utilized to allow for custom events/circumstances to be used to determine when a modifier wears off.
/// </summary>
public interface IModifierRemoveCondition
{
/// <summary>
/// Returns true if this modifier should be removed from the attribute it is effecting.
/// </summary>
/// <returns></returns>
bool WearOff();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace MagicalLifeAPI.Entities.Util.IModifierRemoveConditions
{
/// <summary>
/// We shall never remove this modifier.
/// </summary>
public class NeverRemoveCondition : IModifierRemoveCondition
{
public bool WearOff()
{
return false;
}
}
}
7 changes: 7 additions & 0 deletions MagicalLifeAPI/MagicalLifeAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Entities\Entity Factory\HumanFactory.cs" />
<Compile Include="Entities\Humanoid\Human.cs" />
<Compile Include="Entities\Living.cs" />
<Compile Include="Entities\Util\Attribute.cs" />
<Compile Include="Entities\Util\IModifierRemoveCondition.cs" />
<Compile Include="Entities\Util\IModifierRemoveConditions\NeverRemoveCondition.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Universal\Unique.cs" />
<Compile Include="Universal\MajorEvents.cs" />
Expand All @@ -59,6 +65,7 @@
<Compile Include="World\World.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Entities\Animal\" />
<Folder Include="World\Items\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
6 changes: 6 additions & 0 deletions MagicalLifeAPI/Util/StaticRandom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ public static class StaticRandom
private static readonly ThreadLocal<Random> random =
new ThreadLocal<Random>(() => new Random(Interlocked.Increment(ref seed)));

/// <summary>
/// Returns a random number.
/// </summary>
/// <param name="min">Inclusive minimum.</param>
/// <param name="max">Exclusive maximum.</param>
/// <returns></returns>
public static int Rand(int min, int max)
{
return random.Value.Next(min, max);
Expand Down
9 changes: 7 additions & 2 deletions MagicalLifeAPI/World/Base/Tile.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Drawing;
using MagicalLifeAPI.Entities;
using MagicalLifeAPI.Universal;
using MagicalLifeAPI.World.Base;
using System.Collections.Generic;
using System.Drawing;
using System.Web.UI.DataVisualization.Charting;

namespace MagicalLifeAPI.World
{
public abstract class Tile : Unique
{

/// <summary>
/// Initializes a new tile object.
/// </summary>
Expand Down Expand Up @@ -55,5 +55,10 @@ public static Size GetTileSize()
/// The location of this tile in the tilemap.
/// </summary>
public Point3D Location { get; protected set; }

/// <summary>
/// A list containing all living entities on this tile.
/// </summary>
public Queue<Living> Living { get; set; } = new Queue<Entities.Living>();
}
}
3 changes: 1 addition & 2 deletions MagicalLifeAPI/World/Tiles/Dirt.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Drawing;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.DataVisualization.Charting;

namespace MagicalLifeAPI.World.Tiles
{
Expand Down
16 changes: 14 additions & 2 deletions MagicalLifeAPI/World/World Generation/Generators/Dirtland.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Web.UI.DataVisualization.Charting;
using MagicalLifeAPI.Entities.Entity_Factory;
using MagicalLifeAPI.Util;
using MagicalLifeAPI.World.Tiles;
using System.Web.UI.DataVisualization.Charting;

namespace MagicalLifeAPI.World.World_Generation.Generators
{
Expand Down Expand Up @@ -43,7 +45,17 @@ public class Dirtland : WorldGenerator

public override Tile[,,] GenerateDetails(Tile[,,] map)
{
//We don't generate details in the dirtland.
int xSize = map.GetLength(0);
int ySize = map.GetLength(1);
int zSize = map.GetLength(2);

int x = StaticRandom.Rand(0, xSize);
int y = StaticRandom.Rand(0, ySize);
int z = zSize - 1;

HumanFactory hFactory = new HumanFactory();
map[x, y, z].Living.Enqueue(hFactory.GenerateHuman());

return map;
}

Expand Down
6 changes: 3 additions & 3 deletions MagicalLifeGUI/App.config
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="MagicalLifeGUI.Storage.KeyBindings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="MagicalLifeGUI.Storage.Universal" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="MagicalLifeGUI.Storage.MainWindow" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>
<userSettings>
<MagicalLifeGUI.Storage.KeyBindings>
Expand Down Expand Up @@ -36,4 +36,4 @@
</setting>
</MagicalLifeGUI.Storage.MainWindow>
</userSettings>
</configuration>
</configuration>
9 changes: 4 additions & 5 deletions MagicalLifeGUI/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using MagicalLifeRenderEngine.Main;
using MagicalLifeAPI.World;
using MagicalLifeAPI.World.World_Generation.Generators;
using MagicalLifeGUI.Storage;
using MagicalLifeAPI.World;
using MagicalLifeRenderEngine.Main;
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Windows.Forms;

namespace MagicalLifeGUI
{
Expand All @@ -23,7 +23,6 @@ public Form1()

private void Form1_Load(object sender, System.EventArgs e)
{

}

private void QuitButton_Click(object sender, System.EventArgs e)
Expand All @@ -36,7 +35,7 @@ private void NewGameButton_Click(object sender, EventArgs e)
this.ToggleMainMenu();
this.world = new World(MainWindow.Default.ScreenSize.Height / Tile.GetTileSize().Height,
MainWindow.Default.ScreenSize.Width / Tile.GetTileSize().Width, 2, new Dirtland());
screen = pipe.GetTiles(0, this.world);
screen = pipe.GetTiles(1, this.world);
}

/// <summary>
Expand Down
8 changes: 1 addition & 7 deletions MagicalLifeGUI/StartupForm.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
using MagicalLifeGUI.Storage;
using System.Windows.Forms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace MagicalLifeGUI
{
Expand Down Expand Up @@ -34,4 +28,4 @@ private void InitializeForm(Form form)
form.FormBorderStyle = MainWindow.Default.Boarder;
}
}
}
}
3 changes: 3 additions & 0 deletions MagicalLifeRenderEngine/MagicalLifeRenderEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,8 @@
<ItemGroup>
<EmbeddedResource Include="Resource\Texture\GrassTile.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resource\Texture\Basic Human.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading

0 comments on commit dfdaedd

Please sign in to comment.