• Advertisement
Sign in to follow this  
  • entry
    1
  • comments
    4
  • views
    3028

About this blog

SimpleRTS Development Journal

Entries in this blog

Most of my programming has been hobbyist-theoretical and reading more blogs than is probably healthy. I'm sick of it. I wanna make a game.

I'm going to make a game, using my current game engine.

Presenting SimpleRTS Update 1:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Game_Engine_Toolkit;


namespace SimpleRTS
{
static class Program
{
static System.Diagnostics.Stopwatch watch =
System.Diagnostics.Stopwatch.StartNew();
static double lastSecond = 0.0;
static double deltaSeconds = 0.0;


static Display display = null;
static Scene scene = null;
static Keyboard keyboard = null;
static Vector3 cameraPoint = Vector3.Zero;
static float cameraHeight = 256;
static float minCameraHeight = 32;
static float maxCameraHeight = 768;
static string groundName = "Ground";
static string mainCameraName = "Main Camera";


///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
try
{
{
display = new Display(
typeOfDevice: DeviceType.DirectX9,
threaded: Threaded.SingleThreaded,
screenMode: ScreenMode.Windowed,
onDeviceLost: OnDeviceLost,
onDeviceReset: OnDeviceReset,
title: "Simple RTS",
displayWidth: 1024,
displayHeight: 768
);
}

{
scene = new Scene(display);
}

{
keyboard = new Keyboard();
}


{
Mesh ground = scene.CreateMesh(groundName);
ground.SetCube(1024, 1, 1024);
ground.MaterialDiffuseColourDrawing = Color.SandyBrown;
ground.MaterialSpecularColourDrawing = Color.SandyBrown;
ground.MaterialSpecularColourVector *= 0.5F;
ground.LocalMatrix = Matrix4x4.Translation(Vector3.Down * 0.5F);
}

{
cameraPoint = new Vector3(-384, 0, -384);

Camera camera = scene.CreateCamera(mainCameraName);
camera.SetPerspective(Utility.DegreesToRadians(65), display.AspectRatio, 0.001F, 10000);
camera.SetLookAt(cameraPoint + new Vector3(0, cameraHeight, -64), cameraPoint, Vector3.Up + Vector3.Forward);
}

{
Light light = scene.CreateLight("Sunlight");
light.SetDirectional(
on: true,
direction: new Vector3(-55, -35, 1),
diffuseColour: Color.LightGoldenrodYellow,
specularColour: Color.LightGoldenrodYellow,
specularExponent: 1,
intensity: 0.8F
);
}


lastSecond = watch.Elapsed.TotalSeconds;
while (!display.Closed)
{
deltaSeconds = watch.Elapsed.TotalSeconds - lastSecond;
lastSecond = watch.Elapsed.TotalSeconds;
float deltaSecondsUse = (float)deltaSeconds;


keyboard.Update();


if (keyboard.State.KeyDown(Key.Escape))
break;


if (keyboard.State.KeyDown(Key.PageUp))
cameraHeight = Math.Min(cameraHeight + (cameraHeight * deltaSecondsUse), maxCameraHeight);
if (keyboard.State.KeyDown(Key.PageDown))
cameraHeight = Math.Max(cameraHeight - (cameraHeight * deltaSecondsUse), minCameraHeight);

scene.GetCamera(mainCameraName).SetLookAt(cameraPoint + new Vector3(0, cameraHeight, -64), cameraPoint, Vector3.Up + Vector3.Forward);


display.BeginScene();

display.Clear(Color.LightSkyBlue);


foreach (var light in scene.Lights)
light.Draw();
foreach (var camera in scene.Cameras)
{
camera.Draw(deltaSecondsUse);

foreach (var mesh in scene.Meshes)
{
mesh.Draw(deltaSecondsUse);
}
}


display.EndScene();

display.Present();

display.Update();
}
}
catch (Exception e)
{
Logging.DefaultLog.Log(e);
}
finally
{
Utility.SafeDispose(display);
Utility.SafeDispose(scene);
}
}


private static void OnDeviceLost()
{
if (scene != null) scene.Release();
}
private static void OnDeviceReset()
{
if (scene != null) scene.Reload();
}
}
}
Sign in to follow this  
  • Advertisement