Hey guys,
I'm going to try and create a dual-hand eye coordination test that the Air Force uses to test pilot aptitude. I've made a basic game in C# with DX before but I just read an article about Finite State Machines and I want to try and set up my game to use one so that I can have a menu, the actual game, and an end screen. I'm having trouble already though, setting up my DX window! Could anyone take a look and give me some advice? I think it's pretty obvious what I'm trying to do, but it's not working.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX.DirectInput;
namespace FlightTraining1
{
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
private Microsoft.DirectX.Direct3D.Device device = null;
private FlightTraining1.Menu hMenu = null;
private enum AppState
{
Menu,
Running,
EndScreen,
Exiting
};
private AppState appState;
public Form1()
{
InitializeComponent();
appState = AppState.Menu;
try
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed=true;
presentParams.SwapEffect = SwapEffect.Discard;
//presentParams.BackBufferHeight = 768;
//presentParams.BackBufferWidth = 1024;
//presentParams.BackBufferFormat= Format.X8R8G8B8;
//presentParams.FullScreenRefreshRateInHz = 60;
device = new Microsoft.DirectX.Direct3D.Device(0,
Microsoft.DirectX.Direct3D.DeviceType.Hardware,
this,
CreateFlags.SoftwareVertexProcessing,
presentParams);
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
device.RenderState.AlphaBlendEnable = true;
}
catch (DirectXException)
{
appState = AppState.Exiting;
}
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(1024, 768);
this.Name = "Form1";
this.Text = "Flight Training";
}
#endregion
[STAThread]
static void Main()
{
Form1 app = new Form1();
while(app.Created)
{
switch(app.appState)
{
case AppState.Menu:
if(app.hMenu == null)
app.hMenu = new FlightTraining1.Menu(app.device);
app.hMenu.Render();
break;
case AppState.Running:
break;
case AppState.EndScreen:
break;
case AppState.Exiting:
app.Dispose();
break;
default:
app.Dispose();
break;
}
}
}
}
}
And this:
using System;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX.DirectInput;
namespace FlightTraining1
{
public class Menu
{
private int time;
private bool startSelected;
Microsoft.DirectX.Direct3D.Device device;
public Menu(Microsoft.DirectX.Direct3D.Device deviceRef)
{
device = deviceRef;
time = 3;
startSelected = false;
}
public void Render()
{
if (device == null)
return;
device.Clear(ClearFlags.Target, System.Drawing.Color.Black, 1.0f, 0);
device.BeginScene();
using(Sprite d3dSprite = new Sprite(device))
{
d3dSprite.Begin(SpriteFlags.None);
d3dSprite.End();
}
device.EndScene();
device.Present();
}
}
}