hexagon.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #include "fxlib.h"
  2. #include "MonochromeLib.h"
  3. #include "math.h"
  4. #include "ECode.h"
  5. #include "struct.h"
  6. #include "wall.h"
  7. #include "syscall.h"
  8. #include "states.h"
  9. static const FONTCHARACTER filename[] = {'\\', '\\', 'f', 'l', 's', '0', '\\', 'S', 'H', 'C', '.', 's', 'a', 'v', 0};
  10. static const unsigned int filesize = sizeof(SaveData);
  11. void load_difficulty_names(char **str_list)
  12. {
  13. char c_1[] = "Hard";
  14. char c_2[] = "Harder";
  15. char c_3[] = "Hardest";
  16. char c_4[] = "Hardester";
  17. char c_5[] = "Hardestest";
  18. char c_6[] = "Hardestestest";
  19. int i = 0;
  20. int j = 0;
  21. for(i = 0; i < 6; i++)
  22. {
  23. str_list[i] = NULL;
  24. str_list[i] = malloc(sizeof(char) * 24);
  25. if(str_list[i] == NULL)
  26. return;
  27. for(j = 0; j < 24; str_list[i][j] = 0, j++) {
  28. }
  29. }
  30. memcpy(str_list[0], c_1, sizeof(char) * strlen(c_1));
  31. memcpy(str_list[1], c_2, sizeof(char) * strlen(c_2));
  32. memcpy(str_list[2], c_3, sizeof(char) * strlen(c_3));
  33. memcpy(str_list[3], c_4, sizeof(char) * strlen(c_4));
  34. memcpy(str_list[4], c_5, sizeof(char) * strlen(c_5));
  35. memcpy(str_list[5], c_6, sizeof(char) * strlen(c_6));
  36. }
  37. void loadDataFromSave(Game_Data* data) {
  38. int i, hasLoadedSave;
  39. SaveData dataLoaded;
  40. hasLoadedSave = 0;
  41. data->fileHandle = Bfile_OpenFile(filename, _OPENMODE_READ);
  42. if(data->fileHandle>= 0) {
  43. hasLoadedSave = 1;
  44. //(char*)data->entry_highscores
  45. if(Bfile_ReadFile(data->fileHandle, &dataLoaded, sizeof(dataLoaded), -1) < sizeof(dataLoaded))
  46. hasLoadedSave = 0;
  47. else {
  48. Bfile_CloseFile(data->fileHandle);
  49. Bfile_DeleteFile(filename);
  50. }
  51. }
  52. if(!hasLoadedSave) {
  53. for(i = 0; i < 6; i++) {
  54. data->entry_highscores[i] = 0.0f;
  55. }
  56. } else {
  57. for(i = 0; i < 6; i++) {
  58. data->entry_highscores[i] = dataLoaded.highscores[i];
  59. }
  60. }
  61. }
  62. int AddIn_main(int isAppli, unsigned short OptionNum)
  63. {
  64. SaveData dataToSave;
  65. int i;
  66. Game_Data data;
  67. // variables for fps calculation
  68. unsigned int fps = 0, frame = 0, tempsOrigine = RTC_GetTicks();
  69. // char string to display the fps
  70. unsigned char fps_text[8] = {0};
  71. // rand initialisation
  72. srand(RTC_GetTicks());
  73. // Key init
  74. data.shift_latch_value = 0;
  75. data.alpha_latch_value = 0;
  76. data.entry_highscores = NULL;
  77. data.entry_highscores = malloc(sizeof(float) * 6);
  78. if(data.entry_highscores == NULL)
  79. switch_to_state(OUT_OF_MEMORY, &data);
  80. data.entry_difficulties = NULL;
  81. data.entry_difficulties = malloc(sizeof(char*) * 6);
  82. if(data.entry_difficulties == NULL)
  83. switch_to_state(OUT_OF_MEMORY, &data);
  84. load_difficulty_names(data.entry_difficulties);
  85. loadDataFromSave(&data);
  86. switch_to_state(TITLE, &data);
  87. while(KeyUp(K_EXIT)){ // main loop
  88. // fps
  89. if(RTC_GetTicks() - tempsOrigine >= 32 )// if 1/4 seconds elapsed
  90. {
  91. fps = frame*4;
  92. frame = 0;
  93. tempsOrigine = RTC_GetTicks();
  94. }
  95. frame++;
  96. update(&data);
  97. draw(&data);
  98. // printing debug information
  99. // updating the screen
  100. ML_display_vram();
  101. ML_clear_vram();
  102. Sleep(1/0.06);
  103. }
  104. for(i = 0; i < 6; ++i)
  105. dataToSave.highscores[i] = data.entry_highscores[i];
  106. Bfile_CreateFile(filename, filesize);
  107. data.fileHandle = Bfile_OpenFile(filename, _OPENMODE_WRITE);
  108. if(data.fileHandle >= 0) {
  109. Bfile_WriteFile(data.fileHandle, &dataToSave, filesize);
  110. Bfile_CloseFile(data.fileHandle);
  111. }
  112. free(data.entry_highscores);
  113. return 1;
  114. }
  115. #pragma section _BR_Size
  116. unsigned long BR_Size;
  117. #pragma section
  118. #pragma section _TOP
  119. int InitializeSystem(int isAppli, unsigned short OptionNum)
  120. {
  121. return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
  122. }
  123. #pragma section