I have created my EventReceiver class;
Now i need to implement it into the Device and have the events execute when a key is pressed, how do i do this?
Here is my Main Class
Code: Select all
public class CarGame
{
public static MechEvents MechEvent;
public static Mech Mech1;
public static int fps = 0;
public static Irrlicht.IrrlichtDevice Device;
public static Map Map1;
static void Main()
{
CarGame.SetUpWorld();
Map1 = new Map();
Mech1 = new Mech();
while(Device.Run())
{
CarGame.GameLoop();
}
}
private static void SetUpWorld()
{
//Add device
Device = new IrrlichtDevice(Irrlicht.Video.DriverType.DIRECTX9, new Dimension2D(640,480),32,false, true, false);
Device.WindowCaption = "CarGame";
Device.CursorControl.Visible = false;
Device.EventReceiver = MechEvent;
}
private static void UpdateCam()
{
Irrlicht.Core.Vector3D MechPosition = CarGame.Mech1.ndMech.Position;
Vector3D CamPosition;
CamPosition.X = MechPosition.X-500.0f;
CamPosition.Y = MechPosition.Y-500.0f;
CamPosition.Z = 1000f;
Mech1.MechCam.Position.Set(CamPosition);
Mech1.MechCam.Target.Set(MechPosition);
}
private static void GameLoop()
{
CarGame.UpdateCam();
#region Render
//Render
if (Device.WindowActive)
{
CarGame.UpdateCam();
Device.VideoDriver.BeginScene(true,true, new Color(0,100,100,100));
Device.SceneManager.DrawAll();
Device.VideoDriver.EndScene();
}
// display frames per second value
if (fps != Device.VideoDriver.FPS)
{
fps = Device.VideoDriver.FPS;
Device.WindowCaption =
"Irrlicht.NET C# example 01 - Hello World [" +
Device.VideoDriver.Name + "] fps:" + fps;
}
#endregion
}
}//end class
Code: Select all
public class MechEvents : Irrlicht.IEventReceiver
{
private static Irrlicht.Core.Vector3D Mech1Pos = new Vector3D();
public MechEvents()
{
}
bool Irrlicht.IEventReceiver.OnEvent(Irrlicht.Event Event)
{
if (Event.Type == Irrlicht.EventType.KeyInput && Event.KeyPressedDown == true)
{
//If The W key is pressed, move Sydney forward
if (Event.Key == Irrlicht.KeyCode.KEY_KEY_W)
{
Mech1Pos = CarGame.Mech1.ndMech.Position;
Mech1Pos.Z +=5;
CarGame.Mech1.ndMech.Position.Set(Mech1Pos);
}
return true;
}
return false;
}
}
[\code]
now where do i go... I don understand it from here on the Movement turorial...