/// <summary> /// /// </summary> public void Draw(GameBase game, Tilemap map, Vector location, Color?color) { if (prevFrameCount != game.TotalFrame) { if (timer > Interval) { animationState++; if (animationState >= Animations.Length) { animationState = 0; } timer = 0; } Texture = Animations[animationState]; timer += Time.DeltaTime; } prevFrameCount = game.TotalFrame; TextureDrawer.Draw(game, Texture, location, map.Scale, map.Angle, color); }
public void Draw(GameBase game, Tilemap map, Vector location, Color?color) { if (prevFrameCount != game.TotalFrame) { if (timer > Interval) { animationState = animationState < Textures.Length - 1 ? animationState + 1 : 0; timer = 0; } timer += Time.DeltaTime; } prevFrameCount = game.TotalFrame; const int outside = 4 * 0; const int vertical = 4 * 1; const int horizontal = 4 * 2; const int inside = 4 * 3; const int fill = 4 * 4; var l = (int)Texture[0].Size.X; var topLeft = new Vector(0, 0); var topRight = new Vector(l, 0); var bottomLeft = new Vector(0, l); var bottomRight = new Vector(l, l); void Draw(Texture2D texture, Vector rel) => TextureDrawer.Draw(game, texture, location + rel * map.Scale, map.Scale, map.Angle, color); var(x, y) = map.CurrentDrawingPosition ?? VectorInt.Zero; //top left { var texture = map[x - 1, y] != this && map[x, y - 1] != this ? outside : map[x - 1, y] != this ? vertical : map[x, y - 1] != this ? horizontal : map[x - 1, y - 1] != this ? inside : fill; Draw(Texture[texture + 0], topLeft); } //top right { var texture = map[x + 1, y] != this && map[x, y - 1] != this ? outside : map[x + 1, y] != this ? vertical : map[x, y - 1] != this ? horizontal : map[x + 1, y - 1] != this ? inside : fill; Draw(Texture[texture + 1], topRight); } //bottom left { var texture = map[x - 1, y] != this && map[x, y + 1] != this ? outside : map[x - 1, y] != this ? vertical : map[x, y + 1] != this ? horizontal : map[x - 1, y + 1] != this ? inside : fill; Draw(Texture[texture + 2], bottomLeft); } //bottom right { var texture = map[x + 1, y] != this && map[x, y + 1] != this ? outside : map[x + 1, y] != this ? vertical : map[x, y + 1] != this ? horizontal : map[x + 1, y + 1] != this ? inside : fill; Draw(Texture[texture + 3], bottomRight); } }