Last active
September 28, 2022 02:48
-
-
Save WillSams/3896411 to your computer and use it in GitHub Desktop.
MonoGame w/ IronPython Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, clr | |
clr.AddReferenceToFile("MonoGame.Framework.dll") | |
clr.AddReferenceToFile("OpenTK.dll") | |
from Microsoft.Xna.Framework import * | |
from Microsoft.Xna.Framework.Graphics import * | |
class App(Game): | |
def __init__(self): | |
self.graphics = GraphicsDeviceManager(self) | |
self.Content.RootDirectory = os.getcwd() + "/Content" | |
def Initialize(self): | |
""" Allows the game to perform any initialization it needs to before starting to run. This is where it can query for any required | |
services and load any non-graphic related content. Calling base.Initialize will enumerate through any components and initialize them as well. """ | |
# TODO: Add your initialization logic here | |
self.Initialize() | |
def LoadContent(self): | |
""" LoadContent will be called once per game and is the place to load all of your content. """ | |
# Create a new SpriteBatch, which can be used to draw textures. | |
self.spriteBatch = SpriteBatch(GraphicsDevice) | |
#TODO: use this.Content to load your game content here | |
def Update(self, gameTime): | |
""" Allows the game to run logic such as updating the world, checking for collisions, gathering input, and playing audio. """ | |
# For Mobile devices, this logic will close the Game when the Back button is pressed | |
if GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed: | |
self.Exit() | |
# TODO: Add your update logic here | |
Game.Update(gameTime) | |
def Draw(self, gameTime): | |
""" This is called when the game should draw itself. """ | |
self.graphics.GraphicsDevice.Clear(Color.CornflowerBlue) | |
#TODO: Add your drawing code here | |
Game.Draw(gameTime) | |
game = App() | |
game.Run() |
@WillSams IronPython came back into the spotlight recently - they released a new version a couple of months ago, which is fantastic. Word is they're slowly progressing on IronPython 3 (Python 3), but 2.x (Python 2.7) seems quite stable/functional enough to actually build production things on it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Funny how timely this is, I haven't looked at much Python in years until about 3 days ago because I'm trying to teach modding Minecraft via Python to a kid. Been out of the loop, I seriously didn't realize Iron Python was still being worked on. The latest version supports .NET Core! I need to jump back in.