1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-19 19:06:45 -05:00

Added ability to stop sfx. Minor map engine updates.

This commit is contained in:
Tim Sarbin 2018-12-08 20:29:10 -05:00
parent 3baa4673c9
commit 468ec1ef2a
5 changed files with 46 additions and 30 deletions

View File

@ -8,6 +8,7 @@ namespace OpenDiablo2.Common.Interfaces
void LoadSong(Stream data);
void PlaySong();
void StopSong();
void PlaySfx(byte[] data);
void StopSfx(int channel);
int PlaySfx(byte[] data);
}
}

View File

@ -125,7 +125,7 @@ namespace OpenDiablo2.Core.Map_Engine
foreach (var cellInfo in gameState.GetMapCellInfo((int)ax, (int)ay, eRenderCellType.WallLower))
renderWindow.DrawMapCell(cellInfo, 320 + px + (int)ox + xOffset, 210 + py + (int)oy);
renderWindow.DrawMapCell(cellInfo, 320 + px + (int)ox + xOffset, 210 + py + (int)oy + 80);
foreach (var cellInfo in gameState.GetMapCellInfo((int)ax, (int)ay, eRenderCellType.WallUpper))
renderWindow.DrawMapCell(cellInfo, 320 + px + (int)ox + xOffset, 210 + py + (int)oy);

View File

@ -73,10 +73,15 @@ namespace OpenDiablo2.SDL2_
SDL_mixer.Mix_CloseAudio();
}
public void PlaySfx(byte[] data)
public int PlaySfx(byte[] data)
{
var sound = SDL_mixer.Mix_QuickLoad_WAV(data);
SDL_mixer.Mix_PlayChannel(-1, sound, 0);
return SDL_mixer.Mix_PlayChannel(-1, sound, 0);
}
public void StopSfx(int channel)
{
SDL_mixer.Mix_HaltChannel(channel);
}
}
}

View File

@ -354,11 +354,9 @@ namespace OpenDiablo2.SDL2_
var offX = -minX;
var offY = -minY;
var frameSize = new Size(diffX, Math.Abs(diffY));
var srcRect = new SDL.SDL_Rect { x = 0, y = 0, w = frameSize.Width, h = Math.Abs(frameSize.Height) };
//var frameSizeMax = diffX * Math.Abs(diffY);
var frameSize = new Size(Math.Abs(diffX), Math.Abs(diffY));
var srcRect = new SDL.SDL_Rect { x = minX, y = minY, w = frameSize.Width, h = frameSize.Height };
var texId = SDL.SDL_CreateTexture(renderer, SDL.SDL_PIXELFORMAT_ARGB8888, (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_STREAMING, frameSize.Width, frameSize.Height);
SDL.SDL_SetTextureBlendMode(texId, SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND);
@ -371,10 +369,7 @@ namespace OpenDiablo2.SDL2_
UInt32* data = (UInt32*)pixels;
var pitchChange = pitch / 4;
for (var i = 0; i < frameSize.Height * pitchChange; i++)
data[i] = 0x0;
var colors = getGameState().CurrentPalette.Colors;
foreach (var block in mapCell.Blocks)
{
@ -387,7 +382,7 @@ namespace OpenDiablo2.SDL2_
{
if (colorIndex == 0)
continue;
var color = getGameState().CurrentPalette.Colors[colorIndex];
var color = colors[colorIndex];
if (color > 0)
data[index] = color;
@ -399,8 +394,7 @@ namespace OpenDiablo2.SDL2_
xx++;
if (xx == 32)
{
index -= 32;
index += pitchChange;
index += pitchChange - 32;
xx = 0;
yy++;
}
@ -428,7 +422,7 @@ namespace OpenDiablo2.SDL2_
public void DrawMapCell(MapCellInfo mapCellInfo, int xPixel, int yPixel)
{
var srcRect = new SDL.SDL_Rect { x = 0, y = 0, w = mapCellInfo.FrameWidth, h = Math.Abs(mapCellInfo.FrameHeight) };
var destRect = new SDL.SDL_Rect { x = xPixel - mapCellInfo.OffX, y = yPixel - mapCellInfo.OffY, w = mapCellInfo.FrameWidth, h = mapCellInfo.FrameHeight };
var destRect = new SDL.SDL_Rect { x = xPixel + mapCellInfo.Rect.X, y = yPixel + mapCellInfo.Rect.Y, w = mapCellInfo.FrameWidth, h = mapCellInfo.FrameHeight };
SDL.SDL_RenderCopy(renderer, (mapCellInfo.Texture as SDL2Texture).Pointer, ref srcRect, ref destRect);
}

View File

@ -43,6 +43,8 @@ namespace OpenDiablo2.Scenes
private bool showEntryUi = false;
private eHero? selectedHero = null;
private float secondTimer;
private int sfxChannel = -1;
private int sfxChannel2 = -1;
private readonly ISprite backgroundSprite, campfireSprite;
private readonly IFont headingFont;
private readonly IFont heroDescFont;
@ -242,14 +244,27 @@ namespace OpenDiablo2.Scenes
}, (path => sfxDictionary.Add(path, mpqProvider.GetBytes(path))));
}
private void StopSfx()
{
if (sfxChannel > -1)
soundProvider.StopSfx(sfxChannel);
if (sfxChannel2 > -1)
soundProvider.StopSfx(sfxChannel);
}
private void OnOkclicked()
{
StopSfx();
// TODO: Support other session types
gameState.Initialize(characterNameTextBox.Text, selectedHero.Value, eSessionType.Local);
}
private void OnExitClicked()
{
StopSfx();
var heros = Enum.GetValues(typeof(eHero)).Cast<eHero>();
foreach(var hero in heros)
{
@ -449,6 +464,7 @@ namespace OpenDiablo2.Scenes
if (ri.Value.Stance != eHeroStance.Selected)
continue;
PlayHeroDeselected(ri.Key);
ri.Value.Stance = eHeroStance.Retreating;
ri.Value.SpecialFrameTime = 0;
break;
@ -476,25 +492,25 @@ namespace OpenDiablo2.Scenes
switch (hero)
{
case eHero.Barbarian:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXBarbarianSelect]);
sfxChannel = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXBarbarianSelect]);
break;
case eHero.Necromancer:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXNecromancerSelect]);
sfxChannel = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXNecromancerSelect]);
break;
case eHero.Paladin:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXPaladinSelect]);
sfxChannel = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXPaladinSelect]);
break;
case eHero.Assassin:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAssassinSelect]);
sfxChannel = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAssassinSelect]);
break;
case eHero.Sorceress:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXSorceressSelect]);
sfxChannel = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXSorceressSelect]);
break;
case eHero.Amazon:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAmazonSelect]);
sfxChannel = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAmazonSelect]);
break;
case eHero.Druid:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXDruidSelect]);
sfxChannel = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXDruidSelect]);
break;
default:
break;
@ -506,25 +522,25 @@ namespace OpenDiablo2.Scenes
switch (hero)
{
case eHero.Barbarian:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXBarbarianDeselect]);
sfxChannel2 = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXBarbarianDeselect]);
break;
case eHero.Necromancer:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXNecromancerDeselect]);
sfxChannel2 = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXNecromancerDeselect]);
break;
case eHero.Paladin:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXPaladinDeselect]);
sfxChannel2 = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXPaladinDeselect]);
break;
case eHero.Assassin:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAssassinDeselect]);
sfxChannel2 = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAssassinDeselect]);
break;
case eHero.Sorceress:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXSorceressDeselect]);
sfxChannel2 = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXSorceressDeselect]);
break;
case eHero.Amazon:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAmazonDeselect]);
sfxChannel2 = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAmazonDeselect]);
break;
case eHero.Druid:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXDruidDeselect]);
sfxChannel2 = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXDruidDeselect]);
break;
default:
break;