パスワードを忘れた? アカウント作成
663831 journal

meraの日記: 原点

日記 by mera
// とりあえず動かしてみるところから。
// 何気に C#Builder で動作を確認。
// VisualStudio C#.NET で Direct3D Blank で作成し、
// D3DBlank.cs を下記のコードに書き換えてビルド・実行。
// 最初に定義している GameObject が色々なキャラクタに化ける予定。
// ちなみに移動と描画を同時にやってるのでかなりタコな組み方です。

using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Direct3D=Microsoft.DirectX.Direct3D;

public class GameObject
{
    public float x ;
    public float y ;
    public float xsp ;
    public float ysp ;
    public float tx ;
    public float ty ;
}

public class GraphicsClass : GraphicsSample
{
    public static int iObjects = 16 ;
    private D3DXFont drawingFont = null;
    public GameObject[] oGObjs = new GameObject[iObjects] ;

    public GraphicsClass()
    {
        this.Text = "myBlank";
        this.KeyDown += new KeyEventHandler(this.OnPrivateKeyDown);
        drawingFont = new D3DXFont( "Arial", System.Drawing.FontStyle.Bold );
    }

    private void OnPrivateKeyDown(object sender, KeyEventArgs e)
    {
        switch (e.KeyCode)
        {
            case Keys.NumPad8: break ;
            case Keys.NumPad2: break ;
            case Keys.NumPad4: break ;
            case Keys.NumPad6: break ;
        }
    }

    protected override void Render()
    {
        Random oRandom = new Random() ;

        device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Blue, 1.0f, 0);
        device.BeginScene();
        for( int ii=0; ii<iObjects; ii++ ) {
            if( oGObjs[ii].x < oGObjs[ii].tx ) {
                oGObjs[ii].xsp += 0.4f ;
            } else {
                oGObjs[ii].xsp -= 0.4f ;
            }
            if( oGObjs[ii].y < oGObjs[ii].ty ) {
                oGObjs[ii].ysp += 0.4f ;
            } else {
                oGObjs[ii].ysp -= 0.4f ;
            }
            oGObjs[ii].x += oGObjs[ii].xsp ;
            oGObjs[ii].y += oGObjs[ii].ysp ;
            drawingFont.DrawText( (int)oGObjs[ii].x+oRandom.Next(2), (int)oGObjs[ii].y+oRandom.Next(2), Color.White.ToArgb(), "O");
        }
        device.EndScene();
    }

    protected override void InitializeDeviceObjects()
    {
        int ii ;
        Random oRandom = new Random() ;
        for( ii=0; ii<iObjects; ii++ ) {
            oGObjs[ii] = new GameObject() ;
            oGObjs[ii].x   = (float)oRandom.Next(400) ;
            oGObjs[ii].y   = (float)oRandom.Next(300) ;
            oGObjs[ii].tx  = (float)oRandom.Next(400) ;
            oGObjs[ii].ty  = (float)oRandom.Next(300) ;
            oGObjs[ii].xsp = (float)oRandom.Next(-3,3) ;
            oGObjs[ii].ysp = (float)oRandom.Next(-3,3) ;
        }

        drawingFont.InitializeDeviceObjects(device);

    }

    protected override void RestoreDeviceObjects(System.Object sender, System.EventArgs e)
    {
    }
}
この議論は賞味期限が切れたので、アーカイブ化されています。 新たにコメントを付けることはできません。
typodupeerror

日本発のオープンソースソフトウェアは42件 -- ある官僚

読み込み中...