├── .gitignore ├── Content ├── Content.mgcb ├── bin │ └── DesktopGL │ │ ├── Content │ │ └── logo.xnb │ │ └── logo.xnb └── logo.png ├── MonoGame.Framework.dll ├── MonogameClj.csproj ├── Program.cs ├── README.md └── cljgame ├── game.clj ├── interop.clj └── monogame.clj /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | [Cc]ontent/[Oo]bj/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.tlog 95 | *.vspscc 96 | *.vssscc 97 | .builds 98 | *.pidb 99 | *.svclog 100 | *.scc 101 | 102 | # Chutzpah Test files 103 | _Chutzpah* 104 | 105 | # Visual C++ cache files 106 | ipch/ 107 | *.aps 108 | *.ncb 109 | *.opendb 110 | *.opensdf 111 | *.sdf 112 | *.cachefile 113 | *.VC.db 114 | *.VC.VC.opendb 115 | 116 | # Visual Studio profiler 117 | *.psess 118 | *.vsp 119 | *.vspx 120 | *.sap 121 | 122 | # Visual Studio Trace Files 123 | *.e2e 124 | 125 | # TFS 2012 Local Workspace 126 | $tf/ 127 | 128 | # Guidance Automation Toolkit 129 | *.gpState 130 | 131 | # ReSharper is a .NET coding add-in 132 | _ReSharper*/ 133 | *.[Rr]e[Ss]harper 134 | *.DotSettings.user 135 | 136 | # TeamCity is a build add-in 137 | _TeamCity* 138 | 139 | # DotCover is a Code Coverage Tool 140 | *.dotCover 141 | 142 | # AxoCover is a Code Coverage Tool 143 | .axoCover/* 144 | !.axoCover/settings.json 145 | 146 | # Coverlet is a free, cross platform Code Coverage Tool 147 | coverage*.json 148 | coverage*.xml 149 | coverage*.info 150 | 151 | # Visual Studio code coverage results 152 | *.coverage 153 | *.coveragexml 154 | 155 | # NCrunch 156 | _NCrunch_* 157 | .*crunch*.local.xml 158 | nCrunchTemp_* 159 | 160 | # MightyMoose 161 | *.mm.* 162 | AutoTest.Net/ 163 | 164 | # Web workbench (sass) 165 | .sass-cache/ 166 | 167 | # Installshield output folder 168 | [Ee]xpress/ 169 | 170 | # DocProject is a documentation generator add-in 171 | DocProject/buildhelp/ 172 | DocProject/Help/*.HxT 173 | DocProject/Help/*.HxC 174 | DocProject/Help/*.hhc 175 | DocProject/Help/*.hhk 176 | DocProject/Help/*.hhp 177 | DocProject/Help/Html2 178 | DocProject/Help/html 179 | 180 | # Click-Once directory 181 | publish/ 182 | 183 | # Publish Web Output 184 | *.[Pp]ublish.xml 185 | *.azurePubxml 186 | # Note: Comment the next line if you want to checkin your web deploy settings, 187 | # but database connection strings (with potential passwords) will be unencrypted 188 | *.pubxml 189 | *.publishproj 190 | 191 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 192 | # checkin your Azure Web App publish settings, but sensitive information contained 193 | # in these scripts will be unencrypted 194 | PublishScripts/ 195 | 196 | # NuGet Packages 197 | *.nupkg 198 | # NuGet Symbol Packages 199 | *.snupkg 200 | # The packages folder can be ignored because of Package Restore 201 | **/[Pp]ackages/* 202 | # except build/, which is used as an MSBuild target. 203 | !**/[Pp]ackages/build/ 204 | # Uncomment if necessary however generally it will be regenerated when needed 205 | #!**/[Pp]ackages/repositories.config 206 | # NuGet v3's project.json files produces more ignorable files 207 | *.nuget.props 208 | *.nuget.targets 209 | 210 | # Nuget personal access tokens and Credentials 211 | nuget.config 212 | 213 | # Microsoft Azure Build Output 214 | csx/ 215 | *.build.csdef 216 | 217 | # Microsoft Azure Emulator 218 | ecf/ 219 | rcf/ 220 | 221 | # Windows Store app package directories and files 222 | AppPackages/ 223 | BundleArtifacts/ 224 | Package.StoreAssociation.xml 225 | _pkginfo.txt 226 | *.appx 227 | *.appxbundle 228 | *.appxupload 229 | 230 | # Visual Studio cache files 231 | # files ending in .cache can be ignored 232 | *.[Cc]ache 233 | # but keep track of directories ending in .cache 234 | !?*.[Cc]ache/ 235 | 236 | # Others 237 | ClientBin/ 238 | ~$* 239 | *~ 240 | *.dbmdl 241 | *.dbproj.schemaview 242 | *.jfm 243 | *.pfx 244 | *.publishsettings 245 | orleans.codegen.cs 246 | 247 | # Including strong name files can present a security risk 248 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 249 | #*.snk 250 | 251 | # Since there are multiple workflows, uncomment next line to ignore bower_components 252 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 253 | #bower_components/ 254 | 255 | # RIA/Silverlight projects 256 | Generated_Code/ 257 | 258 | # Backup & report files from converting an old project file 259 | # to a newer Visual Studio version. Backup files are not needed, 260 | # because we have git ;-) 261 | _UpgradeReport_Files/ 262 | Backup*/ 263 | UpgradeLog*.XML 264 | UpgradeLog*.htm 265 | ServiceFabricBackup/ 266 | *.rptproj.bak 267 | 268 | # SQL Server files 269 | *.mdf 270 | *.ldf 271 | *.ndf 272 | 273 | # Business Intelligence projects 274 | *.rdl.data 275 | *.bim.layout 276 | *.bim_*.settings 277 | *.rptproj.rsuser 278 | *- [Bb]ackup.rdl 279 | *- [Bb]ackup ([0-9]).rdl 280 | *- [Bb]ackup ([0-9][0-9]).rdl 281 | 282 | # Microsoft Fakes 283 | FakesAssemblies/ 284 | 285 | # GhostDoc plugin setting file 286 | *.GhostDoc.xml 287 | 288 | # Node.js Tools for Visual Studio 289 | .ntvs_analysis.dat 290 | node_modules/ 291 | 292 | # Visual Studio 6 build log 293 | *.plg 294 | 295 | # Visual Studio 6 workspace options file 296 | *.opt 297 | 298 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 299 | *.vbw 300 | 301 | # Visual Studio LightSwitch build output 302 | **/*.HTMLClient/GeneratedArtifacts 303 | **/*.DesktopClient/GeneratedArtifacts 304 | **/*.DesktopClient/ModelManifest.xml 305 | **/*.Server/GeneratedArtifacts 306 | **/*.Server/ModelManifest.xml 307 | _Pvt_Extensions 308 | 309 | # Paket dependency manager 310 | .paket/paket.exe 311 | paket-files/ 312 | 313 | # FAKE - F# Make 314 | .fake/ 315 | 316 | # CodeRush personal settings 317 | .cr/personal 318 | 319 | # Python Tools for Visual Studio (PTVS) 320 | __pycache__/ 321 | *.pyc 322 | 323 | # Cake - Uncomment if you are using it 324 | # tools/** 325 | # !tools/packages.config 326 | 327 | # Tabs Studio 328 | *.tss 329 | 330 | # Telerik's JustMock configuration file 331 | *.jmconfig 332 | 333 | # BizTalk build output 334 | *.btp.cs 335 | *.btm.cs 336 | *.odx.cs 337 | *.xsd.cs 338 | 339 | # OpenCover UI analysis results 340 | OpenCover/ 341 | 342 | # Azure Stream Analytics local run output 343 | ASALocalRun/ 344 | 345 | # MSBuild Binary and Structured Log 346 | *.binlog 347 | 348 | # NVidia Nsight GPU debugger configuration file 349 | *.nvuser 350 | 351 | # MFractors (Xamarin productivity tool) working folder 352 | .mfractor/ 353 | 354 | # Local History for Visual Studio 355 | .localhistory/ 356 | 357 | # BeatPulse healthcheck temp database 358 | healthchecksdb 359 | 360 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 361 | MigrationBackup/ 362 | 363 | # Ionide (cross platform F# VS Code tools) working folder 364 | .ionide/ 365 | 366 | # Fody - auto-generated XML schema 367 | FodyWeavers.xsd 368 | 369 | # VS Code files for those working on multiple tools 370 | .vscode/* 371 | !.vscode/settings.json 372 | !.vscode/tasks.json 373 | !.vscode/launch.json 374 | !.vscode/extensions.json 375 | *.code-workspace 376 | 377 | # Local History for Visual Studio Code 378 | .history/ 379 | 380 | # Windows Installer files from build outputs 381 | *.cab 382 | *.msi 383 | *.msix 384 | *.msm 385 | *.msp 386 | 387 | # JetBrains Rider 388 | .idea/ 389 | *.sln.iml 390 | 391 | # Mac files 392 | .DS_Store 393 | -------------------------------------------------------------------------------- /Content/Content.mgcb: -------------------------------------------------------------------------------- 1 | 2 | #----------------------------- Global Properties ----------------------------# 3 | 4 | /outputDir:bin/$(Platform) 5 | /intermediateDir:obj/$(Platform) 6 | /platform:DesktopGL 7 | /config: 8 | /profile:Reach 9 | /compress:False 10 | 11 | #-------------------------------- References --------------------------------# 12 | 13 | 14 | #---------------------------------- Content ---------------------------------# 15 | 16 | #begin logo.png 17 | /importer:TextureImporter 18 | /processor:TextureProcessor 19 | /processorParam:ColorKeyColor=255,0,255,255 20 | /processorParam:ColorKeyEnabled=True 21 | /processorParam:GenerateMipmaps=False 22 | /processorParam:PremultiplyAlpha=True 23 | /processorParam:ResizeToPowerOfTwo=False 24 | /processorParam:MakeSquare=False 25 | /processorParam:TextureFormat=Color 26 | /build:logo.png 27 | 28 | -------------------------------------------------------------------------------- /Content/bin/DesktopGL/Content/logo.xnb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucasteles/monogame-clojure/38a6facdf397df2b610a6aeab4ec1261da9604ec/Content/bin/DesktopGL/Content/logo.xnb -------------------------------------------------------------------------------- /Content/bin/DesktopGL/logo.xnb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucasteles/monogame-clojure/38a6facdf397df2b610a6aeab4ec1261da9604ec/Content/bin/DesktopGL/logo.xnb -------------------------------------------------------------------------------- /Content/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucasteles/monogame-clojure/38a6facdf397df2b610a6aeab4ec1261da9604ec/Content/logo.png -------------------------------------------------------------------------------- /MonoGame.Framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucasteles/monogame-clojure/38a6facdf397df2b610a6aeab4ec1261da9604ec/MonoGame.Framework.dll -------------------------------------------------------------------------------- /MonogameClj.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | MonoGameClj 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | PreserveNewest 19 | 20 | 21 | PreserveNewest 22 | 23 | 24 | PreserveNewest 25 | 26 | 27 | PreserveNewest 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using clojure.lang; 4 | using Microsoft.Xna.Framework; 5 | using clojure.clr.api; 6 | 7 | 8 | var load = Clojure.var("clojure.core", "load"); 9 | load.invoke("/cljgame/game"); 10 | var run = Clojure.var("cljgame.game", "-main"); 11 | run.invoke(); 12 | 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # clojure-clr-monogame-test 2 | [Under testing] 3 | 4 | ## Requirements 5 | 6 | - `dotnet sdk 3.1` 7 | 8 | ## Running on Dotnet 9 | Install and register the monogame tools: 10 | ```bash 11 | dotnet tool restore 12 | dotnet mgcb-editor --register 13 | ``` 14 | 15 | Compile and run: 16 | ```bash 17 | dotnet build 18 | dotnet run 19 | ``` 20 | 21 | ## Running on ClojureCLR 22 | 23 | Install the [Clojure.Main](https://www.nuget.org/packages/Clojure.Main) global tool: 24 | ```bash 25 | dotnet tool install --global Clojure.Main 26 | ``` 27 | Run: 28 | ```bash 29 | Clojure.Main -m cljgame.game 30 | ``` 31 | 32 | More info here: 33 | https://github.com/clojure/clojure-clr/wiki/Getting-started 34 | -------------------------------------------------------------------------------- /cljgame/game.clj: -------------------------------------------------------------------------------- 1 | (ns cljgame.game 2 | (:require [cljgame.interop :refer [current current-exe-dir int32 load-monogame]] 3 | [cljgame.monogame :as g]) 4 | (:import [System Console] 5 | [System.IO Path]) 6 | (:gen-class)) 7 | 8 | (load-monogame) 9 | 10 | (import [Microsoft.Xna.Framework Color Vector2] 11 | [Microsoft.Xna.Framework.Input Keyboard Keys] 12 | [Microsoft.Xna.Framework.Graphics SpriteEffects]) 13 | 14 | (defn initialize [game { graphics :graphics-manager 15 | window :window }] 16 | (set! (.IsMouseVisible game) true) 17 | (set! (.PreferredBackBufferWidth graphics) (int32 1024)) 18 | (set! (.PreferredBackBufferHeight graphics) (int32 768)) 19 | (.ApplyChanges graphics) 20 | 21 | {:rotation 0 22 | :position (g/vect (-> window g/width (/ 2)) 23 | (-> window g/height (/ 2))) }) 24 | 25 | (defn read-keys [] 26 | (let [keyboard (Keyboard/GetState) 27 | pressed (fn [k] (.IsKeyDown keyboard k))] 28 | (cond 29 | (and (pressed Keys/W) (pressed Keys/A)) (g/vect -2 -2) 30 | (and (pressed Keys/W) (pressed Keys/D)) (g/vect 2 -2) 31 | (and (pressed Keys/S) (pressed Keys/A)) (g/vect -2 2) 32 | (and (pressed Keys/S) (pressed Keys/D)) (g/vect 2 2) 33 | (pressed Keys/W) (g/vect 0 -2) 34 | (pressed Keys/S) (g/vect 0 2) 35 | (pressed Keys/A) (g/vect -2 0) 36 | (pressed Keys/D) (g/vect 2 0) 37 | :else Vector2/Zero))) 38 | 39 | (defn load-content [game {state :state}] 40 | (assoc state 41 | :texture/logo 42 | (g/load-texture-2d game "logo"))) 43 | 44 | (defn tick [{:keys [game game-time state]}] 45 | (let [{rot :rotation position :position} state 46 | velocity (read-keys)] 47 | (assoc state 48 | :rotation (+ rot 0.01) 49 | :position (g/vect+ position velocity)))) 50 | 51 | (defn draw [{:keys [sprite-batch delta-time graphics-device] 52 | { logo :texture/logo 53 | rotation :rotation 54 | position :position } :state}] 55 | (let [logo-center (g/vect (-> logo .Bounds .Width (/ 2)) 56 | (-> logo .Bounds .Height (/ 2)))] 57 | (g/clear graphics-device Color/LightGray) 58 | 59 | (g/begin sprite-batch) 60 | (g/draw sprite-batch {:texture logo 61 | :position position 62 | :source-rectangle (.Bounds logo) 63 | :color Color/White 64 | :rotation rotation 65 | :origin logo-center 66 | :scale 0.5 67 | :effects SpriteEffects/None 68 | :layer-depth 0}) 69 | (g/end sprite-batch))) 70 | 71 | (defn -main [& args] 72 | (Console/WriteLine "Ola Delboni") 73 | (g/run load-content initialize tick draw)) 74 | -------------------------------------------------------------------------------- /cljgame/interop.clj: -------------------------------------------------------------------------------- 1 | (ns cljgame.interop 2 | (:import [System Convert] 3 | [System.IO Path File] 4 | [System.Reflection Assembly])) 5 | 6 | (defn int32 [n] (Convert/ToInt32 n)) 7 | 8 | (def get-prop 9 | (memoize (fn [obj prop-name] (-> obj .GetType .BaseType (.GetProperty prop-name) (.GetValue obj))))) 10 | 11 | (def current-exe-dir (-> (Assembly/GetEntryAssembly) .Location Path/GetDirectoryName)) 12 | 13 | (def current "MonoGame.Framework.dll") 14 | 15 | (def executable (Path/Combine current-exe-dir current)) 16 | 17 | (defn load-monogame [] 18 | (assembly-load-from 19 | (cond (File/Exists current) current 20 | (File/Exists executable) executable))) 21 | -------------------------------------------------------------------------------- /cljgame/monogame.clj: -------------------------------------------------------------------------------- 1 | (ns cljgame.monogame 2 | (:require [cljgame.interop :refer [current-exe-dir get-prop load-monogame]]) 3 | (:import [System.IO Directory Path Directory] 4 | [System.Linq Enumerable])) 5 | 6 | (load-monogame) 7 | 8 | (import [Microsoft.Xna.Framework Game GraphicsDeviceManager Color Vector2 Rectangle GameWindow] 9 | [Microsoft.Xna.Framework.Graphics SpriteBatch Texture2D SpriteSortMode SpriteEffects SpriteFont] 10 | [Microsoft.Xna.Framework.Content ContentManager]) 11 | 12 | (def graphics-device (fn [game] (get-prop game "GraphicsDevice"))) 13 | (def debug-content-path (Path/Combine (Directory/GetCurrentDirectory) "Content/bin/DesktopGL")) 14 | (def exe-content-path (Path/Combine current-exe-dir "Content")) 15 | 16 | (defn run [load-fn initialize-fn update-fn draw-fn] 17 | (let [props (atom {:state {}}) 18 | game-instance (proxy 19 | ;; first vector contains superclass and interfaces that the created class should extend/implement 20 | ;; second vector contains arguments to superclass constructor 21 | [Game] [] 22 | 23 | ;; below are all overriden/implemented methods 24 | (Initialize [] 25 | (let [state (initialize-fn this @props)] 26 | (when state (swap! props assoc :state state)) 27 | (proxy-super Initialize))) 28 | 29 | (LoadContent [] 30 | (let [p @props 31 | state (load-fn this @props)] 32 | (swap! props assoc :sprite-batch (new SpriteBatch (graphics-device this))) 33 | (when state (swap! props assoc :state state)) 34 | (proxy-super LoadContent))) 35 | 36 | (Update [game-time] 37 | (let [props' @props 38 | state (:state props') 39 | new-state (update-fn {:game this 40 | :game-time game-time 41 | :delta-time (-> game-time .ElapsedGameTime .TotalSeconds) 42 | :state state 43 | :window (:window props') 44 | :graphics-manager (:graphics-manager props')})] 45 | (when (not (identical? state new-state)) 46 | (swap! props assoc :state new-state)) 47 | (proxy-super Update game-time))) 48 | 49 | (Draw [game-time] 50 | (let [props' @props] 51 | (draw-fn {:game this 52 | :delta-time (-> game-time .ElapsedGameTime .TotalSeconds) 53 | :game-time game-time 54 | :state (:state props') 55 | :sprite-batch (:sprite-batch props') 56 | :graphics-device (graphics-device this) 57 | :window (:window props')}) 58 | (proxy-super Draw game-time))))] 59 | 60 | (swap! props assoc :graphics-manager (new GraphicsDeviceManager game-instance)) 61 | (swap! props assoc :window (get-prop game-instance "Window" )) 62 | (set! (->> game-instance .Content .RootDirectory ) 63 | (if (Directory/Exists exe-content-path) exe-content-path debug-content-path)) 64 | (.Run game-instance))) 65 | 66 | (defn clear [graphics-device color] 67 | (.Clear graphics-device Color/LightGray)) 68 | 69 | (defn begin [sprite-batch &{:keys [sort-mode blend-state sampler-state depthStencil-state rasterizer-state effect transform-matrix]}] 70 | (.Begin sprite-batch 71 | (or sort-mode SpriteSortMode/Deferred) 72 | blend-state 73 | sampler-state 74 | depthStencil-state 75 | rasterizer-state 76 | effect 77 | transform-matrix)) 78 | 79 | (defn end [sprite-batch] (.End sprite-batch)) 80 | 81 | (defn draw [sprite-batch {:keys [texture position source-rectangle color rotation origin scale effects layer-depth 82 | destination-rectangle]}] 83 | (cond 84 | (and texture position source-rectangle color rotation origin scale effects layer-depth) 85 | (.Draw sprite-batch texture position source-rectangle color rotation origin scale effects layer-depth) 86 | 87 | (and texture destination-rectangle source-rectangle color rotation origin effects layer-depth) 88 | (.Draw sprite-batch texture destination-rectangle source-rectangle color rotation origin effects layer-depth) 89 | 90 | (and texture position source-rectangle color) 91 | (.Draw sprite-batch texture position source-rectangle color) 92 | 93 | (and texture destination-rectangle source-rectangle color) 94 | (.Draw sprite-batch texture destination-rectangle source-rectangle color) 95 | 96 | (and texture destination-rectangle color) 97 | (.Draw sprite-batch texture destination-rectangle color) 98 | 99 | (and texture position color) 100 | (.Draw sprite-batch texture position color) 101 | 102 | :else 103 | (throw (new Exception "INVALID DRAW PARAMETERS")))) 104 | 105 | (defn draw-text [sprite-batch {:keys [sprite-font text position color 106 | rotation origin scale effects layer-depth]}] 107 | (cond 108 | (and sprite-font text position color) 109 | (.DrawString sprite-batch sprite-font (str text) position color) 110 | 111 | (and sprite-font text position color rotation origin scale effects layer-depth) 112 | (.DrawString sprite-batch sprite-font (str text) position color rotation origin scale effects layer-depth) 113 | 114 | :else 115 | (throw (new Exception "INVALID DRAW TEXT PARAMETERS")))) 116 | 117 | 118 | (defn load-texture-2d [game texture-name] 119 | (let [content (get-prop game "Content")] 120 | (.Load ^ContentManager content (type-args Texture2D) texture-name))) 121 | 122 | (defn load-sprite-font [game font-name] 123 | (let [content (get-prop game "Content")] 124 | (.Load ^ContentManager content (type-args SpriteFont) font-name))) 125 | 126 | (defn pixel-texture [game color] 127 | (let [graphics (graphics-device game) 128 | texture (new Texture2D graphics 1 1) 129 | color-array (Enumerable/ToArray (type-args Color) (Enumerable/Cast (type-args Color) [color]))] 130 | (.SetData ^Texture2D texture (type-args Color) color-array) 131 | texture)) 132 | 133 | (defn vect 134 | ([n] (new Vector2 n)) 135 | ([x y] (new Vector2 x y))) 136 | 137 | (defn vect+ [v1 v2] (Vector2/op_Addition v1 v2)) 138 | (defn vect- 139 | ([v] (Vector2/op_UnaryNegation v)) 140 | ([v1 v2] (Vector2/op_Subtraction v1 v2))) 141 | 142 | (defn vect* [^Vector2 a b] (Vector2/op_Multiply a b)) 143 | (defn vect-div [^Vector2 a b] (Vector2/op_Division a b)) 144 | (defn vect-map [^Vector2 v] { :x (.X v) :y (.Y v)}) 145 | (defn vect-with-x [^Vector2 v x] (vect x (.Y v))) 146 | (defn vect-with-y [^Vector2 v y] (vect (.X v) y)) 147 | 148 | (defn rect [^Vector2 location ^Vector2 size] 149 | (new Rectangle (.ToPoint location) (.ToPoint size)) ) 150 | (defn rect-intersects [^Rectangle r1 ^Rectangle r2] (.Intersects r1 r2)) 151 | (defn width [^GameWindow window] (-> window .ClientBounds .Width)) 152 | (defn height [^GameWindow window] (-> window .ClientBounds .Height)) 153 | (defn window-size [^GameWindow window] (let [bounds (.ClientBounds window)] (vect (.Width bounds) (.Height bounds)))) 154 | (defn tap [v] (println v) v) 155 | 156 | --------------------------------------------------------------------------------