Skip to content

Commit

Permalink
Merge pull request #1 from DISC-Manchester/dev
Browse files Browse the repository at this point in the history
Merge Version 2 Stable
  • Loading branch information
Luke Shore committed May 10, 2023
2 parents d0c92c5 + 2d1a676 commit 0a1375b
Show file tree
Hide file tree
Showing 23 changed files with 1,023 additions and 129 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/check-commit-message.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: 'Check commit message style'
on:
pull_request:
types:
- opened
- edited
- reopened
- synchronize
push:
branches:
- main
- dev

jobs:
check-commit-message-style:
name: Check commit message style
runs-on: ubuntu-latest
steps:
- name: Check
uses: mristin/[email protected]
30 changes: 30 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Lint Code Base
on:
push:
pull_request:
branches: [dev, main]
jobs:
build:
# Name the Job
name: Lint Code Base
# Set the agent to run on
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
statuses: write
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
# Full git history is needed to get a proper
# list of changed files within `super-linter`
fetch-depth: 0
- name: Lint Code Base
uses: github/super-linter@v5
env:
VALIDATE_ALL_CODEBASE: false
# Change to 'master' if your main branch differs
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
149 changes: 117 additions & 32 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
using OpenTK.Graphics.ES30;
using ImGuiNET;
using OpenTK.Graphics.ES30;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.GraphicsLibraryFramework;
using SquareSmash.objects;
using SquareSmash.objects.components;
using SquareSmash.renderer;
using SquareSmash.renderer.gui;
using System.Runtime.InteropServices;

namespace SquareSmash
{
internal class Client : GameWindow
{
public static readonly int Width = 720;
public static readonly int Height = 640;
private long PreviousTime { get; set; }
public QuadBatchRenderer Renderer { get; private set; }
public Paddle paddle;
public Level level;
/*private static readonly DebugProc DebugMessageDelegate = OnDebugMessage;
private static void OnDebugMessage(DebugSource source,DebugType type,int id,DebugSeverity severity,int length,IntPtr pMessage,IntPtr pUserParam)
private static void OnDebugMessage(DebugSource source, DebugType type, int id, DebugSeverity severity, int length, IntPtr pMessage, IntPtr pUserParam)
{
if (severity == DebugSeverity.DebugSeverityNotification || severity == DebugSeverity.DebugSeverityLow || severity == DebugSeverity.DebugSeverityMedium)
return;
string message = Marshal.PtrToStringAnsi(pMessage, length);
Console.WriteLine("[{0} source={1} type={2} id={3}] {4}", severity, source, type, id, message);
if (type == DebugType.DebugTypeError)
throw new Exception(message);
}*/
throw new InvalidOperationException(message);
}

public Client()
: base(GameWindowSettings.Default, new()
{
Size = new(Width, Height),
Title = "DISCout",
Flags = ContextFlags.ForwardCompatible,
MinimumSize = new(Width, Height),
MaximumSize = new(Width, Height)
})
protected override void OnResize(ResizeEventArgs e)
{
//GL.DebugMessageCallback(DebugMessageDelegate, IntPtr.Zero);
Renderer = new();
paddle = new();
level = new();
base.OnResize(e);
GL.Viewport(0, 0, ClientSize.X, ClientSize.Y);
Controller.WindowResized(ClientSize.X, ClientSize.Y);
}

protected override void OnTextInput(TextInputEventArgs e)
{
base.OnTextInput(e);
Controller.PressChar((char)e.Unicode);
PreviousTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
GL.ClearColor(0, 0, 0, 1);
}
public void LevelWon()

protected override void OnMouseWheel(MouseWheelEventArgs e)
{
level = new Level();
base.OnMouseWheel(e);
ImGuiController.MouseScroll(e.Offset);
}

protected override void OnUnload()
{
Renderer.Flush();
ImGui.DestroyContext();
base.OnUnload();
}

Expand All @@ -57,26 +57,111 @@ protected override void OnUpdateFrame(FrameEventArgs args)
base.OnUpdateFrame(args);
long currentTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
long DeltaTime = (currentTime - PreviousTime);
Controller.Update(this, DeltaTime / 1000.0f);
PreviousTime = currentTime;
paddle?.OnUpdate(this, DeltaTime);
level?.OnUpdate(this, DeltaTime);
if (GameRestart)
{
if (KeyboardState.IsKeyDown(Keys.Enter))
{
GameRestart = false;
level = new(this, "assets/levels/level_" + Convert.ToString(CurrentLevel) + ".json");
}
else
return;
}
if (Paddle.IsDead())
{
Paddle.ResetPaddle();
LastScore = level.GetBall().GetScore();
GameRestart = true;
}
Paddle.OnUpdate(this, DeltaTime);
level.OnUpdate(this, DeltaTime);
}

protected override void OnRenderFrame(FrameEventArgs args)
{
base.OnRenderFrame(args);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
paddle?.OnRendering(Renderer);
level?.OnRendering(Renderer);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
Paddle.OnRendering(Renderer);
level.OnRendering(Renderer);
Renderer.Flush();
var screen_size = ImGui.GetIO().DisplaySize;
ImGui.SetNextWindowPos(new System.Numerics.Vector2((screen_size.X / 2), (screen_size.Y / 2)), ImGuiCond.Always, new System.Numerics.Vector2(0.5f, 0.5f));
bool temp = false;
if (GameRestart)
{
ImGui.Begin("Text", ref temp, ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoBringToFrontOnFocus);
ImGui.SetWindowFontScale(3.0f);
ImGui.SetWindowSize(new(500, ImGui.GetTextLineHeightWithSpacing() * 2));
ImGui.Text("Press Enter To Restart");
ImGui.Text("\tFinal Score: " + Convert.ToString(LastScore));
ImGui.End();
}
else
{
if (!level.GetBall().IsAlive())
{
ImGui.Begin("Text", ref temp, ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoBringToFrontOnFocus);
ImGui.SetWindowFontScale(3.0f);
ImGui.Text("Press Space To Start");
ImGui.End();
}
}
Controller.Render();
ImGuiController.CheckGLError("End of frame");
SwapBuffers();
}

public Client(int WidthIn, int HeightIn)
: base(GameWindowSettings.Default, new()
{
Size = new(WidthIn, HeightIn),
Title = "DISCout",
Flags = ContextFlags.ForwardCompatible | ContextFlags.Debug,
MinimumSize = new(WidthIn, HeightIn),
MaximumSize = new(WidthIn, HeightIn)
})
{
Instance = this;
GameRestart = false;
Width = WidthIn;
Height = HeightIn;
GL.DebugMessageCallback(DebugMessageDelegate, IntPtr.Zero);
GL.ClearColor(Color4.Black);
Controller = new ImGuiController(ClientSize.X, ClientSize.Y);
Renderer = new();
Paddle = new();
level = new(this, "assets/levels/level_" + Convert.ToString(CurrentLevel) + ".json");
PreviousTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
}

public void LevelWon()
{
CurrentLevel++;
level = new Level(this, "assets/levels/level_" + Convert.ToString(CurrentLevel) + ".json");
}

private int LastScore = 0;
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public static Client Instance { get; set; }
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public int Width { get; private set; }
public int Height { get; private set; }
private long PreviousTime { get; set; }
public QuadBatchRenderer Renderer { get; private set; }
public Paddle Paddle { get; private set; }
public bool GameRestart { get; private set; }
private int CurrentLevel = 1;
public Level level;
public ImGuiController Controller;
private static readonly DebugProc DebugMessageDelegate = OnDebugMessage;
}
static class ProgramMain
{
public static void Main()
{
Client client = new();
Client client = new(720, 640);
client.Run();
}
}
Expand Down
11 changes: 11 additions & 0 deletions SquareSmash.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand All @@ -14,8 +15,18 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ImGui.NET" Version="1.89.5" />
<PackageReference Include="MongoDB.Driver" Version="2.19.1" />
<PackageReference Include="OpenTK" Version="4.7.7" />
<Content Include="assets/**" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<Compile Remove="temp.cs" />
</ItemGroup>

<ItemGroup>
<None Remove="assets\levels\level_1.json" />
<None Remove="assets\levels\level_2.json" />
</ItemGroup>
</Project>
8 changes: 0 additions & 8 deletions assets/Shader/basic_fragment.glsl

This file was deleted.

25 changes: 25 additions & 0 deletions assets/levels/level_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"BaseBallSpeed": 0.001,
"Bricks": [
{
"Colour": "DiscGreen",
"Type": 1,
"Repeat": 28
},
{
"Colour": "DiscOrange",
"Type": 1,
"Repeat": 28
},
{
"Colour": "DiscBlue",
"Type": 1,
"Repeat": 28
},
{
"Colour": "DiscPink",
"Type": 1,
"Repeat": 28
}
]
}
25 changes: 25 additions & 0 deletions assets/levels/level_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"BaseBallSpeed": 0.002,
"Bricks": [
{
"Colour": "DiscGreen",
"Type": 1,
"Repeat": 28
},
{
"Colour": "DiscOrange",
"Type": 1,
"Repeat": 28
},
{
"Colour": "DiscBlue",
"Type": 1,
"Repeat": 28
},
{
"Colour": "DiscPink",
"Type": 1,
"Repeat": 28
}
]
}
9 changes: 9 additions & 0 deletions assets/shaders/basic_fragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#version 330 core
// input
in vec4 vertex_colour;
// output
out vec4 frag_colour;
void main()
{
frag_colour = vertex_colour;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#version 330 core
// input
layout(location = 0) in vec2 position;
layout(location = 1) in vec4 color;

out vec4 vertexColor;

layout(location = 1) in vec4 colour;
// output
out vec4 vertex_colour;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
vertexColor = color;
vertex_colour = colour;
}
Loading

0 comments on commit 0a1375b

Please sign in to comment.