From 247068241f4d4c0c70605791c520a85995a0ff39 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 7 Mar 2020 19:44:55 +0200 Subject: Worked on moving the player and displaying the map --- Mundus/Controllers/Map/LandSuperLayerGenerator.cs | 27 ++- Mundus/Controllers/Mob/MobMoving.cs | 21 ++ Mundus/Icons/Land/Ground/boulder.png | Bin 4339 -> 0 bytes Mundus/Icons/Land/Ground/old_grass.jpg | Bin 2759 -> 0 bytes Mundus/Icons/Land/Ground/rock.jpg | Bin 2527 -> 0 bytes Mundus/Icons/Land/Items/boulder.png | Bin 0 -> 4339 bytes Mundus/Icons/Land/Items/stick.jpg | Bin 2732 -> 0 bytes Mundus/Icons/Project files/Old icons/old_grass.jpg | Bin 0 -> 2759 bytes Mundus/Icons/Project files/Old icons/rock.jpg | Bin 0 -> 2527 bytes Mundus/Icons/Project files/Old icons/stick.jpg | Bin 0 -> 2732 bytes Mundus/Icons/player.png | Bin 0 -> 3315 bytes Mundus/Models/DI.cs | 19 ++ Mundus/Models/DialogInstances.cs | 19 -- Mundus/Models/LayerInstances.cs | 13 -- Mundus/Models/MapSizes.cs | 6 +- Mundus/Models/Mobs/IMob.cs | 12 ++ Mundus/Models/Mobs/Land_Mobs/LMI.cs | 11 ++ Mundus/Models/Mobs/Land_Mobs/Player.cs | 20 ++ Mundus/Models/SuperLayers/ISuperLayer.cs | 13 +- Mundus/Models/SuperLayers/Land.cs | 41 ++-- Mundus/Models/Tiles/GroundTile.cs | 5 - Mundus/Models/Tiles/ItemTile.cs | 12 +- Mundus/Models/Tiles/LI.cs | 13 ++ Mundus/Models/Tiles/MobTile.cs | 14 ++ Mundus/Models/WI.cs | 40 ++++ Mundus/Models/WindowInstances.cs | 40 ---- Mundus/Mundus.csproj | 19 +- Mundus/Program.cs | 29 ++- Mundus/Views/Windows/MainWindow.cs | 6 +- Mundus/Views/Windows/NewGameWindow.cs | 18 +- Mundus/Views/Windows/PauseWindow.cs | 2 +- Mundus/Views/Windows/SmallGameWindow.cs | 212 ++++++++++++++++++--- .../Mundus.Views.Windows.SmallGameWindow.cs | 25 +++ Mundus/gtk-gui/generated.cs | 4 +- Mundus/gtk-gui/gui.stetic | 36 +++- 35 files changed, 521 insertions(+), 156 deletions(-) create mode 100644 Mundus/Controllers/Mob/MobMoving.cs delete mode 100644 Mundus/Icons/Land/Ground/boulder.png delete mode 100644 Mundus/Icons/Land/Ground/old_grass.jpg delete mode 100644 Mundus/Icons/Land/Ground/rock.jpg create mode 100644 Mundus/Icons/Land/Items/boulder.png delete mode 100644 Mundus/Icons/Land/Items/stick.jpg create mode 100644 Mundus/Icons/Project files/Old icons/old_grass.jpg create mode 100644 Mundus/Icons/Project files/Old icons/rock.jpg create mode 100644 Mundus/Icons/Project files/Old icons/stick.jpg create mode 100644 Mundus/Icons/player.png create mode 100644 Mundus/Models/DI.cs delete mode 100644 Mundus/Models/DialogInstances.cs delete mode 100644 Mundus/Models/LayerInstances.cs create mode 100644 Mundus/Models/Mobs/IMob.cs create mode 100644 Mundus/Models/Mobs/Land_Mobs/LMI.cs create mode 100644 Mundus/Models/Mobs/Land_Mobs/Player.cs create mode 100644 Mundus/Models/Tiles/LI.cs create mode 100644 Mundus/Models/Tiles/MobTile.cs create mode 100644 Mundus/Models/WI.cs delete mode 100644 Mundus/Models/WindowInstances.cs diff --git a/Mundus/Controllers/Map/LandSuperLayerGenerator.cs b/Mundus/Controllers/Map/LandSuperLayerGenerator.cs index 5520330..b19be6d 100644 --- a/Mundus/Controllers/Map/LandSuperLayerGenerator.cs +++ b/Mundus/Controllers/Map/LandSuperLayerGenerator.cs @@ -2,14 +2,32 @@ using Mundus.Models; using Mundus.Models.Tiles; using Mundus.Models.SuperLayers; +using Mundus.Models.Mobs.Land_Mobs; namespace Mundus.Controllers.Map { public static class LandSuperLayerGenerator { private static Random rnd; public static void GenerateAllLayers(int size) { - LayerInstances.Land.SetGroundLayer(GenerateGroundLayer(size)); - LayerInstances.Land.SetItemLayer(GenerateItemLayer(size)); + LI.Land.SetMobLayer(GenerateMobLayer(size)); + LI.Land.SetGroundLayer(GenerateGroundLayer(size)); + LI.Land.SetItemLayer(GenerateItemLayer(size)); + } + + private static MobTile[,] GenerateMobLayer(int size) { + MobTile[,] tiles = new MobTile[size, size]; + + for (int col = 0; col < size; col++) { + for (int row = 0; row < size; row++) { + if (col == size / 2 && row == size / 2) { + LMI.Player.YPos = row; + LMI.Player.XPos = col; + LMI.Player.CurrSuperLayer = LI.Land; + tiles[col, row] = LMI.Player.Tile; + } + } + } + return tiles; } private static GroundTile[,] GenerateGroundLayer(int size) { @@ -18,7 +36,7 @@ namespace Mundus.Controllers.Map { for(int col = 0; col < size; col++) { for(int row = 0; row < size; row++) { - tiles[col, row] = LayerInstances.Land.GetGroundTileType("Grass"); + tiles[col, row] = new GroundTile("grass"); } } return tiles; @@ -26,10 +44,11 @@ namespace Mundus.Controllers.Map { private static ItemTile[,] GenerateItemLayer(int size) { ItemTile[,] tiles = new ItemTile[size, size]; + for (int col = 0; col < size; col++) { for (int row = 0; row < size; row++) { if (rnd.Next( 0, 5 ) == 1) { - tiles[col, row] = LayerInstances.Land.GetItemTileType( "Boulder" ); + tiles[col, row] = new ItemTile("boulder"); } } } diff --git a/Mundus/Controllers/Mob/MobMoving.cs b/Mundus/Controllers/Mob/MobMoving.cs new file mode 100644 index 0000000..99fabab --- /dev/null +++ b/Mundus/Controllers/Mob/MobMoving.cs @@ -0,0 +1,21 @@ +using System; +using Mundus.Models.Mobs; +using Mundus.Models.SuperLayers; + +namespace Mundus.Controllers.Mob { + public static class MobMoving { + public static void MoveMob(IMob mob, int yPos, int xPos) { + + } + + private static void ChangePosition(IMob mob, int yPos, int xPos) { + if (mob.CurrSuperLayer.GetItemLayerTile( yPos, xPos ) == null || + mob.CurrSuperLayer.GetItemLayerTile( yPos, xPos ).IsWalkable) { + mob.CurrSuperLayer.RemoveMobFromPosition( mob.YPos, mob.XPos ); + mob.YPos = yPos; + mob.XPos = xPos; + mob.CurrSuperLayer.SetMobAtPosition( mob.Tile, yPos, xPos ); + } + } + } +} diff --git a/Mundus/Icons/Land/Ground/boulder.png b/Mundus/Icons/Land/Ground/boulder.png deleted file mode 100644 index a5db10a..0000000 Binary files a/Mundus/Icons/Land/Ground/boulder.png and /dev/null differ diff --git a/Mundus/Icons/Land/Ground/old_grass.jpg b/Mundus/Icons/Land/Ground/old_grass.jpg deleted file mode 100644 index 3a6baf0..0000000 Binary files a/Mundus/Icons/Land/Ground/old_grass.jpg and /dev/null differ diff --git a/Mundus/Icons/Land/Ground/rock.jpg b/Mundus/Icons/Land/Ground/rock.jpg deleted file mode 100644 index 408b522..0000000 Binary files a/Mundus/Icons/Land/Ground/rock.jpg and /dev/null differ diff --git a/Mundus/Icons/Land/Items/boulder.png b/Mundus/Icons/Land/Items/boulder.png new file mode 100644 index 0000000..a5db10a Binary files /dev/null and b/Mundus/Icons/Land/Items/boulder.png differ diff --git a/Mundus/Icons/Land/Items/stick.jpg b/Mundus/Icons/Land/Items/stick.jpg deleted file mode 100644 index 84d3280..0000000 Binary files a/Mundus/Icons/Land/Items/stick.jpg and /dev/null differ diff --git a/Mundus/Icons/Project files/Old icons/old_grass.jpg b/Mundus/Icons/Project files/Old icons/old_grass.jpg new file mode 100644 index 0000000..3a6baf0 Binary files /dev/null and b/Mundus/Icons/Project files/Old icons/old_grass.jpg differ diff --git a/Mundus/Icons/Project files/Old icons/rock.jpg b/Mundus/Icons/Project files/Old icons/rock.jpg new file mode 100644 index 0000000..408b522 Binary files /dev/null and b/Mundus/Icons/Project files/Old icons/rock.jpg differ diff --git a/Mundus/Icons/Project files/Old icons/stick.jpg b/Mundus/Icons/Project files/Old icons/stick.jpg new file mode 100644 index 0000000..84d3280 Binary files /dev/null and b/Mundus/Icons/Project files/Old icons/stick.jpg differ diff --git a/Mundus/Icons/player.png b/Mundus/Icons/player.png new file mode 100644 index 0000000..45948b1 Binary files /dev/null and b/Mundus/Icons/player.png differ diff --git a/Mundus/Models/DI.cs b/Mundus/Models/DI.cs new file mode 100644 index 0000000..6f91709 --- /dev/null +++ b/Mundus/Models/DI.cs @@ -0,0 +1,19 @@ +using System; +using Mundus.Views.Dialogs; + +namespace Mundus.Models { + public static class DI { //stands for Dialogue Instances + public static ExitDialog DExit { get; private set; } + + public static void CreateInstances() { + DExit = new ExitDialog(); + + HideAll(); + } + + //Gtk opens all dialog (window) instances in the project automatically, unless they are hidden + private static void HideAll() { + DExit.Hide(); + } + } +} diff --git a/Mundus/Models/DialogInstances.cs b/Mundus/Models/DialogInstances.cs deleted file mode 100644 index d2b0506..0000000 --- a/Mundus/Models/DialogInstances.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using Mundus.Views.Dialogs; - -namespace Mundus.Models { - public static class DialogInstances { - public static ExitDialog DExit { get; private set; } - - public static void CreateInstances() { - DExit = new ExitDialog(); - - HideAll(); - } - - //Gtk opens all dialog (window) instances in the project automatically, unless they are hidden - private static void HideAll() { - DExit.Hide(); - } - } -} diff --git a/Mundus/Models/LayerInstances.cs b/Mundus/Models/LayerInstances.cs deleted file mode 100644 index 6b06596..0000000 --- a/Mundus/Models/LayerInstances.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using Mundus.Models.SuperLayers; - -namespace Mundus.Models { - public static class LayerInstances { - //add other layers - public static Land Land { get; private set; } - - public static void CreateInstances() { - Land = new Land(); - } - } -} diff --git a/Mundus/Models/MapSizes.cs b/Mundus/Models/MapSizes.cs index 7b9b5af..b9fd5e5 100644 --- a/Mundus/Models/MapSizes.cs +++ b/Mundus/Models/MapSizes.cs @@ -1,8 +1,10 @@ namespace Mundus.Models { public static class MapSizes { //These are the map sizes that are generated - public const int SMALL = 100; + public const int SMALL = 5; public const int MEDIUM = 500; - public const int LARGE = 1000; + public const int LARGE = 25; + + public static int CurrSize { get; set; } } } diff --git a/Mundus/Models/Mobs/IMob.cs b/Mundus/Models/Mobs/IMob.cs new file mode 100644 index 0000000..2f66fc6 --- /dev/null +++ b/Mundus/Models/Mobs/IMob.cs @@ -0,0 +1,12 @@ +using System; +using Mundus.Models.SuperLayers; +using Mundus.Models.Tiles; + +namespace Mundus.Models.Mobs { + public interface IMob { + MobTile Tile { get; } + ISuperLayer CurrSuperLayer { get; set; } + int XPos { get; set; } + int YPos { get; set; } + } +} diff --git a/Mundus/Models/Mobs/Land_Mobs/LMI.cs b/Mundus/Models/Mobs/Land_Mobs/LMI.cs new file mode 100644 index 0000000..5b98954 --- /dev/null +++ b/Mundus/Models/Mobs/Land_Mobs/LMI.cs @@ -0,0 +1,11 @@ +using System; + +namespace Mundus.Models.Mobs.Land_Mobs { + public static class LMI { //stands for Land Mob Instances + public static Player Player { get; private set; } + + public static void CreateInstances() { + Player = new Player("player"); + } + } +} diff --git a/Mundus/Models/Mobs/Land_Mobs/Player.cs b/Mundus/Models/Mobs/Land_Mobs/Player.cs new file mode 100644 index 0000000..af00e7a --- /dev/null +++ b/Mundus/Models/Mobs/Land_Mobs/Player.cs @@ -0,0 +1,20 @@ +using System; +using Gtk; +using Mundus.Models.SuperLayers; +using Mundus.Models.Tiles; + +namespace Mundus.Models.Mobs.Land_Mobs { + public class Player : IMob { + public MobTile Tile { get; private set; } + public ISuperLayer CurrSuperLayer { get; set; } + public int YPos { get; set; } + public int XPos { get; set; } + + public Player(string stock_id) : this(new MobTile(stock_id)) + { } + + public Player(MobTile tile) { + this.Tile = tile; + } + } +} diff --git a/Mundus/Models/SuperLayers/ISuperLayer.cs b/Mundus/Models/SuperLayers/ISuperLayer.cs index caf2aff..8040f91 100644 --- a/Mundus/Models/SuperLayers/ISuperLayer.cs +++ b/Mundus/Models/SuperLayers/ISuperLayer.cs @@ -5,13 +5,20 @@ using Gtk; namespace Mundus.Models.SuperLayers { public interface ISuperLayer { - ItemTile GetItemTileType(string name); - GroundTile GetGroundTileType(string name); - + MobTile GetMobLayerTile(int yPpos, int xPos); ItemTile GetItemLayerTile(int yPos, int xPos); GroundTile GetGroundLayerTile(int yPos, int xPos); + void SetMobLayer(MobTile[,] mobTiles); + void SetMobAtPosition(MobTile tile, int yPos, int xPos); + void RemoveMobFromPosition(int yPos, int xPos); + void SetItemLayer(ItemTile[,] itemTiles); + void SetItemAtPosition(ItemTile tile, int yPos, int xPos); + void RemoveItemFromPosition(int yPos, int xPos); + void SetGroundLayer(GroundTile[,] groundTiles); + void SetGroundAtPosition(GroundTile tile, int yPos, int xPos); + void RemoveGroundFromPosition(int yPos, int xPos); } } diff --git a/Mundus/Models/SuperLayers/Land.cs b/Mundus/Models/SuperLayers/Land.cs index 3fe31a1..5507374 100644 --- a/Mundus/Models/SuperLayers/Land.cs +++ b/Mundus/Models/SuperLayers/Land.cs @@ -4,27 +4,15 @@ using Mundus.Models.Tiles; namespace Mundus.Models.SuperLayers { public class Land : ISuperLayer { - - private static Dictionary itemTilesTypes = new Dictionary { - {"Stick", new ItemTile("stick")}, - {"Boulder", new ItemTile("boulder")} - }; - private static Dictionary groundTilesTypes = new Dictionary { - {"Grass", new GroundTile("grass")} - }; - + private static MobTile[,] mobLayer; private static ItemTile[,] itemLayer; private static GroundTile[,] groundLayer; public Land() { } - public ItemTile GetItemTileType(string name) { - return itemTilesTypes[name]; + public MobTile GetMobLayerTile(int yPos, int xPos) { + return mobLayer[yPos, xPos]; } - public GroundTile GetGroundTileType(string name) { - return groundTilesTypes[name]; - } - public ItemTile GetItemLayerTile(int yPos, int xPos) { return itemLayer[yPos, xPos]; } @@ -32,11 +20,34 @@ namespace Mundus.Models.SuperLayers { return groundLayer[yPos, xPos]; } + public void SetMobLayer(MobTile[,] mobTiles) { + mobLayer = mobTiles; + } + public void SetMobAtPosition(MobTile tile, int yPos, int xPos) { + mobLayer[yPos, xPos] = tile; + } + public void RemoveMobFromPosition(int yPos, int xPos) { + mobLayer[yPos, xPos] = null; + } + public void SetItemLayer(ItemTile[,] itemTiles) { itemLayer = itemTiles; } + public void SetItemAtPosition(ItemTile tile, int yPos, int xPos) { + itemLayer[yPos, xPos] = tile; + } + public void RemoveItemFromPosition(int yPos, int xPos) { + itemLayer[yPos, xPos] = null; + } + public void SetGroundLayer(GroundTile[,] groundTiles) { groundLayer = groundTiles; } + public void SetGroundAtPosition(GroundTile tile, int yPos, int xPos) { + groundLayer[yPos, xPos] = tile; + } + public void RemoveGroundFromPosition(int yPos, int xPos) { + groundLayer[yPos, xPos] = null; + } } } diff --git a/Mundus/Models/Tiles/GroundTile.cs b/Mundus/Models/Tiles/GroundTile.cs index 2069656..2314c9d 100644 --- a/Mundus/Models/Tiles/GroundTile.cs +++ b/Mundus/Models/Tiles/GroundTile.cs @@ -10,10 +10,5 @@ namespace Mundus.Models.Tiles { this.stock_id = stock_id; this.Texture = new Image(stock_id, IconSize.Dnd); } - - public GroundTile(Image texture) { - this.stock_id = texture.Name; - this.Texture = texture; - } } } diff --git a/Mundus/Models/Tiles/ItemTile.cs b/Mundus/Models/Tiles/ItemTile.cs index 43df544..92e1d08 100644 --- a/Mundus/Models/Tiles/ItemTile.cs +++ b/Mundus/Models/Tiles/ItemTile.cs @@ -6,14 +6,16 @@ namespace Mundus.Models.Tiles { public string stock_id { get; private set; } public Image Texture { get; private set; } - public ItemTile(string stock_id) { + public bool IsWalkable { get; private set; } + + public ItemTile(string stock_id) : this(stock_id, false ) + { } + + public ItemTile(string stock_id, bool isWalkable) { this.stock_id = stock_id; this.Texture = new Image( stock_id, IconSize.Dnd ); - } - public ItemTile(Image texture) { - this.stock_id = texture.Name; - this.Texture = texture; + this.IsWalkable = isWalkable; } } } diff --git a/Mundus/Models/Tiles/LI.cs b/Mundus/Models/Tiles/LI.cs new file mode 100644 index 0000000..1e741dc --- /dev/null +++ b/Mundus/Models/Tiles/LI.cs @@ -0,0 +1,13 @@ +using System; +using Mundus.Models.SuperLayers; + +namespace Mundus.Models.Tiles { + public static class LI { //stands for Layer Instances + //add other layers + public static Land Land { get; private set; } + + public static void CreateInstances() { + Land = new Land(); + } + } +} diff --git a/Mundus/Models/Tiles/MobTile.cs b/Mundus/Models/Tiles/MobTile.cs new file mode 100644 index 0000000..fc8453d --- /dev/null +++ b/Mundus/Models/Tiles/MobTile.cs @@ -0,0 +1,14 @@ +using System; +using Gtk; + +namespace Mundus.Models.Tiles { + public class MobTile : ITile { + public string stock_id { get; private set; } + public Image Texture { get; private set; } + + public MobTile(string stock_id) { + this.stock_id = stock_id; + this.Texture = new Image(stock_id, IconSize.Dnd); + } + } +} diff --git a/Mundus/Models/WI.cs b/Mundus/Models/WI.cs new file mode 100644 index 0000000..b31a70c --- /dev/null +++ b/Mundus/Models/WI.cs @@ -0,0 +1,40 @@ +using System; +using Mundus.Views.Windows; + +namespace Mundus.Models { + public static class WI { //stands for Window Instances + public static MainWindow WMain { get; private set; } + public static NewGameWindow WNewGame { get; private set; } + public static SmallGameWindow WSGame { get; private set; } + public static MediumGameWindow WMGame { get; private set; } + public static LargeGameWindow WLGame { get; private set; } + public static SettingsWindow WSettings { get; private set; } + public static PauseWindow WPause { get; private set; } + public static MusicWindow WMusic { get; private set; } + + public static void CreateInstances() { + WMain = new MainWindow(); + WNewGame = new NewGameWindow(); + WSGame = new SmallGameWindow(); + WMGame = new MediumGameWindow(); + WLGame = new LargeGameWindow(); + WSettings = new SettingsWindow(); + WPause = new PauseWindow(); + WMusic = new MusicWindow(); + + HideAll(); + } + + //Gtk opens all window instances in the project automatically, unless they are hidden + private static void HideAll() { + WMain.Hide(); + WNewGame.Hide(); + WSGame.Hide(); + WMGame.Hide(); + WLGame.Hide(); + WSettings.Hide(); + WPause.Hide(); + WMusic.Hide(); + } + } +} diff --git a/Mundus/Models/WindowInstances.cs b/Mundus/Models/WindowInstances.cs deleted file mode 100644 index 56bb13e..0000000 --- a/Mundus/Models/WindowInstances.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using Mundus.Views.Windows; - -namespace Mundus.Models { - public static class WindowInstances { - public static MainWindow WMain { get; private set; } - public static NewGameWindow WNewGame { get; private set; } - public static SmallGameWindow WSGame { get; private set; } - public static MediumGameWindow WMGame { get; private set; } - public static LargeGameWindow WLGame { get; private set; } - public static SettingsWindow WSettings { get; private set; } - public static PauseWindow WPause { get; private set; } - public static MusicWindow WMusic { get; private set; } - - public static void CreateInstances() { - WMain = new MainWindow(); - WNewGame = new NewGameWindow(); - WSGame = new SmallGameWindow(); - WMGame = new MediumGameWindow(); - WLGame = new LargeGameWindow(); - WSettings = new SettingsWindow(); - WPause = new PauseWindow(); - WMusic = new MusicWindow(); - - HideAll(); - } - - //Gtk opens all window instances in the project automatically, unless they are hidden - private static void HideAll() { - WMain.Hide(); - WNewGame.Hide(); - WSGame.Hide(); - WMGame.Hide(); - WLGame.Hide(); - WSettings.Hide(); - WPause.Hide(); - WMusic.Hide(); - } - } -} diff --git a/Mundus/Mundus.csproj b/Mundus/Mundus.csproj index 7c69ca3..2e8b062 100644 --- a/Mundus/Mundus.csproj +++ b/Mundus/Mundus.csproj @@ -52,10 +52,10 @@ gui.stetic - - + + @@ -79,10 +79,10 @@ - + - + @@ -91,7 +91,12 @@ - + + + + + + @@ -106,6 +111,10 @@ + + + + \ No newline at end of file diff --git a/Mundus/Program.cs b/Mundus/Program.cs index 7b09f2f..d141816 100644 --- a/Mundus/Program.cs +++ b/Mundus/Program.cs @@ -1,18 +1,37 @@ -using System; +using System.ComponentModel; +using System.Threading; +using System.Threading.Tasks; using Gtk; using Mundus.Models; +using Mundus.Models.Mobs.Land_Mobs; +using Mundus.Models.Tiles; +using Mundus.Views.Windows; namespace Mundus { public static class MainClass { + public static bool runGame = true; + public static void Main(string[] args) { + Initialize(); + } + + private static void Initialize() { Application.Init(); //All windows that are used by user (instances) are saved and created in WindowInstances.cs - WindowInstances.CreateInstances(); - DialogInstances.CreateInstances(); - LayerInstances.CreateInstances(); + WI.CreateInstances(); + DI.CreateInstances(); + LI.CreateInstances(); + LMI.CreateInstances(); - WindowInstances.WMain.Show(); + WI.WMain.Show(); Application.Run(); } + + public static void RunGameLoop() { + while (runGame) { + WI.WSGame.PrintScreen(); + Thread.Sleep( 100 ); + } + } } } diff --git a/Mundus/Views/Windows/MainWindow.cs b/Mundus/Views/Windows/MainWindow.cs index 5fbf3f9..229dc11 100644 --- a/Mundus/Views/Windows/MainWindow.cs +++ b/Mundus/Views/Windows/MainWindow.cs @@ -14,13 +14,13 @@ namespace Mundus.Views.Windows { private void OnBtnNewGameClicked(object sender, EventArgs e) { this.Hide(); - WindowInstances.WNewGame.SetDefaults(); - WindowInstances.WNewGame.Show(); + WI.WNewGame.SetDefaults(); + WI.WNewGame.Show(); } private void OnBtnSettingsClicked(object sender, EventArgs e) { this.Hide(); - WindowInstances.WSettings.Show(this); + WI.WSettings.Show(this); } protected void OnBtnTutorialClicked(object sender, EventArgs e) { diff --git a/Mundus/Views/Windows/NewGameWindow.cs b/Mundus/Views/Windows/NewGameWindow.cs index 9503df7..beed05a 100644 --- a/Mundus/Views/Windows/NewGameWindow.cs +++ b/Mundus/Views/Windows/NewGameWindow.cs @@ -17,7 +17,7 @@ namespace Mundus.Views.Windows { private void OnBtnBackClicked(object sender, EventArgs e) { this.Hide(); - WindowInstances.WMain.Show(); + WI.WMain.Show(); } //You can choose your Map size only in creative, it is predetermined by screen & inventory size in survival. @@ -86,23 +86,21 @@ namespace Mundus.Views.Windows { } private void MapGenerate() { - int mapSize; - if (rbMSmall.Active) { - mapSize = MapSizes.SMALL; + MapSizes.CurrSize = MapSizes.SMALL; } else if (rbMMedium.Active) { - mapSize = MapSizes.MEDIUM; + MapSizes.CurrSize = MapSizes.MEDIUM; } else if (rbMLarge.Active) { - mapSize = MapSizes.LARGE; + MapSizes.CurrSize = MapSizes.LARGE; } else { throw new ArgumentException("No map size was selected"); } //Add the other layers - LandSuperLayerGenerator.GenerateAllLayers(mapSize); + LandSuperLayerGenerator.GenerateAllLayers( MapSizes.CurrSize ); } //Does the inital steps that are required by all windows upon game generation @@ -110,13 +108,13 @@ namespace Mundus.Views.Windows { IGameWindow gameWindow; if (rbSmall.Active) { - gameWindow = WindowInstances.WSGame; + gameWindow = WI.WSGame; } else if (rbMedium.Active) { - gameWindow = WindowInstances.WMGame; + gameWindow = WI.WMGame; } else if (rbLarge.Active) { - gameWindow = WindowInstances.WLGame; + gameWindow = WI.WLGame; } else { throw new ArgumentException("No screen & inventory size was selected"); diff --git a/Mundus/Views/Windows/PauseWindow.cs b/Mundus/Views/Windows/PauseWindow.cs index 08107fe..0e55902 100644 --- a/Mundus/Views/Windows/PauseWindow.cs +++ b/Mundus/Views/Windows/PauseWindow.cs @@ -23,7 +23,7 @@ namespace Mundus.Views.Windows { protected void OnBtnSettingsClicked(object sender, EventArgs e) { this.Hide(); - WindowInstances.WSettings.Show(this); + WI.WSettings.Show(this); } protected void OnBtnSaveClicked(object sender, EventArgs e) { diff --git a/Mundus/Views/Windows/SmallGameWindow.cs b/Mundus/Views/Windows/SmallGameWindow.cs index 0f46f0f..e57a30e 100644 --- a/Mundus/Views/Windows/SmallGameWindow.cs +++ b/Mundus/Views/Windows/SmallGameWindow.cs @@ -1,8 +1,12 @@ using System; using Gtk; using Mundus.Models; +using Mundus.Models.Tiles; using Mundus.Models.SuperLayers; using Mundus.Views.Windows.Interfaces; +using Mundus.Models.Mobs.Land_Mobs; +using Mundus.Controllers.Mob; +using System.ComponentModel; namespace Mundus.Views.Windows { public partial class SmallGameWindow : Gtk.Window, IGameWindow { @@ -16,11 +20,11 @@ namespace Mundus.Views.Windows { public void OnDeleteEvent(object o, Gtk.DeleteEventArgs args) { //Open exit dialogue if you haven't saved in a while - if (true) { //TODO: check if you have saved + if (false) { //TODO: check if you have saved //TODO: pause game cycle - ResponseType rt = (ResponseType)DialogInstances.DExit.Run(); - DialogInstances.DExit.Hide(); + ResponseType rt = (ResponseType)DI.DExit.Run(); + DI.DExit.Hide(); if(rt == ResponseType.Cancel || rt == ResponseType.DeleteEvent) { //cancel the exit procedure and keep the window open @@ -38,12 +42,13 @@ namespace Mundus.Views.Windows { public void SetDefaults() { this.SetMapMenuVisibility(false); this.SetInvMenuVisibility(false); - WindowInstances.WPause.GameWindow = this; + WI.WPause.GameWindow = this; + } protected void OnBtnPauseClicked(object sender, EventArgs e) { //TODO: add code that stops (pauses) game cycle - WindowInstances.WPause.Show(); + WI.WPause.Show(); } protected void OnBtnMapClicked(object sender, EventArgs e) { @@ -206,19 +211,20 @@ namespace Mundus.Views.Windows { } protected void OnBtnMusicClicked(object sender, EventArgs e) { - WindowInstances.WMusic.Show(); + WI.WMusic.Show(); } public void PrintScreen() { - //TODO: get the superlayer that the player is in - ISuperLayer superLayer = LayerInstances.Land; + ISuperLayer superLayer = LMI.Player.CurrSuperLayer; - for(int i = 0; i < 2; i++) { - for (int row = 0; row < SIZE; row++) { - for (int col = 0; col < SIZE; col++) { + for(int i = 0; i < 3; i++) { + int btn = 1; + for (int row = this.CalculateStartY(), maxY = this.CalculateMaxY(); row <= maxY; row++) { + for (int col = this.CalculateStartX(), maxX = this.CalculateMaxX(); col <= maxX; col++, btn++) { //Set the image to be either the ground layer tile, "blank" icon, item layer tile, mob layer tile or don't set it to anything //Note: first the ground and the blank icons are printed, then over them are printed the item tiles and over them are mob tiles Image img = new Image(); + if (i == 0) { if (superLayer.GetGroundLayerTile( row, col ) == null) { img = new Image( "blank", IconSize.Dnd ); @@ -226,12 +232,17 @@ namespace Mundus.Views.Windows { else { img = new Image( superLayer.GetGroundLayerTile( row, col ).stock_id, IconSize.Dnd ); } - } else { + } + else if (i == 1) { if (superLayer.GetItemLayerTile( row, col ) == null) continue; img = new Image( superLayer.GetItemLayerTile( row, col ).stock_id, IconSize.Dnd ); } + else { + if (superLayer.GetMobLayerTile( row, col ) == null) continue; + img = new Image( superLayer.GetMobLayerTile( row, col ).stock_id, IconSize.Dnd ); + } - switch (row * 5 + col + 1) { + switch (btn) { case 1: btnP1.Image = img; break; case 2: btnP2.Image = img; break; case 3: btnP3.Image = img; break; @@ -265,23 +276,27 @@ namespace Mundus.Views.Windows { public void PrintMap() { //TODO: get the superlayer that the player is in - ISuperLayer superLayer = LayerInstances.Land; + ISuperLayer superLayer = LI.Land; string sName; //Prints the "Ground layer" in map menu - for (int row = 0; row < SIZE; row++) { - for (int col = 0; col < SIZE; col++) { + int img = 1; + for (int row = this.CalculateStartY(), maxY = this.CalculateMaxY(); row <= maxY; row++) { + for (int col = this.CalculateStartX(), maxX = this.CalculateMaxX(); col <= maxX; col++, img++) { //Print a tile if it exists, otherwise print the "blank" icon - if (superLayer.GetGroundLayerTile( row, col ) == null) { + if (row < 0 || col < 0 || col >= MapSizes.CurrSize || row >= MapSizes.CurrSize) { + sName = "blank"; + } + else if (superLayer.GetGroundLayerTile( row, col ) == null) { sName = "blank"; } else { sName = superLayer.GetGroundLayerTile( row, col ).stock_id; } - switch (row * 5 + col + 1) { - case 1: imgG1.SetFromStock(sName, IconSize.Dnd); break; + switch (img) { + case 1: imgG1.SetFromStock( sName, IconSize.Dnd ); break; case 2: imgG2.SetFromStock( sName, IconSize.Dnd ); break; case 3: imgG3.SetFromStock( sName, IconSize.Dnd ); break; case 4: imgG4.SetFromStock( sName, IconSize.Dnd ); break; @@ -311,17 +326,21 @@ namespace Mundus.Views.Windows { } //Prints the "Item layer" in map menu - for (int row = 0; row < SIZE; row++) { - for (int col = 0; col < SIZE; col++) { + img = 1; + for (int row = this.CalculateStartY(), maxY = this.CalculateMaxY(); row <= maxY; row++) { + for (int col = this.CalculateStartX(), maxX = this.CalculateMaxX(); col <= maxX; col++, img++) { //Print a tile if it exists, otherwise print the "blank" icon - if (superLayer.GetItemLayerTile( row, col ) == null) { + if (row < 0 || col < 0 || col >= MapSizes.CurrSize || row >= MapSizes.CurrSize) { + sName = "blank"; + } + else if (superLayer.GetItemLayerTile( row, col ) == null) { sName = "blank"; } else { sName = superLayer.GetItemLayerTile( row, col ).stock_id; } - switch (row * 5 + col + 1) { + switch (img) { case 1: imgI1.SetFromStock( sName, IconSize.Dnd ); break; case 2: imgI2.SetFromStock( sName, IconSize.Dnd ); break; case 3: imgI3.SetFromStock( sName, IconSize.Dnd ); break; @@ -357,7 +376,152 @@ namespace Mundus.Views.Windows { } protected void OnBtnH1Clicked(object sender, EventArgs e) { - this.PrintMap(); + this.PrintScreen(); + } + + protected void OnBtnP1Clicked(object sender, EventArgs e) { + ChangePosition(1); + } + + protected void OnBtnP2Clicked(object sender, EventArgs e) { + ChangePosition(2); + } + + protected void OnBtnP3Clicked(object sender, EventArgs e) { + ChangePosition(3); + } + + protected void OnBtnP4Clicked(object sender, EventArgs e) { + ChangePosition(4); + } + + protected void OnBtnP5Clicked(object sender, EventArgs e) { + ChangePosition(5); + } + + protected void OnBtnP6Clicked(object sender, EventArgs e) { + ChangePosition(6); + } + + protected void OnBtnP7Clicked(object sender, EventArgs e) { + ChangePosition(7); + } + + protected void OnBtnP8Clicked(object sender, EventArgs e) { + ChangePosition(8); + } + + protected void OnBtnP9Clicked(object sender, EventArgs e) { + ChangePosition(9); + } + + protected void OnBtnP10Clicked(object sender, EventArgs e) { + ChangePosition(10); + } + + protected void OnBtnP11Clicked(object sender, EventArgs e) { + ChangePosition(11); + } + + protected void OnBtnP12Clicked(object sender, EventArgs e) { + ChangePosition(12); + } + + protected void OnBtnP13Clicked(object sender, EventArgs e) { + ChangePosition(13); + } + + protected void OnBtnP14Clicked(object sender, EventArgs e) { + ChangePosition(14); + } + + protected void OnBtnP15Clicked(object sender, EventArgs e) { + ChangePosition(15); + } + + protected void OnBtnP16Clicked(object sender, EventArgs e) { + ChangePosition(16); + } + + protected void OnBtnP17Clicked(object sender, EventArgs e) { + ChangePosition(17); + } + + protected void OnBtnP18Clicked(object sender, EventArgs e) { + ChangePosition(18); + } + + protected void OnBtnP19Clicked(object sender, EventArgs e) { + ChangePosition(19); + } + + protected void OnBtnP20Clicked(object sender, EventArgs e) { + ChangePosition(20); + } + + protected void OnBtnP21Clicked(object sender, EventArgs e) { + ChangePosition(21); + } + + protected void OnBtnP22Clicked(object sender, EventArgs e) { + ChangePosition(22); + } + + protected void OnBtnP23Clicked(object sender, EventArgs e) { + ChangePosition(23); + } + + protected void OnBtnP24Clicked(object sender, EventArgs e) { + ChangePosition(24); + } + + protected void OnBtnP25Clicked(object sender, EventArgs e) { + ChangePosition(25); + } + + private void ChangePosition(int button) { + int buttonYPos = (button - 1) / 5; + int buttonXPos = button - buttonYPos * 5 - 1; + + int newYPos = (LMI.Player.YPos - 2 >= 0) ? LMI.Player.YPos - 2 + buttonYPos : buttonYPos; + if (LMI.Player.YPos > MapSizes.CurrSize - 3) newYPos = buttonYPos + MapSizes.CurrSize - SIZE; + int newXPos = (LMI.Player.XPos - 2 >= 0) ? LMI.Player.XPos - 2 + buttonXPos : buttonXPos; + if (LMI.Player.XPos > MapSizes.CurrSize - 3) newXPos = buttonXPos + MapSizes.CurrSize - SIZE; + + if (newYPos >= 0 && newXPos >= 0 && newYPos < MapSizes.CurrSize && newXPos < MapSizes.CurrSize) { + MobMoving.MoveMob( LMI.Player, newYPos, newXPos ); + } + + this.PrintScreen(); + if (this.MapMenuIsVisible()) { + this.PrintMap(); + } + } + + /*Depending on whether you are on the edge of the map or in the center, the screen renders a bit differently. + *On the edge it doesn't follow the player and only shows the corner "chunk". In the other parts it follows the + *the player, making sure he stays in the center of the screen. + *This means that when the player is followed, rendered part of the map depend on the player position, but when + *he isn't, it depends on the screen and map sizes.*/ + private int CalculateMaxY() { + int maxY = (LMI.Player.YPos - 2 >= 0) ? LMI.Player.YPos + 2 : SIZE - 1; + if (maxY >= MapSizes.CurrSize) maxY = MapSizes.CurrSize - 1; + return maxY; + } + private int CalculateStartY() { + int startY = (LMI.Player.YPos - 2 <= MapSizes.CurrSize - SIZE) ? LMI.Player.YPos - 2 : MapSizes.CurrSize - SIZE; + if (startY < 0) startY = 0; + return startY; + } + private int CalculateMaxX() { + int maxX = (LMI.Player.XPos - 2 >= 0) ? LMI.Player.XPos + 2 : SIZE - 1; + if (maxX >= MapSizes.CurrSize) maxX = MapSizes.CurrSize - 1; + return maxX; + } + private int CalculateStartX() { + int startX = (LMI.Player.XPos - 2 <= MapSizes.CurrSize - SIZE) ? LMI.Player.XPos - 2 : MapSizes.CurrSize - SIZE; + if (startX < 0) startX = 0; + return startX; } } } diff --git a/Mundus/gtk-gui/Mundus.Views.Windows.SmallGameWindow.cs b/Mundus/gtk-gui/Mundus.Views.Windows.SmallGameWindow.cs index 85a6a45..2d73b26 100644 --- a/Mundus/gtk-gui/Mundus.Views.Windows.SmallGameWindow.cs +++ b/Mundus/gtk-gui/Mundus.Views.Windows.SmallGameWindow.cs @@ -2909,6 +2909,31 @@ namespace Mundus.Views.Windows this.Show(); this.DeleteEvent += new global::Gtk.DeleteEventHandler(this.OnDeleteEvent); this.btnPause.Clicked += new global::System.EventHandler(this.OnBtnPauseClicked); + this.btnP9.Clicked += new global::System.EventHandler(this.OnBtnP9Clicked); + this.btnP8.Clicked += new global::System.EventHandler(this.OnBtnP8Clicked); + this.btnP7.Clicked += new global::System.EventHandler(this.OnBtnP7Clicked); + this.btnP6.Clicked += new global::System.EventHandler(this.OnBtnP6Clicked); + this.btnP5.Clicked += new global::System.EventHandler(this.OnBtnP5Clicked); + this.btnP4.Clicked += new global::System.EventHandler(this.OnBtnP4Clicked); + this.btnP3.Clicked += new global::System.EventHandler(this.OnBtnP3Clicked); + this.btnP25.Clicked += new global::System.EventHandler(this.OnBtnP25Clicked); + this.btnP24.Clicked += new global::System.EventHandler(this.OnBtnP24Clicked); + this.btnP23.Clicked += new global::System.EventHandler(this.OnBtnP23Clicked); + this.btnP22.Clicked += new global::System.EventHandler(this.OnBtnP22Clicked); + this.btnP21.Clicked += new global::System.EventHandler(this.OnBtnP21Clicked); + this.btnP20.Clicked += new global::System.EventHandler(this.OnBtnP20Clicked); + this.btnP2.Clicked += new global::System.EventHandler(this.OnBtnP2Clicked); + this.btnP19.Clicked += new global::System.EventHandler(this.OnBtnP19Clicked); + this.btnP18.Clicked += new global::System.EventHandler(this.OnBtnP18Clicked); + this.btnP17.Clicked += new global::System.EventHandler(this.OnBtnP17Clicked); + this.btnP16.Clicked += new global::System.EventHandler(this.OnBtnP16Clicked); + this.btnP15.Clicked += new global::System.EventHandler(this.OnBtnP15Clicked); + this.btnP14.Clicked += new global::System.EventHandler(this.OnBtnP14Clicked); + this.btnP13.Clicked += new global::System.EventHandler(this.OnBtnP13Clicked); + this.btnP12.Clicked += new global::System.EventHandler(this.OnBtnP12Clicked); + this.btnP11.Clicked += new global::System.EventHandler(this.OnBtnP11Clicked); + this.btnP10.Clicked += new global::System.EventHandler(this.OnBtnP10Clicked); + this.btnP1.Clicked += new global::System.EventHandler(this.OnBtnP1Clicked); this.btnMusic.Clicked += new global::System.EventHandler(this.OnBtnMusicClicked); this.btnMap.Clicked += new global::System.EventHandler(this.OnBtnMapClicked); this.btnInv.Clicked += new global::System.EventHandler(this.OnBtnInvClicked); diff --git a/Mundus/gtk-gui/generated.cs b/Mundus/gtk-gui/generated.cs index 63926e9..82ce78e 100644 --- a/Mundus/gtk-gui/generated.cs +++ b/Mundus/gtk-gui/generated.cs @@ -16,8 +16,10 @@ namespace Stetic w1.Add("grass", w2); global::Gtk.IconSet w3 = new global::Gtk.IconSet(global::Gdk.Pixbuf.LoadFromResource("Mundus.Icons.blank.jpg")); w1.Add("blank", w3); - global::Gtk.IconSet w4 = new global::Gtk.IconSet(global::Gdk.Pixbuf.LoadFromResource("Mundus.Icons.Land.Ground.boulder.png")); + global::Gtk.IconSet w4 = new global::Gtk.IconSet(global::Gdk.Pixbuf.LoadFromResource("Mundus.Icons.Land.Items.boulder.png")); w1.Add("boulder", w4); + global::Gtk.IconSet w5 = new global::Gtk.IconSet(global::Gdk.Pixbuf.LoadFromResource("Mundus.Icons.player.png")); + w1.Add("player", w5); w1.AddDefault(); } } diff --git a/Mundus/gtk-gui/gui.stetic b/Mundus/gtk-gui/gui.stetic index 3fef9fb..2ddfeb3 100644 --- a/Mundus/gtk-gui/gui.stetic +++ b/Mundus/gtk-gui/gui.stetic @@ -19,7 +19,12 @@ - resource:Mundus.Icons.Land.Ground.boulder.png + resource:Mundus.Icons.Land.Items.boulder.png + + + + + resource:Mundus.Icons.player.png @@ -384,6 +389,7 @@ 90 True Creative + True True True True @@ -412,6 +418,7 @@ 90 True Easy + True True True True @@ -493,6 +500,7 @@ 90 True Large + True True True True @@ -548,6 +556,7 @@ True Large + True True True True @@ -2890,6 +2899,7 @@ True None + 1 @@ -2917,6 +2927,7 @@ True None + 2 @@ -2944,6 +2955,7 @@ True None + 3 @@ -2971,6 +2983,7 @@ True None + 3 @@ -2998,6 +3011,7 @@ True None + 3 @@ -3025,6 +3039,7 @@ True None + 3 @@ -3052,6 +3067,7 @@ True None + 3 @@ -3079,6 +3095,7 @@ True None + 4 @@ -3106,6 +3123,7 @@ True None + 4 @@ -3133,6 +3151,7 @@ True None + 4 @@ -3160,6 +3179,7 @@ True None + 4 @@ -3187,6 +3207,7 @@ True None + 1 @@ -3214,6 +3235,7 @@ True None + 4 @@ -3241,6 +3263,7 @@ True None + 5 @@ -3268,6 +3291,7 @@ True None + 5 @@ -3295,6 +3319,7 @@ True None + 5 @@ -3322,6 +3347,7 @@ True None + 5 @@ -3349,6 +3375,7 @@ True None + 5 @@ -3376,6 +3403,7 @@ True None + 1 @@ -3403,6 +3431,7 @@ True None + 1 @@ -3430,6 +3459,7 @@ True None + 1 @@ -3457,6 +3487,7 @@ True None + 2 @@ -3484,6 +3515,7 @@ True None + 2 @@ -3511,6 +3543,7 @@ True None + 2 @@ -3538,6 +3571,7 @@ True None + 2 -- cgit v1.2.3