Created
June 24, 2014 00:18
-
-
Save phrohdoh/96a5fb3e734330e868a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using Microsoft.Xna.Framework; | |
using Microsoft.Xna.Framework.Graphics; | |
namespace PrototypeRPG.Traits | |
{ | |
public class World | |
{ | |
public const int TickTimestep = 40; | |
public SpriteBatch SpriteBatch { get; private set; } | |
public List<Actor> Actors = new List<Actor>(); | |
public int TotalTickCount { get { return TickCount + TickRenderCount; } } | |
public int TickCount { get; private set; } | |
public int TickRenderCount { get; private set; } | |
int lastTickDelta = 0; | |
public World(SpriteBatch spriteBatch) { SpriteBatch = spriteBatch; } | |
public void Tick(GameTime gameTime) | |
{ | |
if (gameTime.ElapsedGameTime >= TickTimestep) | |
{ | |
InnerTick(); | |
lastTickDelta = 0; | |
} | |
else | |
lastTickDelta++; | |
} | |
void InnerTick() | |
{ | |
TickCount++; | |
foreach (var actor in Actors) | |
{ | |
foreach (var trait in actor.TraitsImplementing<ITick>()) | |
trait.Tick(actor); | |
} | |
} | |
public void TickRender() | |
{ | |
TickRenderCount++; | |
foreach (var actor in Actors) | |
foreach (var trait in actor.TraitsImplementing<ITickRender>()) | |
trait.TickRender(actor, SpriteBatch); | |
} | |
public Actor CreateActor(params ITrait[] traits) | |
{ | |
var newActor = new Actor(); | |
foreach (var trait in traits) | |
newActor.AddTrait(trait); | |
Actors.Add(newActor); | |
return newActor; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment