Voci un exemple pour Boo, adapté de C# par Cédric Vidier.
namespace SimpleExample
import System
import System.Collections.Generic
import Microsoft.Xna.Framework
import Microsoft.Xna.Framework.Audio
import Microsoft.Xna.Framework.Content
import Microsoft.Xna.Framework.Graphics
import Microsoft.Xna.Framework.Input
import Microsoft.Xna.Framework.Storage
///
/// When run, you'll see an empty blue screen. This code can
/// be run in both Mono.Xna and Microsoft XNA without changing
/// any code.
///
class SimpleExampleGame(Microsoft.Xna.Framework.Game):
graphics as GraphicsDeviceManager
content as ContentManager
def constructor():
graphics = GraphicsDeviceManager(self)
content = ContentManager(Services)
/// 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.
protected override def Initialize():
// TODO: Add your initialization logic here
super()
/// Load your graphics content. If loadAllContent is true, you should
/// load content from both ResourceManagementMode pools. Otherwise, just
/// load ResourceManagementMode.Manual content.
///Which type of content to load.
protected override def LoadGraphicsContent(loadAllContent as bool):
if loadAllContent:
// TODO: Load any ResourceManagementMode.Automatic content
pass
// TODO: Load any ResourceManagementMode.Manual content
/// Unload your graphics content. If unloadAllContent is true, you should
/// unload content from both ResourceManagementMode pools. Otherwise, just
/// unload ResourceManagementMode.Manual content. Manual content will get
/// Disposed by the GraphicsDevice during a Reset.
///Which type of content to unload.
protected override def UnloadGraphicsContent(unloadAllContent as bool):
if unloadAllContent:
content.Unload()
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input and playing audio.
///Provides a snapshot of timing values.
protected override def Update(gameTime as GameTime):
// Allows the default game to exit on Xbox 360 and Windows
if GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed:
Exit()
// TODO: Add your update logic here
super(gameTime)
/// This is called when the game should draw itself.
///Provides a snapshot of timing values.
protected override def Draw(gameTime as GameTime):
graphics.GraphicsDevice.Clear(Color.CornflowerBlue)
// TODO: Add your drawing code here
super(gameTime)
Tuesday, June 5, 2007
XNA - Boo
Voci un exemple pour Boo, adapté de C# par Cédric Vidier.
Sunday, June 3, 2007
XNA - IronPython
IronPython et la version du célèbre langage (mon favori en fait) porté sur la plateforme .NET.
Xna et le framework de développement de jeux pour XBOX et Windows .Net. Voici un petit exemple écrit par Leaf:
Xna et le framework de développement de jeux pour XBOX et Windows .Net. Voici un petit exemple écrit par Leaf:
import clr
clr.AddReference('Microsoft.Xna.Framework')
clr.AddReference('Microsoft.Xna.Framework.Game')
from Microsoft.Xna.Framework import *
from Microsoft.Xna.Framework.Graphics import *
from Microsoft.Xna.Framework.Content import *
class MyGame(Game):
def __init__(self):
self.spriteX = self.spriteY = 0
self.spriteSpeedX = self.spriteSpeedY = 1
self.InitializeComponent()
def InitializeComponent(self):
self.graphics = GraphicsDeviceManager(self)
self.content = ContentManager(self.Services)
def LoadGraphicsContent(self, loadAllContent):
if loadAllContent:
self.texture = Texture2D.FromFile(self.graphics.GraphicsDevice, "sprite.jpg")
self.spriteBatch = SpriteBatch(self.graphics.GraphicsDevice)
def UnloadGraphicsContent(self, unloadAllContent):
if unloadAllContent:
self.texture.Dispose()
self.spritebatch.Dispose()
def Update(self, gameTime):
self.UpdateSprite()
Game.Update(self, gameTime)
def UpdateSprite(self):
self.spriteX += self.spriteSpeedX
self.spriteY += self.spriteSpeedY
maxX = self.graphics.GraphicsDevice.Viewport.Width - self.texture.Width
if self.spriteX > maxX:
self.spriteSpeedX *= -1
self.spriteX = maxX
elif self.spriteX < 0:
self.spriteSpeedX *= -1
self.spriteX = 0
maxY = self.graphics.GraphicsDevice.Viewport.Height - self.texture.Height
if self.spriteY > maxY:
self.spriteSpeedY *= -1
self.spriteX = maxY
elif self.spriteY < 0:
self.spriteSpeedY *= -1
self.spriteY = 0
def Draw(self, gameTime):
self.graphics.GraphicsDevice.Clear(Color.CornflowerBlue)
self.DrawSprite()
Game.Draw(self, gameTime)
def DrawSprite(self):
self.spriteBatch.Begin()
self.spriteBatch.Draw(self.texture, Rectangle(self.spriteX,
self.spriteY, self.texture.Width, self.texture.Height), Color.White)
self.spriteBatch.End()
game = MyGame()
game.Run()
Subscribe to:
Posts (Atom)