From debdccace2aa290941cc13b0c6b4b7d186d35271 Mon Sep 17 00:00:00 2001 From: Robin Hanssen Date: Sun, 7 Nov 2021 22:24:36 +0100 Subject: [PATCH] Initial commit --- .gitignore | 225 ++++++++++++++++++ README.md | 34 +++ src/GameJamSadConsoleSample.sln | 22 ++ src/GameJamSadConsoleSample/Actor.cs | 58 +++++ .../GameJamSadConsoleSample.csproj | 14 ++ src/GameJamSadConsoleSample/GameLoop.cs | 123 ++++++++++ src/GameJamSadConsoleSample/Player.cs | 12 + src/GameJamSadConsoleSample/TileBase.cs | 23 ++ src/GameJamSadConsoleSample/TileFloor.cs | 12 + src/GameJamSadConsoleSample/TileWall.cs | 12 + 10 files changed, 535 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 src/GameJamSadConsoleSample.sln create mode 100644 src/GameJamSadConsoleSample/Actor.cs create mode 100644 src/GameJamSadConsoleSample/GameJamSadConsoleSample.csproj create mode 100644 src/GameJamSadConsoleSample/GameLoop.cs create mode 100644 src/GameJamSadConsoleSample/Player.cs create mode 100644 src/GameJamSadConsoleSample/TileBase.cs create mode 100644 src/GameJamSadConsoleSample/TileFloor.cs create mode 100644 src/GameJamSadConsoleSample/TileWall.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c5eb50 --- /dev/null +++ b/.gitignore @@ -0,0 +1,225 @@ +# The following command works for downloading when using Git for Windows: +# curl -LOf http://gist.githubusercontent.com/kmorcinek/2710267/raw/.gitignore +# +# Download this file using PowerShell v3 under Windows with the following comand: +# Invoke-WebRequest https://gist.githubusercontent.com/kmorcinek/2710267/raw/ -OutFile .gitignore +# +# or wget: +# wget --no-check-certificate http://gist.githubusercontent.com/kmorcinek/2710267/raw/.gitignore + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Rr]elease/ +x64/ +[Bb]in/ +[Oo]bj/ +# build folder is nowadays used for build scripts and should not be ignored +#build/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# OS generated files # +.DS_Store* +Icon? + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings +modulesbin/ +tempbin/ + +# EPiServer Site file (VPP) +AppData/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# vim +*.txt~ +*.swp +*.swo + +# Temp files when opening LibreOffice on ubuntu +.~lock.* + +# svn +.svn + +# CVS - Source Control +**/CVS/ + +# Remainings from resolving conflicts in Source Control +*.orig + +# SQL Server files +**/App_Data/*.mdf +**/App_Data/*.ldf +**/App_Data/*.sdf + + +#LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml + +# ========================= +# Windows detritus +# ========================= + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac desktop service store files +.DS_Store + +# SASS Compiler cache +.sass-cache + +# Visual Studio 2014 CTP +**/*.sln.ide + +# Visual Studio temp something +.vs/ + +# dotnet stuff +project.lock.json + +# VS 2015+ +*.vc.vc.opendb +*.vc.db + +# Rider +.idea/ + +# Visual Studio Code +.vscode/ + +# Output folder used by Webpack or other FE stuff +**/node_modules/* +**/wwwroot/* + +# SpecFlow specific +*.feature.cs +*.feature.xlsx.* +*.Specs_*.html + +##### +# End of core ignore list, below put you custom 'per project' settings (patterns or path) +##### diff --git a/README.md b/README.md new file mode 100644 index 0000000..6097fba --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# Game Jam: SadConsole Sample + +A sample game project utilizing SadConsole and MonoGame, based on the `ansi|ware` SadConsole v8 tutorials. + +# Purpose +The project is intended as a starter game template to be used at the `Forse Game Jam, November 2021`. + +# How to run the game +`dotnet run` to compile and run the game + +# Controls +Move around: `Arrow keys 🔼 🔽 ◀ ▶` + +Full screen: `F5` + +# Credits +The project is a result of blindly following the the great `ansi|ware` tutorials, pt 1 through 5. + +Sources: https://ansiware.com/ + +Tutorial pt 1: https://ansiware.com/tutorial-part-1-preface-and-hello-world-sadconsole-v8/ + +Tutorial pt 2: https://ansiware.com/tutorial-part-2-player-creation-and-display-v8/ + +Tutorial pt 3: https://ansiware.com/tutorial-part-3-movement-and-keyboard-input-v8/ + +Tutorial pt 4: https://ansiware.com/tutorial-part-4-create-a-room-v8/ + +Tutorial pt 5: https://ansiware.com/tutorial-part-5-actors-and-tiles-v8/ + + + + + diff --git a/src/GameJamSadConsoleSample.sln b/src/GameJamSadConsoleSample.sln new file mode 100644 index 0000000..e0ebfaf --- /dev/null +++ b/src/GameJamSadConsoleSample.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameJamSadConsoleSample", "GameJamSadConsoleSample\GameJamSadConsoleSample.csproj", "{8CDD0893-0D34-4F77-98B0-3324E3EEE0C0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8CDD0893-0D34-4F77-98B0-3324E3EEE0C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8CDD0893-0D34-4F77-98B0-3324E3EEE0C0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8CDD0893-0D34-4F77-98B0-3324E3EEE0C0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8CDD0893-0D34-4F77-98B0-3324E3EEE0C0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/GameJamSadConsoleSample/Actor.cs b/src/GameJamSadConsoleSample/Actor.cs new file mode 100644 index 0000000..5f4369d --- /dev/null +++ b/src/GameJamSadConsoleSample/Actor.cs @@ -0,0 +1,58 @@ +using Microsoft.Xna.Framework; + +namespace GameJamSadConsoleSample +{ + public abstract class Actor : SadConsole.Entities.Entity + { + private int _health; + private int _maxHealth; + + public int Health + { + get + { + return _health; + } + set + { + _health = value; + } + } + + public int MaxHealth + { + get + { + return _maxHealth; + } + set + { + _maxHealth = value; + } + } + + protected Actor(Color foreground, Color background, int glyph, int width=1, int height=1) : base(width, height) + { + Animation.CurrentFrame[0].Foreground = foreground; + Animation.CurrentFrame[0].Background = background; + Animation.CurrentFrame[0].Glyph = glyph; + } + + public bool MoveBy(Point positionChange) + { + if (GameLoop.IsTileWalkable(Position + positionChange)) + { + Position += positionChange; + return true; + } + else + return false; + } + + public bool MoveTo(Point newPosition) + { + Position = newPosition; + return true; + } + } +} diff --git a/src/GameJamSadConsoleSample/GameJamSadConsoleSample.csproj b/src/GameJamSadConsoleSample/GameJamSadConsoleSample.csproj new file mode 100644 index 0000000..25d4585 --- /dev/null +++ b/src/GameJamSadConsoleSample/GameJamSadConsoleSample.csproj @@ -0,0 +1,14 @@ + + + + WinExe + net5.0 + GameJamSadConsoleSample + + + + + + + + diff --git a/src/GameJamSadConsoleSample/GameLoop.cs b/src/GameJamSadConsoleSample/GameLoop.cs new file mode 100644 index 0000000..638fa3b --- /dev/null +++ b/src/GameJamSadConsoleSample/GameLoop.cs @@ -0,0 +1,123 @@ +using SadConsole; +using Console = SadConsole.Console; +using Microsoft.Xna.Framework; + +namespace GameJamSadConsoleSample +{ + // Source and inspiration: "The SadConsole Roguelike Tutorial Series", www.ansiware.com + // Tutorial pt 1: https://ansiware.com/tutorial-part-1-preface-and-hello-world-sadconsole-v8/ + // Tutorial pt 2: https://ansiware.com/tutorial-part-2-player-creation-and-display-v8/ + // Tutorial pt 3: https://ansiware.com/tutorial-part-3-movement-and-keyboard-input-v8/ + // Tutorial pt 4: https://ansiware.com/tutorial-part-4-create-a-room-v8/ + // Tutorial pt 5: https://ansiware.com/tutorial-part-5-actors-and-tiles-v8/ + public class GameLoop + { + public const int Width = 30; + public const int Height = 30; + private static Player player; + + private static TileBase[] _tiles; + private const int roomStartY = 1; + private const int roomStartX = 2; + private const int _roomWidth = 10; + private const int _roomHeight = 10; + + + + static void Main(string[] args) + { + SadConsole.Game.Create(Width, Height); + SadConsole.Game.OnInitialize = Init; + SadConsole.Game.OnUpdate = Update; + SadConsole.Game.Instance.Run(); + SadConsole.Game.Instance.Dispose(); + } + + private static void Init() + { + CreateWalls(); + CreateFloors(); + Console startingConsole = new ScrollingConsole(Width, Height, Global.FontDefault, new Rectangle(0, 0, Width, Height), _tiles); + startingConsole.Print(1, 12, "En m0rk og stormfull aften", ColorAnsi.CyanBright); + SadConsole.Global.CurrentScreen = startingConsole; + CreatePlayer(); + startingConsole.Children.Add(player); + } + + private static void Update(GameTime time) + { + CheckKeyboard(); + } + + private static void CheckKeyboard() + { + if (Global.KeyboardState.IsKeyReleased(Microsoft.Xna.Framework.Input.Keys.F5)) + { + Settings.ToggleFullScreen(); + } + + if (Global.KeyboardState.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Up)) + { + player.MoveBy(new Point(0, -1)); + } + + if (Global.KeyboardState.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Down)) + { + player.MoveBy(new Point(0, 1)); + } + + if (Global.KeyboardState.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Left)) + { + player.MoveBy(new Point(-1, 0)); + } + + if (Global.KeyboardState.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Right)) + { + player.MoveBy(new Point(1, 0)); + } + } + + private static void CreatePlayer() + { + player = new Player(Color.Yellow, Color.Transparent); + player.Position = new Point(5, 5); + } + + private static void CreateFloors() + { + for (int x = roomStartX; x < _roomWidth; x++) + { + for (int y = roomStartY; y < _roomHeight; y++) + { + _tiles[y * Width + x] = new TileFloor(); + } + } + } + + + + private static void CreateWalls() + { + int wallAlternator = 0; + string wallCharacters = "$#$%"; + _tiles = new TileBase[Width * Height]; + + for (int i = 0; i < _tiles.Length; i++) + { + _tiles[i] = new TileWall(wallCharacters[wallAlternator]); + wallAlternator++; + if (wallAlternator == wallCharacters.Length) + { + wallAlternator = 0; + } + } + } + public static bool IsTileWalkable(Point location) + { + if (location.X < 0 || location.Y < 0 || location.X >= Width || location.Y >= Height) + return false; + return !_tiles[location.Y * Width + location.X].IsBlockingMove; + } + } + +} \ No newline at end of file diff --git a/src/GameJamSadConsoleSample/Player.cs b/src/GameJamSadConsoleSample/Player.cs new file mode 100644 index 0000000..2fd8dd5 --- /dev/null +++ b/src/GameJamSadConsoleSample/Player.cs @@ -0,0 +1,12 @@ +using Microsoft.Xna.Framework; + +namespace GameJamSadConsoleSample +{ + public class Player : Actor + { + public Player(Color foreground, Color background) : base(foreground, background, '@') + { + + } + } +} diff --git a/src/GameJamSadConsoleSample/TileBase.cs b/src/GameJamSadConsoleSample/TileBase.cs new file mode 100644 index 0000000..513eead --- /dev/null +++ b/src/GameJamSadConsoleSample/TileBase.cs @@ -0,0 +1,23 @@ +using System; +using Microsoft.Xna.Framework; +using SadConsole; + +namespace GameJamSadConsoleSample +{ + + public abstract class TileBase : Cell + { + + public bool IsBlockingMove; + public bool IsBlockingLOS; + + protected string Name; + + public TileBase(Color foreground, Color background, int glyph, bool blockingMove=false, bool blockingLOS=false, String name="") : base(foreground, background, glyph) + { + IsBlockingMove = blockingMove; + IsBlockingLOS = blockingLOS; + Name = name; + } + } +} diff --git a/src/GameJamSadConsoleSample/TileFloor.cs b/src/GameJamSadConsoleSample/TileFloor.cs new file mode 100644 index 0000000..dd62c71 --- /dev/null +++ b/src/GameJamSadConsoleSample/TileFloor.cs @@ -0,0 +1,12 @@ +using Microsoft.Xna.Framework; + +namespace GameJamSadConsoleSample +{ + public class TileFloor : TileBase + { + public TileFloor(bool blocksMovement = false, bool blocksLOS = false) : base(Color.DarkGray, Color.Transparent, '.', blocksMovement, blocksLOS) + { + Name = "Floor"; + } + } +} diff --git a/src/GameJamSadConsoleSample/TileWall.cs b/src/GameJamSadConsoleSample/TileWall.cs new file mode 100644 index 0000000..5fcb393 --- /dev/null +++ b/src/GameJamSadConsoleSample/TileWall.cs @@ -0,0 +1,12 @@ +using Microsoft.Xna.Framework; + +namespace GameJamSadConsoleSample +{ + public class TileWall : TileBase + { + public TileWall( int glyph, bool blocksMovement=true, bool blocksLOS=true) : base(Color.LightGray, Color.Transparent, glyph, blocksMovement, blocksLOS) + { + Name = "Wall"; + } + } +}