hexagon.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. int AddIn_main(int isAppli, unsigned short OptionNum)
  10. {
  11. const FONTCHARACTER filename[] = {'\\', '\\', 'f', 'l', 's', '0', '\\', 'S', 'H', 'C', '.', 's', 'a', 'v', 0};
  12. const filesize = sizeof(float) * 6;
  13. Game_Data data;
  14. int i;
  15. float buffer[6] = {0};
  16. // variables for fps calculation
  17. unsigned int fps = 0, frame = 0, tempsOrigine = RTC_GetTicks();
  18. // char string to display the fps
  19. unsigned char fps_text[8] = {0};
  20. // rand initialisation
  21. srand(RTC_GetTicks());
  22. // Key init
  23. data.shift_latch_value = 0;
  24. data.alpha_latch_value = 0;
  25. data.entry_highscores = NULL;
  26. data.entry_highscores = malloc(sizeof(float) * 6);
  27. if(data.entry_highscores == NULL)
  28. return 1;
  29. data.is_save_feature_enabled = 1;
  30. data.fileHandle = Bfile_OpenFile(filename, _OPENMODE_READ);
  31. if(data.fileHandle == IML_FILEERR_ENTRYNOTFOUND) {
  32. void;
  33. } else if(data.fileHandle>= 0) {
  34. if(Bfile_ReadFile(data.fileHandle, (char*)data.entry_highscores, filesize, -1) < 0)
  35. data.is_save_feature_enabled = 0;
  36. Bfile_CloseFile(data.fileHandle);
  37. Bfile_DeleteFile(filename);
  38. } else
  39. data.is_save_feature_enabled = 0;
  40. if(!data.is_save_feature_enabled){
  41. for(i = 0; i < 6; i++) {
  42. data.entry_highscores[i] = 0.0f;
  43. }
  44. }
  45. data.entry_difficulties = NULL;
  46. data.entry_difficulties = malloc(sizeof(char*) * 6);
  47. if(data.entry_difficulties == NULL)
  48. return 1;
  49. load_difficulty_names(data.entry_difficulties);
  50. switch_to_state(TITLE, &data);
  51. while(KeyUp(K_EXIT)){ // main loop
  52. // fps
  53. if(RTC_GetTicks() - tempsOrigine >= 32 )// if 1/4 seconds elapsed
  54. {
  55. fps = frame*4;
  56. frame = 0;
  57. tempsOrigine = RTC_GetTicks();
  58. }
  59. frame++;
  60. update(&data);
  61. draw(&data);
  62. // printing debug information
  63. // updating the screen
  64. ML_display_vram();
  65. ML_clear_vram();
  66. Sleep(1/0.06);
  67. }
  68. if(data.is_save_feature_enabled) {
  69. Bfile_CreateFile(filename, filesize);
  70. data.fileHandle = Bfile_OpenFile(filename, _OPENMODE_WRITE);
  71. if(Bfile_WriteFile(data.fileHandle, (char*)data.entry_highscores, filesize) < 0) {
  72. int why;
  73. locate(1,1);
  74. Print("POURQUOI");
  75. GetKey(&why);
  76. }
  77. Bfile_CloseFile(data.fileHandle);
  78. }
  79. free(data.entry_highscores);
  80. return 1;
  81. }
  82. #pragma section _BR_Size
  83. unsigned long BR_Size;
  84. #pragma section
  85. #pragma section _TOP
  86. int InitializeSystem(int isAppli, unsigned short OptionNum)
  87. {
  88. return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
  89. }
  90. #pragma section