Rev 124 | Rev 131 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 124 | Rev 130 | ||
---|---|---|---|
Line 19... | Line 19... | ||
19 | 2.35f, // #define PART_BISHOP 3 |
19 | 2.35f, // #define PART_BISHOP 3 |
20 | 2.25f, // #define PART_KNIGHT 4 |
20 | 2.25f, // #define PART_KNIGHT 4 |
21 | 2.15f, // #define PART_ROOK 5 |
21 | 2.15f, // #define PART_ROOK 5 |
22 | 2.0f, // #define PART_PAWN 6 |
22 | 2.0f, // #define PART_PAWN 6 |
23 | }; |
23 | }; |
- | 24 | static bool has_endsound_played = false; |
|
24 | 25 | ||
25 | 26 | ||
26 | void Scene_Init (scene_t *scene, board_t *board) |
27 | void Scene_Init (scene_t *scene, board_t *board) |
27 | { |
28 | { |
28 | // this function initializes the scene objects array and inserts the chess table in it |
29 | // this function initializes the scene objects array and inserts the chess table in it |
Line 150... | Line 151... | ||
150 | int length; |
151 | int length; |
151 | int threat_line; |
152 | int threat_line; |
152 | int threat_column; |
153 | int threat_column; |
153 | int minutes; |
154 | int minutes; |
154 | int seconds; |
155 | int seconds; |
- | 156 | bool is_sliding; |
|
155 | float flaticons_yaw; |
157 | float flaticons_yaw; |
156 | float source_x; |
158 | float source_x; |
157 | float source_y; |
159 | float source_y; |
158 | float target_x; |
160 | float target_x; |
159 | float target_y; |
161 | float target_y; |
160 | float current_x; |
162 | float current_x; |
161 | float current_y; |
163 | float current_y; |
162 | float current_z; |
164 | float current_z; |
- | 165 | float current_p; |
|
163 | int movement_diffco; |
166 | int movement_diffco; |
164 | int movement_diffli; |
167 | int movement_diffli; |
165 | float movement_maxheight; |
168 | float movement_maxheight; |
166 | float movement_ratio; |
169 | float movement_ratio; |
167 | 170 | ||
Line 820... | Line 823... | ||
820 | 823 | ||
821 | // has a movement happened yet AND does it land on this slot ? |
824 | // has a movement happened yet AND does it land on this slot ? |
822 | if ((board->viewed_move > 0) |
825 | if ((board->viewed_move > 0) |
823 | && (line == currentmove->target[0]) && (column == currentmove->target[1])) |
826 | && (line == currentmove->target[0]) && (column == currentmove->target[1])) |
824 | { |
827 | { |
- | 828 | // should this part slide ? parts moving orthogonally slide instead of jumping AND only if the distance is 1 square |
|
- | 829 | is_sliding = options.want_slidinganimations |
|
- | 830 | && ((currentmove->source[0] == currentmove->target[0]) || (currentmove->source[1] == currentmove->target[1])) |
|
- | 831 | && (abs (currentmove->target[0] - currentmove->source[0]) < 2) |
|
- | 832 | && (abs (currentmove->target[1] - currentmove->source[1]) < 2); |
|
- | 833 | ||
825 | // do we want animations AND is it still time to play the animation ? |
834 | // do we want animations AND is it still time to play the animation ? |
826 | if (options.want_animations && (animation_endtime > current_time)) |
835 | if (options.want_animations && (animation_endtime > current_time)) |
827 | { |
836 | { |
828 | // get the source and target X and Y positions |
837 | // get the source and target X and Y positions |
829 | source_x = 17.5f - (7 - currentmove->source[1]) * 5.0f; |
838 | source_x = 17.5f - (7 - currentmove->source[1]) * 5.0f; |
Line 840... | Line 849... | ||
840 | 849 | ||
841 | // do we want the 3D models or the flat icons ? |
850 | // do we want the 3D models or the flat icons ? |
842 | // we do when EITHER we don't want flat icons OR the player playing the current move is looking downstraight |
851 | // we do when EITHER we don't want flat icons OR the player playing the current move is looking downstraight |
843 | if (!want_flaticons || (current_pitch < MAX_PITCH_FOR_FLAT_ICONS)) |
852 | if (!want_flaticons || (current_pitch < MAX_PITCH_FOR_FLAT_ICONS)) |
844 | { |
853 | { |
- | 854 | // should this part be sliding or jumping ? |
|
- | 855 | if (is_sliding) |
|
- | 856 | { |
|
- | 857 | current_z = 0.04f; // just slide |
|
- | 858 | current_p = 0.0f; // and stay vertical |
|
- | 859 | } |
|
- | 860 | else |
|
- | 861 | { |
|
845 | // height is a sine positive, max height is proportional to travelled distance |
862 | // height is a sine positive, max height is proportional to travelled distance |
846 | movement_diffco = abs |
863 | movement_diffco = abs(currentmove->target[1] - currentmove->source[1]); |
847 | movement_diffli = abs |
864 | movement_diffli = abs(currentmove->target[0] - currentmove->source[0]); |
848 | movement_maxheight = 0.5f + (float) |
865 | movement_maxheight = 0.5f + (float)movement_diffco + (float)movement_diffli; |
849 | if (currentmove->part == PART_KNIGHT) |
866 | if (currentmove->part == PART_KNIGHT) |
850 | movement_maxheight *= 2.0f; // knights jump high |
867 | movement_maxheight *= 2.0f; // knights jump high |
851 | else if ((currentmove->part == PART_KING) && (movement_diffco == 2)) |
868 | else if ((currentmove->part == PART_KING) && (movement_diffco == 2)) |
852 | movement_maxheight *= 5.0f; // kings jump VERY high when castling too |
869 | movement_maxheight *= 5.0f; // kings jump VERY high when castling too |
853 | else if (movement_maxheight > 5.0f) |
870 | else if (movement_maxheight > 5.0f) |
854 | movement_maxheight = 5.0f; // all other parts just hover above the ground |
871 | movement_maxheight = 5.0f; // all other parts just hover above the ground |
855 | current_z = 0.04f + (float) |
872 | current_z = 0.04f + (float)sin(MATH_PI * movement_ratio) * movement_maxheight; // part height |
- | 873 | current_p = (boardslot->color == COLOR_BLACK ? -1 : 1) * min(current_z * 3.0f, 10.0f); // part inclination |
|
- | 874 | } |
|
856 | 875 | ||
857 | // make this part move realistically |
876 | // make this part move realistically |
858 | Scene_AddPart (scene, boardslot->part, boardslot->color, current_x, current_y, current_z, 0.0f, |
877 | Scene_AddPart (scene, boardslot->part, boardslot->color, current_x, current_y, current_z, 0.0f, current_p); |
859 | } |
878 | } |
860 | else |
879 | else |
861 | Scene_AddTile (scene, theme->flattextures[boardslot->color][boardslot->part], 2.5f, current_x, current_y, 0.07f, flaticons_yaw); |
880 | Scene_AddTile (scene, theme->flattextures[boardslot->color][boardslot->part], 2.5f, current_x, current_y, 0.07f, flaticons_yaw); |
862 | } |
881 | } |
863 | else |
882 | else |
Line 868... | Line 887... | ||
868 | Scene_AddPart (scene, boardslot->part, boardslot->color, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f, 0.0f, 0.0f); |
887 | Scene_AddPart (scene, boardslot->part, boardslot->color, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f, 0.0f, 0.0f); |
869 | else |
888 | else |
870 | Scene_AddTile (scene, theme->flattextures[boardslot->color][boardslot->part], 2.5f, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.05f, flaticons_yaw); |
889 | Scene_AddTile (scene, theme->flattextures[boardslot->color][boardslot->part], 2.5f, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.05f, flaticons_yaw); |
871 | } |
890 | } |
872 | 891 | ||
873 | // is it time to play a |
892 | // is it time to play a "start of animation" sound ? |
874 | if ( |
893 | if (current_time + ANIMATION_DURATION == animation_endtime) |
875 | { |
894 | { |
- | 895 | has_endsound_played = false; // an animation just started, remember the ending sound hasn't played yet |
|
- | 896 | if (is_sliding) |
|
- | 897 | Audio_PlaySound (SOUNDTYPE_SLIDE, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f); // play the sliding move sound |
|
- | 898 | } |
|
- | 899 | ||
- | 900 | // is it time to play an "end of animation" sound ? |
|
- | 901 | else if ((animation_endtime - 0.1f < current_time) && !has_endsound_played) |
|
- | 902 | { |
|
- | 903 | if (!is_sliding) |
|
- | 904 | Audio_PlaySound (SOUNDTYPE_MOVE, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f); // play the normal move sound (unless the part was sliding) |
|
- | 905 | ||
- | 906 | if (currentmove->has_captured) |
|
- | 907 | Audio_PlaySound (SOUNDTYPE_PIECETAKEN, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f); // on capture, play the capture sound |
|
- | 908 | ||
876 | // is the current player in checkmate, in check, in stalemate or is it a capture ? (to play the right sound) |
909 | // is the current player in checkmate, in check, in stalemate or is it a capture ? (to play the right sound) |
877 | // read as: was the last move an opponent's move AND did it put us to check ? |
910 | // read as: was the last move an opponent's move AND did it put us to check ? |
878 | if (currentmove->is_check) |
911 | if (currentmove->is_check) |
879 | { |
912 | { |
880 | Audio_PlaySound (SOUNDTYPE_MOVE, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f); // play the normal move sound |
- | |
881 | - | ||
882 | // is it a checkmate or a normal check ? (checkmate == check + stalemate) |
913 | // is it a checkmate or a normal check ? (checkmate == check + stalemate) |
883 | if (currentmove->is_stalemate) |
914 | if (currentmove->is_stalemate) |
884 | Audio_PlaySound (board->players[currentmove->color].type == PLAYER_HUMAN ? SOUNDTYPE_VICTORY : SOUNDTYPE_DEFEAT, 0.0f, 0.0f, 0.04f); // if so, play endgame sound at the center of the board |
915 | Audio_PlaySound (board->players[currentmove->color].type == PLAYER_HUMAN ? SOUNDTYPE_VICTORY : SOUNDTYPE_DEFEAT, 0.0f, 0.0f, 0.04f); // if so, play endgame sound at the center of the board |
885 | else |
916 | else |
886 | Audio_PlaySound (SOUNDTYPE_CHECK, 0.0f, 0.0f, 0.04f); // else play the check sound at the center of the board |
917 | Audio_PlaySound (SOUNDTYPE_CHECK, 0.0f, 0.0f, 0.04f); // else play the check sound at the center of the board |
887 | } |
918 | } |
888 | else if (currentmove->is_stalemate) |
919 | else if (currentmove->is_stalemate) |
889 | { |
- | |
890 | Audio_PlaySound (SOUNDTYPE_MOVE, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f); // play the normal move sound |
- | |
891 | Audio_PlaySound (SOUNDTYPE_DEFEAT, 0.0f, 0.0f, 0.04f); // on stalemate, play defeat sound at the center of the board |
920 | Audio_PlaySound (SOUNDTYPE_DEFEAT, 0.0f, 0.0f, 0.04f); // on stalemate, play defeat sound at the center of the board |
892 | } |
- | |
893 | else if (currentmove->has_captured) |
- | |
894 | Audio_PlaySound (SOUNDTYPE_PIECETAKEN, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f); // on capture, play the capture sound |
- | |
895 | else |
- | |
896 | Audio_PlaySound (SOUNDTYPE_MOVE, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f); // play the normal move sound |
- | |
897 | 921 | ||
898 |
|
922 | has_endsound_played = true; // remember the "end of animation" sound has been played (this will be reset at the beginning of the next animation) |
899 | } |
923 | } |
900 | } |
924 | } |
901 | 925 | ||
902 | // else has a movement happened yet AND is this movement a castle AND is this the concerned tower ? |
926 | // else has a movement happened yet AND is this movement a castle AND is this the concerned tower ? |
903 | else if ((board->viewed_move > 0) |
927 | else if ((board->viewed_move > 0) |