public static LevelGrid Copy(this ILevelGrid level) { var copy = new LevelGrid(level.Width, level.Height); for (int x = 0; x < level.Width; ++x) { for (int y = 0; y < level.Height; ++y) { copy.SetElement(x, y, level.GetElement(x, y)); } } return(copy); }
public static bool IsEmpty(this ILevelGrid level) { for (int x = 0; x < level.Width; ++x) { for (int y = 0; y < level.Height; ++y) { if (level.GetElement(x, y).ContainsBox()) { return(false); } } } return(true); }
public static Point?FindPlayerPos(this ILevelGrid level) { for (int x = 0; x < level.Width; ++x) { for (int y = 0; y < level.Height; ++y) { var type = level.GetElement(x, y); if (type.ContainsMan()) { return(new Point(x, y)); } } } return(null); }
internal void DrawLevelState(ILevelGrid levelState, Color tint) { UpdateLevelGeometry(levelState); shdTexColor.Activate(); texArray.Activate(); var fitBox = Box2DExtensions.CreateContainingBox(levelState.Width, levelState.Height, windowAspect); var camera = Matrix4x4.CreateOrthographicOffCenter(fitBox.MinX, fitBox.MaxX, fitBox.MinY, fitBox.MaxY, 0, 1); shdTexColor.Uniform(nameof(tint), tint.ToVector4()); shdTexColor.Uniform(nameof(camera), camera, true); vaoLevelGeometry.Draw(levelState.Width * levelState.Height); texArray.Deactivate(); shdTexColor.Deactivate(); }
public static bool IsWon(this ILevelGrid level) { for (int x = 0; x < level.Width; ++x) { for (int y = 0; y < level.Height; ++y) { var type = level.GetElement(x, y); //if a single goal without a box is found the game is not yet won. if (ElementType.Goal == type || ElementType.ManOnGoal == type) { return(false); } } } return(true); }
public void DrawLevelState(ILevelGrid level, Color tint) { GL.Color3(tint); GL.LoadIdentity(); var fitBox = Box2DExtensions.CreateContainingBox(level.Width, level.Height, windowAspect); GL.Ortho(fitBox.MinX, fitBox.MaxX, fitBox.MinY, fitBox.MaxY, 0.0, 1.0); for (int x = 0; x < level.Width; ++x) { for (int y = 0; y < level.Height; ++y) { var tile = new Box2D(x, y, 1.0f, 1.0f); var element = level.GetElement(x, y); var tex = tileSet[element]; tex.Activate(); tile.DrawTexturedRect(Box2D.BOX01); tex.Deactivate(); } } }
private void UpdateLevelGeometry(ILevelGrid levelState) { if (!ReferenceEquals(levelState, lastLevelState)) { //move or different level size lastLevelState = levelState; var size = new Size(levelState.Width, levelState.Height); if (lastLevelSize != size) { //different level size -> create translates for tiles var instanceTranslate = new List <Vector2>(); for (int x = 0; x < levelState.Width; ++x) { for (int y = 0; y < levelState.Height; ++y) { instanceTranslate.Add(new Vector2(x, y)); } } var locInstanceTranslate = shdTexColor.GetResourceLocation(ShaderResourceType.Attribute, "instanceTranslate"); vaoLevelGeometry.SetAttribute(locInstanceTranslate, instanceTranslate.ToArray(), true); lastLevelSize = size; } //update all tile types var texId = new List <float>(); for (int x = 0; x < levelState.Width; ++x) { for (int y = 0; y < levelState.Height; ++y) { var type = levelState.GetElement(x, y); texId.Add(tileTypes[type].Item2); } } var locTexId = shdTexColor.GetResourceLocation(ShaderResourceType.Attribute, "texId"); vaoLevelGeometry.SetAttribute(locTexId, texId.ToArray(), true); drawLevel = DrawableGL.CreateDrawCallGL(PrimitiveType.Quads, 4, levelState.Width * levelState.Height, vaoLevelGeometry); } }
public void DrawLevelState(ILevelGrid levelState, Color tint) { levelVisual.DrawLevelState(levelState, tint); }
public static ElementType GetElement(this ILevelGrid level, Point position) { return(level.GetElement(position.X, position.Y)); }