summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave/sfcave.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp
index 93f5f82..d551afe 100644
--- a/noncore/games/sfcave/sfcave.cpp
+++ b/noncore/games/sfcave/sfcave.cpp
@@ -805,110 +805,112 @@ void SFCave :: keyPressEvent( QKeyEvent *e )
805 } 805 }
806 else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) 806 else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY )
807 { 807 {
808 currentGameDifficulty ++; 808 currentGameDifficulty ++;
809 if ( currentGameDifficulty == NR_GAME_DIFFICULTIES ) 809 if ( currentGameDifficulty == NR_GAME_DIFFICULTIES )
810 currentGameDifficulty = 0; 810 currentGameDifficulty = 0;
811 } 811 }
812 } 812 }
813 break; 813 break;
814 814
815 case Qt::Key_Space: 815 case Qt::Key_Space:
816 case Qt::Key_Return: 816 case Qt::Key_Return:
817 case Qt::Key_Enter: 817 case Qt::Key_Enter:
818 dealWithMenuSelection(); 818 dealWithMenuSelection();
819 break; 819 break;
820 } 820 }
821 } 821 }
822 else 822 else
823 { 823 {
824 switch( e->key() ) 824 switch( e->key() )
825 { 825 {
826 case Qt::Key_Up: 826 case Qt::Key_Up:
827 case Qt::Key_F9: 827 case Qt::Key_F9:
828 case Qt::Key_Space: 828 case Qt::Key_Space:
829 if ( !press ) 829 if ( !replay && !press )
830 { 830 {
831 press = true; 831 press = true;
832 replayList.append( new int( nrFrames ) ); 832 replayList.append( new int( nrFrames ) );
833 } 833 }
834 break; 834 break;
835 case Qt::Key_M: 835 case Qt::Key_M:
836 case Qt::Key_Return: 836 case Qt::Key_Return:
837 case Qt::Key_Enter: 837 case Qt::Key_Enter:
838 if ( state == STATE_CRASHED ) 838 if ( state == STATE_CRASHED )
839 state = STATE_MENU; 839 state = STATE_MENU;
840 break; 840 break;
841 841
842 case Qt::Key_Z: 842 case Qt::Key_Z:
843 showScoreZones = !showScoreZones; 843 showScoreZones = !showScoreZones;
844 break; 844 break;
845 845
846 default: 846 default:
847 e->ignore(); 847 e->ignore();
848 break; 848 break;
849 } 849 }
850 } 850 }
851} 851}
852 852
853void SFCave :: keyReleaseEvent( QKeyEvent *e ) 853void SFCave :: keyReleaseEvent( QKeyEvent *e )
854{ 854{
855 if ( state == STATE_MENU ) 855 if ( state == STATE_MENU )
856 { 856 {
857 } 857 }
858 else 858 else
859 { 859 {
860 switch( e->key() ) 860 switch( e->key() )
861 { 861 {
862 case Qt::Key_F9: 862 case Qt::Key_F9:
863 case Qt::Key_Space: 863 case Qt::Key_Space:
864 case Qt::Key_Up: 864 case Qt::Key_Up:
865 if ( press ) 865 if ( !replay && press )
866 { 866 {
867 press = false; 867 press = false;
868 868
869 replayList.append( new int( nrFrames ) ); 869 replayList.append( new int( nrFrames ) );
870 } 870 }
871 break; 871 break;
872 872
873 case Qt::Key_R: 873 case Qt::Key_R:
874 if ( state == STATE_CRASHED ) 874 if ( state == STATE_CRASHED )
875 { 875 {
876 state = STATE_REPLAY; 876 state = STATE_REPLAY;
877 } 877 }
878 break; 878 break;
879 879
880 case Qt::Key_Down: 880 case Qt::Key_Down:
881 if ( state == STATE_CRASHED ) 881 if ( state == STATE_CRASHED )
882 state = STATE_NEWGAME; 882 state = STATE_NEWGAME;
883 break; 883 break;
884 884
885 case Qt::Key_S: 885 case Qt::Key_S:
886 saveReplay(); 886 if ( state == STATE_CRASHED )
887 saveReplay();
887 break; 888 break;
888 889
889 case Qt::Key_L: 890 case Qt::Key_L:
890 loadReplay(); 891 if ( state == STATE_CRASHED )
892 loadReplay();
891 break; 893 break;
892 default: 894 default:
893 e->ignore(); 895 e->ignore();
894 break; 896 break;
895 } 897 }
896 } 898 }
897 899
898} 900}
899 901
900void SFCave :: displayMenu() 902void SFCave :: displayMenu()
901{ 903{
902 offscreen->fill( Qt::black ); 904 offscreen->fill( Qt::black );
903 905
904 QPainter p( offscreen ); 906 QPainter p( offscreen );
905 p.setPen( Qt::white ); 907 p.setPen( Qt::white );
906 908
907 QFont f( "Helvetica", 16 ); 909 QFont f( "Helvetica", 16 );
908 p.setFont( f ); 910 p.setFont( f );
909 911
910 QFontMetrics fm = p.fontMetrics(); 912 QFontMetrics fm = p.fontMetrics();
911 913
912 QString text = "SFCave"; 914 QString text = "SFCave";
913 p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text ); 915 p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text );
914 916
@@ -1044,53 +1046,60 @@ void SFCave :: saveReplay()
1044 { 1046 {
1045 QString tmp; 1047 QString tmp;
1046 tmp.sprintf( "%d ", (*it.current()) ); 1048 tmp.sprintf( "%d ", (*it.current()) );
1047 val += tmp; 1049 val += tmp;
1048 1050
1049 ++it; 1051 ++it;
1050 } 1052 }
1051 val += "\n"; 1053 val += "\n";
1052 1054
1053 QString line; 1055 QString line;
1054 line.sprintf( "%d\n", val.length() ); 1056 line.sprintf( "%d\n", val.length() );
1055 fwrite( (const char *)line, 1, line.length(), out ); 1057 fwrite( (const char *)line, 1, line.length(), out );
1056 fwrite( (const char *)val, 1, val.length(), out ); 1058 fwrite( (const char *)val, 1, val.length(), out );
1057 1059
1058 fclose( out ); 1060 fclose( out );
1059 1061
1060 printf( "Replay saved to %s\n", (const char *)replayFile ); 1062 printf( "Replay saved to %s\n", (const char *)replayFile );
1061 1063
1062} 1064}
1063 1065
1064void SFCave :: loadReplay() 1066void SFCave :: loadReplay()
1065{ 1067{
1066 FILE *in = fopen( (const char *)replayFile, "r" ); 1068 FILE *in = fopen( (const char *)replayFile, "r" );
1067 1069
1070 if ( in == 0 )
1071 {
1072 printf( "Couldn't load replay file!\n" );
1073 return;
1074 }
1068 // Read size of next line 1075 // Read size of next line
1069 char line[10+1]; 1076 char line[10+1];
1070 fgets( line, 10, in ); 1077 fgets( line, 10, in );
1071 1078
1072 int length = -1; 1079 int length = -1;
1073 sscanf( line, "%d", &length ); 1080 sscanf( line, "%d", &length );
1074 char *data = new char[length+1]; 1081 char *data = new char[length+1];
1075 1082
1076 fread( data, 1, length, in ); 1083 fread( data, 1, length, in );
1077 1084
1078 QString sep = " "; 1085 QString sep = " ";
1079 QStringList list = QStringList::split( sep, QString( data ) ); 1086 QStringList list = QStringList::split( sep, QString( data ) );
1080 1087
1081 // print it out 1088 // print it out
1082 QStringList::Iterator it = list.begin(); 1089 QStringList::Iterator it = list.begin();
1083 currentSeed = (*it).toInt(); 1090 currentSeed = (*it).toInt();
1084 ++it; 1091 ++it;
1085 1092
1086 replayList.clear(); 1093 replayList.clear();
1087 for ( ; it != list.end(); ++it ) 1094 for ( ; it != list.end(); ++it )
1088 { 1095 {
1089 int v = (*it).toInt(); 1096 int v = (*it).toInt();
1090 replayList.append( new int( v ) ); 1097 replayList.append( new int( v ) );
1091 } 1098 }
1092 1099
1093 delete data; 1100 delete data;
1094 1101
1095 fclose( in ); 1102 fclose( in );
1103
1104 printf( "Replay loaded from %s\n", (const char *)replayFile );
1096} \ No newline at end of file 1105} \ No newline at end of file