IronPython で XNA

screenshot
してみるテスト。

# -*- coding: utf-8 -*-
u"""IronPython XNA template

XNA Game Studio 3.1 の吐く「Windows ゲーム」テンプレートを
IronPython 2.6 用にベタ移植してみました。
"""
import clr

clr.AddReference('System')
clr.AddReference('System.Core')
clr.AddReference('Microsoft.Xna.Framework')
clr.AddReference('Microsoft.Xna.Framework.Game')

##################
#### Game1.cs ####

##using System;
##using System.Collections.Generic;
##using System.Linq;
##using Microsoft.Xna.Framework;
##using Microsoft.Xna.Framework.Audio;
##using Microsoft.Xna.Framework.Content;
##using Microsoft.Xna.Framework.GamerServices;
##using Microsoft.Xna.Framework.Graphics;
##using Microsoft.Xna.Framework.Input;
##using Microsoft.Xna.Framework.Media;
##using Microsoft.Xna.Framework.Net;
##using Microsoft.Xna.Framework.Storage;
from System import *
from System.Collections.Generic import *
from System.Linq import *
from Microsoft.Xna.Framework import *
from Microsoft.Xna.Framework.Audio import *
from Microsoft.Xna.Framework.Content import *
from Microsoft.Xna.Framework.GamerServices import *
from Microsoft.Xna.Framework.Graphics import *
from Microsoft.Xna.Framework.Input import *
from Microsoft.Xna.Framework.Media import *
from Microsoft.Xna.Framework.Net import *
from Microsoft.Xna.Framework.Storage import *

##namespace hoge
##{
##    /// <summary>
##    /// This is the main type for your game
##    /// </summary>
##    public class Game1 : Microsoft.Xna.Framework.Game
##    {
##        GraphicsDeviceManager graphics;
##        SpriteBatch spriteBatch;
##
##        public Game1()
##        {
##            graphics = new GraphicsDeviceManager(this);
##            Content.RootDirectory = "Content";
##        }
class Game1(Game):
    def __init__(self):
        self.graphics = GraphicsDeviceManager(self)
        self.Content.RootDirectory = 'Content'
##
##        /// <summary>
##        /// 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.
##        /// </summary>
##        protected override void Initialize()
##        {
##            // TODO: Add your initialization logic here
##
##            base.Initialize();
##        }
    def Initialize(self):
        Game.Initialize(self)
##
##        /// <summary>
##        /// LoadContent will be called once per game and is the place to load
##        /// all of your content.
##        /// </summary>
##        protected override void LoadContent()
##        {
##            // Create a new SpriteBatch, which can be used to draw textures.
##            spriteBatch = new SpriteBatch(GraphicsDevice);
##
##            // TODO: use this.Content to load your game content here
##        }
    def LoadContent(self):
        pass
##
##        /// <summary>
##        /// UnloadContent will be called once per game and is the place to unload
##        /// all content.
##        /// </summary>
##        protected override void UnloadContent()
##        {
##            // TODO: Unload any non ContentManager content here
##        }
    def UnloadContent(self):
        pass    
##
##        /// <summary>
##        /// Allows the game to run logic such as updating the world,
##        /// checking for collisions, gathering input, and playing audio.
##        /// </summary>
##        /// <param name="gameTime">Provides a snapshot of timing values.</param>
##        protected override void Update(GameTime gameTime)
##        {
##            // Allows the game to exit
##            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
##                this.Exit();
##
##            // TODO: Add your update logic here
##
##            base.Update(gameTime);
##        }
    def Update(self, gameTime):
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed):
            self.Exit()
##
##        /// <summary>
##        /// This is called when the game should draw itself.
##        /// </summary>
##        /// <param name="gameTime">Provides a snapshot of timing values.</param>
##        protected override void Draw(GameTime gameTime)
##        {
##            GraphicsDevice.Clear(Color.CornflowerBlue);
##
##            // TODO: Add your drawing code here
##
##            base.Draw(gameTime);
##        }
    def Draw(self, gameTime):
        self.graphics.GraphicsDevice.Clear(Color.CornflowerBlue)
        Game.Draw(self, gameTime)
##    }
##}


####################
#### Program.cs ####

##using System;
##namespace hoge
##{
##    static class Program
##    {
##        /// <summary>
##        /// The main entry point for the application.
##        /// </summary>
##        static void Main(string[] args)
##        {
##            using (Game1 game = new Game1())
##            {
##                game.Run();
##            }
##        }
##    }
##}
if __name__ == '__main__':
    game = Game1()
    try:
        game.Run()
    finally:
        game.Dispose()

しかし Visual Studio 上でインタラクティブに操作する部分(SpriteFont の作成と登録、とか)の組み入れ方が分からないので "Hello, world!" の表示にすら進めない罠。

というかゲームなら大抵、いきなりゲーム画面が始まったりはせずにオープニング画面やらコンフィグ画面やら自動デモ画面やら操作説明画面やら状況説明のためのADVモードのシーンやらと複数の状態を遷移して行くことになるわけだけれども、こういう「Game オブジェクトを作って Run」みたいなフレームワークではそれをどうコーディングして行くのだろうか。(まさか Update メソッドの中に if 文の山作って状態ごとに……なんてことはしないでしょうし……)

とりあえず、他人のソース読むところから始めないといけないかな。