SimpleRTS Update #1

Published April 07, 2012
Advertisement
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();
}
}
}
0 likes 4 comments

Comments

peous
Well... It's step 1 :)
Next time, could you post some screenshot too, or some explanation of your code ? (for now it's simple enough to read but well... someday you'll have a game !!!!!)
Good luck !
April 09, 2012 08:23 PM
KenjiSenpai
Ya, comment the code please !
April 10, 2012 06:44 AM
Narf the Mouse
The next update will be commented. :)
April 10, 2012 04:42 PM
omnomnom
I'm going to make a game...<INSERTS CODE>

but seriously an RTS is a nice idea. Now I wish I was making an RTS too. Maybe my next project (ie 2014). You going to make it singleplayer or multiplayer?
April 14, 2012 10:13 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

SimpleRTS Update #1

1968 views
Advertisement