-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEngine.cs
More file actions
126 lines (99 loc) · 3.12 KB
/
Engine.cs
File metadata and controls
126 lines (99 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using Microsoft.Xna;
using Dabrorius.MonoPunk;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
namespace Dabrorius.MonoPunk
{
public class Engine : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
public static Engine currentEngine;
public Engine (int width, int height, string assetsDirectory = "./") : base()
{
MP.Width = width;
MP.Height = height;
MP.currentWorld = new World ();
Window.AllowUserResizing = true;
graphics = new GraphicsDeviceManager (this);
graphics.SynchronizeWithVerticalRetrace = false;
graphics.PreferredBackBufferWidth = MP.Width;
graphics.PreferredBackBufferHeight = MP.Height;
graphics.ApplyChanges ();
this.IsFixedTimeStep = false;
//graphics.IsFullScreen = true;
//graphics.ApplyChanges ();
Content.RootDirectory = assetsDirectory;
Engine.currentEngine = this;
}
public static Texture2D EmbeddFile(String filename)
{
return currentEngine.Content.Load<Texture2D>(filename);
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures
MP.Buffer = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
//eater.LoadGraphic(Content,"smiley.png");
//MP.CurrentWorld.Add (eater);
//myWorld.addRender(eater);
//myWorld.addUpdate(eater);
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
MP.Buffer.Begin();
Render();
MP.Buffer.End();
base.Draw(gameTime);
}
protected override void Update (GameTime gameTime)
{
Input.UpdateKeyboardInput ();
MP.Elapsed = gameTime.ElapsedGameTime.TotalMilliseconds / 1000;
// Write frame rate to console
frameRateSum += 1 / MP.Elapsed;
frameRateCount += 1;
if (frameRateCount == 100) {
Console.WriteLine (frameRateSum / frameRateCount);
frameRateSum = 0;
frameRateCount = 0;
}
//if (FP.tweener.active && FP.tweener._tween) FP.tweener.updateTweens();
if (MP.CurrentWorld.Active)
{
//if (FP._world._tween) FP._world.updateTweens();
MP.CurrentWorld.Update();
}
MP.CurrentWorld.UpdateLists();
if (MP.nextWorld != null) checkWorld();
Input.SaveOldKeyboardInput();
base.Update (gameTime);
}
/**
* Renders the game, rendering the World and Entities.
*/
public void Render()
{
MP.CurrentWorld.Render();
}
/** @private Switch Worlds if they've changed. */
private void checkWorld()
{
if (MP.nextWorld == null) return;
MP.currentWorld.End();
MP.currentWorld.UpdateLists();
//if (FP._world && FP._world.autoClear && FP._world._tween) FP._world.clearTweens();
MP.currentWorld = MP.nextWorld;
MP.nextWorld = null;
MP.Camera = MP.CurrentWorld.Camera;
MP.currentWorld.UpdateLists();
MP.currentWorld.Begin();
MP.currentWorld.UpdateLists();
}
private double frameRateSum = 0;
private int frameRateCount = 0;
}
}