Rendering fixes. Console started

This commit is contained in:
Matt Thorson 2020-06-14 17:51:13 -07:00
parent e1620cb930
commit 272ec43e69
4 changed files with 36 additions and 4 deletions

View File

@ -189,6 +189,8 @@ namespace Strawberry
Time.PreviousElapsed = Time.Elapsed; Time.PreviousElapsed = Time.Elapsed;
Time.Elapsed += Time.Delta; Time.Elapsed += Time.Delta;
} }
Strawberry.Console.Update();
} }
private void Render() private void Render()
@ -204,6 +206,9 @@ namespace Strawberry
{ {
if (Scene != null) if (Scene != null)
Scene.Draw(); Scene.Draw();
if (Console.Enabled)
Strawberry.Console.Draw();
} }
public Scene Scene public Scene Scene
@ -231,7 +236,7 @@ namespace Strawberry
if (Directory.Exists(root)) if (Directory.Exists(root))
LoadSpritesDir(root); LoadSpritesDir(root);
else else
Console.WriteLine("Content/Sprites folder does not exist!"); Calc.Log("Content/Sprites folder does not exist!");
} }
private void LoadSpritesDir(String directory) private void LoadSpritesDir(String directory)

View File

@ -394,9 +394,9 @@ namespace Strawberry
{ {
for (int p = 0, int b = 0; p < len; p++, b += 4) for (int p = 0, int b = 0; p < len; p++, b += 4)
{ {
pixels[p].R = (uint8)((int)bytes[b + 0] * bytes[b + 3] / 255); pixels[p].R = (uint8)((int)bytes[b + 0] * (int)bytes[b + 3] / 255);
pixels[p].G = (uint8)((int)bytes[b + 1] * bytes[b + 3] / 255); pixels[p].G = (uint8)((int)bytes[b + 1] * (int)bytes[b + 3] / 255);
pixels[p].B = (uint8)((int)bytes[b + 2] * bytes[b + 3] / 255); pixels[p].B = (uint8)((int)bytes[b + 2] * (int)bytes[b + 3] / 255);
pixels[p].A = bytes[b + 3]; pixels[p].A = bytes[b + 3];
} }
} }

19
src/Static/Console.bf Normal file
View File

@ -0,0 +1,19 @@
namespace Strawberry
{
static public class Console
{
static public bool Enabled;
static public void Update()
{
if (Input.KeyPressed(.Grave))
Enabled = !Enabled;
}
static public void Draw()
{
Calc.Log();
Draw.Rect(0, 0, Game.Width, Game.Height, .Black * 0.4f);
}
}
}

View File

@ -9,6 +9,7 @@ namespace Strawberry
static public void Rect(int x, int y, int w, int h, Color color) static public void Rect(int x, int y, int w, int h, Color color)
{ {
SDL.SetRenderDrawBlendMode(Game.Renderer, .Blend);
SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A); SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
SDL.RenderFillRect(Game.Renderer, &SDL.Rect((int32)(x - Camera.X), (int32)(y - Camera.Y), (int32)w, (int32)h)); SDL.RenderFillRect(Game.Renderer, &SDL.Rect((int32)(x - Camera.X), (int32)(y - Camera.Y), (int32)w, (int32)h));
} }
@ -20,6 +21,7 @@ namespace Strawberry
static public void HollowRect(int x, int y, int w, int h, Color color) static public void HollowRect(int x, int y, int w, int h, Color color)
{ {
SDL.SetRenderDrawBlendMode(Game.Renderer, .Blend);
SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A); SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
SDL.RenderDrawRect(Game.Renderer, &SDL.Rect((int32)(x - Camera.X), (int32)(y - Camera.Y), (int32)w, (int32)h)); SDL.RenderDrawRect(Game.Renderer, &SDL.Rect((int32)(x - Camera.X), (int32)(y - Camera.Y), (int32)w, (int32)h));
} }
@ -34,6 +36,7 @@ namespace Strawberry
let fromn = (Point)(from - Camera); let fromn = (Point)(from - Camera);
let ton = (Point)(to - Camera); let ton = (Point)(to - Camera);
SDL.SetRenderDrawBlendMode(Game.Renderer, .Blend);
SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A); SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
SDL.RenderDrawLine(Game.Renderer, (int32)fromn.X, (int32)fromn.Y, (int32)ton.X, (int32)ton.Y); SDL.RenderDrawLine(Game.Renderer, (int32)fromn.X, (int32)fromn.Y, (int32)ton.X, (int32)ton.Y);
} }
@ -55,6 +58,7 @@ namespace Strawberry
); );
} }
SDL.SetRenderDrawBlendMode(Game.Renderer, .Blend);
SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A); SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
SDL.RenderDrawLines(Game.Renderer, &points[0], (int32)steps + 1); SDL.RenderDrawLines(Game.Renderer, &points[0], (int32)steps + 1);
} }
@ -63,6 +67,8 @@ namespace Strawberry
{ {
SDL.Rect src = Strawberry.Rect(0, 0, sprite.Width, sprite.Height); SDL.Rect src = Strawberry.Rect(0, 0, sprite.Width, sprite.Height);
SDL.Rect dst = Strawberry.Rect(position.X - Camera.X, position.Y - Camera.Y, sprite.Width, sprite.Height); SDL.Rect dst = Strawberry.Rect(position.X - Camera.X, position.Y - Camera.Y, sprite.Width, sprite.Height);
SDL.SetTextureBlendMode(sprite[frame].Texture, .Blend);
SDL.RenderCopy(Game.Renderer, sprite[frame].Texture, &src, &dst); SDL.RenderCopy(Game.Renderer, sprite[frame].Texture, &src, &dst);
} }
@ -71,6 +77,8 @@ namespace Strawberry
SDL.Point cnt = origin; SDL.Point cnt = origin;
SDL.Rect src = Strawberry.Rect(0, 0, sprite.Width, sprite.Height); SDL.Rect src = Strawberry.Rect(0, 0, sprite.Width, sprite.Height);
SDL.Rect dst = Strawberry.Rect(position.X - origin.X - Camera.X, position.Y - origin.Y - Camera.Y, sprite.Width, sprite.Height); SDL.Rect dst = Strawberry.Rect(position.X - origin.X - Camera.X, position.Y - origin.Y - Camera.Y, sprite.Width, sprite.Height);
SDL.SetTextureBlendMode(sprite[frame].Texture, .Blend);
SDL.RenderCopyEx(Game.Renderer, sprite[frame].Texture, &src, &dst, rotation, &cnt, .None); SDL.RenderCopyEx(Game.Renderer, sprite[frame].Texture, &src, &dst, rotation, &cnt, .None);
} }
} }