From 76c15e72ca30d0ef68b5900f3a4a1a328766c939 Mon Sep 17 00:00:00 2001 From: Jonathan Riedel Date: Sun, 7 May 2023 20:10:27 +0200 Subject: [PATCH] Switch to MonoGame using WPFGame --- CityGame.sln | 8 +- CityGame/App.xaml.cs | 18 +- CityGame/AssemblyInfo.cs | 10 - CityGame/Car.cs | 9 +- CityGame/CityGame.csproj | 78 ++++--- CityGame/CustomShader.cs | 7 +- CityGame/Entity.cs | 29 ++- CityGame/Extensions.cs | 3 +- CityGame/Helicopter.cs | 69 ++++++ CityGame/ISelectable.cs | 10 + CityGame/MainWindow.xaml.cs | 269 +++++++++++------------ CityGame/OCanvas.cs | 4 +- CityGame/Renderer.cs | 7 +- CityGame/Resources/BlueTint.hlsl | 9 - CityGame/Resources/Garage.png | Bin 0 -> 298 bytes CityGame/Resources/Helicopter.png | Bin 0 -> 502 bytes CityGame/Resources/HelicopterBlades.png | Bin 0 -> 423 bytes CityGame/Resources/HelicopterBlades2.png | Bin 0 -> 298 bytes CityGame/Resources/HelicopterFlight.png | Bin 0 -> 630 bytes CityGame/Resources/Helipad.png | Bin 0 -> 650 bytes CityGame/SourcedImage.cs | 26 ++- CityGame/Tile.cs | 22 +- 22 files changed, 351 insertions(+), 227 deletions(-) create mode 100644 CityGame/Helicopter.cs create mode 100644 CityGame/ISelectable.cs delete mode 100644 CityGame/Resources/BlueTint.hlsl create mode 100644 CityGame/Resources/Garage.png create mode 100644 CityGame/Resources/Helicopter.png create mode 100644 CityGame/Resources/HelicopterBlades.png create mode 100644 CityGame/Resources/HelicopterBlades2.png create mode 100644 CityGame/Resources/HelicopterFlight.png create mode 100644 CityGame/Resources/Helipad.png diff --git a/CityGame.sln b/CityGame.sln index 5109268..5f86bc4 100644 --- a/CityGame.sln +++ b/CityGame.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32929.385 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CityGame", "CityGame\CityGame.csproj", "{5D76B596-FC17-4F47-B5C6-D811DE04F806}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CityGame", "CityGame\CityGame.csproj", "{5D76B596-FC17-4F47-B5C6-D811DE04F806}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WPFGame", "..\WPFGame\WPFGame\WPFGame.csproj", "{4F2DC7EE-24BA-4383-9AB6-EBA46EB191DF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {5D76B596-FC17-4F47-B5C6-D811DE04F806}.Debug|Any CPU.Build.0 = Debug|Any CPU {5D76B596-FC17-4F47-B5C6-D811DE04F806}.Release|Any CPU.ActiveCfg = Release|Any CPU {5D76B596-FC17-4F47-B5C6-D811DE04F806}.Release|Any CPU.Build.0 = Release|Any CPU + {4F2DC7EE-24BA-4383-9AB6-EBA46EB191DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F2DC7EE-24BA-4383-9AB6-EBA46EB191DF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F2DC7EE-24BA-4383-9AB6-EBA46EB191DF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F2DC7EE-24BA-4383-9AB6-EBA46EB191DF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CityGame/App.xaml.cs b/CityGame/App.xaml.cs index f5fe8e0..5f28270 100644 --- a/CityGame/App.xaml.cs +++ b/CityGame/App.xaml.cs @@ -1,17 +1 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; - -namespace CityGame -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } -} + \ No newline at end of file diff --git a/CityGame/AssemblyInfo.cs b/CityGame/AssemblyInfo.cs index 8b5504e..e69de29 100644 --- a/CityGame/AssemblyInfo.cs +++ b/CityGame/AssemblyInfo.cs @@ -1,10 +0,0 @@ -using System.Windows; - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] diff --git a/CityGame/Car.cs b/CityGame/Car.cs index 4a13f93..5fd9838 100644 --- a/CityGame/Car.cs +++ b/CityGame/Car.cs @@ -1,7 +1,8 @@ -using System; +using Microsoft.Xna.Framework; +using System; using System.Linq; -using System.Numerics; using System.Windows; +using WPFGame; namespace CityGame { @@ -25,7 +26,7 @@ namespace CityGame Y = (float)value.Y * MainWindow.TileSize; } } - public float Speed { get; set; } = 256; + public float Speed { get; set; } = 128; public override OCanvas Render() { return new SourcedImage("Car.png"); @@ -40,7 +41,7 @@ namespace CityGame { if (Target is not null) { - if(Object is not null) Object.ToolTip = Target.ToString(); + //if(Object is not null) Object.ToolTip = Target.ToString(); if (Path is null) { Path = MainWindow.pathfinder.FindPath(Point.Convert(), ((Point)Target).Convert()).Select(x => x.Convert()).ToArray(); diff --git a/CityGame/CityGame.csproj b/CityGame/CityGame.csproj index d48a3b7..dd3bdf2 100644 --- a/CityGame/CityGame.csproj +++ b/CityGame/CityGame.csproj @@ -4,13 +4,9 @@ WinExe net6.0-windows enable - true + False - - - - @@ -19,7 +15,7 @@ - + @@ -39,82 +35,100 @@ - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest - Always + PreserveNewest diff --git a/CityGame/CustomShader.cs b/CityGame/CustomShader.cs index 451c60b..dc7ac84 100644 --- a/CityGame/CustomShader.cs +++ b/CityGame/CustomShader.cs @@ -1,9 +1,6 @@ using System; using System.IO; -using System.Windows; -using System.Windows.Media; -using System.Windows.Media.Effects; - +/* namespace CityGame { public class CustomShader : ShaderEffect @@ -32,4 +29,4 @@ namespace CityGame ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(CustomShader), 0); } -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/CityGame/Entity.cs b/CityGame/Entity.cs index cb9f616..1631935 100644 --- a/CityGame/Entity.cs +++ b/CityGame/Entity.cs @@ -1,13 +1,40 @@ namespace CityGame { - public abstract class Entity + public abstract class Entity : ISelectable { public float X { get; set; } public float Y { get; set; } public float Rotation { get; set; } public long Time { get; set; } public OCanvas Object { get; set; } + + public OCanvas GetImage() + { + return Object; + } + public abstract OCanvas Render(); + + public bool RunAction(ISelectable target) + { + if(this is Helicopter heli) + { + heli.Target = target; + return true; + } + return false; + } + public abstract void Tick(long deltaTime); + + int ISelectable.X() + { + return (int)X; + } + + int ISelectable.Y() + { + return (int)Y; + } } } \ No newline at end of file diff --git a/CityGame/Extensions.cs b/CityGame/Extensions.cs index abb201b..0bcf6a5 100644 --- a/CityGame/Extensions.cs +++ b/CityGame/Extensions.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Xna.Framework; +using System; using System.Windows; namespace CityGame diff --git a/CityGame/Helicopter.cs b/CityGame/Helicopter.cs new file mode 100644 index 0000000..7d1da92 --- /dev/null +++ b/CityGame/Helicopter.cs @@ -0,0 +1,69 @@ +using System; +using System.Numerics; +using WPFGame; + +namespace CityGame +{ + public class Helicopter : Entity + { + public float Speed { get; set; } = 256; + public bool Landed = false; + Image Heli1; + Image Heli2; + Image Blades1; + Image Blades2; + int RotorState = 0; + public ISelectable Target; + bool Move; + public override OCanvas Render() + { + OCanvas canvas = new OCanvas(); + Heli1 = new SourcedImage("Helicopter.png"); + Heli2 = new SourcedImage("HelicopterFlight.png"); + Blades1 = new SourcedImage("HelicopterBlades.png"); + Blades2 = new SourcedImage("HelicopterBlades2.png"); + + Heli1.Visible = false; + Blades2.Visible = false; + + canvas.Children.Add(Heli1); + canvas.Children.Add(Heli2); + canvas.Children.Add(Blades1); + canvas.Children.Add(Blades2); + + return canvas; + } + + public override void Tick(long deltaTime) + { + if (Heli1 is null) return; + long ms = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; + if (ms / 250 % 2 == 0) + { + Blades1.Visible = false; + Blades2.Visible = true; + } else + { + Blades1.Visible = true; + Blades2.Visible = false; + } + if (Target is not null) + { + IntPoint nextTarget = new IntPoint(Target.X(), Target.Y()); + Vector2 travel = new Vector2((float)nextTarget.X - X, (float)nextTarget.Y - Y); + if (travel.Length() < MainWindow.TileSize * 1) Move = false; + if (travel.Length() > MainWindow.TileSize * 3) Move = true; + Vector2 direction = Vector2.Normalize(travel); + float degrees = (float)(Math.Atan2(direction.Y, direction.X) * (180 / Math.PI)) + 90; + Rotation = degrees; + float Speedmulti = 1; + if (travel.Length() < MainWindow.TileSize * 3) Speedmulti = (travel.Length() - MainWindow.TileSize) / (MainWindow.TileSize * 2); + var possibleDistance = Speed * Speedmulti * deltaTime / 1000; + var finalDistance = Math.Min(possibleDistance, travel.Length()); + Vector2 travelFinal = direction * finalDistance; + X += travelFinal.X; + Y += travelFinal.Y; + } + } + } +} \ No newline at end of file diff --git a/CityGame/ISelectable.cs b/CityGame/ISelectable.cs new file mode 100644 index 0000000..36299f3 --- /dev/null +++ b/CityGame/ISelectable.cs @@ -0,0 +1,10 @@ +namespace CityGame +{ + public interface ISelectable + { + public OCanvas GetImage(); + public bool RunAction(ISelectable target); + public int X(); + public int Y(); + } +} \ No newline at end of file diff --git a/CityGame/MainWindow.xaml.cs b/CityGame/MainWindow.xaml.cs index 0f9eb49..bf913aa 100644 --- a/CityGame/MainWindow.xaml.cs +++ b/CityGame/MainWindow.xaml.cs @@ -1,32 +1,58 @@ using AStar; using AStar.Options; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; using SimplexNoise; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Net.WebSockets; -using System.Reflection.Metadata; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Navigation; -using System.Windows.Shapes; -using System.Windows.Threading; +using WPFGame; namespace CityGame { + + public class Program { public static void Main() { new MainWindow(); } } /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { + public ISelectable GetSelectableFromClick(MouseState click) + { + Point point = new Point(click.X, click.Y); + point.X -= (int)Canvas.GetLeft(CameraCanvas); + point.Y -= (int)Canvas.GetTop(CameraCanvas); + point.X = (int)(point.X / CameraCanvas.ScaleX); + point.Y = (int)(point.Y / CameraCanvas.ScaleY); + + foreach (Entity entity in Entities) + { + double diff = new Vector2((int)entity.X + TileSize / 2 - point.X, (int)entity.Y + TileSize / 2 - point.Y).Length(); + if (diff < TileSize / 2) return entity; + } + int x = point.X / TileSize; + int y = point.Y / TileSize; + if (x < 0 || y < 0) return null; + if (x > Grid.GetLength(0) - 1 || y > Grid.GetLength(1) - 1) return null; + + return Grid[x, y]; + } + public static Entity GetEntityFromImage(Image image) + { + foreach (Entity entity in Entities) + { + if (entity.Object == image.Parent) return entity; + } + return null; + } + public static Tile? GetTileFromImage(Image image) + { + double x = Canvas.GetLeft(image.Parent) / TileSize; + double y = Canvas.GetTop(image.Parent) / TileSize; + if (x % 1 != 0 || y % 1 != 0) return null; + return Grid[(int)x, (int)y]; + } public static Random random; public static bool MouseIsDown = false; public static Point MousePos = new Point(0, 0); @@ -36,6 +62,15 @@ namespace CityGame public static List npcWalkable = new List(); public static List Entities { get; set; } = new List(); public const int TileSize = 64; + public static Tile[,] Grid; + public static ISelectable Selected; + public static OCanvas[,] ImageGrid; + + Canvas MainCanvas = new OCanvas(); + Canvas BGCanvas = new OCanvas(); + Canvas GameCanvas = new OCanvas(); + Canvas CameraCanvas = new OCanvas(); + Canvas UICanvas = new OCanvas(); public MainWindow() { #region | Texture Conversions | @@ -63,11 +98,7 @@ namespace CityGame ImageConverter.ChangeColor("Error", "ErrorRed", new Dictionary { { "#000000", "#ff0000" } }); #endregion - InitializeComponent(); - - #region | Map Generation | - #region | Map Generation Constants | - int seed = 3; + int seed = 8; Noise.Seed = seed; @@ -93,12 +124,10 @@ namespace CityGame int minBlockHeight = 3; int minBlockWidth = 3; - int NPCCount = 1; + int NPCCount = (int)Math.Ceiling(mapHeight * mapWidth / 100f); random = new Random(seed); - #endregion - #region | Map Initialization | Tile[,] InitialGrid = new Tile[mapWidth, mapHeight]; @@ -179,9 +208,6 @@ namespace CityGame IntermediateGrid[x * 2 + 1, y * 2].Y = y * 2; } } - #endregion - - #region | Roads and Bridges | Dictionary decidedBridges = new Dictionary(); pathfindingGrid = new short[doubleWidth, doubleHeight]; pathfindingGridDesperate = new short[doubleWidth, doubleHeight]; @@ -214,10 +240,6 @@ namespace CityGame } } - #endregion - - #region | Pathfinding | - int mainRoadCount = random.Next(1, 5); for (int m = 0; m < mainRoadCount; m++) { @@ -228,20 +250,20 @@ namespace CityGame if (variant == 0) { int x = 0; - int y = random.Next(0, doubleHeight); + int y = random.Next(0 + 2, doubleHeight - 2); startPoint = new IntPoint(x, y); endPoint = new IntPoint(doubleWidth, y); step = new IntPoint(1, 0); } else { - int x = random.Next(0, doubleWidth); + int x = random.Next(0 + 2, doubleWidth - 2); int y = 0; startPoint = new IntPoint(x, y); endPoint = new IntPoint(x, doubleHeight); step = new IntPoint(0, 1); } - while(startPoint != endPoint) + while (startPoint != endPoint) { int x = (int)startPoint.X; int y = (int)startPoint.Y; @@ -280,7 +302,7 @@ namespace CityGame #endregion - Tile[,] Grid = IntermediateGrid; + Grid = IntermediateGrid; //for(int y = 0; y < mapHeight; y++) //{ // for(int x = 0; x < mapWidth; x++) @@ -292,33 +314,18 @@ namespace CityGame mapHeight *= 2; mapWidth *= 2; - #endregion - - Show(); - - #region | Rendering | - - Canvas MainCanvas = new OCanvas(); - Canvas BGCanvas = new OCanvas(); - Canvas GameCanvas = new OCanvas(); - Canvas CameraCanvas = new OCanvas(); - Canvas UICanvas = new OCanvas(); + ImageGrid = new OCanvas[doubleWidth, doubleHeight]; Canvas.SetLeft(CameraCanvas, 0); Canvas.SetTop(CameraCanvas, 0); - RenderOptions.SetEdgeMode(GameCanvas, EdgeMode.Aliased); - MainCanvas.Children.Add(CameraCanvas); MainCanvas.Children.Add(UICanvas); CameraCanvas.Children.Add(BGCanvas); CameraCanvas.Children.Add(GameCanvas); - MainCanvas.HorizontalAlignment = HorizontalAlignment.Left; - MainCanvas.VerticalAlignment = VerticalAlignment.Top; - - Content = MainCanvas; + ContentCanvas = MainCanvas; int tileSize = TileSize; for (int x = 0; x < mapWidth; x++) @@ -327,95 +334,24 @@ namespace CityGame { Canvas image = Renderer.Render(Grid[x, y].Type, x, y, Grid); - image.Height = tileSize; - image.Width = tileSize; - - RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.NearestNeighbor); - Canvas.SetLeft(image, x * tileSize); Canvas.SetTop(image, y * tileSize); + ImageGrid[x, y] = (OCanvas)image; + //image.Opacity = pathfindingGrid[y, x]; GameCanvas.Children.Add(image); } } - #endregion - - #region | Controls | - - MainCanvas.MouseDown += (a, b) => MouseIsDown = true; - MainCanvas.MouseUp += (a, b) => MouseIsDown = false; - MainCanvas.MouseMove += (a, b) => + foreach (Image image in SourcedImage.GetObjectsBySourceFile("Helipad.png")) { - if (MouseIsDown) - { - var newpos = PointToScreen(Mouse.GetPosition(this)); - var diff = newpos - MousePos; - Canvas.SetLeft(CameraCanvas, Canvas.GetLeft(CameraCanvas) + diff.X); - Canvas.SetTop(CameraCanvas, Canvas.GetTop(CameraCanvas) + diff.Y); - } - MousePos = PointToScreen(Mouse.GetPosition(this)); - }; + float x = (float)Canvas.GetLeft(image.Parent); + float y = (float)Canvas.GetTop(image.Parent); - ScaleTransform scale = new ScaleTransform(1, 1); - CameraCanvas.RenderTransform = scale; - - MainCanvas.MouseWheel += (a, b) => - { - float multi = 0.952f; - if (b.Delta > 0) multi = 1.05f; - - scale.ScaleX *= multi; - scale.ScaleY *= multi; - - if (b.Delta < 0) - { - scale.ScaleX = Math.Floor(scale.ScaleX * 100) / 100f; - scale.ScaleY = Math.Floor(scale.ScaleY * 100) / 100f; - } - else - { - scale.ScaleX = Math.Ceiling(scale.ScaleX * 100) / 100f; - scale.ScaleY = Math.Ceiling(scale.ScaleY * 100) / 100f; - } - - Debug.WriteLine(scale.ScaleX); - }; - #endregion - - #region | Entities | - - DispatcherTimer EntityLoop = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1 / 10) }; - EntityLoop.Tick += (a, b) => - { - long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; - foreach (Entity entity in Entities) - { - long delta = milliseconds - entity.Time; - entity.Time = milliseconds; - entity.Tick(delta); - - if (entity.Object is null) - { - entity.Object = entity.Render(); - RenderOptions.SetBitmapScalingMode(entity.Object, BitmapScalingMode.NearestNeighbor); - var rt = new RotateTransform(entity.Rotation); - rt.CenterX = MainWindow.TileSize / 2; - rt.CenterY = MainWindow.TileSize / 2; - entity.Object.RenderTransform = rt; - GameCanvas.Children.Add(entity.Object); - } - ((RotateTransform)entity.Object.RenderTransform).Angle = entity.Rotation; - Canvas.SetLeft(entity.Object, entity.X); - Canvas.SetTop(entity.Object, entity.Y); - - } - }; - EntityLoop.Start(); - - #endregion + Entities.Add(new Helicopter { X = x, Y = y }); + } for (int n = 0; n < NPCCount; n++) { @@ -430,13 +366,7 @@ namespace CityGame Car.CarEvent reset = car => { Tile targetTile = npcWalkable[random.Next(0, npcWalkable.Count)]; - DispatcherTimer delay = new DispatcherTimer { Interval = TimeSpan.FromSeconds(random.Next(1, 5)) }; - delay.Tick += (a, b) => - { - car.Target = new Point(targetTile.X, targetTile.Y); - delay.Stop(); - }; - delay.Start(); + car.Target = new Point(targetTile.X, targetTile.Y); }; car.JourneyFinished += reset; @@ -444,6 +374,75 @@ namespace CityGame Entities.Add(car); } + + Show(); + } + int swv; + protected override void Update(GameTime time) + { + MouseState state = Mouse.GetState(); + + if (state.MiddleButton == ButtonState.Pressed) + { + var newpos = new Point(state.X, state.Y); + var diff = newpos - MousePos; + Canvas.SetLeft(CameraCanvas, Canvas.GetLeft(CameraCanvas) + diff.X); + Canvas.SetTop(CameraCanvas, Canvas.GetTop(CameraCanvas) + diff.Y); + } + MousePos = new Point(state.X, state.Y); + + + float delta = state.ScrollWheelValue - swv; + swv = state.ScrollWheelValue; + if (delta != 0) + { + Debug.WriteLine(delta); + } + float multi = 1.05f; + if (delta < 0) multi = 1 / multi; + + if (delta != 0) + { + CameraCanvas.ScaleX *= multi; + CameraCanvas.ScaleY *= multi; + } + + if (state.LeftButton == ButtonState.Pressed) + { + ISelectable select = GetSelectableFromClick(state); + if (select is not null) + { + if (Selected is not null) Selected.GetImage().Opacity = 1; + Selected = select; + Selected.GetImage().Opacity = 0.5f; + } + } + else if (state.RightButton == ButtonState.Pressed) + { + ISelectable select = GetSelectableFromClick(state); + if (select is not null) + { + Selected.RunAction(select); + } + } + + long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; + foreach (Entity entity in Entities) + { + long deltaTime = milliseconds - entity.Time; + entity.Time = milliseconds; + entity.Tick(deltaTime); + + if (entity.Object is null) + { + entity.Object = entity.Render(); + GameCanvas.Children.Add(entity.Object); + } + entity.Object.Rotation = (int)entity.Rotation; + Canvas.SetLeft(entity.Object, entity.X); + Canvas.SetTop(entity.Object, entity.Y); + + } } } } \ No newline at end of file diff --git a/CityGame/OCanvas.cs b/CityGame/OCanvas.cs index c4d8ce8..a6b089f 100644 --- a/CityGame/OCanvas.cs +++ b/CityGame/OCanvas.cs @@ -1,4 +1,4 @@ -using System.Windows.Controls; +using WPFGame; namespace CityGame { @@ -12,8 +12,6 @@ namespace CityGame } public OCanvas() : base() { - this.Height = 100; - this.Width = 100; } } } \ No newline at end of file diff --git a/CityGame/Renderer.cs b/CityGame/Renderer.cs index 59b257a..f109ff9 100644 --- a/CityGame/Renderer.cs +++ b/CityGame/Renderer.cs @@ -1,4 +1,4 @@ -using System.Windows.Controls; +using WPFGame; namespace CityGame { @@ -32,7 +32,10 @@ namespace CityGame if (pattern.PatternCode == "3" && MainWindow.random.Next(0, 12) == 1) pattern.PatternCode = "3ab"; OCanvas canvas = new SourcedImage("Building"+ theme + pattern.PatternCode + ".png:" + pattern.Rotation, tooltip); - if (MainWindow.random.Next(0, 10) == 0 && pattern.PatternCode != "3a") canvas.Children.Add(new SourcedImage("Vent" + (MainWindow.random.Next(0, 3) + 1) + ".png:" + (MainWindow.random.Next(0, 4) * 90))); + if (theme == "Blue" && pattern.PatternCode == "8" && MainWindow.random.Next(0, 4) == 0) canvas.Children.Add(new SourcedImage("Helipad.png")); + else if (theme == "Blue" && pattern.PatternCode == "5" && MainWindow.random.Next(0, 2) == 0) canvas.Children.Add(new SourcedImage("Garage.png:" + pattern.Rotation)); + else if (theme == "Blue" && pattern.PatternCode == "0") canvas.Children.Add(new SourcedImage("Garage.png:270")); + else if (MainWindow.random.Next(0, 10) == 0 && pattern.PatternCode != "3a") canvas.Children.Add(new SourcedImage("Vent" + (MainWindow.random.Next(0, 3) + 1) + ".png:" + (MainWindow.random.Next(0, 4) * 90))); return canvas; } diff --git a/CityGame/Resources/BlueTint.hlsl b/CityGame/Resources/BlueTint.hlsl deleted file mode 100644 index b356f0d..0000000 --- a/CityGame/Resources/BlueTint.hlsl +++ /dev/null @@ -1,9 +0,0 @@ -Texture2D inputTexture : register(t0); -SamplerState inputSampler : register(s0); - -float4 main(float2 uv : TEXCOORD) : SV_Target -{ - float4 color = inputTexture.Sample(inputSampler, uv); - float4 grayscaleColor = float4(dot(color.rgb, float3(0.299, 0.587, 0.114)), dot(color.rgb, float3(0.299, 0.587, 0.114)), dot(color.rgb, float3(0.299, 0.587, 0.114)), color.a); - return grayscaleColor; -} \ No newline at end of file diff --git a/CityGame/Resources/Garage.png b/CityGame/Resources/Garage.png new file mode 100644 index 0000000000000000000000000000000000000000..5257f7dc30ccb930296a035a7fdc13a286e35010 GIT binary patch literal 298 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=jKx9jP7LeL$-D$|o_M-AhE&A8 zz3C{_tiaQnXcKvXC?L50W90kVDpjRrzn9;RKCOGkUeJL-P=WOdgKI&+gO^(SZ@a!>+U97d zaCNSc)0z*97_`rDZ9cTd07%t~7Kk+*F>nkh2}vlQxBqq@`vb-b2Du48cMAzHx-d+P zWOU&WbZQY$1XFfg4oMRvRMPx$ut`KgRCr$PnoW|zAP|MgWw=qcp2VdmnQd;wWw1!V>B{gEt?EZP{oH93cwav{ zbjQURe=WxKI|85sj1%A%Fm8ZpNia6R!ySp9uqFJ=1GX;MM9#UF_-)&&23Xfsehyh1 zWRff5i*hss1b{!04+mFOooS?c!)xnGP-xZI900r>wnL}&^wRNfu zoW<_@zm@ezK>iJYkAo@55v|L~c zKn+3*04Vxc2M|Cd7t|a8j6U80XBU_RAR(LqfTKUh0R$j&fpoxx=+ARNaRC8{YLE`l z`xi*B8KYkgw`NbZ0k;6Rz~PV75n>LomIEF!x_jONkLcXp5`ZK=y(EC+Jv=GHC)|Y- sfOQ8H7nscfy`vfU+MFB!7TKHb34lKAL8gneLI3~&07*qoM6N<$g3DUdLI3~& literal 0 HcmV?d00001 diff --git a/CityGame/Resources/HelicopterBlades.png b/CityGame/Resources/HelicopterBlades.png new file mode 100644 index 0000000000000000000000000000000000000000..62cf8b020bdccd25973e7da8979b8e135496bca5 GIT binary patch literal 423 zcmV;Y0a*TtP)Px$VM# z51>q=be^tr6aWYa9^p@)Gyp3Qyu#A~%s}uA?*d>1f_Hc~02T-l;avedL5K?P4&Wbz z$nYTmt`Pb?8u{cn^8bc<8+l-1oX|x{w zogm{4E<-c)QP{el9>-Cx0UpLtzaao9l38`sfUJ{4`Bno^B(v(M0a+)9@~sA-NM_Yh z1F}vIXHEumcD4g_I3G_03yPxnE(F;k^3&lmCR?hX}8tgSl!@yLM=m7F8btgq1~)9&ik_sY)?)O zSIKI8KF61F$;Wzs2POqo{UC=~a}*B=Bz73MNGS0LwsANgQ91(T_N;x9+$pK_QuS-l zpA}4ThXnqzF$&hQ9ux@(IKsii>heXDCD_4HP?JP)Px%FiAu~RCr$PnLU!jAPj}^Wqc#InORPeB4vs_1v|5?Z{*8(2MivC1>zVQ%fY@TE{_TuBj1B9dE z3r-loz0e<8BmmA;J z#B;SkZyR*AfC7k{omv}lgrGX0bGN81(DM|~43M4yVVT;1z!8GI%i*pJPyp(HxLd2V z0d))X+TYKZ3UzttDz_f<0@E2>0a{SmMzE!Iss6KCk1c_!W##q>Qjj)2e21?T+1GR*8Wbtpa4J?KnGk<{p%c%T%Z8JZcrUSzwR&X3HbH``RIN*+u=&ED2x$gL%Yf&) znn!Gb=W5JD5&$pWUl73dnmv@+2Mod$fOH2W7l_S()-f&fXV+u^v&hzPe<~hyP;}bu Q!~g&Q07*qoM6N<$f~KAcUjP6A literal 0 HcmV?d00001 diff --git a/CityGame/Resources/Helipad.png b/CityGame/Resources/Helipad.png new file mode 100644 index 0000000000000000000000000000000000000000..80a2461cab68f8587816be4fb43979efe8028cc6 GIT binary patch literal 650 zcmV;50(Jd~P)Px%L`g(JRCr$Pnrn{3APj`tdnETiSaOeDAuSR@5YHH!u)_V@1U#R|=FxsXn}5EW z>;D9RaKPpSq69WKKr}(R1dikQS=lxBeN&p?hew59*F|wV&y#w-ei#J-0nmzPMfVhI zVIUA(09XmHfv_M<05IA25@e+=@p*6p`1Kt)dxuJ#-0EDvvwG3*qpWk82 z19=aL$J7C>2_<2Okk%OheNT$X3;;rVL`bjEp@4haWmf=Fa49G>lUe}f9OW1}wg6z! z1f@EAy1AI)fF~E2I3NHtuCtK(pVb4VI{+0w6F>_>iqoY80swJiD;=Aqt6vT5Jmyjk zkc3*?2-mQe0>ETa+dBe4wOYA3AY};6Xl#W3vVsDuFFerqdYd(uWpFzONGGnh&jL?d zbrS~!fZ|-w{!ZuJ1f`1_GY4p0@CJagak>ML8loovDf=llQvf{|NDwsJU GetObjectsBySourceFile(params string[] files) + { + List objects = new List(); + foreach(string file in files) + { + if (!ObjectsBySourceFile.ContainsKey(file)) continue; + foreach (var image in ObjectsBySourceFile[file]) objects.Add(image); + } + return objects; + } + static Dictionary> ObjectsBySourceFile = new Dictionary>(); public Dictionary Alternatives = new Dictionary() { {"Path3.png", "Path3c.png" } @@ -49,6 +58,11 @@ namespace CityGame { uri = Alternatives[uri]; } + if(!ObjectsBySourceFile.ContainsKey(uri)) + { + ObjectsBySourceFile.Add(uri, new List()); + } + ObjectsBySourceFile[uri].Add(this); uri = Environment.CurrentDirectory + "\\Resources\\" + uri; if (loadedSources.ContainsKey(src)) { @@ -65,4 +79,4 @@ namespace CityGame } } } -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/CityGame/Tile.cs b/CityGame/Tile.cs index b95e8bc..c77eece 100644 --- a/CityGame/Tile.cs +++ b/CityGame/Tile.cs @@ -1,10 +1,30 @@ namespace CityGame { - public struct Tile + public struct Tile : ISelectable { public int BlockID; public TileType Type; public int X; public int Y; + + public OCanvas GetImage() + { + return MainWindow.ImageGrid[X, Y]; + } + + public bool RunAction(ISelectable target) + { + return false; + } + + int ISelectable.X() + { + return X * MainWindow.TileSize; + } + + int ISelectable.Y() + { + return Y * MainWindow.TileSize; + } } } \ No newline at end of file