I'm not necessarily against open source, however I'm looking at a good amount of the player's airland intra-actions being done client-side, and in a multiplayer environment I could see this being problematic with a completely open source project. Again I still have a lot to learn about programming, and networking and security are one of the areas that I don't know a lot about, so i could be very wrong.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace Airlands
{
public class Core : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
GraphicsDevice device;
//BasicEffect effect;
Matrix viewMatrix;
Matrix projectionMatrix;
//VertexBuffer mapVertexBuffer;
//VertexDeclaration texturedVertexDeclaration;
//Texture2D grassTexture;
float xrotangle;
float yrotangle;
double yDouble = new double();
float yValue = new float();
float zoomValue = new float();
Model hexTileModel;
Vector3 hexOnelocation;
Vector3 hexTwolocation;
Vector3 hexThreelocation;
Model mainTowerModel;
Vector3 mainTowerlocation;
Matrix worldMatrix;
Vector3 lightDirection = new Vector3(5.0f, -3.0f, -3.0f);
private void SetUpCamera()
{
Vector3 xrotAxis = new Vector3(3 * xrotangle, xrotangle, 2 * xrotangle);
xrotAxis.Normalize();
Vector3 yrotAxis = new Vector3(3 * yrotangle, yrotangle, 2 * yrotangle);
yrotAxis.Normalize();
worldMatrix = Matrix.CreateTranslation(0, 0, 0) * Matrix.CreateRotationZ(-yrotangle) * Matrix.CreateRotationX(xrotangle);
viewMatrix = Matrix.CreateLookAt(new Vector3 (0,0,zoomValue),new Vector3 (0,0,0), new Vector3(0,1,0));
projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 0.01f, 3000.0f);
}
private Model LoadModel(string assetName)
{
Model newModel = Content.Load<Model>(assetName);
//foreach (ModelMesh mesh in newModel.Meshes)
// foreach (ModelMeshPart meshPart in mesh.MeshParts)
// meshPart.Effect = effect.Clone(device);
return newModel;
}
//private void SetUpVertices()
//{
// List<VertexPositionNormalTexture> verticesList = new List<VertexPositionNormalTexture>();
//
//
// verticesList.Add(new VertexPositionNormalTexture(new Vector3(.5f, 0, 0), new Vector3(0, 0, 1), new Vector2(.25f, 0)));
// verticesList.Add(new VertexPositionNormalTexture(new Vector3(0,(yValue/2), 0), new Vector3(0, 0, 1), new Vector2(0,.5f)));
// verticesList.Add(new VertexPositionNormalTexture(new Vector3(.5f,yValue, 0), new Vector3(0, 0, 1), new Vector2(.25f, 1)));
// verticesList.Add(new VertexPositionNormalTexture(new Vector3(.5f, 0, 0), new Vector3(0, 0, 1), new Vector2 (.25f, 0)));
// verticesList.Add(new VertexPositionNormalTexture(new Vector3(.5f, yValue, 0), new Vector3(0, 0, 1), new Vector2(.25f, 1)));
// verticesList.Add(new VertexPositionNormalTexture(new Vector3(1.5f, yValue, 0), new Vector3(0, 0, 1), new Vector2(.75f, 1)));
//
// verticesList.Add(new VertexPositionNormalTexture(new Vector3(.5f, 0, 0), new Vector3(0, 0, 1), new Vector2(.25f, 0)));
// verticesList.Add(new VertexPositionNormalTexture(new Vector3(1.5f, yValue, 0), new Vector3(0, 0, 1), new Vector2(.75f, 1)));
// verticesList.Add(new VertexPositionNormalTexture(new Vector3(1.5f, 0, 0), new Vector3(0, 0, 1), new Vector2(.75f, 0)));
// verticesList.Add(new VertexPositionNormalTexture(new Vector3(1.5f, 0, 0), new Vector3(0, 0, 1), new Vector2(.75f, 0)));
// verticesList.Add(new VertexPositionNormalTexture(new Vector3(1.5f, yValue, 0), new Vector3(0, 0, 1), new Vector2(.75f, 1)));
// verticesList.Add(new VertexPositionNormalTexture(new Vector3(2, (yValue/ 2), 0), new Vector3(0, 0, 1), new Vector2(1, .5f)));
// mapVertexBuffer = new VertexBuffer(device, verticesList.Count * VertexPositionNormalTexture.SizeInBytes, BufferUsage.WriteOnly);
// mapVertexBuffer.SetData<VertexPositionNormalTexture>(verticesList.ToArray());
// texturedVertexDeclaration = new VertexDeclaration(device, VertexPositionNormalTexture.VertexElements);
//}
// private void DrawHex()
// {
// effect.CurrentTechnique = effect.Techniques["Textured"];
// effect.Parameters["xWorld"].SetValue(worldMatrix);
// effect.Parameters["xView"].SetValue(viewMatrix);
// effect.Parameters["xProjection"].SetValue(projectionMatrix);
// effect.Parameters["xTexture"].SetValue(grassTexture);
// effect.Begin();
// foreach (EffectPass pass in effect.CurrentTechnique.Passes)
// {
// pass.Begin();
// device.VertexDeclaration = texturedVertexDeclaration;
// device.Vertices[0].SetSource(mapVertexBuffer, 0, VertexPositionNormalTexture.SizeInBytes);
// device.DrawPrimitives(PrimitiveType.TriangleList, 0, mapVertexBuffer.SizeInBytes / VertexPositionNormalTexture.SizeInBytes / 3);
// pass.End();
// }
// effect.End();
//}
private void DrawModel(Model currentModel, Vector3 currentModelLocation)
{
Matrix[] CurrentTransforms = new Matrix[currentModel.Bones.Count];
currentModel.CopyAbsoluteBoneTransformsTo(CurrentTransforms);
foreach (ModelMesh mesh in currentModel.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = (CurrentTransforms[mesh.ParentBone.Index]*Matrix.CreateRotationX (MathHelper.PiOver2)* Matrix.CreateTranslation (currentModelLocation)* worldMatrix);
effect.View = viewMatrix;
effect.Projection = projectionMatrix;
effect.EnableDefaultLighting();
//effect.CurrentTechnique = effect.Techniques["Colored"];
//effect.Parameters["xWorld"].SetValue(HexTileTransforms[mesh.ParentBone.Index]*worldMatrix);
//effect.Parameters["xView"].SetValue(viewMatrix);
//effect.Parameters["xProjection"].SetValue(projectionMatrix);
//effect.
//effect.EnableDefaultLighting();
//effect.Parameters["xEnableLighting"].SetValue(true);
//effect.Parameters["xLightDirection"].SetValue(lightDirection);
//effect.Parameters["xAmbient"].SetValue(0.5f);
}
mesh.Draw();
}
}
public Core()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
graphics.PreferredBackBufferWidth = 400;
graphics.PreferredBackBufferHeight = 400;
graphics.IsFullScreen = false;
graphics.ApplyChanges();
Window.Title = "Airlands";
Window.AllowUserResizing = false;
lightDirection.Normalize();
base.Initialize();
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
device = graphics.GraphicsDevice;
//effect = Content.Load<Effect>("effects");
yDouble = Math.Sqrt(3);
yValue = (float)yDouble;
xrotangle = 0;
yrotangle = 0;
zoomValue = 20;
//grassTexture = Content.Load<Texture2D>("GrassTexture");
//SetUpVertices();
hexTileModel = LoadModel("Models\\HexTile");
mainTowerModel = LoadModel("Models\\MainTower");
hexOnelocation = new Vector3(0,0,0);
hexTwolocation = new Vector3(0,-yValue*2,0);
hexThreelocation= new Vector3(3,-yValue,0);
mainTowerlocation= new Vector3(0,0,0);
// TODO: use this.Content to load your game content here
}
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
KeyboardState keyState = Keyboard.GetState();
if (keyState.IsKeyDown(Keys.Up))
xrotangle += 0.05f;
if (keyState.IsKeyDown(Keys.Down))
xrotangle -= 0.05f;
if (keyState.IsKeyDown(Keys.Left))
yrotangle -= 0.05f;
if (keyState.IsKeyDown(Keys.Right))
yrotangle += 0.05f;
if (keyState.IsKeyDown(Keys.Q))
zoomValue -= 0.15f;
if (keyState.IsKeyDown(Keys.A))
zoomValue += 0.15f;
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
SetUpCamera();
// TODO: Add your update logic here
base.Update(gameTime);
}
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
device.Clear(Color.CornflowerBlue);
//effect.CurrentTechnique = effect.Techniques["Pretransformed"];
//effect.Parameters["xEnableLighting"].SetValue(true);
// effect.Parameters["xLightDirection"].SetValue(lightDirection);
//effect.Parameters["xAmbient"].SetValue(0.5f);
// effect.Begin();
// foreach (EffectPass pass in effect.CurrentTechnique.Passes)
// {
// pass.Begin();
//
//
// pass.End();
//}
// effect.End();
//effect.Parameters["xView"].SetValue(viewMatrix);
//effect.Parameters["xProjection"].SetValue(projectionMatrix);
// effect.Parameters["xWorld"].SetValue(Matrix.Identity);
//DrawHex();
DrawModel(hexTileModel, hexOnelocation);
DrawModel(hexTileModel, hexTwolocation);
DrawModel(hexTileModel, hexThreelocation);
DrawModel(mainTowerModel, mainTowerlocation);
base.Draw(gameTime);
}
}
}
Its a bit sloppy right now, as i've still got some stuff in there from the first rendering tests, My next step is going to be to tighten it up, and convert into objects.
Also Thanks everyone for their suggestions/comments, even if i'm not responding to everything I'm reading it all and taking everything into consideration. (I'm a ponderer, so it may take me some time to digest a suggestion that i haven't considered before)