2015-05-12 16:48:58 -06:00
|
|
|
|
using System;
|
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Input;
|
2015-05-12 17:39:34 -06:00
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2015-05-13 11:30:29 -06:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using TrueCraft.Client.Linux.Interface;
|
|
|
|
|
using System.IO;
|
2015-05-13 14:20:35 -06:00
|
|
|
|
using System.Net;
|
2015-05-12 16:48:58 -06:00
|
|
|
|
|
|
|
|
|
namespace TrueCraft.Client.Linux
|
|
|
|
|
{
|
|
|
|
|
public class TrueCraftGame : Game
|
|
|
|
|
{
|
2015-05-12 17:30:56 -06:00
|
|
|
|
private MultiplayerClient Client { get; set; }
|
2015-05-12 16:48:58 -06:00
|
|
|
|
private GraphicsDeviceManager Graphics { get; set; }
|
2015-05-13 11:30:29 -06:00
|
|
|
|
private List<IGameInterface> Interfaces { get; set; }
|
|
|
|
|
private FontRenderer DejaVu { get; set; }
|
|
|
|
|
private SpriteBatch SpriteBatch { get; set; }
|
2015-05-13 14:20:35 -06:00
|
|
|
|
private IPEndPoint EndPoint { get; set; }
|
|
|
|
|
private ChunkConverter ChunkConverter { get; set; }
|
2015-05-12 17:39:34 -06:00
|
|
|
|
|
2015-05-13 14:20:35 -06:00
|
|
|
|
public TrueCraftGame(MultiplayerClient client, IPEndPoint endPoint)
|
2015-05-12 16:48:58 -06:00
|
|
|
|
{
|
|
|
|
|
Window.Title = "TrueCraft";
|
2015-05-13 11:30:29 -06:00
|
|
|
|
Content.RootDirectory = "Content";
|
2015-05-12 16:48:58 -06:00
|
|
|
|
Graphics = new GraphicsDeviceManager(this);
|
|
|
|
|
Graphics.IsFullScreen = false;
|
2015-05-12 17:39:34 -06:00
|
|
|
|
Graphics.PreferredBackBufferWidth = 1280;
|
|
|
|
|
Graphics.PreferredBackBufferHeight = 720;
|
2015-05-12 17:30:56 -06:00
|
|
|
|
Client = client;
|
2015-05-13 14:20:35 -06:00
|
|
|
|
EndPoint = endPoint;
|
|
|
|
|
ChunkConverter = new ChunkConverter();
|
|
|
|
|
Client.ChunkLoaded += (sender, e) => ChunkConverter.QueueChunk(e.Chunk);
|
2015-05-12 16:48:58 -06:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-13 11:30:29 -06:00
|
|
|
|
protected override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
Interfaces = new List<IGameInterface>();
|
|
|
|
|
SpriteBatch = new SpriteBatch(GraphicsDevice);
|
2015-05-13 14:20:35 -06:00
|
|
|
|
base.Initialize(); // (calls LoadContent)
|
|
|
|
|
ChunkConverter.Start();
|
|
|
|
|
Client.Connect(EndPoint);
|
2015-05-13 11:30:29 -06:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-12 17:39:34 -06:00
|
|
|
|
protected override void LoadContent()
|
|
|
|
|
{
|
2015-05-13 11:30:29 -06:00
|
|
|
|
FontFile fontFile;
|
|
|
|
|
using (var f = File.OpenRead(Path.Combine(Content.RootDirectory, "dejavu.fnt")))
|
|
|
|
|
fontFile = FontLoader.Load(f);
|
|
|
|
|
var fontTexture = Content.Load<Texture2D>("dejavu_0.png");
|
|
|
|
|
DejaVu = new FontRenderer(fontFile, fontTexture);
|
|
|
|
|
Interfaces.Add(new ChatInterface(Client, DejaVu));
|
2015-05-12 17:39:34 -06:00
|
|
|
|
base.LoadContent();
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-12 16:48:58 -06:00
|
|
|
|
protected override void Update(GameTime gameTime)
|
|
|
|
|
{
|
|
|
|
|
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
|
|
|
|
|
Exit();
|
2015-05-13 11:30:29 -06:00
|
|
|
|
foreach (var i in Interfaces)
|
|
|
|
|
{
|
|
|
|
|
i.Update(gameTime);
|
|
|
|
|
}
|
2015-05-12 16:48:58 -06:00
|
|
|
|
base.Update(gameTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Draw(GameTime gameTime)
|
|
|
|
|
{
|
|
|
|
|
Graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
|
2015-05-13 11:30:29 -06:00
|
|
|
|
SpriteBatch.Begin();
|
|
|
|
|
foreach (var i in Interfaces)
|
|
|
|
|
{
|
|
|
|
|
i.DrawSprites(gameTime, SpriteBatch);
|
|
|
|
|
}
|
|
|
|
|
SpriteBatch.End();
|
2015-05-12 16:48:58 -06:00
|
|
|
|
base.Draw(gameTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|