Skip to content

Commit

Permalink
Latest
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarisic committed Oct 6, 2023
1 parent 17f53ba commit 992ed16
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 102 deletions.
60 changes: 60 additions & 0 deletions FishGfx/AdvGraphics/ParallaxSprite.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using FishGfx.Graphics.Drawables;
using FishGfx.Graphics;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using FishGfx.Game;

namespace FishGfx.AdvGraphics {
public class ParallaxSprite {
Texture[] Layers = new Texture[] { };
Sprite Sprite;

public ParallaxSprite(FishGfxGame Game) {
Sprite = new Sprite();
Sprite.Shader = Game.DefaultShader;
}

public void AddLayer(Texture Tex) {
Layers = Layers.Add(Tex);
}

public void AddLayers(params Texture[] Tex) {
foreach (var T in Tex)
AddLayer(T);
}

void DrawTiled(Sprite S, Vector2 ScrollPos, Vector2 CamPos) {
float DiffX = (CamPos - ScrollPos).X;
float ModX = (int)(DiffX / S.Scale.X);

for (int i = 0; i < 2; i++) {
Vector2 Scroll = new Vector2(S.Scale.X, 0) * i;

S.Position = ScrollPos + new Vector2(S.Scale.X, 0) * ModX + Scroll;
S.Draw();
}
}

public void Draw(Camera Cam) {
const float LayerScale = 0.8f;

for (int i = 0; i < Layers.Length; i++) {
//int i = Layers.Length - 1;

Sprite.Texture = Layers[i];
Sprite.Scale = Sprite.Texture.Size * 3;

float ScaleX = (float)Math.Pow(LayerScale, i + 1);
float ScaleY = 1;

Vector2 ScrollPos = Cam.Position.XY() * new Vector2(ScaleX, ScaleY);
DrawTiled(Sprite, ScrollPos, Cam.Position.XY());
}
}
}
}
4 changes: 4 additions & 0 deletions FishGfx/FishGfx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AABB.cs" />
<Compile Include="AdvGraphics\ParallaxSprite.cs" />
<Compile Include="BoundSphere.cs" />
<Compile Include="Color.cs" />
<Compile Include="Formats\BitmapFont.cs" />
Expand Down Expand Up @@ -300,6 +301,9 @@
<Content Include="data\fonts\proggy_0.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="data\fonts\tileset\cheepicus16.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="data\fonts\tileset\cheepicus8.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
13 changes: 12 additions & 1 deletion FishGfx/Game/FishGfxGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public abstract class FishGfxGame {
protected RenderWindow Window;
protected int Framerate = 60;

private int WindowWidth;
private int WindowHeight;

Stopwatch GameStopwatch;
public float GameTime {
get {
Expand All @@ -24,10 +27,18 @@ public InputManager Input {
private set;
}

public FishGfxGame() : this(1366, 768) {
}

public FishGfxGame(int Width, int Height) {
WindowWidth = Width;
WindowHeight = Height;
}

protected virtual RenderWindow CreateWindow() {
string CurTypeName = GetType().Name;

return new RenderWindow(800, 600, CurTypeName);
return new RenderWindow(WindowWidth, WindowHeight, CurTypeName);
}

public ShaderProgram DefaultShader;
Expand Down
8 changes: 7 additions & 1 deletion FishGfx/GfxUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,5 +296,11 @@ public static void NormalToPitchYaw(this Vector3 Normal, out float Pitch, out fl
Pitch = (float)Math.Asin(-Normal.Y);
Yaw = (float)Math.Atan2(Normal.X, Normal.Z);
}
}

public static T[] Add<T>(this T[] Arr, T New) {
Array.Resize(ref Arr, Arr.Length + 1);
Arr[Arr.Length - 1] = New;
return Arr;
}
}
}
Binary file added FishGfx/data/fonts/tileset/cheepicus16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 0 additions & 59 deletions Test/Parallax.cs

This file was deleted.

19 changes: 12 additions & 7 deletions Test/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Threading.Tasks;
using FishGfx.Game;
using Humper;
using FishGfx.AdvGraphics;

namespace Test {
[Flags]
Expand All @@ -30,14 +31,14 @@ class TestGame : FishGfxGame {
public World PhysWorld;
public GameLevel Lvl;

public Parallax Background;
public ParallaxSprite Background;
public ParticleSystem Particles;

List<Entity> Entities = new List<Entity>();


protected override RenderWindow CreateWindow() {
return new RenderWindow(800, 600, "Test");
return new RenderWindow(1920, 1080, "Test");
}

protected override void Init() {
Expand Down Expand Up @@ -148,18 +149,22 @@ public void InitGame() {
Spawn(E);

// Create background parallax
Background = new Parallax(this);
Background = new ParallaxSprite(this);

// Create particle system
Particles = new ParticleSystem(this);

string BackgroundFolder = "data/textures/background/" + Lvl.Background;
/*string BackgroundFolder = "data/textures/background/" + Lvl.Background;
string[] BackgroundImages = Directory.GetFiles(BackgroundFolder);
foreach (var Img in BackgroundImages)
Background.AddLayer(Texture.FromFile(Img));
Background.AddLayer(Texture.FromFile(Img));*/

// Spawn player
Player Ply = new Player();
Background.AddLayer(Texture.FromFile("data/textures/background/space1/1.png"));
Background.AddLayer(Texture.FromFile("data/textures/background/space1/2.png"));
Background.AddLayer(Texture.FromFile("data/textures/background/space1/3.png"));

// Spawn player
Player Ply = new Player();
Ply.Position = Lvl.GetEntitiesByName("spawn_player").First().Position;
Spawn(Ply);
}
Expand Down
1 change: 0 additions & 1 deletion Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
<Compile Include="Humper\Responses\TouchResponse.cs" />
<Compile Include="Humper\World.cs" />
<Compile Include="Interfaces.cs" />
<Compile Include="Parallax.cs" />
<Compile Include="ParticleSystem.cs" />
<Compile Include="Entities\Pawn.cs" />
<Compile Include="Entities\Player.cs" />
Expand Down
128 changes: 95 additions & 33 deletions Test2/Test2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,118 @@
using FishGfx;
using FishGfx.Game;
using FishGfx.Graphics;
using FishGfx.AdvGraphics;

namespace Test2 {
class FishGfxTest2 : FishGfxGame {
protected override void Init() {
RenderState RS = Gfx.CreateDefaultRenderState();
RS.EnableDepthTest = false;
Gfx.PushRenderState(RS);
}
class FishGfxTest2 : FishGfxGame {
public DevConsole Con;
public ParallaxSprite Background;

protected override void Update(float Dt) {
}
bool ShouldClose = false;

protected override void Draw(float Dt) {
Color[] Colors = new[] { Color.Red, Color.Green, Color.Blue, Color.Orange };
public FishGfxTest2() : base(1920, 1080) {
}

Gfx.Clear(Color.Coal, true, true, true);
protected override void Init() {
int FontSize = 16;
int W = (int)Math.Floor((float)Window.WindowWidth / FontSize);
int H = (int)((Window.WindowHeight * 0.4f) / FontSize);

Con = new DevConsole(Texture.FromFile("data/fonts/tileset/cheepicus16.png"), FontSize, W, H, H * 2, DefaultShader);
Con.Position = new Vector2(0, Window.WindowHeight - H * Con.CharSize);

Con.OnInput += (In) => {
if (In.Length == 0) {
Con.PrintLine();
return;
}

if (In == "quit")
ShouldClose = true;

if (In.StartsWith("rainbow")) {
foreach (var C in In.Substring(7).Trim()) {
Con.TextColor = GfxUtils.RandomColor();
Con.PutChar(C);
}

Con.TextColor = Color.White;
Con.PrintLine();
return;
}

Con.PrintLine("You wrote '{0}'", In);
};

Con.PrintLine("Welcome to the Developer Console");
Con.BeginInput();
Con.Enabled = false;

Window.OnChar += (Wnd, Chr, Uni) => Con.SendInput(Chr);
Window.OnKey += Con.SendKey;

Background = new ParallaxSprite(this);
Background.AddLayer(Texture.FromFile("data/textures/background/space1/1.png"));
Background.AddLayer(Texture.FromFile("data/textures/background/space1/2.png"));
Background.AddLayer(Texture.FromFile("data/textures/background/space1/3.png"));

RenderState RS = Gfx.CreateDefaultRenderState();
RS.EnableDepthTest = false;
RS.EnableCullFace = false;
Gfx.PushRenderState(RS);
}

// Draw some fancy lines
protected override void Update(float Dt) {
if (Input.GetKeyPressed(Key.Escape) || ShouldClose)
Window.Close();
}

for (int i = 0; i < 10; i++) {
Color ClrA = Colors[i % Colors.Length];
Color ClrB = Colors[(i + 1) % Colors.Length];
protected override void Draw(float Dt) {
Camera Cam = ShaderUniforms.Current.Camera;

Vector2 XOffset = new Vector2(40, 0);
Vertex2 A = new Vertex2(new Vector2(100, 100) + XOffset * i, ClrA);
Vertex2 B = new Vertex2(new Vector2(150, 200) + XOffset * i, ClrB);
Color[] Colors = new[] { Color.Red, Color.Green, Color.Blue, Color.Orange };
Gfx.Clear(Color.Orange, true, true, true);
Background.Draw(Cam);

Gfx.Line(A, B, i + 1);
}
// Draw some fancy lines
for (int i = 0; i < 10; i++) {
Color ClrA = Colors[i % Colors.Length];
Color ClrB = Colors[(i + 1) % Colors.Length];

// Draw rectangles
Vector2 XOffset = new Vector2(40, 0);
Vertex2 A = new Vertex2(new Vector2(100, 100) + XOffset * i, ClrA);
Vertex2 B = new Vertex2(new Vector2(150, 200) + XOffset * i, ClrB);

for (int i = 0; i < 3; i++) {
Vector2 Offset = new Vector2(20, 20);
Gfx.Line(A, B, i + 1);
}

Gfx.FilledRectangle(100 + Offset.X * i, 300 + Offset.Y * i, 200, 90, Colors[i % Colors.Length]);
}
// Draw rectangles

for (int i = 0; i < 3; i++) {
Vector2 Offset = new Vector2(20, 20);

for (int i = 0; i < 3; i++) {
Vector2 Offset = new Vector2(20, 20);
Gfx.FilledRectangle(100 + Offset.X * i, 300 + Offset.Y * i, 200, 90, Colors[i % Colors.Length]);
}

Gfx.Rectangle(400 + Offset.X * i, 300 + Offset.Y * i, 200, 90, i + 1, Colors[i % Colors.Length]);

for (int i = 0; i < 3; i++) {
Vector2 Offset = new Vector2(20, 20);

Gfx.Rectangle(400 + Offset.X * i, 300 + Offset.Y * i, 200, 90, i + 1, Colors[i % Colors.Length]);
}


// TODO: Handle that shit better, what the fuck
Vector2 ConPos = Con.Position;
Con.Position = Cam.Position.XY() + ConPos;
Con.Draw();
Con.Position = ConPos;
}
}
}

internal class Program {
static void Main(string[] args) {
FishGfxGame.Run(new FishGfxTest2());
internal class Program {
static void Main(string[] args) {
FishGfxGame.Run(new FishGfxTest2());
}
}
}
}
Loading

0 comments on commit 992ed16

Please sign in to comment.