Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from DISC-Manchester/dev
Browse files Browse the repository at this point in the history
Release Version 3.0.0
  • Loading branch information
Luke Shore authored Jun 28, 2023
2 parents 0a1375b + 4ce4a5c commit 37b6f01
Show file tree
Hide file tree
Showing 61 changed files with 1,356 additions and 1,663 deletions.
38 changes: 19 additions & 19 deletions .github/workflows/check-commit-message.yml
Original file line number Diff line number Diff line change
@@ -1,20 +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
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]
58 changes: 29 additions & 29 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,30 +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
---
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 }}
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.vs
packages
bin
obj
.vs
packages
bin
obj
Properties
*.pfx
18 changes: 18 additions & 0 deletions DiscOut/Avolonia/DiscWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:DiscOut.Avalonia"
Width="640" Height="720"
x:Class="DiscOut.Avalonia.DiscWindow"
Title="DISCout" Margin="0" Padding="0" Background="Gray" Icon="/build_assets/icon.ico">
<Panel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10">
<Grid Margin="0">
<Panel Background="Black" Margin="0">
<controls:GameOpenGLControl Name="GLView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</Panel>
<TextBlock Foreground ="White" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10" Name="ScoreText"/>
<TextBlock Foreground ="White" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="36" Name="DisplayText"/>
</Grid>
</Panel>
</Window>
126 changes: 126 additions & 0 deletions DiscOut/Avolonia/DiscWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Media;
using Avalonia.Threading;
using DiscOut.GameObjects.Dynamic;
using DiscOut.GameObjects.World;
using DiscOut.GameObjects.World.Score;
using DiscOut.Util;
using NAudio.Wave;
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace DiscOut.Avalonia
{
public partial class DiscWindow : Window
{
private readonly HashSet<Key> keys = new HashSet<Key>();
private static readonly WaveOutEvent MusicPlayer = new WaveOutEvent();
private readonly ScoreBoard ScoreBoard;
private int CurrentLevel = 1;
private bool GameRestart = false;
private readonly DispatcherTimer ticker = new DispatcherTimer() { Interval = new TimeSpan(0, 0, 0, 0, 1000 / 60) };
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public static DiscWindow Instance { get; set; }
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
internal Paddle Paddle { get; } = new Paddle();
internal Level Level { get; private set; }
public DiscWindow()
{
InitializeComponent();
Instance = this;
Level = new Level("assets.levels.level_1.json");
ScoreBoard = ScoreBoard.Load();
MusicPlayer.Init(new Mp3FileReader(AssetUtil.OpenEmbeddedFile("assets.sounds.music.mp3")));
MusicPlayer.Volume = 0.25f;
MusicPlayer.Play();
ticker.Tick += delegate
{
if (GameRestart)
{
if (keys.Contains(Key.Enter))
{
SoundUtils.PlaySound(SoundUtils.CLICK_SOUND);
GameRestart = false;
DisplayText.Text = "";
Level = new Level("assets.levels.level_" + Convert.ToString(CurrentLevel) + ".json");
keys.Clear();
}
DisplayText.Text = "Press Enter To Restart";
}
else
{
Paddle.OnKeyDown(keys);
Level.GetBall().OnKeyDown(keys);
if (!Level.GetBall().IsAlive())
{
DisplayText.Text = "Press Space To Start!\n " + ScoreBoard.ToString();
}
else
DisplayText.Text = "";
}
if (Paddle.IsDead())
{
Paddle.ResetPaddle();
int Score = Level.GetBall().GetScore();
if (Score > ScoreBoard.entry[0].Score)
{
Action<int, string> callback = FinishNewUser;
var popupWindow = new PopUpWindow(Score, callback);
var task = popupWindow.ShowDialog(this);
}
GameRestart = true;
}
Level.OnUpdate();
Paddle.OnUpdate();
};
ticker.IsEnabled = true;
Level.OnUpdate();
Paddle.OnUpdate();
GC.Collect(GC.MaxGeneration, GCCollectionMode.Optimized, true, true);
GC.WaitForPendingFinalizers();
}

protected override void OnKeyDown(KeyEventArgs e)
{
keys.Add(e.Key);
base.OnKeyDown(e);
}

protected override void OnKeyUp(KeyEventArgs e)
{
keys.Remove(e.Key);
base.OnKeyUp(e);
}

public override void Render(DrawingContext context)
{
GLView.Render(context);
base.Render(context);
Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.MaxValue);
}

protected void FinishNewUser(int LastScoreData, string UserNameData)
{
ScoreBoard.AddScore(new ScoreEntry(UserNameData, LastScoreData));
ScoreBoard.Save(ScoreBoard);
}

protected override void OnClosing(CancelEventArgs e)
{
ticker.IsEnabled = false;
SoundUtils.CleanUp();
MusicPlayer.Stop();
MusicPlayer.Dispose();
Renderer.Dispose();
ScoreBoard.Save(ScoreBoard);
base.OnClosing(e);
}

public void LevelWon()
{
CurrentLevel++;
Level = new Level("assets.levels.level_" + Convert.ToString(CurrentLevel) + ".json");
}
}
}
4 changes: 4 additions & 0 deletions DiscOut/Avolonia/GameOpenGLControl.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="DiscOut.Avalonia.GameOpenGLControl">
</UserControl>
28 changes: 28 additions & 0 deletions DiscOut/Avolonia/GameOpenGLControl.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Avalonia.OpenGL;
using Avalonia.OpenGL.Controls;
using DiscOut.Renderer;
using static Avalonia.OpenGL.GlConsts;
namespace DiscOut.Avalonia
{
public partial class GameOpenGLControl : OpenGlControlBase
{
internal QuadBatchRenderer Renderer { get; private set; }
public GameOpenGLControl()
=> InitializeComponent();

protected override unsafe void OnOpenGlRender(GlInterface gl, int fb)
{
gl.ClearColor(0, 0, 0, 0);
gl.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
gl.Viewport(0, 0, (int)DiscWindow.Instance.Width - 25, (int)DiscWindow.Instance.Height);
DiscWindow.Instance.Paddle.OnRendering(Renderer);
DiscWindow.Instance.Level.OnRendering(Renderer);
}

protected override void OnOpenGlInit(GlInterface gl, int fb)
=> Renderer = new QuadBatchRenderer(gl);

protected override void OnOpenGlDeinit(GlInterface gl, int fb)
=> Renderer.Dispose();
}
}
13 changes: 13 additions & 0 deletions DiscOut/Avolonia/PopUpWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
MinWidth="210" MinHeight="110" MaxWidth="210" MaxHeight="110"
x:Class="DiscOut.Avalonia.PopUpWindow"
Title="New High Score" TransparencyLevelHint="AcrylicBlur" Background="Transparent"
ExtendClientAreaToDecorationsHint="True" HasSystemDecorations="False">
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Center" Spacing="5" Margin="10">
<TextBlock Text="New High Score Enter Name:" />
<TextBox x:Name="TextInput" Width="200" />
<Button x:Name="OKButton" Content="OK" Width="100" Click="OnButtonClick" />
</StackPanel>
</Window>
41 changes: 41 additions & 0 deletions DiscOut/Avolonia/PopUpWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using DiscOut.Util;
using System;
namespace DiscOut.Avalonia
{
public partial class PopUpWindow : Window
{
private readonly Action<int, string> Callback;
private readonly int Score;

public PopUpWindow()
{
Score = 0;
Callback = (int n, string s) => { };
InitializeComponent();
TextInput.Text = "";
}

public PopUpWindow(int score, Action<int, string> callback)
{
Callback = callback;
Score = score;
InitializeComponent();
TextInput.Text = "";
}

private void OnButtonClick(object sender, RoutedEventArgs e)
{
TextInput.Focus();
SoundUtils.PlaySound(SoundUtils.CLICK_SOUND);
if (TextInput.Text.Length >= 1 && TextInput.Text.Length <= 10)
{
Callback.Invoke(Score, TextInput.Text);
Close();
return;
}
TextInput.Text = "must be between 1 & 10 chars";
}
}
}
Loading

0 comments on commit 37b6f01

Please sign in to comment.