Skip to content

Commit

Permalink
Звуки! Пользовательское обновление!
Browse files Browse the repository at this point in the history
Добавлены звуки при поддержке NAudio
https://github.com/naudio/NAudio
Добавлена помощь.
Добавлен счетчик очков.
Скрыты отладочные данные. (можно включить, нажав на ~)
  • Loading branch information
Vladisvell committed Jun 2, 2022
1 parent dbaf079 commit 6c7a241
Show file tree
Hide file tree
Showing 13 changed files with 478 additions and 111 deletions.
77 changes: 74 additions & 3 deletions Astroshooter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -33,8 +48,38 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Win32.Registry, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll</HintPath>
</Reference>
<Reference Include="NAudio, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>packages\NAudio.2.1.0\lib\net472\NAudio.dll</HintPath>
</Reference>
<Reference Include="NAudio.Asio, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll</HintPath>
</Reference>
<Reference Include="NAudio.Core, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll</HintPath>
</Reference>
<Reference Include="NAudio.Midi, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll</HintPath>
</Reference>
<Reference Include="NAudio.Wasapi, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll</HintPath>
</Reference>
<Reference Include="NAudio.WinForms, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll</HintPath>
</Reference>
<Reference Include="NAudio.WinMM, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e279aa5131008a41, processorArchitecture=MSIL">
<HintPath>packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Security.AccessControl, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll</HintPath>
</Reference>
<Reference Include="System.Security.Principal.Windows, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -46,11 +91,11 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="SoundEngine.cs" />
<Compile Include="Controller.cs" />
<Compile Include="Objects\Asteroid.cs" />
<Compile Include="Objects\Booster.cs" />
<Compile Include="Objects\Bullet.cs" />
<Compile Include="Objects\Interface1.cs" />
<Compile Include="Objects\SpaceObject_Interface.cs" />
<Compile Include="Objects\Ship.cs" />
<Compile Include="Rendering.cs">
<SubType>Form</SubType>
Expand All @@ -71,6 +116,10 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="Rendering.resx">
<DependentUpon>Rendering.cs</DependentUpon>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand All @@ -84,6 +133,28 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<COMReference Include="WMPLib">
<Guid>{6BF52A50-394A-11D3-B153-00C04F79FAA6}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.7.2 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
70 changes: 34 additions & 36 deletions Controller.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;

namespace Astroshooter
Expand All @@ -16,8 +12,9 @@ class Controller
private Random random = new Random((int)DateTime.Now.Ticks);
private List<Image> asteroidTextureList;
private Queue<SpaceObject> toSpawn = new Queue<SpaceObject>(100);
private bool isPaused;
private double circularParameter = 0;
private readonly Dictionary<string, CachedSound> soundLibrary = new Dictionary<string, CachedSound>();
private int score = 0;


public Controller(Ship ship, SpaceField spacefield, List<SpaceObject> spaceObjects, List<Image> asteroidImages)
Expand All @@ -26,6 +23,26 @@ public Controller(Ship ship, SpaceField spacefield, List<SpaceObject> spaceObjec
this.spacefield = spacefield;
this.spaceObjects = spaceObjects;
asteroidTextureList = asteroidImages;
InitializeSoundLibrary();
}

private void InitializeSoundLibrary()
{
soundLibrary.Add("AsteroidExplode", new CachedSound(@".\audio\explode.wav"));
soundLibrary.Add("ShipShootSound", new CachedSound(@".\audio\impulse.wav"));
}

public void CreateBullet(float angle)
{
if (ship.cooldown <= 0)
{
var pelleteVelocity = new Vec2();
pelleteVelocity.X = -Math.Cos(angle / 180 * Math.PI);
pelleteVelocity.Y = -Math.Sin(angle / 180 * Math.PI);
spaceObjects.Add(new Bullet(ship.GetCurrentCoordinates(), pelleteVelocity));
AudioPlaybackEngine.Instance.PlaySound(soundLibrary["ShipShootSound"]);
ship.SetShootCooldown(300);
}
}

private void BoundaryCollisionHandle(SpaceObject obj)
Expand Down Expand Up @@ -73,31 +90,22 @@ void SimulateSpaceObjectsTimeFrame(double dt)

for(int i = 0; i < spaceObjects.Count; i++)
{
//if(spaceObjects[i] != null)
//{
spaceObjects[i].SimulateTimeFrame(dt);
BoundaryCollisionHandle(spaceObjects[i]);
Collision(spaceObjects[i]);
if (spaceObjects[i].IsDead())
toDelete.Add(i);
//}
}

//while(toDeleteQ.Count != 0)
//{
// var idToDelete = toDeleteQ.Dequeue();
// if (idToDelete == spaceObjects.Count - 1)
// spaceObjects.RemoveAt(spaceObjects.Count - 1);
// else if(idToDelete < spaceObjects.Count - 1)
// {
// spaceObjects[idToDelete] = spaceObjects[spaceObjects.Count - 1];
// spaceObjects.RemoveAt(spaceObjects.Count - 1);
// }
//}

for(int i = 0; i < toDelete.Count; i++)
{

if(spaceObjects[toDelete[i] - i] is Asteroid)
{
if (spacefield.isSoundEnabled)
AudioPlaybackEngine.Instance.PlaySound(soundLibrary["AsteroidExplode"]);
score += 100;
spacefield.UpdateScore(score);
}
spaceObjects[toDelete[i] - i] = spaceObjects[spaceObjects.Count - 1];
spaceObjects.RemoveAt(spaceObjects.Count - 1);
}
Expand Down Expand Up @@ -129,31 +137,19 @@ private Vec2 GetRandomVelocity()
return new Vec2(xvel, yvel);
}

public void CreateRandomAsteroid()
{
//if(spaceObjects.Count <= 32 && toSpawn.Count <= 16)
//{
// Vec2 pos = GetRandomPositionOutsidePlayzone();
// Vec2 vel = GetRandomVelocity();
// var asteroid = new Asteroid(pos, vel * 3, asteroidTextureList[random.Next(0, asteroidTextureList.Count - 1)]);
// asteroid.SetCooldown(2000);
// toSpawn.Enqueue(asteroid);
//}
CreateAsteroidInCircle(2000);
//return new Asteroid(pos, vel, asteroidTextureList[random.Next(0, asteroidTextureList.Count-1)]);
}
public void CreateRandomAsteroid() => CreateAsteroidInRadius(2000);

public void CreateAsteroidInCircle(double spawnRadius)
public void CreateAsteroidInRadius(double spawnRadius)
{
circularParameter %= Math.PI * 2;
if(spaceObjects.Count <= 32 && toSpawn.Count <= 16)
{
circularParameter += Math.PI / 6;
Vec2 pos = new Vec2()
{
X = spawnRadius * Math.Cos(circularParameter) + spacefield.Width / 2,
Y = spawnRadius * Math.Sin(circularParameter) + spacefield.Height / 2
};
circularParameter += Math.PI / 6;
Vec2 vel = GetRandomVelocity();
var asteroid = new Asteroid(pos, vel * 3, asteroidTextureList[random.Next(0, asteroidTextureList.Count - 1)]);
asteroid.SetCooldown(300);
Expand All @@ -166,6 +162,8 @@ public void Respawn()
if (ship.IsDead())
{
ship.SetDeadState(false);
score = 0;
spacefield.UpdateScore(score);
ship.SetCurrentCoordinates(spacefield.Width / 2, spacefield.Height / 2);
spaceObjects.Add(ship);
}
Expand Down
6 changes: 2 additions & 4 deletions Objects/Asteroid.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Astroshooter
{
Expand Down Expand Up @@ -115,5 +112,6 @@ public void Collide(SpaceObject spaceObject)
public Image GetImage() => texture;

public bool IsDead() => isDead;

}
}
12 changes: 0 additions & 12 deletions Objects/Booster.cs

This file was deleted.

5 changes: 0 additions & 5 deletions Objects/Bullet.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Astroshooter
{
Expand Down Expand Up @@ -101,7 +97,6 @@ public Bullet(Vec2 spawnloc, Vec2 velocity, Image image = null)
{
location = spawnloc * 1;
this.velocity = velocity * 1;
//acceleration = this.velocity * 0.05 + new Vec2(0.01, 0.01);
if (image != null)
texture = image;
timeToLive = 2000;
Expand Down
5 changes: 0 additions & 5 deletions Objects/Ship.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing.Imaging;
using System.Drawing;

namespace Astroshooter
Expand Down
File renamed without changes.
9 changes: 8 additions & 1 deletion Rendering.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6c7a241

Please sign in to comment.