Sign in to follow this  
  • entry
    1
  • comments
    4
  • views
    2872

SimpleRTS Update #1

Sign in to follow this  
Narf the Mouse

1332 views

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  


4 Comments


Recommended Comments

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 !

Share this comment


Link to comment
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?

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now