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;
namespace Draw2DTransForm
{
/// <summary>
/// ゲームの根幹となる部分
/// </summary>
/// XNAで用意されたGameクラスを継承してGameMainクラスを作成
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics; //描画に関するデバイスの構成、管理を行うクラス
SpriteBatch spriteBatch;//同じ設定でスプライトのグループを描画できるようにするクラス
Texture2D square; //矩形の為のテクスチャ
Rectangle rect; //矩形のサイズ指定
int v_x, v_y; //変化速度
int accel_x, accel_y; //変化の加速度
private const int Accel = 3;
/// <summary>
/// コンストラクタ、newする時に呼ばれる。
/// </summary>
/// 最低限の初期化処理を行う。
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
//ウィンドウの横、縦幅。デフォルトで800x600
graphics.PreferredBackBufferWidth = 1200;
graphics.PreferredBackBufferHeight = 900;
rect = new Rectangle(0,100,0,0);
v_x = 0;
v_y = 0;
accel_x = 0;
accel_y = 0;
//フルスクリーン
//graphics.PreferMultiSampling = false;
//graphics.IsFullScreen = true;
}
/// <summary>
/// 初期化処理
/// </summary>
protected override void Initialize()
{
base.Window.Title = "RDD 製作委員会"; //ウィンドウのキャプションを設定
// TODO: Add your initialization logic here
//継承元のGameクラスのInitialize()メソッドを呼び出す。
base.Initialize();
}
/// <summary>
/// グラフィックスコンテントの読み込み
/// </summary>
protected override void LoadContent()
{
// テクスチャを描画するためのスプライトを作成
spriteBatch = new SpriteBatch(GraphicsDevice);
//単純にテクスチャを白で塗りつぶす
square = Content.Load<Texture2D>("white");
// TODO: use this.Content to load your game content here
}
/// <summary>
/// グラフィックスコンテントの解放
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// 更新処理
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// 終了
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
Keyboard.GetState().IsKeyDown(Keys.Escape)
)
this.Exit();
if (rect.Width <= 0)
{
rect.Width = 0;
accel_x = Accel;
}else if(rect.Width > graphics.PreferredBackBufferWidth)
{
rect.Width = graphics.PreferredBackBufferWidth;
accel_x = -Accel;
}
if (rect.Height <= 0)
{
rect.Height = 0;
accel_y = Accel;
}
else if (rect.Height > graphics.PreferredBackBufferHeight)
{
rect.Height = graphics.PreferredBackBufferHeight;
accel_y = -Accel;
}
v_x += accel_x;
v_y += accel_y;
rect.Width += v_x;
rect.Height += v_y;
// TODO: Add your update logic here
//ベースの更新、継承元クラスのUpdate()を呼び出す
base.Update(gameTime);
}
/// <summary>
/// 描画処理
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
//背景色で塗りつぶし
GraphicsDevice.Clear(Color.CornflowerBlue);
//スプライトの描画、アルファブレンド有効
spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
//矩形の描画
spriteBatch.Draw(square, rect,
new Rectangle(0, 0, 64, 64), new Color(255, 255, 0, 192));
spriteBatch.End();
// TODO: Add your drawing code here
//継承元クラスのDraw()を呼び出す。
base.Draw(gameTime);
}
}
}
最終更新:2009年11月03日 03:48