diff --git a/assets.go b/assets.go index 4f98276..c097da8 100644 --- a/assets.go +++ b/assets.go @@ -58,6 +58,28 @@ type AssetManager struct { fontComicSansMs rl.Font fontComicSansMsBig rl.Font + + sfxClick rl.Sound + sfxClickAlt rl.Sound + sfxChaosRoll rl.Sound + sfxTileAddRemove rl.Sound + sfxPieceMove rl.Sound + sfxPieceCapture rl.Sound + sfxPiecePromote rl.Sound + sfxPieceAdd rl.Sound + sfxPieceRemove rl.Sound + sfxPieceColorChange rl.Sound + sfxPieceSizeChange rl.Sound + sfxStatusEffectAdd rl.Sound + sfxStatusEffectRemove rl.Sound + sfxObstacleAdd rl.Sound + sfxObstacleRemove rl.Sound + sfxShopMoneyEarn rl.Sound + sfxShopQuickbuy rl.Sound + sfxShopQuickbuyUndo rl.Sound + sfxShopUnlock rl.Sound + sfxShopShuffle rl.Sound + sfxShopPriceChange rl.Sound } func (am *AssetManager) LoadAll() { @@ -112,6 +134,28 @@ func (am *AssetManager) LoadAll() { am.fontComicSansMs = rl.LoadFontEx("assets/comic.ttf", 20, []rune(FontChars)) am.fontComicSansMsBig = rl.LoadFontEx("assets/comic.ttf", 28, []rune(FontChars)) + + am.sfxClick = rl.LoadSound("assets/sfx/click3.wav") + am.sfxClickAlt = rl.LoadSound("assets/sfx/click.wav") + am.sfxChaosRoll = rl.LoadSound("assets/sfx/chaos_roll.ogg") + am.sfxTileAddRemove = rl.LoadSound("assets/sfx/tile_add_remove.ogg") + am.sfxPieceMove = rl.LoadSound("assets/sfx/piece_move.mp3") + am.sfxPieceCapture = rl.LoadSound("assets/sfx/piece_capture.mp3") + am.sfxPiecePromote = rl.LoadSound("assets/sfx/piece_promote.mp3") + am.sfxPieceAdd = rl.LoadSound("assets/sfx/piece_add.ogg") + am.sfxPieceRemove = rl.LoadSound("assets/sfx/piece_remove.ogg") + am.sfxPieceColorChange = rl.LoadSound("assets/sfx/piece_color_change.ogg") + am.sfxPieceSizeChange = rl.LoadSound("assets/sfx/piece_size_change.wav") + am.sfxStatusEffectAdd = rl.LoadSound("assets/sfx/status_effect_add.ogg") + am.sfxStatusEffectRemove = rl.LoadSound("assets/sfx/status_effect_remove.ogg") + am.sfxObstacleAdd = rl.LoadSound("assets/sfx/obstacle_add.wav") + am.sfxObstacleRemove = rl.LoadSound("assets/sfx/obstacle_remove.wav") + am.sfxShopMoneyEarn = rl.LoadSound("assets/sfx/shop_money_earn.ogg") + am.sfxShopQuickbuy = rl.LoadSound("assets/sfx/shop_quickbuy.ogg") + am.sfxShopQuickbuyUndo = rl.LoadSound("assets/sfx/shop_quickbuy_undo.ogg") + am.sfxShopUnlock = rl.LoadSound("assets/sfx/shop_unlock.ogg") + am.sfxShopShuffle = rl.LoadSound("assets/sfx/shop_shuffle.ogg") + am.sfxShopPriceChange = rl.LoadSound("assets/sfx/shop_price_change.ogg") } func (am *AssetManager) UnloadAll() { @@ -166,4 +210,26 @@ func (am *AssetManager) UnloadAll() { rl.UnloadFont(am.fontComicSansMs) rl.UnloadFont(am.fontComicSansMsBig) + + rl.UnloadSound(am.sfxClick) + rl.UnloadSound(am.sfxClickAlt) + rl.UnloadSound(am.sfxChaosRoll) + rl.UnloadSound(am.sfxTileAddRemove) + rl.UnloadSound(am.sfxPieceMove) + rl.UnloadSound(am.sfxPieceCapture) + rl.UnloadSound(am.sfxPiecePromote) + rl.UnloadSound(am.sfxPieceAdd) + rl.UnloadSound(am.sfxPieceRemove) + rl.UnloadSound(am.sfxPieceColorChange) + rl.UnloadSound(am.sfxPieceSizeChange) + rl.UnloadSound(am.sfxStatusEffectAdd) + rl.UnloadSound(am.sfxStatusEffectRemove) + rl.UnloadSound(am.sfxObstacleAdd) + rl.UnloadSound(am.sfxObstacleRemove) + rl.UnloadSound(am.sfxShopMoneyEarn) + rl.UnloadSound(am.sfxShopQuickbuy) + rl.UnloadSound(am.sfxShopQuickbuyUndo) + rl.UnloadSound(am.sfxShopUnlock) + rl.UnloadSound(am.sfxShopShuffle) + rl.UnloadSound(am.sfxShopPriceChange) } diff --git a/assets/sfx/chaos_roll.ogg b/assets/sfx/chaos_roll.ogg new file mode 100644 index 0000000..faeb0c4 Binary files /dev/null and b/assets/sfx/chaos_roll.ogg differ diff --git a/assets/sfx/click.wav b/assets/sfx/click.wav new file mode 100644 index 0000000..8666dea Binary files /dev/null and b/assets/sfx/click.wav differ diff --git a/assets/sfx/click2.wav b/assets/sfx/click2.wav new file mode 100644 index 0000000..0964edb Binary files /dev/null and b/assets/sfx/click2.wav differ diff --git a/assets/sfx/click3.wav b/assets/sfx/click3.wav new file mode 100644 index 0000000..9d86575 Binary files /dev/null and b/assets/sfx/click3.wav differ diff --git a/assets/sfx/obstacle_add.wav b/assets/sfx/obstacle_add.wav new file mode 100644 index 0000000..e4fb3ac Binary files /dev/null and b/assets/sfx/obstacle_add.wav differ diff --git a/assets/sfx/obstacle_remove.wav b/assets/sfx/obstacle_remove.wav new file mode 100644 index 0000000..39fb81c Binary files /dev/null and b/assets/sfx/obstacle_remove.wav differ diff --git a/assets/sfx/piece_add.ogg b/assets/sfx/piece_add.ogg new file mode 100644 index 0000000..4374b08 Binary files /dev/null and b/assets/sfx/piece_add.ogg differ diff --git a/assets/sfx/piece_capture.mp3 b/assets/sfx/piece_capture.mp3 new file mode 100644 index 0000000..c71b93f Binary files /dev/null and b/assets/sfx/piece_capture.mp3 differ diff --git a/assets/sfx/piece_color_change.ogg b/assets/sfx/piece_color_change.ogg new file mode 100644 index 0000000..a1edab2 Binary files /dev/null and b/assets/sfx/piece_color_change.ogg differ diff --git a/assets/sfx/piece_move.mp3 b/assets/sfx/piece_move.mp3 new file mode 100644 index 0000000..e678ff7 Binary files /dev/null and b/assets/sfx/piece_move.mp3 differ diff --git a/assets/sfx/piece_promote.mp3 b/assets/sfx/piece_promote.mp3 new file mode 100644 index 0000000..25242a5 Binary files /dev/null and b/assets/sfx/piece_promote.mp3 differ diff --git a/assets/sfx/piece_remove.ogg b/assets/sfx/piece_remove.ogg new file mode 100644 index 0000000..b171dc9 Binary files /dev/null and b/assets/sfx/piece_remove.ogg differ diff --git a/assets/sfx/piece_size_change.wav b/assets/sfx/piece_size_change.wav new file mode 100644 index 0000000..e804894 Binary files /dev/null and b/assets/sfx/piece_size_change.wav differ diff --git a/assets/sfx/shop_money_earn.ogg b/assets/sfx/shop_money_earn.ogg new file mode 100644 index 0000000..a0034b1 Binary files /dev/null and b/assets/sfx/shop_money_earn.ogg differ diff --git a/assets/sfx/shop_price_change.ogg b/assets/sfx/shop_price_change.ogg new file mode 100644 index 0000000..48a8a8a Binary files /dev/null and b/assets/sfx/shop_price_change.ogg differ diff --git a/assets/sfx/shop_quickbuy.ogg b/assets/sfx/shop_quickbuy.ogg new file mode 100644 index 0000000..7365b2e Binary files /dev/null and b/assets/sfx/shop_quickbuy.ogg differ diff --git a/assets/sfx/shop_quickbuy_undo.ogg b/assets/sfx/shop_quickbuy_undo.ogg new file mode 100644 index 0000000..ff08969 Binary files /dev/null and b/assets/sfx/shop_quickbuy_undo.ogg differ diff --git a/assets/sfx/shop_shuffle.ogg b/assets/sfx/shop_shuffle.ogg new file mode 100644 index 0000000..0cca832 Binary files /dev/null and b/assets/sfx/shop_shuffle.ogg differ diff --git a/assets/sfx/shop_unlock.ogg b/assets/sfx/shop_unlock.ogg new file mode 100644 index 0000000..b7cc821 Binary files /dev/null and b/assets/sfx/shop_unlock.ogg differ diff --git a/assets/sfx/status_effect_add.ogg b/assets/sfx/status_effect_add.ogg new file mode 100644 index 0000000..9de8a02 Binary files /dev/null and b/assets/sfx/status_effect_add.ogg differ diff --git a/assets/sfx/status_effect_remove.ogg b/assets/sfx/status_effect_remove.ogg new file mode 100644 index 0000000..e88ccaf Binary files /dev/null and b/assets/sfx/status_effect_remove.ogg differ diff --git a/assets/sfx/tile_add_remove.ogg b/assets/sfx/tile_add_remove.ogg new file mode 100644 index 0000000..50628ef Binary files /dev/null and b/assets/sfx/tile_add_remove.ogg differ diff --git a/assets/sfx/tools_05.ogg b/assets/sfx/tools_05.ogg new file mode 100644 index 0000000..adbaf9b Binary files /dev/null and b/assets/sfx/tools_05.ogg differ diff --git a/assets/sfx/tools_07.ogg b/assets/sfx/tools_07.ogg new file mode 100644 index 0000000..bd40e65 Binary files /dev/null and b/assets/sfx/tools_07.ogg differ diff --git a/assets/sfx/wood_cracking_02.ogg b/assets/sfx/wood_cracking_02.ogg new file mode 100644 index 0000000..fdde449 Binary files /dev/null and b/assets/sfx/wood_cracking_02.ogg differ diff --git a/assets/sfx/wood_cracking_03.ogg b/assets/sfx/wood_cracking_03.ogg new file mode 100644 index 0000000..0655cb3 Binary files /dev/null and b/assets/sfx/wood_cracking_03.ogg differ diff --git a/assets/sfx/wood_misc_01.ogg b/assets/sfx/wood_misc_01.ogg new file mode 100644 index 0000000..9d1dbe9 Binary files /dev/null and b/assets/sfx/wood_misc_01.ogg differ diff --git a/chaos.go b/chaos.go index 38909a7..7d09375 100644 --- a/chaos.go +++ b/chaos.go @@ -24,7 +24,7 @@ func NewRngStuff() RngStuff { res.AddChaosOption("Summon two Imps on Earth on random empty tiles") res.AddChaosOption("Pick a file in a plane. Curse all non-royal pieces in the chosen file") res.AddChaosOption("Replace all Bishops with Rooks and vice versa") - res.AddChaosOption("Reset both player’s coin count to 0") + res.AddChaosOption("Reset both players' coin count to 0") res.AddChaosOption("Spread all ice to adjacent tiles") res.AddChaosOption("Summon the Devil (Giant Imp with double move) in the middle of Hell") res.AddChaosOption("Summon an Angel on an empty tile in Heaven") diff --git a/command.go b/command.go index 5c74ec1..49b5637 100644 --- a/command.go +++ b/command.go @@ -1,6 +1,9 @@ package main -import "math/rand" +import ( + rl "github.com/gen2brain/raylib-go/raylib" + "math/rand" +) type CreatePieceCmd struct { piece Piece @@ -21,6 +24,9 @@ func NewCreatePieceCmd(sb *Sandbox, typ uint32, color PieceColor, board uint32, cmd.captureAfterCoord = sb.FindUnoccupiedOffBoardCoord() captured.Board = OffBoard captured.Coord = cmd.captureAfterCoord + rl.PlaySound(assets.sfxPieceCapture) + } else { + rl.PlaySound(assets.sfxPieceAdd) } cmd.piece = *sb.NewPiece(typ, color, board, coord) return &cmd @@ -32,6 +38,9 @@ func (cmd *CreatePieceCmd) redo(sb *Sandbox, ui *UiState) { var captured = sb.GetPiece(cmd.capturedPiece) captured.Board = OffBoard captured.Coord = cmd.captureAfterCoord + rl.PlaySound(assets.sfxPieceCapture) + } else { + rl.PlaySound(assets.sfxPieceAdd) } if cmd.piece.Board != OffBoard { ui.board = int32(cmd.piece.Board) @@ -49,6 +58,9 @@ func (cmd *CreatePieceCmd) undo(sb *Sandbox, ui *UiState) { var captured = sb.GetPiece(cmd.capturedPiece) captured.Board = cmd.piece.Board captured.Coord = cmd.piece.Coord + rl.PlaySound(assets.sfxPieceCapture) + } else { + rl.PlaySound(assets.sfxPieceRemove) } if cmd.piece.Board != OffBoard { ui.board = int32(cmd.piece.Board) @@ -67,7 +79,7 @@ func NewDeletePieceCmd(sb *Sandbox, ui *UiState, id uint32) *DeletePieceCmd { piece: *sb.GetPiece(id), effects: sb.GetStatusEffectsOnPiece(id), } - + rl.PlaySound(assets.sfxPieceRemove) sb.RemovePiece(id) ui.selection.Deselect() return &cmd @@ -78,6 +90,7 @@ func (cmd *DeletePieceCmd) redo(sb *Sandbox, ui *UiState) { ui.selection.Deselect() } sb.RemovePiece(cmd.piece.Id) + rl.PlaySound(assets.sfxPieceRemove) if cmd.piece.Board != OffBoard { ui.board = int32(cmd.piece.Board) } @@ -89,6 +102,7 @@ func (cmd *DeletePieceCmd) undo(sb *Sandbox, ui *UiState) { for _, effect := range cmd.effects { sb.NewStatusEffect(cmd.piece.Id, effect) } + rl.PlaySound(assets.sfxPieceAdd) if cmd.piece.Board != OffBoard { ui.board = int32(cmd.piece.Board) } @@ -127,6 +141,9 @@ func NewMovePieceCmd(sb *Sandbox, id uint32, destCoord Vec2, destBoard uint32) * cmd.captureAfterCoord = sb.FindUnoccupiedOffBoardCoord() captured.Board = OffBoard captured.Coord = cmd.captureAfterCoord + rl.PlaySound(assets.sfxPieceCapture) + } else { + rl.PlaySound(assets.sfxPieceMove) } cmd.afterBoard = destBoard cmd.afterCoord = destCoord @@ -143,6 +160,9 @@ func (cmd *MovePieceCmd) redo(sb *Sandbox, ui *UiState) { var captured = sb.GetPiece(cmd.capturedPiece) captured.Board = OffBoard captured.Coord = cmd.captureAfterCoord + rl.PlaySound(assets.sfxPieceCapture) + } else { + rl.PlaySound(assets.sfxPieceMove) } if piece.Board != OffBoard { ui.board = int32(piece.Board) @@ -159,6 +179,9 @@ func (cmd *MovePieceCmd) undo(sb *Sandbox, ui *UiState) { var captured = sb.GetPiece(cmd.capturedPiece) captured.Board = cmd.afterBoard captured.Coord = cmd.afterCoord + rl.PlaySound(assets.sfxPieceCapture) + } else { + rl.PlaySound(assets.sfxPieceMove) } if piece.Board != OffBoard { ui.board = int32(piece.Board) @@ -174,6 +197,7 @@ type CreateStatusEffectCmd struct { func NewCreateStatusEffectCmd(sb *Sandbox, piece uint32, effect uint32) *CreateStatusEffectCmd { sb.NewStatusEffect(piece, effect) + rl.PlaySound(assets.sfxStatusEffectAdd) return &CreateStatusEffectCmd{ piece: piece, effect: effect, @@ -183,6 +207,7 @@ func NewCreateStatusEffectCmd(sb *Sandbox, piece uint32, effect uint32) *CreateS func (cmd *CreateStatusEffectCmd) redo(sb *Sandbox, ui *UiState) { sb.NewStatusEffect(cmd.piece, cmd.effect) var piece = sb.GetPiece(cmd.piece) + rl.PlaySound(assets.sfxStatusEffectAdd) if piece.Board != OffBoard { ui.board = int32(piece.Board) } @@ -193,6 +218,7 @@ func (cmd *CreateStatusEffectCmd) redo(sb *Sandbox, ui *UiState) { func (cmd *CreateStatusEffectCmd) undo(sb *Sandbox, ui *UiState) { sb.RemoveStatusEffect(cmd.piece, cmd.effect) var piece = sb.GetPiece(cmd.piece) + rl.PlaySound(assets.sfxStatusEffectRemove) if piece.Board != OffBoard { ui.board = int32(piece.Board) } @@ -207,6 +233,7 @@ type DeleteStatusEffectCmd struct { func NewDeleteStatusEffectCmd(sb *Sandbox, piece uint32, effect uint32) *DeleteStatusEffectCmd { sb.RemoveStatusEffect(piece, effect) + rl.PlaySound(assets.sfxStatusEffectRemove) return &DeleteStatusEffectCmd{ piece: piece, effect: effect, @@ -216,6 +243,7 @@ func NewDeleteStatusEffectCmd(sb *Sandbox, piece uint32, effect uint32) *DeleteS func (cmd *DeleteStatusEffectCmd) redo(sb *Sandbox, ui *UiState) { sb.RemoveStatusEffect(cmd.piece, cmd.effect) var piece = sb.GetPiece(cmd.piece) + rl.PlaySound(assets.sfxStatusEffectRemove) if piece.Board != OffBoard { ui.board = int32(piece.Board) } @@ -226,6 +254,7 @@ func (cmd *DeleteStatusEffectCmd) redo(sb *Sandbox, ui *UiState) { func (cmd *DeleteStatusEffectCmd) undo(sb *Sandbox, ui *UiState) { sb.NewStatusEffect(cmd.piece, cmd.effect) var piece = sb.GetPiece(cmd.piece) + rl.PlaySound(assets.sfxStatusEffectAdd) if piece.Board != OffBoard { ui.board = int32(piece.Board) } @@ -233,51 +262,28 @@ func (cmd *DeleteStatusEffectCmd) undo(sb *Sandbox, ui *UiState) { ui.tab = TabBoard } -type IncreasePieceScaleCmd struct { - piece uint32 -} - -func NewIncreasePieceScaleCmd(sb *Sandbox, piece uint32) *IncreasePieceScaleCmd { - sb.GetPiece(piece).Scale++ - return &IncreasePieceScaleCmd{ - piece: piece, - } -} - -func (cmd *IncreasePieceScaleCmd) redo(sb *Sandbox, ui *UiState) { - var piece = sb.GetPiece(cmd.piece) - piece.Scale++ - if piece.Board != OffBoard { - ui.board = int32(piece.Board) - } - ui.selection.SelectPiece(cmd.piece) - ui.tab = TabBoard -} - -func (cmd *IncreasePieceScaleCmd) undo(sb *Sandbox, ui *UiState) { - var piece = sb.GetPiece(cmd.piece) - piece.Scale-- - if piece.Board != OffBoard { - ui.board = int32(piece.Board) - } - ui.selection.SelectPiece(cmd.piece) - ui.tab = TabBoard -} - -type DecreasePieceScaleCmd struct { - piece uint32 +type ChangePieceScaleCmd struct { + piece uint32 + newScale uint32 + oldScale uint32 } -func NewDecreasePieceScaleCmd(sb *Sandbox, piece uint32) *DecreasePieceScaleCmd { - sb.GetPiece(piece).Scale-- - return &DecreasePieceScaleCmd{ - piece: piece, +func NewChangePieceScaleCmd(sb *Sandbox, id uint32, newScale uint32) *ChangePieceScaleCmd { + var piece = sb.GetPiece(id) + var oldScale = piece.Scale + piece.Scale = newScale + rl.PlaySound(assets.sfxPieceSizeChange) + return &ChangePieceScaleCmd{ + piece: id, + newScale: newScale, + oldScale: oldScale, } } -func (cmd *DecreasePieceScaleCmd) redo(sb *Sandbox, ui *UiState) { +func (cmd *ChangePieceScaleCmd) redo(sb *Sandbox, ui *UiState) { var piece = sb.GetPiece(cmd.piece) - piece.Scale-- + piece.Scale = cmd.newScale + rl.PlaySound(assets.sfxPieceSizeChange) if piece.Board != OffBoard { ui.board = int32(piece.Board) } @@ -285,9 +291,9 @@ func (cmd *DecreasePieceScaleCmd) redo(sb *Sandbox, ui *UiState) { ui.tab = TabBoard } -func (cmd *DecreasePieceScaleCmd) undo(sb *Sandbox, ui *UiState) { +func (cmd *ChangePieceScaleCmd) undo(sb *Sandbox, ui *UiState) { var piece = sb.GetPiece(cmd.piece) - piece.Scale++ + piece.Scale = cmd.oldScale if piece.Board != OffBoard { ui.board = int32(piece.Board) } @@ -302,6 +308,7 @@ type CreateTileCmd struct { func NewCreateTileCmd(sb *Sandbox, board uint32, coord Vec2) *CreateTileCmd { sb.NewTile(board, coord) + rl.PlaySound(assets.sfxTileAddRemove) return &CreateTileCmd{ board: board, coord: coord, @@ -310,6 +317,7 @@ func NewCreateTileCmd(sb *Sandbox, board uint32, coord Vec2) *CreateTileCmd { func (cmd *CreateTileCmd) redo(sb *Sandbox, ui *UiState) { sb.NewTile(cmd.board, cmd.coord) + rl.PlaySound(assets.sfxTileAddRemove) ui.board = int32(cmd.board) ui.selection.SelectCoord(cmd.coord) ui.tab = TabBoard @@ -317,6 +325,7 @@ func (cmd *CreateTileCmd) redo(sb *Sandbox, ui *UiState) { func (cmd *CreateTileCmd) undo(sb *Sandbox, ui *UiState) { sb.RemoveTile(cmd.board, cmd.coord) + rl.PlaySound(assets.sfxTileAddRemove) ui.board = int32(cmd.board) ui.selection.SelectCoord(cmd.coord) ui.tab = TabBoard @@ -329,6 +338,7 @@ type DeleteTileCmd struct { func NewDeleteTileCmd(sb *Sandbox, board uint32, coord Vec2) *DeleteTileCmd { sb.RemoveTile(board, coord) + rl.PlaySound(assets.sfxTileAddRemove) return &DeleteTileCmd{ board: board, coord: coord, @@ -337,6 +347,7 @@ func NewDeleteTileCmd(sb *Sandbox, board uint32, coord Vec2) *DeleteTileCmd { func (cmd *DeleteTileCmd) redo(sb *Sandbox, ui *UiState) { sb.RemoveTile(cmd.board, cmd.coord) + rl.PlaySound(assets.sfxTileAddRemove) ui.board = int32(cmd.board) ui.selection.SelectCoord(cmd.coord) ui.tab = TabBoard @@ -344,6 +355,7 @@ func (cmd *DeleteTileCmd) redo(sb *Sandbox, ui *UiState) { func (cmd *DeleteTileCmd) undo(sb *Sandbox, ui *UiState) { sb.NewTile(cmd.board, cmd.coord) + rl.PlaySound(assets.sfxTileAddRemove) ui.board = int32(cmd.board) ui.selection.SelectCoord(cmd.coord) ui.tab = TabBoard @@ -357,6 +369,7 @@ type CreateObstacleCmd struct { func NewCreateObstacleCmd(sb *Sandbox, coord Vec2, board uint32, obstacle uint32) *CreateObstacleCmd { sb.NewObstacle(coord, board, obstacle) + rl.PlaySound(assets.sfxObstacleAdd) return &CreateObstacleCmd{ obstacle: obstacle, board: board, @@ -366,6 +379,7 @@ func NewCreateObstacleCmd(sb *Sandbox, coord Vec2, board uint32, obstacle uint32 func (cmd *CreateObstacleCmd) redo(sb *Sandbox, ui *UiState) { sb.NewObstacle(cmd.coord, cmd.board, cmd.obstacle) + rl.PlaySound(assets.sfxObstacleAdd) ui.board = int32(cmd.board) ui.selection.SelectCoord(cmd.coord) ui.tab = TabBoard @@ -373,6 +387,7 @@ func (cmd *CreateObstacleCmd) redo(sb *Sandbox, ui *UiState) { func (cmd *CreateObstacleCmd) undo(sb *Sandbox, ui *UiState) { sb.RemoveObstacle(cmd.coord, cmd.board, cmd.obstacle) + rl.PlaySound(assets.sfxObstacleRemove) ui.board = int32(cmd.board) ui.selection.SelectCoord(cmd.coord) ui.tab = TabBoard @@ -386,6 +401,7 @@ type DeleteObstacleCmd struct { func NewDeleteObstacleCmd(sb *Sandbox, coord Vec2, board uint32, obstacle uint32) *DeleteObstacleCmd { sb.RemoveObstacle(coord, board, obstacle) + rl.PlaySound(assets.sfxObstacleRemove) return &DeleteObstacleCmd{ obstacle: obstacle, board: board, @@ -395,6 +411,7 @@ func NewDeleteObstacleCmd(sb *Sandbox, coord Vec2, board uint32, obstacle uint32 func (cmd *DeleteObstacleCmd) redo(sb *Sandbox, ui *UiState) { sb.RemoveObstacle(cmd.coord, cmd.board, cmd.obstacle) + rl.PlaySound(assets.sfxObstacleRemove) ui.board = int32(cmd.board) ui.selection.SelectCoord(cmd.coord) ui.tab = TabBoard @@ -402,6 +419,7 @@ func (cmd *DeleteObstacleCmd) redo(sb *Sandbox, ui *UiState) { func (cmd *DeleteObstacleCmd) undo(sb *Sandbox, ui *UiState) { sb.NewObstacle(cmd.coord, cmd.board, cmd.obstacle) + rl.PlaySound(assets.sfxObstacleAdd) ui.board = int32(cmd.board) ui.selection.SelectCoord(cmd.coord) ui.tab = TabBoard @@ -427,6 +445,9 @@ func NewPastePieceCmd(sb *Sandbox, ui *UiState, coord Vec2, board uint32) *Paste cmd.captureAfterCoord = sb.FindUnoccupiedOffBoardCoord() captured.Board = OffBoard captured.Coord = cmd.captureAfterCoord + rl.PlaySound(assets.sfxPieceCapture) + } else { + rl.PlaySound(assets.sfxPieceAdd) } var piece = sb.NewPiece(ui.clipboard.typ, ui.clipboard.color, board, coord) piece.Scale = ui.clipboard.scale @@ -445,6 +466,14 @@ func (cmd *PastePieceCmd) redo(sb *Sandbox, ui *UiState) { for _, effect := range cmd.effects { sb.NewStatusEffect(cmd.piece.Id, effect) } + if cmd.anyCaptured { + var captured = sb.GetPiece(cmd.capturedPiece) + captured.Board = OffBoard + captured.Coord = cmd.captureAfterCoord + rl.PlaySound(assets.sfxPieceCapture) + } else { + rl.PlaySound(assets.sfxPieceMove) + } if cmd.piece.Board != OffBoard { ui.board = int32(cmd.piece.Board) } @@ -461,6 +490,9 @@ func (cmd *PastePieceCmd) undo(sb *Sandbox, ui *UiState) { var captured = sb.GetPiece(cmd.capturedPiece) captured.Board = cmd.piece.Board captured.Coord = cmd.piece.Coord + rl.PlaySound(assets.sfxPieceCapture) + } else { + rl.PlaySound(assets.sfxPieceAdd) } if cmd.piece.Board != OffBoard { ui.board = int32(cmd.piece.Board) @@ -483,6 +515,7 @@ func NewDuplicatePieceCmd(sb *Sandbox, ui *UiState, id uint32) *DuplicatePieceCm sb.NewStatusEffect(piece.Id, effect) } ui.selection.SelectPiece(piece.Id) + rl.PlaySound(assets.sfxPieceAdd) return &DuplicatePieceCmd{ originalId: id, piece: *piece, @@ -497,12 +530,14 @@ func (cmd *DuplicatePieceCmd) redo(sb *Sandbox, ui *UiState) { } ui.selection.SelectPiece(cmd.piece.Id) ui.tab = TabBoard + rl.PlaySound(assets.sfxPieceAdd) } func (cmd *DuplicatePieceCmd) undo(sb *Sandbox, ui *UiState) { sb.RemovePiece(cmd.piece.Id) ui.selection.SelectPiece(cmd.originalId) ui.tab = TabBoard + rl.PlaySound(assets.sfxPieceAdd) // TODO Remove piece? } type ChangeColorOfPieceCmd struct { @@ -515,6 +550,7 @@ func NewChangeColorOfPieceCmd(sb *Sandbox, id uint32, color PieceColor) *ChangeC piece := sb.GetPiece(id) var before = piece.Color piece.Color = color + rl.PlaySound(assets.sfxPieceColorChange) return &ChangeColorOfPieceCmd{ piece: id, before: before, @@ -524,12 +560,14 @@ func NewChangeColorOfPieceCmd(sb *Sandbox, id uint32, color PieceColor) *ChangeC func (cmd *ChangeColorOfPieceCmd) redo(sb *Sandbox, ui *UiState) { sb.GetPiece(cmd.piece).Color = cmd.after + rl.PlaySound(assets.sfxPieceColorChange) ui.selection.SelectPiece(cmd.piece) ui.tab = TabBoard } func (cmd *ChangeColorOfPieceCmd) undo(sb *Sandbox, ui *UiState) { sb.GetPiece(cmd.piece).Color = cmd.before + rl.PlaySound(assets.sfxPieceColorChange) ui.selection.SelectPiece(cmd.piece) ui.tab = TabBoard } @@ -544,6 +582,7 @@ func NewChangeTypeOfPieceCmd(sb *Sandbox, id uint32, typ uint32) *ChangeTypeOfPi piece := sb.GetPiece(id) var before = piece.Typ piece.Typ = typ + rl.PlaySound(assets.sfxPiecePromote) return &ChangeTypeOfPieceCmd{ piece: id, before: before, @@ -555,12 +594,14 @@ func (cmd *ChangeTypeOfPieceCmd) redo(sb *Sandbox, ui *UiState) { sb.GetPiece(cmd.piece).Typ = cmd.after ui.selection.SelectPiece(cmd.piece) ui.tab = TabBoard + rl.PlaySound(assets.sfxPiecePromote) } func (cmd *ChangeTypeOfPieceCmd) undo(sb *Sandbox, ui *UiState) { sb.GetPiece(cmd.piece).Typ = cmd.before ui.selection.SelectPiece(cmd.piece) ui.tab = TabBoard + rl.PlaySound(assets.sfxPiecePromote) } type ChangeMoneyAmountCmd struct { @@ -575,6 +616,7 @@ func NewChangeMoneyAmountCmd(sb *Sandbox, whiteNewAmount int, blackNewAmount int var blackBefore = sb.Shop.Money[1] sb.Shop.Money[0] = whiteNewAmount sb.Shop.Money[1] = blackNewAmount + rl.PlaySound(assets.sfxShopMoneyEarn) return &ChangeMoneyAmountCmd{ whiteBefore: whiteBefore, whiteAfter: whiteNewAmount, @@ -586,11 +628,13 @@ func NewChangeMoneyAmountCmd(sb *Sandbox, whiteNewAmount int, blackNewAmount int func (cmd *ChangeMoneyAmountCmd) redo(sb *Sandbox, ui *UiState) { sb.Shop.Money[0] = cmd.whiteAfter sb.Shop.Money[1] = cmd.blackAfter + rl.PlaySound(assets.sfxShopMoneyEarn) } func (cmd *ChangeMoneyAmountCmd) undo(sb *Sandbox, ui *UiState) { sb.Shop.Money[0] = cmd.whiteBefore sb.Shop.Money[1] = cmd.blackBefore + rl.PlaySound(assets.sfxShopMoneyEarn) } type ChangeShopUnlockCountCmd struct { @@ -601,6 +645,7 @@ type ChangeShopUnlockCountCmd struct { func NewChangeShopUnlockCountCmd(sb *Sandbox, newCount int) *ChangeShopUnlockCountCmd { var before = sb.Shop.UnlockedCount sb.Shop.UnlockedCount = newCount + rl.PlaySound(assets.sfxShopUnlock) return &ChangeShopUnlockCountCmd{ before: before, after: newCount, @@ -609,11 +654,13 @@ func NewChangeShopUnlockCountCmd(sb *Sandbox, newCount int) *ChangeShopUnlockCou func (cmd *ChangeShopUnlockCountCmd) redo(sb *Sandbox, ui *UiState) { sb.Shop.UnlockedCount = cmd.after + rl.PlaySound(assets.sfxShopUnlock) ui.tab = TabShop } func (cmd *ChangeShopUnlockCountCmd) undo(sb *Sandbox, ui *UiState) { sb.Shop.UnlockedCount = cmd.before + rl.PlaySound(assets.sfxShopUnlock) ui.tab = TabShop } @@ -629,6 +676,7 @@ func NewShuffleShopCmd(shop *Shop) *ShuffleShopCmd { swaps = append(swaps, j) shop.Entries[i], shop.Entries[j] = shop.Entries[j], shop.Entries[i] } + rl.PlaySound(assets.sfxShopShuffle) return &ShuffleShopCmd{ swaps: swaps, } @@ -639,6 +687,7 @@ func (cmd *ShuffleShopCmd) redo(sb *Sandbox, ui *UiState) { var j = cmd.swaps[len(sb.Shop.Entries)-1-i] sb.Shop.Entries[i], sb.Shop.Entries[j] = sb.Shop.Entries[j], sb.Shop.Entries[i] } + rl.PlaySound(assets.sfxShopShuffle) ui.tab = TabShop } @@ -647,6 +696,7 @@ func (cmd *ShuffleShopCmd) undo(sb *Sandbox, ui *UiState) { var j = cmd.swaps[len(sb.Shop.Entries)-1-i] sb.Shop.Entries[i], sb.Shop.Entries[j] = sb.Shop.Entries[j], sb.Shop.Entries[i] } + rl.PlaySound(assets.sfxShopShuffle) ui.tab = TabShop } @@ -660,6 +710,7 @@ func NewChangeShopEntryPriceCmd(shop *Shop, entry uint32, newPrice int) *ChangeS var e = shop.GetEntry(entry) var priceBefore = e.Price e.Price = newPrice + rl.PlaySound(assets.sfxShopPriceChange) return &ChangeShopEntryPriceCmd{ entry: entry, priceBefore: priceBefore, @@ -669,11 +720,13 @@ func NewChangeShopEntryPriceCmd(shop *Shop, entry uint32, newPrice int) *ChangeS func (cmd *ChangeShopEntryPriceCmd) redo(sb *Sandbox, ui *UiState) { sb.Shop.GetEntry(cmd.entry).Price = cmd.priceAfter + rl.PlaySound(assets.sfxShopPriceChange) ui.tab = TabShop } func (cmd *ChangeShopEntryPriceCmd) undo(sb *Sandbox, ui *UiState) { sb.Shop.GetEntry(cmd.entry).Price = cmd.priceBefore + rl.PlaySound(assets.sfxShopPriceChange) ui.tab = TabShop } @@ -691,6 +744,7 @@ func NewQuickBuyCmd(shop *Shop, player uint32, entry uint32) *QuickBuyCmd { if unlock { shop.UnlockedCount++ } + rl.PlaySound(assets.sfxShopQuickbuy) return &QuickBuyCmd{ player: player, entry: entry, @@ -705,6 +759,7 @@ func (cmd *QuickBuyCmd) redo(sb *Sandbox, ui *UiState) { if cmd.unlock { sb.Shop.UnlockedCount++ } + rl.PlaySound(assets.sfxShopQuickbuy) ui.tab = TabShop } @@ -715,5 +770,6 @@ func (cmd *QuickBuyCmd) undo(sb *Sandbox, ui *UiState) { var e = sb.Shop.GetEntry(cmd.entry) e.Price-- sb.Shop.Money[cmd.player] += e.Price + rl.PlaySound(assets.sfxShopQuickbuyUndo) ui.tab = TabShop } diff --git a/main.go b/main.go index 5affeb0..b8cef6c 100644 --- a/main.go +++ b/main.go @@ -28,11 +28,15 @@ var Commit = func() string { func main() { var version = fmt.Sprintf("v1.1/%s", Commit[:7]) fmt.Printf("Starting Chess Heaven and Hell %s\n", version) + rl.SetConfigFlags(rl.FlagWindowResizable) + rl.InitWindow(WindowWidth, WindowHeight, fmt.Sprintf("Chess - Heaven and Hell %s", version)) defer rl.CloseWindow() rl.SetExitKey(rl.KeyNull) - var exit = false + + rl.InitAudioDevice() + defer rl.CloseAudioDevice() rl.SetTargetFPS(60) @@ -64,6 +68,7 @@ func main() { var ui = NewUiState() defer ui.Dispose() + var exit = false for !exit { if rl.WindowShouldClose() { diff --git a/ui.go b/ui.go index ea68173..33775c7 100644 --- a/ui.go +++ b/ui.go @@ -106,6 +106,7 @@ func (s *UiState) Render(undo *UndoRedoSystem) { s.RenderMoneyWidget(&sandbox, undo) if rl.IsKeyPressed(rl.KeyS) && !ctrlDown { + rl.PlaySound(assets.sfxClick) if s.tab == TabShop { s.tab = TabBoard } else { @@ -159,6 +160,7 @@ func (s *UiState) RenderBoardUi(undo *UndoRedoSystem) { s.mode = 1 - s.mode } if oldMode != s.mode { + rl.PlaySound(assets.sfxClickAlt) s.selection.Deselect() } @@ -180,13 +182,20 @@ func (s *UiState) RenderBoardUi(undo *UndoRedoSystem) { } func (s *UiState) RenderPiecesMode() { + var colorBefore = s.color s.color = rg.ToggleSlider(rl.NewRectangle(float32(rl.GetScreenWidth()-UiMargin-UiButtonW), 2*UiMargin+UiButtonH, UiButtonW, UiButtonH), "White;Black", s.color) if rl.IsKeyPressed(rl.KeyC) { s.color = 1 - s.color } + if s.color != colorBefore { + rl.PlaySound(assets.sfxClickAlt) + } for i := 0; i < len(sandbox.PieceTypes); i++ { - if rg.Toggle(rl.NewRectangle(float32(rl.GetScreenWidth()-UiMargin-UiButtonW), float32(3*UiMargin+2*UiButtonH+i*(UiMarginSmall+UiButtonH)), UiButtonW, UiButtonH), sandbox.GetPieceType(uint32(i)).Name, s.selection.IsPieceTypeSelected(uint32(i))) { + var activeOld = s.selection.IsPieceTypeSelected(uint32(i)) + var active = rg.Toggle(rl.NewRectangle(float32(rl.GetScreenWidth()-UiMargin-UiButtonW), float32(3*UiMargin+2*UiButtonH+i*(UiMarginSmall+UiButtonH)), UiButtonW, UiButtonH), sandbox.GetPieceType(uint32(i)).Name, activeOld) + if active && !activeOld { + rl.PlaySound(assets.sfxClick) s.selection.SelectPieceType(uint32(i)) } } @@ -196,9 +205,10 @@ func (s *UiState) RenderPieceContextMenu(undo *UndoRedoSystem) { var selectedPieceId, _ = s.selection.GetSelectedPieceId() piece := sandbox.GetPiece(selectedPieceId) + var showEffectsOrTypesBefore = s.showEffectsOrTypes s.showEffectsOrTypes = rg.ToggleSlider(rl.NewRectangle(float32(rl.GetScreenWidth()-UiMargin-UiButtonW), 2*UiMargin+UiButtonH, UiButtonW, UiButtonH), "Effect;Types", s.showEffectsOrTypes) - if rl.IsKeyPressed(rl.KeyC) { - s.color = 1 - s.color + if s.showEffectsOrTypes != showEffectsOrTypesBefore { + rl.PlaySound(assets.sfxClickAlt) } if s.showEffectsOrTypes == 1 { @@ -219,10 +229,10 @@ func (s *UiState) RenderPieceContextMenu(undo *UndoRedoSystem) { var pieceScale = piece.Scale var change = SpinnerWithIcon(spinnerX, spinnerY, fmt.Sprint(pieceScale), assets.texPieceScale) if change < 0 && pieceScale > 1 { - undo.Append(NewDecreasePieceScaleCmd(&sandbox, selectedPieceId)) + undo.Append(NewChangePieceScaleCmd(&sandbox, selectedPieceId, sandbox.GetPiece(selectedPieceId).Scale-1)) } if change > 0 { - undo.Append(NewIncreasePieceScaleCmd(&sandbox, selectedPieceId)) + undo.Append(NewChangePieceScaleCmd(&sandbox, selectedPieceId, sandbox.GetPiece(selectedPieceId).Scale+1)) } } @@ -363,6 +373,7 @@ func (s *UiState) RenderMoneyWidget(sb *Sandbox, undo *UndoRedoSystem) { rl.DrawTextEx(assets.fontComicSansMsBig, fmt.Sprint("White money: ", *sb.Shop.WhiteMoney()), rl.NewVector2(posX+2*UiButtonH+UiMarginSmall+UiMargin, posY+UiButtonFlatH/2-UiFontSizeBig/2), UiFontSizeBig, 1, rl.Black) var inRngTab = rg.Toggle(rl.NewRectangle(posX+UiShopWidth-UiButtonNarrowW, posY, UiButtonNarrowW, UiButtonH), "Rng", s.tab == TabRng) var inShopTab = rg.Toggle(rl.NewRectangle(posX+UiShopWidth-2*UiButtonNarrowW-UiMarginSmall, posY, UiButtonNarrowW, UiButtonH), "Shop", s.tab == TabShop) + var tabOld = s.tab if inRngTab && inShopTab { if s.tab == TabShop { s.tab = TabRng @@ -376,6 +387,9 @@ func (s *UiState) RenderMoneyWidget(sb *Sandbox, undo *UndoRedoSystem) { } else { s.tab = TabBoard } + if tabOld != s.tab { + rl.PlaySound(assets.sfxClick) + } if rg.Button(rl.NewRectangle(posX+UiShopWidth-3*UiButtonNarrowW-2*UiMarginSmall, posY, UiButtonNarrowW, UiButtonH), "++Both") { undo.Append(NewChangeMoneyAmountCmd(sb, *sb.Shop.WhiteMoney()+1, *sb.Shop.BlackMoney()+1)) } @@ -405,6 +419,8 @@ func (s *UiState) RenderRngMenu(undo *UndoRedoSystem) { } posY += UiMarginSmall if rg.Button(rl.NewRectangle(posX, posY, UiButtonNarrowW, UiButtonH), "Reroll") { + rl.PlaySound(assets.sfxClick) + rl.PlaySound(assets.sfxChaosRoll) s.rng.RerollChaosShown() } posY += 3 * UiMarginBig @@ -413,30 +429,35 @@ func (s *UiState) RenderRngMenu(undo *UndoRedoSystem) { posY += UiButtonFlatH + UiMarginSmall if rg.Button(rl.NewRectangle(posX, posY, UiButtonNarrowW, UiButtonH), "Reroll") { + rl.PlaySound(assets.sfxClick) s.rng.RerollPiece(&sandbox) } rl.DrawTextEx(assets.fontComicSansMsBig, "Random Piece: "+s.rng.piece, rl.NewVector2(posX+UiButtonNarrowW+UiMarginSmall, posY+UiButtonH/2-UiFontSizeBig/2), UiFontSizeBig, 1, rl.Black) posY += UiButtonH + UiMarginSmall if rg.Button(rl.NewRectangle(posX, posY, UiButtonNarrowW, UiButtonH), "Reroll") { + rl.PlaySound(assets.sfxClick) s.rng.RerollPlane() } rl.DrawTextEx(assets.fontComicSansMsBig, "Random plane: "+s.rng.plane, rl.NewVector2(posX+UiButtonNarrowW+UiMarginSmall, posY+UiButtonH/2-UiFontSizeBig/2), UiFontSizeBig, 1, rl.Black) posY += UiButtonH + UiMarginSmall if rg.Button(rl.NewRectangle(posX, posY, UiButtonNarrowW, UiButtonH), "Reroll") { + rl.PlaySound(assets.sfxClick) s.rng.RerollTile() } rl.DrawTextEx(assets.fontComicSansMsBig, "Random tile: "+s.rng.tile, rl.NewVector2(posX+UiButtonNarrowW+UiMarginSmall, posY+UiButtonH/2-UiFontSizeBig/2), UiFontSizeBig, 1, rl.Black) posY += UiButtonH + UiMarginSmall if rg.Button(rl.NewRectangle(posX, posY, UiButtonNarrowW, UiButtonH), "Reroll") { + rl.PlaySound(assets.sfxClick) s.rng.RerollUnoccupiedTile(&sandbox) } rl.DrawTextEx(assets.fontComicSansMsBig, "Random unoccupied tile: "+s.rng.unoccupiedTile, rl.NewVector2(posX+UiButtonNarrowW+UiMarginSmall, posY+UiButtonH/2-UiFontSizeBig/2), UiFontSizeBig, 1, rl.Black) posY += UiButtonH + UiMarginSmall if rg.Button(rl.NewRectangle(posX, posY, UiButtonNarrowW, UiButtonH), "Reroll") { + rl.PlaySound(assets.sfxClick) s.rng.RerollEmptyTile(&sandbox) } rl.DrawTextEx(assets.fontComicSansMsBig, "Random empty tile: "+s.rng.emptyTile, rl.NewVector2(posX+UiButtonNarrowW+UiMarginSmall, posY+UiButtonH/2-UiFontSizeBig/2), UiFontSizeBig, 1, rl.Black)