parent
633c37eb89
commit
0932b0d0d0
|
@ -1,5 +1,5 @@
|
|||
#Soundtrack data
|
||||
testexetrisathlon/*.wav
|
||||
testexetrisathlon/*.mp3
|
||||
|
||||
|
||||
# Created by https://www.gitignore.io/api/rider,csharp,visualstudio
|
||||
|
|
|
@ -1,24 +1,32 @@
|
|||
import os
|
||||
import os.path
|
||||
import wave
|
||||
import youtube_dl
|
||||
import wave
|
||||
|
||||
|
||||
os.chdir("testexetrisathlon")
|
||||
|
||||
def dl_vid(url, outfile):
|
||||
def dl_vid(url, outfile, filetype):
|
||||
ydl_opts = {
|
||||
'outtmpl': outfile,
|
||||
'noplaylist': True,
|
||||
'continue_dl': True,
|
||||
'postprocessors': [{
|
||||
'key': 'FFmpegExtractAudio',
|
||||
'preferredcodec': 'wav' }]
|
||||
'preferredcodec': filetype }]
|
||||
}
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
ydl.download([url])
|
||||
|
||||
def merge_vids(infiles, outfile):
|
||||
#lStream = open("list.txt", "w")
|
||||
#for infile in infiles:
|
||||
# lStream.write("file '" + infile + ".wav'\n")
|
||||
#lStream.close()
|
||||
#os.system("ffmpeg -f concat -i list.txt -c copy " + outfile + ".mp3")
|
||||
#os.remove("list.txt")
|
||||
#for infile in infiles:
|
||||
# os.remove(infile + ".mp3")
|
||||
data= []
|
||||
for infile in infiles:
|
||||
w = wave.open(infile + ".wav", 'rb')
|
||||
|
@ -31,21 +39,24 @@ def merge_vids(infiles, outfile):
|
|||
output.writeframes(data[0][1])
|
||||
output.writeframes(data[1][1])
|
||||
output.close()
|
||||
os.system("ffmpeg -y -i " + outfile + ".wav " + outfile + ".mp3")
|
||||
os.remove(outfile + ".wav")
|
||||
|
||||
if not os.path.isfile("Intro.wav"):
|
||||
dl_vid("https://youtu.be/U06jlgpMtQs", "Intro")
|
||||
if not os.path.isfile("Intro.mp3"):
|
||||
dl_vid("https://youtu.be/U06jlgpMtQs", "Intro", "mp3")
|
||||
|
||||
|
||||
if not os.path.isfile("InGame1.wav"):
|
||||
dl_vid("https://youtu.be/hueJrl83sOQ", "st1")
|
||||
dl_vid("https://youtu.be/7gSS4h47rLU", "st2")
|
||||
dl_vid("https://youtu.be/NDjDgvXlfVw", "st3")
|
||||
if not os.path.isfile("InGame1.mp3"):
|
||||
dl_vid("https://youtu.be/hueJrl83sOQ", "st1", "wav")
|
||||
dl_vid("https://youtu.be/7gSS4h47rLU", "st2", "wav")
|
||||
dl_vid("https://youtu.be/NDjDgvXlfVw", "st3", "wav")
|
||||
merge_vids(["st1", "st2", "st3"], "InGame1")
|
||||
|
||||
if not os.path.isfile("InGame2.wav"):
|
||||
dl_vid("https://youtu.be/umEDct4BoGc", "st1")
|
||||
dl_vid("https://youtu.be/NVpjt9gHlDw", "st2")
|
||||
dl_vid("https://youtu.be/zgKazTrhXmI", "st3")
|
||||
if not os.path.isfile("InGame2.mp3"):
|
||||
dl_vid("https://youtu.be/umEDct4BoGc", "st1", "wav")
|
||||
dl_vid("https://youtu.be/NVpjt9gHlDw", "st2", "wav")
|
||||
dl_vid("https://youtu.be/zgKazTrhXmI", "st3", "wav")
|
||||
merge_vids(["st1", "st2", "st3"], "InGame2")
|
||||
|
||||
if not os.path.isfile("GameOver.wav"):
|
||||
dl_vid("https://youtu.be/J_3Zad-e9f4", "GameOver")
|
||||
if not os.path.isfile("GameOver.mp3"):
|
||||
dl_vid("https://youtu.be/J_3Zad-e9f4", "GameOver", "mp3")
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
namespace testexetrisathlon
|
||||
{
|
||||
public static class SizeSetter
|
||||
{
|
||||
public static void SetWindowSize(int width, int height)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace testexetrisathlon
|
||||
{
|
||||
internal static class OSCheck
|
||||
{
|
||||
private static bool _checkedWindows;
|
||||
private static bool _isWindows;
|
||||
|
||||
public static bool IsWindows
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_checkedWindows) return _isWindows;
|
||||
_isWindows =
|
||||
new[] {PlatformID.Win32S, PlatformID.Win32Windows, PlatformID.Win32NT, PlatformID.WinCE}
|
||||
.Contains(Environment.OSVersion.Platform);
|
||||
_checkedWindows = true;
|
||||
return _isWindows;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using testexetrisathlon.SoundManagement;
|
||||
using static System.Console;
|
||||
|
||||
|
@ -51,7 +50,8 @@ namespace testexetrisathlon
|
|||
public static bool Debug;
|
||||
|
||||
public static readonly Random Rnd = new Random();
|
||||
private static ISoundManager soundManager;
|
||||
private static ISoundManager _soundManager;
|
||||
public static IBeeper Beeper;
|
||||
private static string InGame => SettingsMan.UsingAltTrack ? "InGame2" : "InGame1";
|
||||
|
||||
#if DEBUG
|
||||
|
@ -63,22 +63,20 @@ namespace testexetrisathlon
|
|||
{
|
||||
Debug = args.Contains("debug");
|
||||
#endif
|
||||
Beeper = new Beeper();
|
||||
BackgroundColor = ConsoleColor.Red;
|
||||
ForegroundColor = ConsoleColor.Yellow;
|
||||
soundManager = OSCheck.IsWindows ? (ISoundManager) new WindowsSoundManager() : new LinuxSoundManager();
|
||||
soundManager.Init(new Dictionary<string, string>
|
||||
_soundManager = new SoundManager();
|
||||
_soundManager.Init(new Dictionary<string, string>
|
||||
{
|
||||
{"Intro", "testexetrisathlon.Intro.wav"},
|
||||
{"InGame1", "testexetrisathlon.InGame1.wav"},
|
||||
{"InGame2", "testexetrisathlon.InGame2.wav"},
|
||||
{"GameOver", "testexetrisathlon.GameOver.wav"}
|
||||
{"Intro", "testexetrisathlon.Intro.mp3"},
|
||||
{"InGame1", "testexetrisathlon.InGame1.mp3"},
|
||||
{"InGame2", "testexetrisathlon.InGame2.mp3"},
|
||||
{"GameOver", "testexetrisathlon.GameOver.mp3"}
|
||||
});
|
||||
if (OSCheck.IsWindows)
|
||||
{
|
||||
SetWindowSize(42, 29);
|
||||
if (Debug)
|
||||
SetWindowSize(50, 40);
|
||||
}
|
||||
SizeSetter.SetWindowSize(42, 29);
|
||||
if (Debug)
|
||||
SizeSetter.SetWindowSize(50, 40);
|
||||
SetCursorPosition(0, 0);
|
||||
bool playing = true;
|
||||
GameState state = GameState.Menu;
|
||||
|
@ -89,7 +87,7 @@ namespace testexetrisathlon
|
|||
{
|
||||
case GameState.Menu:
|
||||
Clear();
|
||||
soundManager.SetCurrent(Intro);
|
||||
_soundManager.SetCurrent(Intro);
|
||||
DrawSymbol();
|
||||
SetCursorPosition(12, 18);
|
||||
Write("HighScore: " + SettingsMan.HighScore);
|
||||
|
@ -124,7 +122,7 @@ namespace testexetrisathlon
|
|||
}
|
||||
break;
|
||||
case GameState.Game:
|
||||
soundManager.SetCurrent(InGame);
|
||||
_soundManager.SetCurrent(InGame);
|
||||
_dropTimer.Start();
|
||||
SetCursorPosition(25, 0);
|
||||
WriteLine("Level " + _level);
|
||||
|
@ -143,7 +141,7 @@ namespace testexetrisathlon
|
|||
break;
|
||||
case GameState.GameOver:
|
||||
SettingsMan.HighScore = _score;
|
||||
soundManager.SetCurrent(GameOver);
|
||||
_soundManager.SetCurrent(GameOver);
|
||||
string input = "";
|
||||
while (input != "y" && input != "n")
|
||||
{
|
||||
|
@ -179,7 +177,7 @@ namespace testexetrisathlon
|
|||
}
|
||||
finally
|
||||
{
|
||||
soundManager.Dispose();
|
||||
_soundManager.Dispose();
|
||||
}
|
||||
BackgroundColor = Colors[0];
|
||||
ForegroundColor = Colors[1];
|
||||
|
@ -262,7 +260,7 @@ namespace testexetrisathlon
|
|||
}
|
||||
break;
|
||||
}
|
||||
soundManager.SetVolume(SettingsMan.Volume * 10);
|
||||
_soundManager.SetVolume(SettingsMan.Volume * 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace testexetrisathlon.SoundManagement
|
||||
{
|
||||
public interface IBeeper : IDisposable
|
||||
{
|
||||
public void Beep(int frequency, int duration);
|
||||
}
|
||||
}
|
|
@ -5,28 +5,23 @@ using Bassoon;
|
|||
|
||||
namespace testexetrisathlon.SoundManagement
|
||||
{
|
||||
public static class Beeper
|
||||
public class Beeper : IBeeper
|
||||
{
|
||||
private static readonly Dictionary<Tuple<int, int>, Tuple<string, Sound>> Beeps = new Dictionary<Tuple<int, int>, Tuple<string, Sound>>();
|
||||
public static void Beep(int frequency, int duration)
|
||||
public void Beep(int frequency, int duration)
|
||||
{
|
||||
if (OSCheck.IsWindows)
|
||||
Console.Beep(frequency, duration);
|
||||
else
|
||||
Tuple<int, int> key = new Tuple<int, int>(frequency, duration);
|
||||
if (!Beeps.ContainsKey(key))
|
||||
{
|
||||
Tuple<int, int> key = new Tuple<int, int>(frequency, duration);
|
||||
if (!Beeps.ContainsKey(key))
|
||||
{
|
||||
string file = Path.GetTempFileName();
|
||||
File.Move(file, Path.ChangeExtension(file, "wav"));
|
||||
file = Path.ChangeExtension(file, "wav");
|
||||
File.WriteAllBytes(file, BeepBeep(1000, frequency, duration));
|
||||
Beeps.Add(key, new Tuple<string, Sound>(file, new Sound(file)));
|
||||
}
|
||||
Beeps[key].Item2.Cursor = 0;
|
||||
Beeps[key].Item2.Play();
|
||||
Console.Clear();
|
||||
string file = Path.GetTempFileName();
|
||||
File.Move(file, Path.ChangeExtension(file, "wav"));
|
||||
file = Path.ChangeExtension(file, "wav");
|
||||
File.WriteAllBytes(file, BeepBeep(1000, frequency, duration));
|
||||
Beeps.Add(key, new Tuple<string, Sound>(file, new Sound(file)));
|
||||
}
|
||||
Beeps[key].Item2.Cursor = 0;
|
||||
Beeps[key].Item2.Play();
|
||||
Console.Clear();
|
||||
}
|
||||
|
||||
private static byte[] BeepBeep(int amplitude, int frequency, int duration)
|
||||
|
@ -51,10 +46,9 @@ namespace testexetrisathlon.SoundManagement
|
|||
return ms.ToArray();
|
||||
}
|
||||
|
||||
public static void Dispose()
|
||||
public void Dispose()
|
||||
{
|
||||
if (OSCheck.IsWindows)
|
||||
foreach (Tuple<string, Sound> file in Beeps.Values) File.Delete(file.Item1);
|
||||
foreach (Tuple<string, Sound> file in Beeps.Values) File.Delete(file.Item1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ using Bassoon;
|
|||
|
||||
namespace testexetrisathlon.SoundManagement
|
||||
{
|
||||
public class LinuxSoundManager : ISoundManager
|
||||
public class SoundManager : ISoundManager
|
||||
{
|
||||
private BassoonEngine _bassoon;
|
||||
private Dictionary<string, Sound> _loadedSounds;
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
|
||||
namespace testexetrisathlon.SoundManagement
|
||||
{
|
||||
public class Beeper : IBeeper
|
||||
{
|
||||
public void Beep(int frequency, int duration) => Console.Beep(frequency, duration);
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +1,12 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using NAudio.Wave;
|
||||
|
||||
namespace testexetrisathlon.SoundManagement
|
||||
{
|
||||
public sealed class WindowsSoundManager : ISoundManager
|
||||
public sealed class SoundManager : ISoundManager
|
||||
{
|
||||
private static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
|
||||
private WaveStream _current;
|
||||
|
@ -17,7 +18,7 @@ namespace testexetrisathlon.SoundManagement
|
|||
{
|
||||
_output = new WaveOutEvent();
|
||||
_loadedSounds = manifestResources.ToDictionary(s => s.Key,
|
||||
s => new LoopStream(new WaveFileReader(Assembly.GetManifestResourceStream(s.Value))));
|
||||
s => new LoopStream(new WaveFileReader(Mp3ToWav(Assembly.GetManifestResourceStream(s.Value)))));
|
||||
}
|
||||
|
||||
public void SetCurrent(string id)
|
||||
|
@ -39,5 +40,15 @@ namespace testexetrisathlon.SoundManagement
|
|||
foreach (LoopStream reader in _loadedSounds.Values) reader.Dispose();
|
||||
_output.Dispose();
|
||||
}
|
||||
|
||||
private static MemoryStream Mp3ToWav(Stream mp3File)
|
||||
{
|
||||
using Mp3FileReader reader = new Mp3FileReader(mp3File);
|
||||
using WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader);
|
||||
MemoryStream ms = new MemoryStream();
|
||||
WaveFileWriter.WriteWavFileToStream(ms, pcmStream);
|
||||
ms.Position = 0;
|
||||
return ms;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -86,7 +86,7 @@ namespace testexetrisathlon
|
|||
{
|
||||
Location.ForEach(s => Program.DroppedTetrominoeLocationGrid[s[0], s[1]] = 1);
|
||||
Program.IsDropped = true;
|
||||
Beeper.Beep(800, 200);
|
||||
Program.Beeper.Beep(800, 200);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace testexetrisathlon
|
||||
{
|
||||
public static class SizeSetter
|
||||
{
|
||||
public static void SetWindowSize(int width, int height) => Console.SetWindowSize(width, height);
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
<Deterministic>false</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent Condition="'$(OS)' == 'Windows_NT' ">
|
||||
<PostBuildEvent Condition="'$(OS)' == 'Windows_NT'">
|
||||
if exist "$(SolutionDir)Data\pkgtool.exe" ($(SolutionDir)Data\pkgtool.exe build --noLogo --binDir .) else if exist "%appdata%\UpTool2\Apps\0e35d154-d0d3-45e0-b080-62f521263a44\app\pkgtool.exe" ("%appdata%\UpTool2\Apps\0e35d154-d0d3-45e0-b080-62f521263a44\app\pkgtool.exe" build --noLogo --binDir .) else echo Cound not find Package build tools, skipping
|
||||
</PostBuildEvent>
|
||||
<PostBuildEvent Condition="'$(OS)' != 'Windows_NT'">
|
||||
|
@ -19,16 +19,20 @@
|
|||
<ApplicationIcon>tetris_yUxH6t_256px.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Intro.wav" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="GameOver.wav" />
|
||||
<EmbeddedResource Include="InGame1.wav" />
|
||||
<EmbeddedResource Include="InGame2.wav" />
|
||||
<EmbeddedResource Include="GameOver.mp3" />
|
||||
<EmbeddedResource Include="InGame1.mp3" />
|
||||
<EmbeddedResource Include="InGame2.mp3" />
|
||||
<EmbeddedResource Include="Intro.mp3" />
|
||||
<Content Include="tetris_yUxH6t_256px.ico" />
|
||||
<Compile Remove="SoundManagement/LinuxSoundManager.cs" Condition="'$(OS)' == 'Windows_NT'" />
|
||||
<Compile Remove="SoundManagement/WindowsSoundManager.cs" Condition="'$(OS)' != 'Windows_NT'" />
|
||||
<Compile Remove="SoundManagement/LinuxBeeper.cs" Condition="'$(OS)' == 'Windows_NT'" />
|
||||
<Compile Remove="SoundManagement/WindowsBeeper.cs" Condition="'$(OS)' != 'Windows_NT'" />
|
||||
<Compile Remove="LinuxSizeSetter.cs" Condition="'$(OS)' == 'Windows_NT'" />
|
||||
<Compile Remove="WindowsSizeSetter.cs" Condition="'$(OS)' != 'Windows_NT'" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Bassoon" Version="1.1.1" />
|
||||
<PackageReference Include="NAudio" Version="1.10.0" />
|
||||
<PackageReference Include="Bassoon" Version="1.1.1" Condition="'$(OS)' != 'Windows_NT'" />
|
||||
<PackageReference Include="NAudio" Version="1.10.0" Condition="'$(OS)' == 'Windows_NT'" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Reference in New Issue