diff --git a/Game/.gitignore b/.gitignore similarity index 94% rename from Game/.gitignore rename to .gitignore index 104b544..5e57f18 100644 --- a/Game/.gitignore +++ b/.gitignore @@ -1,484 +1,484 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from `dotnet new gitignore` - -# dotenv files -.env - -# User-specific files -*.rsuser -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Mono auto generated files -mono_crash.* - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -[Ww][Ii][Nn]32/ -[Aa][Rr][Mm]/ -[Aa][Rr][Mm]64/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ -[Ll]ogs/ - -# Visual Studio 2015/2017 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# Visual Studio 2017 auto generated files -Generated\ Files/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUnit -*.VisualState.xml -TestResult.xml -nunit-*.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# Benchmark Results -BenchmarkDotNet.Artifacts/ - -# .NET -project.lock.json -project.fragment.lock.json -artifacts/ - -# Tye -.tye/ - -# ASP.NET Scaffolding -ScaffoldingReadMe.txt - -# StyleCop -StyleCopReport.xml - -# Files built by Visual Studio -*_i.c -*_p.c -*_h.h -*.ilk -*.meta -*.obj -*.iobj -*.pch -*.pdb -*.ipdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*_wpftmp.csproj -*.log -*.tlog -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# Visual Studio Trace Files -*.e2e - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# AxoCover is a Code Coverage Tool -.axoCover/* -!.axoCover/settings.json - -# Coverlet is a free, cross platform Code Coverage Tool -coverage*.json -coverage*.xml -coverage*.info - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# 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 -*.[Pp]ublish.xml -*.azurePubxml -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# NuGet Symbol Packages -*.snupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/[Pp]ackages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt -*.appx -*.appxbundle -*.appxupload - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!?*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -orleans.codegen.cs - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) -#*.snk - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# 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 -ServiceFabricBackup/ -*.rptproj.bak - -# SQL Server files -*.mdf -*.ldf -*.ndf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings -*.rptproj.rsuser -*- [Bb]ackup.rdl -*- [Bb]ackup ([0-9]).rdl -*- [Bb]ackup ([0-9][0-9]).rdl - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat -node_modules/ - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio 6 auto-generated project file (contains which files were open etc.) -*.vbp - -# Visual Studio 6 workspace and project file (working project files containing files to include in project) -*.dsw -*.dsp - -# Visual Studio 6 technical files -*.ncb -*.aps - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# CodeRush personal settings -.cr/personal - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Tabs Studio -*.tss - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs - -# OpenCover UI analysis results -OpenCover/ - -# Azure Stream Analytics local run output -ASALocalRun/ - -# MSBuild Binary and Structured Log -*.binlog - -# NVidia Nsight GPU debugger configuration file -*.nvuser - -# MFractors (Xamarin productivity tool) working folder -.mfractor/ - -# Local History for Visual Studio -.localhistory/ - -# Visual Studio History (VSHistory) files -.vshistory/ - -# BeatPulse healthcheck temp database -healthchecksdb - -# Backup folder for Package Reference Convert tool in Visual Studio 2017 -MigrationBackup/ - -# Ionide (cross platform F# VS Code tools) working folder -.ionide/ - -# Fody - auto-generated XML schema -FodyWeavers.xsd - -# VS Code files for those working on multiple tools -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -*.code-workspace - -# Local History for Visual Studio Code -.history/ - -# Windows Installer files from build outputs -*.cab -*.msi -*.msix -*.msm -*.msp - -# JetBrains Rider -*.sln.iml -.idea - -## -## Visual studio for Mac -## - - -# globs -Makefile.in -*.userprefs -*.usertasks -config.make -config.status -aclocal.m4 -install-sh -autom4te.cache/ -*.tar.gz -tarballs/ -test-results/ - -# Mac bundle stuff -*.dmg -*.app - -# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore -# Windows thumbnail cache files -Thumbs.db -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# Vim temporary swap files -*.swp +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from `dotnet new gitignore` + +# dotenv files +.env + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET +project.lock.json +project.fragment.lock.json +artifacts/ + +# Tye +.tye/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# 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 +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# 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 +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml +.idea + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# Vim temporary swap files +*.swp diff --git a/Engine b/Engine index ef21cdf..c135035 160000 --- a/Engine +++ b/Engine @@ -1 +1 @@ -Subproject commit ef21cdf2138a2f5107a628c0fe970b88bc03dcfd +Subproject commit c135035d5b72730a71665de3c9f27611880f32c8 diff --git a/Game/.vscode/launch.json b/Game/.vscode/launch.json deleted file mode 100644 index cfb97f2..0000000 --- a/Game/.vscode/launch.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": ".NET Core Launch (console)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/bin/Debug/net8.0/${workspaceFolderBasename}.dll", - "args": [], - "cwd": "${workspaceFolder}", - // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console - "console": "internalConsole", - "stopAtEntry": false - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach", - "processId": "${command:pickProcess}" - } - ] -} diff --git a/Game/.vscode/settings.json b/Game/.vscode/settings.json deleted file mode 100644 index f39a2ca..0000000 --- a/Game/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "cSpell.words": [ - "AABB", - "DAABB", - "Syntriax" - ] -} diff --git a/Game/.vscode/tasks.json b/Game/.vscode/tasks.json deleted file mode 100644 index e324491..0000000 --- a/Game/.vscode/tasks.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "type": "dotnet", - "task": "build", - "problemMatcher": ["$msCompile"], - "group": { - "kind": "build", - "isDefault": true - }, - "label": "build" - } - ] -} diff --git a/Game/GamePong.cs b/Game/GamePong.cs deleted file mode 100644 index b5e4e7c..0000000 --- a/Game/GamePong.cs +++ /dev/null @@ -1,168 +0,0 @@ -using System; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; - -using Pong.Behaviours; -using Apos.Shapes; - -using Syntriax.Engine.Core; -using Syntriax.Engine.Core.Abstract; -using Syntriax.Engine.Physics2D; -using Syntriax.Engine.Physics2D.Primitives; -using Syntriax.Engine.Physics2D.Abstract; - -namespace Pong; - -public class GamePong : Game -{ - private readonly GraphicsDeviceManager graphics = null!; - private IPhysicsEngine2D physicsEngine = null!; - private SpriteBatch spriteBatch = null!; - private ShapeBatch shapeBatch = null!; - - private GameManager gameManager = null!; - private BehaviourCollector displayableCollector = null!; - private BehaviourCollector displayableShapeCollector = null!; - private MonoGameCamera2DBehaviour cameraBehaviour = null!; - - private PongManagerBehaviour pongManager = null!; - - private float physicsTimer = 0f; - - public GamePong() - { - graphics = new GraphicsDeviceManager(this) - { - PreferredBackBufferWidth = 1024, - PreferredBackBufferHeight = 576, - GraphicsProfile = GraphicsProfile.HiDef - }; - - Content.RootDirectory = "Content"; - IsMouseVisible = true; - } - - protected override void Initialize() - { - // TODO: Add your initialization logic here - gameManager = new(); - displayableCollector = new(gameManager); - displayableShapeCollector = new(gameManager); - physicsEngine = new PhysicsEngine2DCollector(gameManager) { IterationPerStep = 3 }; - - gameManager.Initialize(); - - base.Initialize(); - } - - protected override void LoadContent() - { - spriteBatch = new SpriteBatch(GraphicsDevice); - shapeBatch = new ShapeBatch(GraphicsDevice, Content); - SpriteFont spriteFont = Content.Load("UbuntuMono"); - - //////////////////////////////////////////////////////////////////////////////////// - - IGameObject gameObjectCamera = gameManager.InstantiateGameObject().SetGameObject("Camera"); ; - gameObjectCamera.BehaviourController.AddBehaviour(); - cameraBehaviour = gameObjectCamera.BehaviourController.AddBehaviour(graphics); - - //////////////////////////////////////////////////////////////////////////////////// - - IGameObject gameObjectPongManager = gameManager.InstantiateGameObject().SetGameObject("Pong Game Manager"); - pongManager = gameObjectPongManager.BehaviourController.AddBehaviour(5); - - //////////////////////////////////////////////////////////////////////////////////// - - IGameObject gameObjectBall = gameManager.InstantiateGameObject().SetGameObject("Ball"); - gameObjectBall.Transform.SetTransform(position: new Vector2D(0, 0f), scale: new Vector2D(10f, 10f)); - - gameObjectBall.BehaviourController.AddBehaviour(new Circle(Vector2D.Zero, 1f)); - gameObjectBall.BehaviourController.AddBehaviour(); - gameObjectBall.BehaviourController.AddBehaviour(); - - //////////////////////////////////////////////////////////////////////////////////// - - IGameObject gameObjectLeftPaddle = gameManager.InstantiateGameObject().SetGameObject("Left Paddle"); - gameObjectLeftPaddle.Transform.SetTransform(position: new Vector2D(-468f, 0f), scale: new Vector2D(15f, 60f)); - - gameObjectLeftPaddle.BehaviourController.AddBehaviour(Keys.W, Keys.S, 228f, -228f, 400f); - gameObjectLeftPaddle.BehaviourController.AddBehaviour(Shape.Box); - gameObjectLeftPaddle.BehaviourController.AddBehaviour().IsStatic = true; - - IGameObject gameObjectRightPaddle = gameManager.InstantiateGameObject().SetGameObject("Right Paddle"); - gameObjectRightPaddle.Transform.SetTransform(position: new Vector2D(468f, 0f), scale: new Vector2D(15f, 60f)); - gameObjectRightPaddle.BehaviourController.AddBehaviour(Keys.Up, Keys.Down, 228f, -228f, 400f); - gameObjectRightPaddle.BehaviourController.AddBehaviour(Shape.Box); - gameObjectRightPaddle.BehaviourController.AddBehaviour().IsStatic = true; - - //////////////////////////////////////////////////////////////////////////////////// - - IGameObject gameObjectWallTop = gameManager.InstantiateGameObject().SetGameObject("Wall Top"); - gameObjectWallTop.Transform.SetTransform(position: new Vector2D(0f, 308f), scale: new Vector2D(552f, 20f)); - gameObjectWallTop.BehaviourController.AddBehaviour(Shape.Box); - gameObjectWallTop.BehaviourController.AddBehaviour().IsStatic = true; - - IGameObject gameObjectWallBottom = gameManager.InstantiateGameObject().SetGameObject("Wall Bottom"); - gameObjectWallBottom.Transform.SetTransform(position: new Vector2D(0f, -308f), scale: new Vector2D(552f, 20f)); - gameObjectWallBottom.BehaviourController.AddBehaviour(Shape.Box); - gameObjectWallBottom.BehaviourController.AddBehaviour().IsStatic = true; - - IGameObject gameObjectWallRight = gameManager.InstantiateGameObject().SetGameObject("Wall Right"); - gameObjectWallRight.Transform.SetTransform(position: new Vector2D(532f, 0f), scale: new Vector2D(20f, 328f)); - gameObjectWallRight.BehaviourController.AddBehaviour((Action)pongManager.ScoreToLeft); - gameObjectWallRight.BehaviourController.AddBehaviour(Shape.Box); - gameObjectWallRight.BehaviourController.AddBehaviour().IsStatic = true; - - IGameObject gameObjectWallLeft = gameManager.InstantiateGameObject().SetGameObject("Wall Left"); - gameObjectWallLeft.Transform.SetTransform(position: new Vector2D(-532f, 0f), scale: new Vector2D(20f, 328f)); - gameObjectWallLeft.BehaviourController.AddBehaviour((Action)pongManager.ScoreToRight); - gameObjectWallLeft.BehaviourController.AddBehaviour(Shape.Box); - gameObjectWallLeft.BehaviourController.AddBehaviour().IsStatic = true; - - //////////////////////////////////////////////////////////////////////////////////// - - IGameObject gameObjectLeftScoreText = gameManager.InstantiateGameObject().SetGameObject("Score Left"); - gameObjectLeftScoreText.Transform.SetTransform(position: new Vector2D(-250f, 250f), scale: Vector2D.One * .25f); - gameObjectLeftScoreText.BehaviourController.AddBehaviour(true, spriteFont); - - IGameObject gameObjectRightScoreText = gameManager.InstantiateGameObject().SetGameObject("Score Right"); - gameObjectRightScoreText.Transform.SetTransform(position: new Vector2D(250f, 250f), scale: Vector2D.One * .25f); - gameObjectRightScoreText.BehaviourController.AddBehaviour(false, spriteFont); - } - - protected override void Update(GameTime gameTime) - { - if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) - Exit(); - - gameManager.Update(gameTime.ToEngineTime()); - while (physicsTimer + 0.01f < gameTime.TotalGameTime.TotalMilliseconds * .001f)//seconds) - { - physicsTimer += 0.01f; - physicsEngine.Step(.01f); - } - base.Update(gameTime); - } - - protected override void Draw(GameTime gameTime) - { - GraphicsDevice.Clear(new Color() { R = 32, G = 32, B = 32 }); - - // TODO: Add your drawing code here - gameManager.PreDraw(); - - spriteBatch.Begin(SpriteSortMode.Deferred, transformMatrix: cameraBehaviour.MatrixTransform); - foreach (var displayable in displayableCollector) - displayable.Draw(spriteBatch); - spriteBatch.End(); - - shapeBatch.Begin(cameraBehaviour.MatrixTransform); - foreach (var displayableShape in displayableShapeCollector) - displayableShape.Draw(shapeBatch); - shapeBatch.End(); - - base.Draw(gameTime); - } -} diff --git a/Game/Program.cs b/Game/Program.cs deleted file mode 100644 index d379b45..0000000 --- a/Game/Program.cs +++ /dev/null @@ -1,3 +0,0 @@ - -using var game = new Pong.GamePong(); -game.Run(); diff --git a/Game/.config/dotnet-tools.json b/Platforms/Desktop/.config/dotnet-tools.json similarity index 76% rename from Game/.config/dotnet-tools.json rename to Platforms/Desktop/.config/dotnet-tools.json index efabe22..84ff03d 100644 --- a/Game/.config/dotnet-tools.json +++ b/Platforms/Desktop/.config/dotnet-tools.json @@ -3,31 +3,31 @@ "isRoot": true, "tools": { "dotnet-mgcb": { - "version": "3.8.1.303", + "version": "3.8.2.1105", "commands": [ "mgcb" ] }, "dotnet-mgcb-editor": { - "version": "3.8.1.303", + "version": "3.8.2.1105", "commands": [ "mgcb-editor" ] }, "dotnet-mgcb-editor-linux": { - "version": "3.8.1.303", + "version": "3.8.2.1105", "commands": [ "mgcb-editor-linux" ] }, "dotnet-mgcb-editor-windows": { - "version": "3.8.1.303", + "version": "3.8.2.1105", "commands": [ "mgcb-editor-windows" ] }, "dotnet-mgcb-editor-mac": { - "version": "3.8.1.303", + "version": "3.8.2.1105", "commands": [ "mgcb-editor-mac" ] diff --git a/Platforms/Desktop/Content/Content.mgcb b/Platforms/Desktop/Content/Content.mgcb new file mode 100644 index 0000000..ddc4c36 --- /dev/null +++ b/Platforms/Desktop/Content/Content.mgcb @@ -0,0 +1,15 @@ + +#----------------------------- Global Properties ----------------------------# + +/outputDir:bin/$(Platform) +/intermediateDir:obj/$(Platform) +/platform:DesktopGL +/config: +/profile:Reach +/compress:False + +#-------------------------------- References --------------------------------# + + +#---------------------------------- Content ---------------------------------# + diff --git a/Game/Game.csproj b/Platforms/Desktop/Desktop.csproj similarity index 59% rename from Game/Game.csproj rename to Platforms/Desktop/Desktop.csproj index f15750f..89d8332 100644 --- a/Game/Game.csproj +++ b/Platforms/Desktop/Desktop.csproj @@ -6,6 +6,7 @@ false false enable + Pong.Platforms.Desktop app.manifest @@ -16,18 +17,28 @@ - - + + Icon.ico + + + Icon.bmp + - - - + + - - - + + + + + + Content/Content.mgcb + + + + diff --git a/Game/Icon.bmp b/Platforms/Desktop/Icon.bmp similarity index 100% rename from Game/Icon.bmp rename to Platforms/Desktop/Icon.bmp diff --git a/Game/Icon.ico b/Platforms/Desktop/Icon.ico similarity index 100% rename from Game/Icon.ico rename to Platforms/Desktop/Icon.ico diff --git a/Game/Behaviours/KeyboardInputsBehaviour.cs b/Platforms/Desktop/KeyboardInputsBehaviour.cs similarity index 69% rename from Game/Behaviours/KeyboardInputsBehaviour.cs rename to Platforms/Desktop/KeyboardInputsBehaviour.cs index 46bf534..8d94fdb 100644 --- a/Game/Behaviours/KeyboardInputsBehaviour.cs +++ b/Platforms/Desktop/KeyboardInputsBehaviour.cs @@ -4,14 +4,14 @@ using System.Collections.Generic; using Microsoft.Xna.Framework.Input; using Syntriax.Engine.Core; -using Syntriax.Engine.Input; +using Syntriax.Engine.Systems.Input; -namespace Pong.Behaviours; +namespace Pong.Platforms.Desktop; -public class KeyboardInputsBehaviour : BehaviourOverride, IButtonInputs +public class KeyboardInputsBehaviour : Behaviour, IButtonInputs { - private readonly Dictionary, Keys>> OnPressed = new(256); - private readonly Dictionary, Keys>> OnReleased = new(256); + private readonly Dictionary.ButtonCallbackEventHandler> OnPressed = new(256); + private readonly Dictionary.ButtonCallbackEventHandler> OnReleased = new(256); private int cachePressedCurrentlyCount = 0; private readonly Keys[] cachePressedCurrently = new Keys[256]; @@ -19,7 +19,10 @@ public class KeyboardInputsBehaviour : BehaviourOverride, IButtonInputs private int cachePressedPreviouslyCount = 0; private readonly Keys[] cachePressedPreviously = new Keys[256]; - public void RegisterOnPress(Keys key, Action, Keys> callback) + public event IButtonInputs.ButtonCallbackEventHandler? OnAnyButtonPressed = null; + public event IButtonInputs.ButtonCallbackEventHandler? OnAnyButtonReleased = null; + + public void RegisterOnPress(Keys key, IButtonInputs.ButtonCallbackEventHandler callback) { if (OnPressed.TryGetValue(key, out var action)) { @@ -30,13 +33,13 @@ public class KeyboardInputsBehaviour : BehaviourOverride, IButtonInputs OnPressed.Add(key, callback); } - public void UnregisterOnPress(Keys key, Action, Keys> callback) + public void UnregisterOnPress(Keys key, IButtonInputs.ButtonCallbackEventHandler callback) { if (OnPressed.TryGetValue(key, out var action)) action -= callback; } - public void RegisterOnRelease(Keys key, Action, Keys> callback) + public void RegisterOnRelease(Keys key, IButtonInputs.ButtonCallbackEventHandler callback) { if (OnReleased.TryGetValue(key, out var action)) { @@ -47,7 +50,7 @@ public class KeyboardInputsBehaviour : BehaviourOverride, IButtonInputs OnReleased.Add(key, callback); } - public void UnregisterOnRelease(Keys key, Action, Keys> callback) + public void UnregisterOnRelease(Keys key, IButtonInputs.ButtonCallbackEventHandler callback) { if (OnReleased.TryGetValue(key, out var action)) action -= callback; @@ -70,6 +73,7 @@ public class KeyboardInputsBehaviour : BehaviourOverride, IButtonInputs continue; action.Invoke(this, currentlyPressedKey); + OnAnyButtonPressed?.Invoke(this, currentlyPressedKey); } for (int i = 0; i < cachePressedPreviouslyCount; i++) @@ -83,6 +87,7 @@ public class KeyboardInputsBehaviour : BehaviourOverride, IButtonInputs continue; action.Invoke(this, previouslyPressedKey); + OnAnyButtonReleased?.Invoke(this, previouslyPressedKey); } Array.Copy(cachePressedCurrently, cachePressedPreviously, cachePressedCurrentlyCount); diff --git a/Platforms/Desktop/Program.cs b/Platforms/Desktop/Program.cs new file mode 100644 index 0000000..a3e4e99 --- /dev/null +++ b/Platforms/Desktop/Program.cs @@ -0,0 +1,7 @@ +using Pong.Platforms.Desktop; +using Syntriax.Engine.Core; + +Syntriax.Engine.Core.Abstract.IHierarchyObject hierarchyObject = Syntriax.Engine.Core.Factory.HierarchyObjectFactory.Instantiate().SetHierarchyObject("Desktop HO"); +hierarchyObject.BehaviourController.AddBehaviour(); +using var game = new Pong.GamePong(hierarchyObject); +game.Run(); diff --git a/Game/app.manifest b/Platforms/Desktop/app.manifest similarity index 96% rename from Game/app.manifest rename to Platforms/Desktop/app.manifest index 1faf258..ede0b4e 100644 --- a/Game/app.manifest +++ b/Platforms/Desktop/app.manifest @@ -1,6 +1,6 @@  - + diff --git a/Pong.sln b/Pong.sln index f5561fd..156c86a 100644 --- a/Pong.sln +++ b/Pong.sln @@ -7,41 +7,57 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Engine", "Engine", "{F7F626 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Core", "Engine\Engine.Core\Engine.Core.csproj", "{990CA10C-1EBB-4395-A43A-456B7029D8C9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Game", "Game\Game.csproj", "{500E1B05-39D7-4232-8051-E7351D745306}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Input", "Engine\Engine.Input\Engine.Input.csproj", "{7EED4EC3-79D5-4C6C-A54D-1B396213C0E4}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Physics2D", "Engine\Engine.Physics2D\Engine.Physics2D.csproj", "{0D97F83C-B043-48B1-B155-7354C4E84FC0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine", "Engine\Engine\Engine.csproj", "{2F6B1E26-1217-4EFD-874C-05ADEE4C7969}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{590E392E-9FB3-49FA-B4DA-6C8F7126FFE5}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Platforms", "Platforms", "{FECFFD54-338F-4060-9161-1E5770D1DC33}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Desktop", "Platforms\Desktop\Desktop.csproj", "{2B627F66-5A61-4F69-B479-62EEAB603D01}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Systems", "Engine\Engine.Systems\Engine.Systems.csproj", "{8863A1BA-2E83-419F-BACB-D4A4156EC71C}" +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 {990CA10C-1EBB-4395-A43A-456B7029D8C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {990CA10C-1EBB-4395-A43A-456B7029D8C9}.Debug|Any CPU.Build.0 = Debug|Any CPU {990CA10C-1EBB-4395-A43A-456B7029D8C9}.Release|Any CPU.ActiveCfg = Release|Any CPU {990CA10C-1EBB-4395-A43A-456B7029D8C9}.Release|Any CPU.Build.0 = Release|Any CPU - {500E1B05-39D7-4232-8051-E7351D745306}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {500E1B05-39D7-4232-8051-E7351D745306}.Debug|Any CPU.Build.0 = Debug|Any CPU - {500E1B05-39D7-4232-8051-E7351D745306}.Release|Any CPU.ActiveCfg = Release|Any CPU - {500E1B05-39D7-4232-8051-E7351D745306}.Release|Any CPU.Build.0 = Release|Any CPU - {7EED4EC3-79D5-4C6C-A54D-1B396213C0E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7EED4EC3-79D5-4C6C-A54D-1B396213C0E4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7EED4EC3-79D5-4C6C-A54D-1B396213C0E4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7EED4EC3-79D5-4C6C-A54D-1B396213C0E4}.Release|Any CPU.Build.0 = Release|Any CPU {0D97F83C-B043-48B1-B155-7354C4E84FC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0D97F83C-B043-48B1-B155-7354C4E84FC0}.Debug|Any CPU.Build.0 = Debug|Any CPU {0D97F83C-B043-48B1-B155-7354C4E84FC0}.Release|Any CPU.ActiveCfg = Release|Any CPU {0D97F83C-B043-48B1-B155-7354C4E84FC0}.Release|Any CPU.Build.0 = Release|Any CPU + {2F6B1E26-1217-4EFD-874C-05ADEE4C7969}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2F6B1E26-1217-4EFD-874C-05ADEE4C7969}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2F6B1E26-1217-4EFD-874C-05ADEE4C7969}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2F6B1E26-1217-4EFD-874C-05ADEE4C7969}.Release|Any CPU.Build.0 = Release|Any CPU + {590E392E-9FB3-49FA-B4DA-6C8F7126FFE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {590E392E-9FB3-49FA-B4DA-6C8F7126FFE5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {590E392E-9FB3-49FA-B4DA-6C8F7126FFE5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {590E392E-9FB3-49FA-B4DA-6C8F7126FFE5}.Release|Any CPU.Build.0 = Release|Any CPU + {2B627F66-5A61-4F69-B479-62EEAB603D01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2B627F66-5A61-4F69-B479-62EEAB603D01}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2B627F66-5A61-4F69-B479-62EEAB603D01}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2B627F66-5A61-4F69-B479-62EEAB603D01}.Release|Any CPU.Build.0 = Release|Any CPU + {8863A1BA-2E83-419F-BACB-D4A4156EC71C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8863A1BA-2E83-419F-BACB-D4A4156EC71C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8863A1BA-2E83-419F-BACB-D4A4156EC71C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8863A1BA-2E83-419F-BACB-D4A4156EC71C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {990CA10C-1EBB-4395-A43A-456B7029D8C9} = {F7F62670-237A-4C93-A30E-CE661C6FC401} - {7EED4EC3-79D5-4C6C-A54D-1B396213C0E4} = {F7F62670-237A-4C93-A30E-CE661C6FC401} {0D97F83C-B043-48B1-B155-7354C4E84FC0} = {F7F62670-237A-4C93-A30E-CE661C6FC401} + {2F6B1E26-1217-4EFD-874C-05ADEE4C7969} = {F7F62670-237A-4C93-A30E-CE661C6FC401} + {2B627F66-5A61-4F69-B479-62EEAB603D01} = {FECFFD54-338F-4060-9161-1E5770D1DC33} + {8863A1BA-2E83-419F-BACB-D4A4156EC71C} = {F7F62670-237A-4C93-A30E-CE661C6FC401} EndGlobalSection EndGlobal diff --git a/Shared/.config/dotnet-tools.json b/Shared/.config/dotnet-tools.json new file mode 100644 index 0000000..84ff03d --- /dev/null +++ b/Shared/.config/dotnet-tools.json @@ -0,0 +1,36 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-mgcb": { + "version": "3.8.2.1105", + "commands": [ + "mgcb" + ] + }, + "dotnet-mgcb-editor": { + "version": "3.8.2.1105", + "commands": [ + "mgcb-editor" + ] + }, + "dotnet-mgcb-editor-linux": { + "version": "3.8.2.1105", + "commands": [ + "mgcb-editor-linux" + ] + }, + "dotnet-mgcb-editor-windows": { + "version": "3.8.2.1105", + "commands": [ + "mgcb-editor-windows" + ] + }, + "dotnet-mgcb-editor-mac": { + "version": "3.8.2.1105", + "commands": [ + "mgcb-editor-mac" + ] + } + } +} \ No newline at end of file diff --git a/Game/Abstract/IDisplayableShape.cs b/Shared/Abstract/IDisplayableShape.cs similarity index 100% rename from Game/Abstract/IDisplayableShape.cs rename to Shared/Abstract/IDisplayableShape.cs diff --git a/Game/Abstract/IDisplayableSprite.cs b/Shared/Abstract/IDisplayableSprite.cs similarity index 100% rename from Game/Abstract/IDisplayableSprite.cs rename to Shared/Abstract/IDisplayableSprite.cs diff --git a/Game/Behaviours/BallBehaviour.cs b/Shared/Behaviours/BallBehaviour.cs similarity index 80% rename from Game/Behaviours/BallBehaviour.cs rename to Shared/Behaviours/BallBehaviour.cs index 2e6ff53..68dfa4e 100644 --- a/Game/Behaviours/BallBehaviour.cs +++ b/Shared/Behaviours/BallBehaviour.cs @@ -6,7 +6,7 @@ using Syntriax.Engine.Physics2D.Abstract; namespace Pong.Behaviours; -public class BallBehaviour : BehaviourOverride +public class BallBehaviour : Behaviour2D { public Vector2D StartDirection { get; private set; } = Vector2D.Zero; public float Speed { get; set; } = 500f; @@ -18,15 +18,15 @@ public class BallBehaviour : BehaviourOverride protected override void OnFirstActiveFrame() { if (!BehaviourController.TryGetBehaviour(out IRigidBody2D? foundRigidBody)) - throw new Exception($"{nameof(IRigidBody2D)} is missing on {GameObject.Name}."); + throw new Exception($"{nameof(IRigidBody2D)} is missing on {HierarchyObject.Name}."); if (!BehaviourController.TryGetBehaviour(out ICollider2D? foundCollider)) - throw new Exception($"{nameof(ICollider2D)} is missing on {GameObject.Name}."); + throw new Exception($"{nameof(ICollider2D)} is missing on {HierarchyObject.Name}."); foundCollider.OnCollisionDetected += OnCollisionDetected; rigidBody = foundRigidBody; - if (GameObject.GameManager.TryFindBehaviour(out PongManagerBehaviour? pongManager)) + if (HierarchyObject.GameManager.TryFindBehaviour(out PongManagerBehaviour? pongManager)) { pongManager.OnReset += ResetBall; pongManager.OnScored += ResetBall; @@ -36,14 +36,14 @@ public class BallBehaviour : BehaviourOverride private void DisableBall(PongManagerBehaviour pongManager) { - BehaviourController.GameObject.Transform.Position = Vector2D.Zero; + Transform.Position = Vector2D.Zero; rigidBody.Velocity = Vector2D.Zero; } private void ResetBall(PongManagerBehaviour pongManager) { StateEnable.Enabled = true; - BehaviourController.GameObject.Transform.Position = Vector2D.Zero; + Transform.Position = Vector2D.Zero; rigidBody.Velocity = GetRandomDirection() * Speed; } @@ -60,14 +60,14 @@ public class BallBehaviour : BehaviourOverride if (rigidBody.Velocity.MagnitudeSquared <= 0.01f) return; - Vector2D speedUp = rigidBody.Velocity.Normalized * Time.DeltaTimeFrame; + Vector2D speedUp = rigidBody.Velocity.Normalized * GameManager.Time.DeltaTime; rigidBody.Velocity += speedUp * SpeedUpMultiplier; } private void OnCollisionDetected(ICollider2D collider2D, CollisionDetectionInformation information) { if (Syntriax.Engine.Core.Math.Abs(information.Normal.Dot(Vector2D.Right)) > .25) - rigidBody.Velocity = information.Left.Transform.Position.FromTo(information.Right.Transform.Position).Normalized * rigidBody.Velocity.Magnitude; + rigidBody.Velocity = information.Detected.Transform.Position.FromTo(information.Detector.Transform.Position).Normalized * rigidBody.Velocity.Magnitude; else rigidBody.Velocity = rigidBody.Velocity.Reflect(information.Normal); } diff --git a/Game/Behaviours/CameraController.cs b/Shared/Behaviours/CameraController.cs similarity index 64% rename from Game/Behaviours/CameraController.cs rename to Shared/Behaviours/CameraController.cs index 6235943..c2f2123 100644 --- a/Game/Behaviours/CameraController.cs +++ b/Shared/Behaviours/CameraController.cs @@ -1,11 +1,11 @@ using Microsoft.Xna.Framework.Input; using Syntriax.Engine.Core; -using Syntriax.Engine.Input; +using Syntriax.Engine.Systems.Input; namespace Pong.Behaviours; -public class CameraController : BehaviourOverride +public class CameraController : Behaviour { private MonoGameCamera2DBehaviour cameraBehaviour = null!; private IButtonInputs buttonInputs = null!; @@ -19,10 +19,7 @@ public class CameraController : BehaviourOverride cameraBehaviour ??= BehaviourController.AddBehaviour(); - if (BehaviourController.TryGetBehaviour(out IButtonInputs? foundButtonInputs)) - buttonInputs = foundButtonInputs; - - buttonInputs ??= BehaviourController.AddBehaviour(); + buttonInputs = GameManager.FindBehaviour>() ?? throw new("Unable to find inputs"); buttonInputs.RegisterOnPress(Keys.F, SwitchToFullScreen); buttonInputs.RegisterOnPress(Keys.R, ResetCamera); } @@ -30,21 +27,21 @@ public class CameraController : BehaviourOverride protected override void OnUpdate() { if (buttonInputs.IsPressed(Keys.U)) - cameraBehaviour.Zoom += Time.Elapsed.Nanoseconds * 0.00025f; + cameraBehaviour.Zoom += GameManager.Time.DeltaTime * 5f; if (buttonInputs.IsPressed(Keys.J)) - cameraBehaviour.Zoom -= Time.Elapsed.Nanoseconds * 0.00025f; + cameraBehaviour.Zoom -= GameManager.Time.DeltaTime * 5f; - if (buttonInputs.IsPressed(Keys.NumPad8)) cameraBehaviour.BehaviourController.GameObject.Transform.Position += Vector2D.Up.Rotate(Transform.Rotation * Math.DegreeToRadian) * Time.DeltaTimeFrame; - if (buttonInputs.IsPressed(Keys.NumPad2)) cameraBehaviour.BehaviourController.GameObject.Transform.Position -= Vector2D.Up.Rotate(Transform.Rotation * Math.DegreeToRadian) * Time.DeltaTimeFrame; - if (buttonInputs.IsPressed(Keys.NumPad6)) cameraBehaviour.BehaviourController.GameObject.Transform.Position += Vector2D.Right.Rotate(Transform.Rotation * Math.DegreeToRadian) * Time.DeltaTimeFrame; - if (buttonInputs.IsPressed(Keys.NumPad4)) cameraBehaviour.BehaviourController.GameObject.Transform.Position -= Vector2D.Right.Rotate(Transform.Rotation * Math.DegreeToRadian) * Time.DeltaTimeFrame; + if (buttonInputs.IsPressed(Keys.NumPad8)) cameraBehaviour.Transform.LocalPosition += Vector2D.Up * GameManager.Time.DeltaTime * 500f; + if (buttonInputs.IsPressed(Keys.NumPad2)) cameraBehaviour.Transform.LocalPosition -= Vector2D.Up * GameManager.Time.DeltaTime * 500f; + if (buttonInputs.IsPressed(Keys.NumPad6)) cameraBehaviour.Transform.LocalPosition += Vector2D.Right * GameManager.Time.DeltaTime * 500f; + if (buttonInputs.IsPressed(Keys.NumPad4)) cameraBehaviour.Transform.LocalPosition -= Vector2D.Right * GameManager.Time.DeltaTime * 500f; if (buttonInputs.IsPressed(Keys.Q)) - cameraBehaviour.BehaviourController.GameObject.Transform.Rotation += Time.Elapsed.Nanoseconds * 0.0025f; + cameraBehaviour.Transform.Rotation += GameManager.Time.DeltaTime * 45f; if (buttonInputs.IsPressed(Keys.E)) - cameraBehaviour.BehaviourController.GameObject.Transform.Rotation -= Time.Elapsed.Nanoseconds * 0.0025f; + cameraBehaviour.Transform.Rotation -= GameManager.Time.DeltaTime * 45f; } private void SwitchToFullScreen(IButtonInputs inputs, Keys keys) @@ -68,7 +65,7 @@ public class CameraController : BehaviourOverride private void ResetCamera(IButtonInputs inputs, Keys keys) { cameraBehaviour.Zoom = defaultZoomLevel; - Transform.Position = Vector2D.Zero; - Transform.Rotation = 0f; + cameraBehaviour.Transform.LocalPosition = Vector2D.Zero; + cameraBehaviour.Transform.LocalRotation = 0f; } } diff --git a/Game/Behaviours/CircleBehaviour.cs b/Shared/Behaviours/CircleBehaviour.cs similarity index 95% rename from Game/Behaviours/CircleBehaviour.cs rename to Shared/Behaviours/CircleBehaviour.cs index ae224ff..bd03642 100644 --- a/Game/Behaviours/CircleBehaviour.cs +++ b/Shared/Behaviours/CircleBehaviour.cs @@ -2,8 +2,8 @@ using Microsoft.Xna.Framework; using Apos.Shapes; +using Syntriax.Engine.Core; using Syntriax.Engine.Core.Abstract; -using Syntriax.Engine.Physics2D.Primitives; namespace Pong.Behaviours; diff --git a/Game/Behaviours/MonoGameCamera2DBehaviour.cs b/Shared/Behaviours/MonoGameCamera2DBehaviour.cs similarity index 88% rename from Game/Behaviours/MonoGameCamera2DBehaviour.cs rename to Shared/Behaviours/MonoGameCamera2DBehaviour.cs index 7feb1fe..9a7e13f 100644 --- a/Game/Behaviours/MonoGameCamera2DBehaviour.cs +++ b/Shared/Behaviours/MonoGameCamera2DBehaviour.cs @@ -6,7 +6,7 @@ using Syntriax.Engine.Core.Abstract; namespace Pong.Behaviours; -public class MonoGameCamera2DBehaviour(GraphicsDeviceManager Graphics) : BehaviourOverride, ICamera2D +public class MonoGameCamera2DBehaviour(GraphicsDeviceManager Graphics) : Behaviour2D, ICamera2D { public event OnMatrixTransformChangedDelegate? OnMatrixTransformChanged = null; public event OnViewportChangedDelegate? OnViewportChanged = null; @@ -72,10 +72,6 @@ public class MonoGameCamera2DBehaviour(GraphicsDeviceManager Graphics) : Behavio set => Transform.Rotation = value; } - public event IAssignableTransform.OnTransformAssignedDelegate? OnTransformAssigned { add => GameObject.OnTransformAssigned += value; remove => GameObject.OnTransformAssigned -= value; } - ITransform IAssignableTransform.Transform => GameObject.Transform; - bool IAssignableTransform.Assign(ITransform transform) => GameObject.Assign(transform); - // TODO This causes delay since OnPreDraw calls assuming this is called in in Update public Vector2D ScreenToWorldPosition(Vector2D screenPosition) { diff --git a/Game/Behaviours/MovementBallBehaviour.cs b/Shared/Behaviours/MovementBallBehaviour.cs similarity index 81% rename from Game/Behaviours/MovementBallBehaviour.cs rename to Shared/Behaviours/MovementBallBehaviour.cs index 3d584f9..80d28b7 100644 --- a/Game/Behaviours/MovementBallBehaviour.cs +++ b/Shared/Behaviours/MovementBallBehaviour.cs @@ -6,7 +6,7 @@ using Syntriax.Engine.Physics2D.Abstract; namespace Pong.Behaviours; -public class MovementBallBehaviour : BehaviourOverride +public class MovementBallBehaviour : Behaviour2D { public Vector2D StartDirection { get; private set; } = Vector2D.Zero; public float Speed { get; set; } = 500f; @@ -17,9 +17,9 @@ public class MovementBallBehaviour : BehaviourOverride protected override void OnFirstActiveFrame() { if (!BehaviourController.TryGetBehaviour(out IRigidBody2D? foundRigidBody)) - throw new Exception($"{nameof(IRigidBody2D)} is missing on {GameObject.Name}."); + throw new Exception($"{nameof(IRigidBody2D)} is missing on {HierarchyObject.Name}."); if (!BehaviourController.TryGetBehaviour(out ICollider2D? foundCollider)) - throw new Exception($"{nameof(ICollider2D)} is missing on {GameObject.Name}."); + throw new Exception($"{nameof(ICollider2D)} is missing on {HierarchyObject.Name}."); foundRigidBody.Velocity = StartDirection * Speed; foundCollider.OnCollisionDetected += OnCollisionDetected; @@ -32,14 +32,14 @@ public class MovementBallBehaviour : BehaviourOverride if (rigidBody.Velocity.MagnitudeSquared <= 0.01f) return; - Vector2D speedUp = rigidBody.Velocity.Normalized * Time.DeltaTimeFrame; + Vector2D speedUp = rigidBody.Velocity.Normalized * GameManager.Time.DeltaTime; rigidBody.Velocity += speedUp * SpeedUpMultiplier; } private void OnCollisionDetected(ICollider2D collider2D, CollisionDetectionInformation information) { if (Syntriax.Engine.Core.Math.Abs(information.Normal.Dot(Vector2D.Right)) > .25) - rigidBody.Velocity = information.Left.Transform.Position.FromTo(information.Right.Transform.Position).Normalized * rigidBody.Velocity.Magnitude; + rigidBody.Velocity = information.Detector.Transform.Position.FromTo(information.Detected.Transform.Position).Normalized * rigidBody.Velocity.Magnitude; else rigidBody.Velocity = rigidBody.Velocity.Reflect(information.Normal); } diff --git a/Game/Behaviours/PaddleBehaviour.cs b/Shared/Behaviours/PaddleBehaviour.cs similarity index 70% rename from Game/Behaviours/PaddleBehaviour.cs rename to Shared/Behaviours/PaddleBehaviour.cs index d944847..fe243c4 100644 --- a/Game/Behaviours/PaddleBehaviour.cs +++ b/Shared/Behaviours/PaddleBehaviour.cs @@ -3,11 +3,11 @@ using System; using Microsoft.Xna.Framework.Input; using Syntriax.Engine.Core; -using Syntriax.Engine.Input; +using Syntriax.Engine.Systems.Input; namespace Pong.Behaviours; -public class PaddleBehaviour(Keys Up, Keys Down, float High, float Low, float Speed) : BehaviourOverride +public class PaddleBehaviour(Keys Up, Keys Down, float High, float Low, float Speed) : Behaviour2D { private Keys Up { get; } = Up; private Keys Down { get; } = Down; @@ -26,17 +26,16 @@ public class PaddleBehaviour(Keys Up, Keys Down, float High, float Low, float Sp return; if (isUpPressed) - GameObject.Transform.Position = GameObject.Transform.Position + Vector2D.Up * (float)Time.Elapsed.TotalSeconds * Speed; + Transform.Position = Transform.Position + Vector2D.Up * GameManager.Time.DeltaTime * Speed; else if (isDownPressed) - GameObject.Transform.Position = GameObject.Transform.Position + -Vector2D.Up * (float)Time.Elapsed.TotalSeconds * Speed; + Transform.Position = Transform.Position + -Vector2D.Up * GameManager.Time.DeltaTime * Speed; - GameObject.Transform.Position = new Vector2D(GameObject.Transform.Position.X, MathF.Max(MathF.Min(GameObject.Transform.Position.Y, High), Low)); + Transform.Position = new Vector2D(Transform.Position.X, MathF.Max(MathF.Min(Transform.Position.Y, High), Low)); } protected override void OnFirstActiveFrame() { - if (!BehaviourController.TryGetBehaviour>(out var behaviourResult)) - inputs = behaviourResult ?? BehaviourController.AddBehaviour(); + inputs = GameManager.FindBehaviour>() ?? throw new("Unable to find inputs"); inputs.RegisterOnPress(Up, OnUpPressed); inputs.RegisterOnRelease(Up, OnUpReleased); diff --git a/Game/Behaviours/PongManagerBehaviour.cs b/Shared/Behaviours/PongManagerBehaviour.cs similarity index 83% rename from Game/Behaviours/PongManagerBehaviour.cs rename to Shared/Behaviours/PongManagerBehaviour.cs index dbdb3d7..52c23ab 100644 --- a/Game/Behaviours/PongManagerBehaviour.cs +++ b/Shared/Behaviours/PongManagerBehaviour.cs @@ -3,10 +3,11 @@ using System; using Microsoft.Xna.Framework.Input; using Syntriax.Engine.Core; +using Syntriax.Engine.Systems.Input; namespace Pong.Behaviours; -public class PongManagerBehaviour : BehaviourOverride +public class PongManagerBehaviour : Behaviour { public Action? OnReset { get; set; } = null; public Action? OnFinished { get; set; } = null; @@ -23,11 +24,7 @@ public class PongManagerBehaviour : BehaviourOverride protected override void OnFirstActiveFrame() { - KeyboardInputsBehaviour? buttonInputs = null!; - - if (!BehaviourController.TryGetBehaviour(out buttonInputs)) - buttonInputs = BehaviourController.AddBehaviour(); - + var buttonInputs = GameManager.FindBehaviour>() ?? throw new("Unable to find inputs"); buttonInputs.RegisterOnRelease(Keys.Space, (_, _1) => Reset()); } diff --git a/Game/Behaviours/ShapeAABBBehaviour.cs b/Shared/Behaviours/ShapeAABBBehaviour.cs similarity index 91% rename from Game/Behaviours/ShapeAABBBehaviour.cs rename to Shared/Behaviours/ShapeAABBBehaviour.cs index 391019d..ece1e9f 100644 --- a/Game/Behaviours/ShapeAABBBehaviour.cs +++ b/Shared/Behaviours/ShapeAABBBehaviour.cs @@ -4,13 +4,12 @@ using Apos.Shapes; using Syntriax.Engine.Core; using Syntriax.Engine.Core.Abstract; -using Syntriax.Engine.Input; using Syntriax.Engine.Physics2D.Abstract; -using Syntriax.Engine.Physics2D.Primitives; +using Syntriax.Engine.Systems.Input; namespace Pong.Behaviours; -public class ShapeAABBBehaviour : BehaviourOverride, IDisplayableShape +public class ShapeAABBBehaviour : Behaviour2D, IDisplayableShape { private IShapeCollider2D? shapeCollider = null; diff --git a/Game/Behaviours/ShapeBehaviour.cs b/Shared/Behaviours/ShapeBehaviour.cs similarity index 66% rename from Game/Behaviours/ShapeBehaviour.cs rename to Shared/Behaviours/ShapeBehaviour.cs index ffbb52d..12d0e88 100644 --- a/Game/Behaviours/ShapeBehaviour.cs +++ b/Shared/Behaviours/ShapeBehaviour.cs @@ -2,8 +2,8 @@ using Microsoft.Xna.Framework; using Apos.Shapes; +using Syntriax.Engine.Core; using Syntriax.Engine.Core.Abstract; -using Syntriax.Engine.Physics2D.Primitives; namespace Pong.Behaviours; @@ -26,8 +26,8 @@ public class ShapeBehaviour : Syntriax.Engine.Physics2D.Collider2DShapeBehaviour shapeBatch.DrawLine(ShapeWorld[0].ToDisplayVector2(), ShapeWorld[^1].ToDisplayVector2(), Thickness, Color, Color); } - public ShapeBehaviour(Shape shape) : base(shape) { } - public ShapeBehaviour(Shape shape, float thickness) : base(shape) { Thickness = thickness; } - public ShapeBehaviour(Shape shape, Color color) : base(shape) { Color = color; } - public ShapeBehaviour(Shape shape, Color color, float thickness) : base(shape) { Thickness = thickness; Color = color; } + public ShapeBehaviour(Shape2D shape) : base(shape) { } + public ShapeBehaviour(Shape2D shape, float thickness) : base(shape) { Thickness = thickness; } + public ShapeBehaviour(Shape2D shape, Color color) : base(shape) { Color = color; } + public ShapeBehaviour(Shape2D shape, Color color, float thickness) : base(shape) { Thickness = thickness; Color = color; } } diff --git a/Game/Behaviours/TextBehaviour.cs b/Shared/Behaviours/TextBehaviour.cs similarity index 91% rename from Game/Behaviours/TextBehaviour.cs rename to Shared/Behaviours/TextBehaviour.cs index 0710f20..833cb16 100644 --- a/Game/Behaviours/TextBehaviour.cs +++ b/Shared/Behaviours/TextBehaviour.cs @@ -6,7 +6,7 @@ using Syntriax.Engine.Core.Abstract; namespace Pong.Behaviours; -public class TextBehaviour : BehaviourOverride, IDisplayableSprite +public class TextBehaviour : Behaviour2D, IDisplayableSprite { public SpriteFont? Font { get; set; } = null; public int Size { get; set; } = 16; diff --git a/Game/Behaviours/TextScoreBehaviour.cs b/Shared/Behaviours/TextScoreBehaviour.cs similarity index 91% rename from Game/Behaviours/TextScoreBehaviour.cs rename to Shared/Behaviours/TextScoreBehaviour.cs index 452f660..f1de1d7 100644 --- a/Game/Behaviours/TextScoreBehaviour.cs +++ b/Shared/Behaviours/TextScoreBehaviour.cs @@ -11,7 +11,7 @@ public class TextScoreBehaviour : TextBehaviour protected override void OnFirstActiveFrame() { - if (!GameObject.GameManager.TryFindBehaviour(out pongManager)) + if (!HierarchyObject.GameManager.TryFindBehaviour(out pongManager)) return; pongManager.OnScored += UpdateScores; diff --git a/Game/Behaviours/WallScoreBehaviour.cs b/Shared/Behaviours/WallScoreBehaviour.cs similarity index 85% rename from Game/Behaviours/WallScoreBehaviour.cs rename to Shared/Behaviours/WallScoreBehaviour.cs index bd8cf05..6482716 100644 --- a/Game/Behaviours/WallScoreBehaviour.cs +++ b/Shared/Behaviours/WallScoreBehaviour.cs @@ -5,7 +5,7 @@ using Syntriax.Engine.Physics2D.Abstract; namespace Pong.Behaviours; -public class WallScoreBehaviour(Action OnCollision) : BehaviourOverride +public class WallScoreBehaviour(Action OnCollision) : Behaviour2D { private Action OnCollision { get; } = OnCollision; diff --git a/Game/Content/Content.mgcb b/Shared/Content/Content.mgcb similarity index 100% rename from Game/Content/Content.mgcb rename to Shared/Content/Content.mgcb diff --git a/Shared/Content/Ubuntu Mono.ttf b/Shared/Content/Ubuntu Mono.ttf new file mode 100644 index 0000000..4977028 Binary files /dev/null and b/Shared/Content/Ubuntu Mono.ttf differ diff --git a/Game/Content/UbuntuMono.spritefont b/Shared/Content/UbuntuMono.spritefont similarity index 100% rename from Game/Content/UbuntuMono.spritefont rename to Shared/Content/UbuntuMono.spritefont diff --git a/Game/EngineConverter.cs b/Shared/EngineConverter.cs similarity index 100% rename from Game/EngineConverter.cs rename to Shared/EngineConverter.cs diff --git a/Shared/GamePong.cs b/Shared/GamePong.cs new file mode 100644 index 0000000..52a0c03 --- /dev/null +++ b/Shared/GamePong.cs @@ -0,0 +1,165 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; + +using Pong.Behaviours; +using Apos.Shapes; + +using Syntriax.Engine.Core; +using Syntriax.Engine.Core.Abstract; +using Syntriax.Engine.Physics2D; + +namespace Pong; + +public class GamePong : Game +{ + private readonly IHierarchyObject platformSpecificHierarchyObject = null!; + private readonly GraphicsDeviceManager graphics = null!; + private SpriteBatch spriteBatch = null!; + private ShapeBatch shapeBatch = null!; + + private GameManager gameManager = null!; + private BehaviourCollector displayableCollector = null!; + private BehaviourCollector displayableShapeCollector = null!; + private MonoGameCamera2DBehaviour cameraBehaviour = null!; + + private PongManagerBehaviour pongManager = null!; + + public GamePong(IHierarchyObject platformSpecificHierarchyObject) + { + this.platformSpecificHierarchyObject = platformSpecificHierarchyObject; + graphics = new GraphicsDeviceManager(this) + { + PreferredBackBufferWidth = 1024, + PreferredBackBufferHeight = 576, + GraphicsProfile = GraphicsProfile.HiDef + }; + + Content.RootDirectory = "Content"; + IsMouseVisible = true; + } + + protected override void Initialize() + { + // TODO: Add your initialization logic here + gameManager = new(); + displayableCollector = new(gameManager); + displayableShapeCollector = new(gameManager); + + gameManager.Initialize(); + + base.Initialize(); + } + + protected override void LoadContent() + { + spriteBatch = new SpriteBatch(GraphicsDevice); + shapeBatch = new ShapeBatch(GraphicsDevice, Content); + SpriteFont spriteFont = Content.Load("UbuntuMono"); + + gameManager.Register(platformSpecificHierarchyObject); + gameManager.InstantiateHierarchyObject().SetHierarchyObject("Physics Engine 2D"); + + //////////////////////////////////////////////////////////////////////////////////// + + IHierarchyObject HierarchyObjectCamera = gameManager.InstantiateHierarchyObject().SetHierarchyObject("Camera"); ; + HierarchyObjectCamera.BehaviourController.AddBehaviour(); + + HierarchyObjectCamera.BehaviourController.AddBehaviour(); + cameraBehaviour = HierarchyObjectCamera.BehaviourController.AddBehaviour(graphics); + + //////////////////////////////////////////////////////////////////////////////////// + + IHierarchyObject HierarchyObjectPongManager = gameManager.InstantiateHierarchyObject().SetHierarchyObject("Pong Game Manager"); + pongManager = HierarchyObjectPongManager.BehaviourController.AddBehaviour(5); + + //////////////////////////////////////////////////////////////////////////////////// + + IHierarchyObject HierarchyObjectBall = gameManager.InstantiateHierarchyObject().SetHierarchyObject("Ball"); + HierarchyObjectBall.BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(0, 0f), scale: new Vector2D(10f, 10f)); + + HierarchyObjectBall.BehaviourController.AddBehaviour(new Circle(Vector2D.Zero, 1f)); + HierarchyObjectBall.BehaviourController.AddBehaviour(); + HierarchyObjectBall.BehaviourController.AddBehaviour(); + + //////////////////////////////////////////////////////////////////////////////////// + + IHierarchyObject HierarchyObjectLeftPaddle = gameManager.InstantiateHierarchyObject().SetHierarchyObject("Left Paddle"); + HierarchyObjectLeftPaddle.BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(-468f, 0f), scale: new Vector2D(15f, 60f)); + + HierarchyObjectLeftPaddle.BehaviourController.AddBehaviour(Keys.W, Keys.S, 228f, -228f, 400f); + HierarchyObjectLeftPaddle.BehaviourController.AddBehaviour(Shape2D.Square); + HierarchyObjectLeftPaddle.BehaviourController.AddBehaviour().IsStatic = true; + + IHierarchyObject HierarchyObjectRightPaddle = gameManager.InstantiateHierarchyObject().SetHierarchyObject("Right Paddle"); + HierarchyObjectRightPaddle.BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(468f, 0f), scale: new Vector2D(15f, 60f)); + HierarchyObjectRightPaddle.BehaviourController.AddBehaviour(Keys.Up, Keys.Down, 228f, -228f, 400f); + HierarchyObjectRightPaddle.BehaviourController.AddBehaviour(Shape2D.Square); + HierarchyObjectRightPaddle.BehaviourController.AddBehaviour().IsStatic = true; + + //////////////////////////////////////////////////////////////////////////////////// + + IHierarchyObject HierarchyObjectWallTop = gameManager.InstantiateHierarchyObject().SetHierarchyObject("Wall Top"); + HierarchyObjectWallTop.BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(0f, 308f), scale: new Vector2D(552f, 20f)); + HierarchyObjectWallTop.BehaviourController.AddBehaviour(Shape2D.Square); + HierarchyObjectWallTop.BehaviourController.AddBehaviour().IsStatic = true; + + IHierarchyObject HierarchyObjectWallBottom = gameManager.InstantiateHierarchyObject().SetHierarchyObject("Wall Bottom"); + HierarchyObjectWallBottom.BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(0f, -308f), scale: new Vector2D(552f, 20f)); + HierarchyObjectWallBottom.BehaviourController.AddBehaviour(Shape2D.Square); + HierarchyObjectWallBottom.BehaviourController.AddBehaviour().IsStatic = true; + + IHierarchyObject HierarchyObjectWallRight = gameManager.InstantiateHierarchyObject().SetHierarchyObject("Wall Right"); + HierarchyObjectWallRight.BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(532f, 0f), scale: new Vector2D(20f, 328f)); + HierarchyObjectWallRight.BehaviourController.AddBehaviour((Action)pongManager.ScoreToLeft); + HierarchyObjectWallRight.BehaviourController.AddBehaviour(Shape2D.Square); + HierarchyObjectWallRight.BehaviourController.AddBehaviour().IsStatic = true; + + IHierarchyObject HierarchyObjectWallLeft = gameManager.InstantiateHierarchyObject().SetHierarchyObject("Wall Left"); + HierarchyObjectWallLeft.BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(-532f, 0f), scale: new Vector2D(20f, 328f)); + HierarchyObjectWallLeft.BehaviourController.AddBehaviour((Action)pongManager.ScoreToRight); + HierarchyObjectWallLeft.BehaviourController.AddBehaviour(Shape2D.Square); + HierarchyObjectWallLeft.BehaviourController.AddBehaviour().IsStatic = true; + + //////////////////////////////////////////////////////////////////////////////////// + + IHierarchyObject HierarchyObjectLeftScoreText = gameManager.InstantiateHierarchyObject().SetHierarchyObject("Score Left"); + HierarchyObjectLeftScoreText.BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(-250f, 250f), scale: Vector2D.One * .25f); + HierarchyObjectLeftScoreText.BehaviourController.AddBehaviour(true, spriteFont); + + IHierarchyObject HierarchyObjectRightScoreText = gameManager.InstantiateHierarchyObject().SetHierarchyObject("Score Right"); + HierarchyObjectRightScoreText.BehaviourController.AddBehaviour().SetTransform(position: new Vector2D(250f, 250f), scale: Vector2D.One * .25f); + HierarchyObjectRightScoreText.BehaviourController.AddBehaviour(false, spriteFont); + } + + protected override void Update(GameTime gameTime) + { + if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) + Exit(); + + gameManager.Update(gameTime.ToEngineTime()); + + base.Update(gameTime); + } + + protected override void Draw(GameTime gameTime) + { + GraphicsDevice.Clear(new Color() { R = 32, G = 32, B = 32 }); + + // TODO: Add your drawing code here + gameManager.PreDraw(); + + spriteBatch.Begin(SpriteSortMode.Deferred, transformMatrix: cameraBehaviour.MatrixTransform); + foreach (var displayable in displayableCollector) + displayable.Draw(spriteBatch); + spriteBatch.End(); + + shapeBatch.Begin(cameraBehaviour.MatrixTransform); + foreach (var displayableShape in displayableShapeCollector) + displayableShape.Draw(shapeBatch); + shapeBatch.End(); + + base.Draw(gameTime); + } +} diff --git a/Shared/Shared.csproj b/Shared/Shared.csproj new file mode 100644 index 0000000..6c58620 --- /dev/null +++ b/Shared/Shared.csproj @@ -0,0 +1,16 @@ + + + net8.0 + enable + + + + + + All + + + + + +