I just finished to code the most important parts of my game engine (not a tile-map one), such as lights, shadows, objects update/draw, input, ecc. Now I'm making a level editor to simplify the creation of levels. I have a form that does only simple things: place the player, place a block, choose a background, place an enemy... These two components are divided between them (sorry for my bad english).
My question relies on the relation between the form (level editor) and the game engine (the game itself)
These are my thoughts:
For a better explaination, take this example:
- My game_engine project holds a Light class, a Player class, a Background class, an Enemy class. My engine (in abstract) is like this:
namespace game_engine
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
enum GameStates { TitleScreen, Playing, PlayerDead, GameOver };
GameStates gameState = GameStates.Playing;
Enemy zombie1;
Enemy zombie2;
Light sun;
Light lamp1;
Player player;
Background mountains;
}
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
this.graphics.PreferredBackBufferWidth = 800;
this.graphics.PreferredBackBufferHeight = 600;
this.graphics.ApplyChanges();
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
Camera.ViewPortWidth = 800;
Camera.ViewPortHeight = 600;
Camera.Position = new Vector2(0, 0);
mountains = new Background(...);
zombie1 = new Enemy(...);
zombie2 = new Enemy(...);
sun = new Light(...);
lamp1 = new Light(...);
enemy_manager.Add(zombie1);
enemy_manager.Add(zombie2);
light_manager.Add(sun);
light_manager.Add(lamp1);
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
switch (gameState)
{
case GameStates.TitleScreen:
//Something
break;
case GameStates.Playing:
enemy_manager.Update(gameTime);
light_manager.Update(gameTime);
mountains.Update(gameTime);
player.Update(gameTime);
break;
case GameStates.PlayerDead:
//Something
break;
case GameStates.GameOver:
//Something
break;
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
switch (gameState)
{
case GameStates.TitleScreen:
//Something
break;
case GameStates.Playing:
enemy_manager.Draw(spriteBatch);
light_manager.Draw(spriteBatch);
mountains.Draw(spriteBatch);
player.Draw(spriteBatch);
break;
case GameStates.PlayerDead:
//Something
break;
case GameStates.GameOver:
//Something
break;
}
base.Draw(gameTime);
}
Then I have another project which is a form (Level editor) with some function/tool to help me out not putting manually every entity (enemy, light, ecc ...) when initializing the game:
At this point I have to "link" the form and my game engine. To make my tests I just did copy and paste game engine code into form project. But this is the wrong idea, because I want my code to be written once. Here there are my doubts: is it possible to create a link between them, considering that:
- Inside the form there is a PictureBox where I want to render my game for full (With lights, shadows, etc)
- I want to write once the game engine so that if I modify something for example inside "Enemy" class, when editing both Level editor and Game itself would run the new code
I miss that logical link between my two entities, I need some hint to go on, something to think about in order to clear things up. I put some code, please give me some code.