Subversion Repositories Kolibri OS

Rev

Rev 5286 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //screen Width and Height
  2. #define Width  600
  3. #define Height 600
  4. int ScreenX=0;
  5. int ScreenY=0;
  6. int OffsetX=0;
  7. int OffsetY=0;
  8. int BufferDraw [Width][Height];
  9. char BufferCarry [Height][Width][3];
  10. int BufferCarry2 [Height][Width];
  11. int DRAW_TECH=0;
  12. int Analyx [Width][Height];
  13. int CollideVerts[10][2]={};
  14. int DeltaH [8]={11,16,19,20,21,22,23,23};
  15. //-1-quit, 0-menu, 1-game
  16. int GAME_TYPE=0;
  17.  
  18. int GLOBAL_SPEED=0;
  19. int Max_Speed=5;
  20. //colors
  21. int COLOR_INDEX=0;
  22. char RAINBOW_NAME[7][7]={"red","orange","yellow","green","blue","indigo","violet"};
  23. int RAINBOW_TABLE[7][5]= {{0x00ff0000, 0x00e80c7a, 0x00ff0dff, 0x00e82c0c, 0x00ff530d},
  24.                           {0x00ff4700, 0x00e8690c, 0x00ff970d, 0x00ff0d18, 0x00e8290c},
  25.                           {0x00ffff00, 0x00e8d20c, 0x00ffce0d, 0x009be80c, 0x0056ff0d},
  26.                           {0x0000ff00, 0x000ce84a, 0x0059e80c, 0x000dff96, 0x00b6ff0d},
  27.                           {0x0000ffff, 0x000d7fff, 0x000caeeb, 0x000dff76, 0x000ce8aa},
  28.                           {0x000000ff, 0x000c46eb, 0x00480ce8, 0x00910dff, 0x000d8cff},
  29.                           {0x006700ff, 0x00a00ce8, 0x00f20dff, 0x000d2eff, 0x00280ce8}};
  30. int GLOBAL_BLOCKCOLOR=0x00e80c7a;
  31. int GLOBAL_BATUTCOLOR=0x00ff0dff;
  32. int GLOBAL_PITCOLOR=0x00e82c0c;
  33. int GLOBAL_FLAGCOLOR=0x00ff530d;
  34. int GLOBAL_BACKGROUNDCOLOR=0x00000000;
  35. int GLOBAL_FRONTCOLOR=0x00ffffff;
  36. //menu settings
  37. int MENU_SELECTED=0;
  38. char NUMBER[100]="0";
  39. int CURRENT_LEVEL=3;
  40. int MAX_LEVEL=3;
  41. int TO_NEXT_LEVEL=0;
  42. int DeltaSpeed=0;
  43. int GLOBAL_CHECKPOINT=0;
  44. int SPAWN_Y=0;
  45. int isRestart=1;
  46. int CurrentCheck=0;
  47.  
  48. //Hero data
  49. int HeroX=100;
  50. int HeroY=100;
  51. int HeroSides=3;
  52. int HeroAngle=0;
  53. int HeroFly=0;
  54. char HeroIsDead=0;
  55. int HeroColor=0x00ff0000;
  56. char Key=0;
  57.  
  58. //Saveload folder
  59. int SAVE_FOLDER_TYPE=0;
  60.  
  61. //EDITOR
  62. int Tile_X=0;
  63. int Tile_Y=0;
  64. int Panel=0;  //0-grid,1-tools, 2-props
  65. int Tile_Type=0;
  66. int Q_SELECTED=0;
  67. char TILENAME[6][11]={"empty","block","spike","jump pad","checkpt","finish"};
  68.  
  69. //OTHER
  70. int THE_END_COUNT=600;
  71. char Arrow='0';
  72. //Libraries
  73. #include <stdio.h>
  74. #include <stdlib.h>
  75. #include <string.h>
  76. #include <kolibrisys.h>
  77. #include <GameAlphabet.h>
  78. #include <Shimath.h>
  79. #include <Draw2D.h>
  80. #include <Levels.h>
  81. #include <GameFunctions.h>
  82.  
  83.  
  84.  
  85. //result of getKey is key character. Condition for Escape - if (getKey()==27)
  86. char getKey() {
  87.         int NewKey=_ksys_get_key();
  88.         NewKey/=256;
  89.         Arrow=(NewKey/256)%256;
  90.         return (NewKey%256);
  91. }
  92. void LoadData () {
  93.         FILE *Profile;
  94.         if (SAVE_FOLDER_TYPE==1) {
  95.                 Profile=fopen ("/usbhd0/1/Profile.bin","rb");
  96.         } else {
  97.                 Profile=fopen ("Profile.bin","rb");
  98.         }
  99.         char Format=0;
  100.         Format=fgetc (Profile);
  101.         if (Format!='N') {
  102.                 DrawText (100,300,"error (cannot load data)",GLOBAL_FRONTCOLOR);
  103.                 Update();
  104.                 _ksys_delay(200);
  105.                 MENU_SELECTED=1;
  106.                 fclose (Profile);
  107.                 return;
  108.         }
  109.         //Loading operations
  110.         fread (&(COLOR_INDEX), sizeof(int),1,Profile);
  111.         HeroColor=COLOR_INDEX;
  112.         fread (&(GLOBAL_BACKGROUNDCOLOR), sizeof(int),1,Profile);
  113.         fread (&(GLOBAL_FRONTCOLOR),sizeof(int),1,Profile);
  114.         Update();
  115.         fread (&(DRAW_TECH),sizeof(int),1,Profile);
  116.         Update();
  117.         MAX_LEVEL=fgetc (Profile);
  118.         CURRENT_LEVEL=MAX_LEVEL;
  119.         fread (&(LevelProps[0][2]), sizeof(int),1, Profile);
  120.         fread (USER_LEVEL0,1,9*LEVEL_MAXLEN,Profile);
  121.         fread (&(LevelProps[1][2]), sizeof(int),1,Profile);
  122.         fread (USER_LEVEL1,1,9*LEVEL_MAXLEN,Profile);
  123.         fread (&(LevelProps[2][2]), sizeof(int),1,Profile);
  124.         fread (USER_LEVEL2,1,9*LEVEL_MAXLEN,Profile);
  125.         DrawText (100,300,"loaded successfully",GLOBAL_FRONTCOLOR);
  126.         Update();
  127.         _ksys_delay(200);
  128.         Update();
  129.  
  130.         MENU_SELECTED=1;
  131.         fclose (Profile);
  132. }
  133.  
  134. void SaveData () {
  135.         FILE *Profile;
  136.         if (SAVE_FOLDER_TYPE==1) {
  137.                 Profile=fopen ("/usbhd0/1/Profile.bin","wb");
  138.         } else {
  139.                 Profile=fopen ("Profile.bin","wb");
  140.         }
  141.         if (Profile==NULL) {
  142.                 DrawText (100,300,"error (cannot save data)",GLOBAL_FRONTCOLOR);
  143.                 Update();
  144.                 _ksys_delay(200);
  145.                 MENU_SELECTED=1;
  146.                 return;
  147.         }
  148.         fputc ('N',Profile);
  149.         fwrite (&(COLOR_INDEX), sizeof(int),1,Profile);
  150.         fwrite (&(GLOBAL_BACKGROUNDCOLOR), sizeof(int),1,Profile);
  151.         fwrite (&(GLOBAL_FRONTCOLOR),sizeof(int),1,Profile);
  152.         fwrite (&(DRAW_TECH),sizeof(int),1,Profile);
  153.         fputc (MAX_LEVEL,Profile);
  154.         fwrite (&(LevelProps[0][2]), sizeof(int),1, Profile);
  155.         fwrite (USER_LEVEL0,1,9*LEVEL_MAXLEN,Profile);
  156.         fwrite (&(LevelProps[1][2]), sizeof(int),1,Profile);
  157.         fwrite (USER_LEVEL1,1,9*LEVEL_MAXLEN,Profile);
  158.         fwrite (&(LevelProps[2][2]), sizeof(int),1,Profile);
  159.         fwrite (USER_LEVEL2,1,9*LEVEL_MAXLEN,Profile);
  160.         DrawText (100,300,"saved successfully",GLOBAL_FRONTCOLOR);
  161.         Update();
  162.         _ksys_delay(200);
  163.         MENU_SELECTED=1;
  164.         fclose (Profile);
  165. }
  166.  
  167. void MainMenu () {
  168.         if (Key==27) GAME_TYPE=-1;
  169.         if (MENU_SELECTED==11 && (Key==' ' || Arrow==28)) GAME_TYPE=-1;
  170.         if (Key=='s' || Arrow=='P') MENU_SELECTED++;
  171.         if (Key=='w' || Arrow=='H') MENU_SELECTED--;
  172.         if (MENU_SELECTED<0) MENU_SELECTED=11;
  173.         if (MENU_SELECTED>11) MENU_SELECTED=0;
  174.         if (MENU_SELECTED==0 && (Key==' ' || Arrow==28)) {
  175.                 GAME_TYPE=1;
  176.                 GLOBAL_CHECKPOINT=0;
  177.                 return;
  178.         }
  179.         if (MENU_SELECTED==3 && (Key=='a' || Key=='d' || Arrow=='K' || Arrow=='M')) {
  180.                 if (GLOBAL_BACKGROUNDCOLOR==0) {
  181.                         GLOBAL_BACKGROUNDCOLOR=0x00ffffff;
  182.                         GLOBAL_FRONTCOLOR=0;
  183.                 } else {
  184.                         GLOBAL_BACKGROUNDCOLOR=0;
  185.                         GLOBAL_FRONTCOLOR=0x00ffffff;
  186.                 }
  187.         }
  188.         if (MENU_SELECTED==1) {
  189.                 if ((Key=='a' || Arrow=='K') && CURRENT_LEVEL>0) CURRENT_LEVEL--;
  190.                 if ((Key=='d' || Arrow=='M') && CURRENT_LEVEL<MAX_LEVEL) CURRENT_LEVEL++;
  191.                 HeroSides=LevelProps[CURRENT_LEVEL][2];
  192.         }
  193.         if (MENU_SELECTED==2) {
  194.                 if ((Key=='a' || Arrow=='K') && COLOR_INDEX>0) COLOR_INDEX--;
  195.                 if ((Key=='d' || Arrow=='M') && COLOR_INDEX<6) COLOR_INDEX++;
  196.                 HeroColor=RAINBOW_TABLE [COLOR_INDEX][0];
  197.                 GLOBAL_BLOCKCOLOR=RAINBOW_TABLE [COLOR_INDEX][1];
  198.                 GLOBAL_BATUTCOLOR=RAINBOW_TABLE [COLOR_INDEX][2];
  199.                 GLOBAL_PITCOLOR=RAINBOW_TABLE [COLOR_INDEX][3];
  200.                 GLOBAL_FLAGCOLOR=RAINBOW_TABLE [COLOR_INDEX][4];
  201.         }
  202.         if (MENU_SELECTED==7 && (Key=='a' || Key=='d' || Arrow=='K' || Arrow=='M')) {
  203.                 if (SAVE_FOLDER_TYPE==0) {
  204.                         SAVE_FOLDER_TYPE=1;
  205.                 } else {
  206.                         SAVE_FOLDER_TYPE=0;
  207.                 }
  208.         }
  209.         if (MENU_SELECTED==8 && (Key=='a' || Key=='d' || Arrow=='K' || Arrow=='M')) {
  210.                 int i=0;
  211.                 int j=0;
  212.                 for (i=0; i<Width; i++) {
  213.                         for (j=0; j<Height; j++) {
  214.                                 BufferDraw[i][j]=GLOBAL_BACKGROUNDCOLOR;
  215.                         }
  216.                 }
  217.                 Update();
  218.                 if (DRAW_TECH==0) {
  219.                         DRAW_TECH=1;
  220.                 } else {
  221.                         DRAW_TECH=0;
  222.                 }
  223.                 Update();
  224.         }
  225.         if (MENU_SELECTED==9) {
  226.                 if ((Key=='a' || Arrow=='K') && Max_Speed>1) Max_Speed--;
  227.                 if ((Key=='d' || Arrow=='M') && Max_Speed<14) Max_Speed++;
  228.         }
  229.         if (MENU_SELECTED==4 && (Key==' ' || Arrow==28)) LoadData();
  230.         if (MENU_SELECTED==5 && (Key==' ' || Arrow==28)) SaveData();
  231.         if (MENU_SELECTED==6 && (Key==' ' || Arrow==28)) {
  232.                 if (CURRENT_LEVEL>=3) {
  233.                         DrawText (300,300,"error",GLOBAL_FRONTCOLOR);
  234.                         DrawText (30,320,"(choose level 0/1/2 to edit them)",GLOBAL_FRONTCOLOR);
  235.                         Update();
  236.                         _ksys_delay(200);
  237.                         MENU_SELECTED=1;
  238.                 } else {
  239.                         GAME_TYPE=3;
  240.                         Panel=1;
  241.                 }
  242.         }
  243.         if (Key=='f' && CURRENT_LEVEL<3) {
  244.                 GAME_TYPE=3;
  245.                 Panel=1;
  246.         }
  247.         if (MENU_SELECTED==10 && (Key==' ' || Arrow==28)) GAME_TYPE=2;
  248.  
  249.  
  250.         DrawTitle (60,100,GLOBAL_FRONTCOLOR);
  251.         DrawText (100,300,"start game",GLOBAL_FRONTCOLOR);
  252.         DrawText (100,320,"choose level <   >",GLOBAL_FRONTCOLOR);
  253.         IntToStr(CURRENT_LEVEL,NUMBER);
  254.         DrawText (345,320,NUMBER,GLOBAL_FRONTCOLOR);
  255.         DrawText (100,340,"hero color <        >",GLOBAL_FRONTCOLOR);
  256.         DrawText (330, 340, RAINBOW_NAME [COLOR_INDEX], GLOBAL_FRONTCOLOR);
  257.         DrawText (100,360,"background color <        >",GLOBAL_FRONTCOLOR);
  258.         if (GLOBAL_BACKGROUNDCOLOR==0) {
  259.                 DrawText (430,360,"black",GLOBAL_FRONTCOLOR);
  260.         } else {
  261.                 DrawText (430,360,"white",GLOBAL_FRONTCOLOR);
  262.         }
  263.  
  264.         DrawText (100,400,"load game",GLOBAL_FRONTCOLOR);
  265.         DrawText (100,420,"save game",GLOBAL_FRONTCOLOR);
  266.         DrawText (100,440,"level editor",GLOBAL_FRONTCOLOR);
  267.         DrawText (100,460,"saveload folder <          >",GLOBAL_FRONTCOLOR);
  268.         if (SAVE_FOLDER_TYPE==0) {
  269.                 DrawText (400,460,"local",GLOBAL_FRONTCOLOR);
  270.         } else {
  271.                 DrawText (400,460,"usbhd0/1/",GLOBAL_FRONTCOLOR);
  272.         }
  273.         DrawText (100,480,"redraw technology <        >",GLOBAL_FRONTCOLOR);
  274.         if (DRAW_TECH==0) {
  275.                 DrawText (450,480,"frame",GLOBAL_FRONTCOLOR);
  276.         } else {
  277.                 DrawText (450,480,"lines",GLOBAL_FRONTCOLOR);
  278.         }
  279.         DrawText (100,500,"max speed <   >",GLOBAL_FRONTCOLOR);
  280.         IntToStr(Max_Speed,NUMBER);
  281.         DrawText (300,500,NUMBER,GLOBAL_FRONTCOLOR);
  282.         DrawText (100,520,"help",GLOBAL_FRONTCOLOR);
  283.         DrawText (100,540,"quit",GLOBAL_FRONTCOLOR);
  284.         DrawText (20,580,"developed by e_shi games 2014",GLOBAL_FRONTCOLOR);
  285.  
  286.         if (MENU_SELECTED==0) DrawText (100,300,"start game",HeroColor);
  287.         if (MENU_SELECTED==1) DrawText (100,320,"choose level <   >",HeroColor);
  288.         if (MENU_SELECTED==2) DrawText (100,340,"hero color <        >",HeroColor);
  289.         if (MENU_SELECTED==3) DrawText (100,360,"background color <        >",HeroColor);
  290.         if (MENU_SELECTED==4) DrawText (100,400,"load game",HeroColor);
  291.         if (MENU_SELECTED==5) DrawText (100,420,"save game",HeroColor);
  292.         if (MENU_SELECTED==6) DrawText (100,440,"level editor",HeroColor);
  293.         if (MENU_SELECTED==7) DrawText (100,460,"saveload folder <          >",HeroColor);
  294.         if (MENU_SELECTED==8) DrawText (100,480,"redraw technology <        >",HeroColor);
  295.         if (MENU_SELECTED==9) DrawText (100,500,"max speed <   >",HeroColor);
  296.         if (MENU_SELECTED==10) DrawText (100,520,"help",HeroColor);
  297.         if (MENU_SELECTED==11) DrawText (100,540,"quit",HeroColor);
  298.  
  299.  
  300. }
  301.  
  302.  
  303.  
  304.  
  305.  
  306. void GamePlay () {
  307.         DrawLine (0,500,800,500,GLOBAL_FRONTCOLOR);
  308.         if (Objects==0 || DataBase[Objects-1][1]<=Width-40) {
  309.                 ReadLevel(CURRENT_LEVEL);
  310.          }
  311.  
  312.          if (HeroIsDead==0) {
  313.                 if (isRestart==1) {
  314.                         HeroAngle=(HeroAngle+10)%360;
  315.                         HeroIsDead=CheckCollision();
  316.                         HeroY+=HeroFly;
  317.                         DrawHero (125,HeroY, HeroSides, HeroAngle, HeroColor);
  318.                 } else {
  319.                         DrawHero (125,HeroY,HeroSides,HeroAngle,GLOBAL_FRONTCOLOR);
  320.                 }
  321.                 if (TO_NEXT_LEVEL>0) {
  322.                         DrawText (Width-TO_NEXT_LEVEL,300,"jump to start new level",GLOBAL_FRONTCOLOR);
  323.                         if (TO_NEXT_LEVEL<500) {
  324.                                 TO_NEXT_LEVEL+=2;
  325.                         } else {
  326.                                 if ((Key==' ' || Arrow==28) && TO_NEXT_LEVEL<=504) {
  327.                                         CURRENT_LEVEL++;
  328.                                         HeroSides=CURRENT_LEVEL;
  329.                                         if (CURRENT_LEVEL>MAX_LEVEL) MAX_LEVEL=CURRENT_LEVEL;
  330.                                         GLOBAL_CHECKPOINT=0;
  331.                                         TO_NEXT_LEVEL=505;
  332.                                 }
  333.                                 if (TO_NEXT_LEVEL>=505) {
  334.                                         TO_NEXT_LEVEL+=2;
  335.                                         if (TO_NEXT_LEVEL>1000) TO_NEXT_LEVEL=0;
  336.                                 }
  337.                         }
  338.  
  339.                 }
  340.  
  341.           } else {
  342.                 GLOBAL_SPEED=0;
  343.                 DeltaSpeed=0;
  344.                 TO_NEXT_LEVEL=0;
  345.                 HeroIsDead++;
  346.                 DrawPew (125,HeroY,HeroIsDead,HeroColor);
  347.                 if (HeroIsDead>100) {
  348.                          ResetLevel(CURRENT_LEVEL);
  349.                          if (GLOBAL_CHECKPOINT==0) {
  350.                                 isRestart=1;
  351.                                 HeroY=100;
  352.                          } else {
  353.                                 isRestart=0;
  354.                                 HeroY=SPAWN_Y+41-DeltaH[HeroSides];
  355.                                 if (HeroSides>7) HeroY-=22;
  356.                          }
  357.                          HeroIsDead=0;
  358.                          HeroFly=0;
  359.                          if (HeroSides%2==0) {
  360.                                 HeroAngle=360/(HeroSides*2);
  361.                          } else {
  362.                                 HeroAngle=0;
  363.                          }
  364.                 }
  365.           }
  366.           if (Key=='f'&& CURRENT_LEVEL<3) {
  367.                 int i=0;
  368.                 Objects=0;
  369.                 for (i=0; i<11; i++) LevelProps[i][0]=0;
  370.                 isRestart=1;
  371.                 HeroIsDead=0;
  372.                 HeroY=100;
  373.                 HeroFly=1;
  374.                 TO_NEXT_LEVEL=0;
  375.                 GAME_TYPE=3;
  376.                 Panel=1;
  377.           }
  378.           if (Key==27) {
  379.                 GLOBAL_CHECKPOINT=0;
  380.                 int i=0;
  381.                 for (i=0; i<11; i++) ResetLevel (i);
  382.                 isRestart=1;
  383.                 HeroIsDead=0;
  384.                 HeroY=100;
  385.                 HeroFly=1;
  386.                 TO_NEXT_LEVEL=0;
  387.                 if (CURRENT_LEVEL<3) {
  388.                         GAME_TYPE=3;
  389.                         Panel=1;
  390.                         Key=' ';
  391.                 } else {
  392.                         GAME_TYPE=0;
  393.                 }
  394.           }
  395. }
  396.  
  397. void ShowHelp() {
  398.         DrawText (5,10,"controls",HeroColor);
  399.         DrawText (5,30,"w/a/s/d or arrow keys to choose",GLOBAL_FRONTCOLOR);
  400.         DrawText (5,50,"space jump",GLOBAL_FRONTCOLOR);
  401.         DrawText (5,70,"space/enter to select",GLOBAL_FRONTCOLOR);
  402.         DrawText (5,90,"escape return to menu/exit",GLOBAL_FRONTCOLOR);
  403.         DrawText (5,130,"level editor notes",HeroColor);
  404.         DrawText (5,150,"press e to switch grid/tools panel",GLOBAL_FRONTCOLOR);
  405.         DrawText (5,170,"press q to switch grid/properties",GLOBAL_FRONTCOLOR);
  406.         DrawText (5,190,"select save game to save all levels",GLOBAL_FRONTCOLOR);
  407.         DrawText (5,210,"select load game to load all levels",GLOBAL_FRONTCOLOR);
  408.         DrawText (5,230,"select level 0/1/2 to play/edit",GLOBAL_FRONTCOLOR);
  409.         DrawText (5,250,"use f to go to level editor quickly",GLOBAL_FRONTCOLOR);
  410.         DrawText (5,270,"use start column to test level from",GLOBAL_FRONTCOLOR);
  411.         DrawText (5,290,"desired place (you can test",GLOBAL_FRONTCOLOR);
  412.         DrawText (5,310,"level from column which contains",GLOBAL_FRONTCOLOR);
  413.         DrawText (5,330,"checkpoint)",GLOBAL_FRONTCOLOR);
  414.         DrawText (5,370,"redraw technology notes",HeroColor);
  415.         DrawText (5,390,"lines tech works faster but",GLOBAL_FRONTCOLOR);
  416.         DrawText (5,410,"sometimes it can be unstable",GLOBAL_FRONTCOLOR);
  417.         DrawText (5,430,"frame tech works slower but stable",GLOBAL_FRONTCOLOR);
  418.  
  419.          if (Key=='f' && CURRENT_LEVEL<3) {
  420.                 GAME_TYPE=3;
  421.                 Panel=1;
  422.         }
  423.  
  424.         if (Key==27) GAME_TYPE=0;
  425. }
  426.  
  427. void SaveArray() {
  428.         FILE *ArrTxt;
  429.  
  430.         if (SAVE_FOLDER_TYPE==1) {
  431.                 ArrTxt=fopen ("/usbhd0/1/LEVEL2D.txt","wb");
  432.         } else {
  433.                 ArrTxt=fopen ("LEVEL2D.txt","wb");
  434.         }
  435.         if (ArrTxt==NULL) {
  436.                 DrawText (100,300,"error (cannot save data)",GLOBAL_FRONTCOLOR);
  437.                 Update();
  438.                 _ksys_delay(200);
  439.                 Panel=1;
  440.                 return;
  441.         }
  442.         char StringLevel[3*9*LEVEL_MAXLEN]="unsigned char NEW_LEVEL[9][LEVEL_MAXLEN]=\n{";
  443.         int CurCharIndex=43;
  444.         int i=0;
  445.         int j=0;
  446.         for (i=0;i<9;i++) {
  447.                 StringLevel[CurCharIndex]='{';
  448.                 CurCharIndex++;
  449.                 for (j=0; j<LEVEL_MAXLEN; j++) {
  450.                         StringLevel[CurCharIndex]= *(Levels[CURRENT_LEVEL]+i*LEVEL_MAXLEN+j)+48;
  451.                         CurCharIndex++;
  452.                         if (j<LEVEL_MAXLEN-1) {
  453.                                 StringLevel[CurCharIndex]=',';
  454.                                 CurCharIndex++;
  455.                         }
  456.                 }
  457.                 StringLevel[CurCharIndex]='}';
  458.                 CurCharIndex++;
  459.                 if (i<8) {
  460.                         StringLevel[CurCharIndex]=',';
  461.                         CurCharIndex++;
  462.                 }
  463.                 StringLevel[CurCharIndex]='\n';
  464.                 CurCharIndex++;
  465.         }
  466.         StringLevel[CurCharIndex]='}';
  467.         CurCharIndex++;
  468.         StringLevel[CurCharIndex]=';';
  469.         CurCharIndex++;
  470.         StringLevel[CurCharIndex]='\0';
  471.         fwrite (StringLevel,1,CurCharIndex,ArrTxt);
  472.         fclose (ArrTxt);
  473. }
  474.  
  475. void LevelEditor () {
  476.         int i=0;
  477.         int j=0;
  478.         if (Panel==0) {
  479.                 if ((Key=='d' || Arrow=='M') && Tile_X<399) Tile_X++;
  480.                 if ((Key=='a' || Arrow=='K') && Tile_X>0) Tile_X--;
  481.                 if ((Key=='s' || Arrow=='P') && Tile_Y<8) Tile_Y++;
  482.                 if ((Key=='w' || Arrow=='H') && Tile_Y>0) Tile_Y--;
  483.                 if ((Key==' ' || Arrow==28)) {
  484.                         if (Tile_Type==5) {
  485.                                 for (i=0; i<LEVEL_MAXLEN; i++) if (*(Levels[CURRENT_LEVEL]+0*LEVEL_MAXLEN+i)==5) *(Levels[CURRENT_LEVEL]+0*LEVEL_MAXLEN+i)=0;
  486.                                 *(Levels[CURRENT_LEVEL]+0*LEVEL_MAXLEN+Tile_X)=5;
  487.                         } else {
  488.                                 *(Levels[CURRENT_LEVEL]+Tile_Y*LEVEL_MAXLEN+Tile_X)=Tile_Type;
  489.                         }
  490.                 }
  491.         }
  492.         if (Panel==1) {
  493.                 if ((Key=='s' || Arrow=='P') && Tile_Type<5) Tile_Type++;
  494.                 if ((Key=='w' || Arrow=='H') && Tile_Type>0) Tile_Type--;
  495.         }
  496.         if (Panel==2) {
  497.                 if ((Key=='s' || Arrow=='P') && Q_SELECTED<5) Q_SELECTED++;
  498.                 if ((Key=='w' || Arrow=='H') && Q_SELECTED>0) Q_SELECTED--;
  499.                 if ((Key==' ' || Arrow==28) && Q_SELECTED==0) {
  500.                         GAME_TYPE=1;
  501.                         if (GLOBAL_CHECKPOINT>0) {
  502.                                 int isCheck=0;
  503.                                 for (i=0;i<9; i++) {
  504.                                         int CurBlock=*(Levels[CURRENT_LEVEL]+i*LEVEL_MAXLEN+GLOBAL_CHECKPOINT);
  505.                                         if (CurBlock==4) {
  506.                                                 SPAWN_Y=(i+1)*43+41+70-DeltaH[HeroSides];
  507.                                                 isCheck=1;
  508.                                                 break;
  509.                                         }
  510.                                 }
  511.                                 if (isCheck==0) {
  512.                                         DrawText (100,300,"error (checkpoint not found)",GLOBAL_FRONTCOLOR);
  513.                                         Update();
  514.                                         _ksys_delay(200);
  515.                                         GAME_TYPE=3;
  516.                                         Panel=1;
  517.                                         return;
  518.                                 }
  519.                                 ResetLevel(CURRENT_LEVEL);
  520.                                 isRestart=0;
  521.                                 HeroIsDead=0;
  522.                                 HeroFly=0;
  523.                                 HeroY=SPAWN_Y;
  524.                                 if (HeroSides>7) HeroY-=22;
  525.                                 if (HeroSides%2==0) {
  526.                                        HeroAngle=360/(HeroSides*2);
  527.                                 } else {
  528.                                        HeroAngle=0;
  529.                                 }
  530.                         }
  531.                 }
  532.                 if (Q_SELECTED==1) {
  533.                         if ((Key=='d' || Arrow=='M') && GLOBAL_CHECKPOINT<399) GLOBAL_CHECKPOINT++;
  534.                         if ((Key=='a' || Arrow=='K') && GLOBAL_CHECKPOINT>0) GLOBAL_CHECKPOINT--;
  535.                 }
  536.                 if ((Key==' ' || Arrow==28) && Q_SELECTED==2) {
  537.                         for (i=0; i<9; i++) {
  538.                                 for (j=0; j<LEVEL_MAXLEN; j++) {
  539.                                         *(Levels[CURRENT_LEVEL]+i*LEVEL_MAXLEN+j)=0;
  540.                                 }
  541.                         }
  542.                 }
  543.                 if ((Key==' ' || Arrow==28) && Q_SELECTED==3) SaveArray();
  544.                 if (Q_SELECTED==4) {
  545.                         if ((Key=='a' || Arrow=='K') && LevelProps[CURRENT_LEVEL][2]>3) LevelProps[CURRENT_LEVEL][2]--;
  546.                         if ((Key=='d' || Arrow=='M') && LevelProps[CURRENT_LEVEL][2]<10) LevelProps[CURRENT_LEVEL][2]++;
  547.                         HeroSides=LevelProps[CURRENT_LEVEL][2];
  548.                 }
  549.                 if ((Key==' ' || Arrow==28) && Q_SELECTED==5) GAME_TYPE=0;
  550.         }
  551.         if (Key=='e') {
  552.                 if (Panel==0) {
  553.                         Panel=1;
  554.                 } else {
  555.                         Panel=0;
  556.                 }
  557.         }
  558.         if (Key=='q') {
  559.                 if (Panel==0) {
  560.                         Panel=2;
  561.                 } else {
  562.                         Panel=0;
  563.                 }
  564.         }
  565.         //Draw grid
  566.         for (i=0; i<=10; i++) {
  567.                 DrawLine (43*i,0,43*i,43*9,GLOBAL_FRONTCOLOR);
  568.         }
  569.         for (i=0; i<=9; i++) {
  570.                 DrawLine (0,43*i,430,43*i,GLOBAL_FRONTCOLOR);
  571.         }
  572.         //Draw panel
  573.         DrawText (450,10,"e_tools",GLOBAL_FRONTCOLOR);
  574.         IntToStr (Tile_X,NUMBER);
  575.         DrawText (450,30,"(",GLOBAL_FRONTCOLOR);
  576.         DrawText (470,30,NUMBER,GLOBAL_FRONTCOLOR);
  577.         DrawText (530,30,"/",GLOBAL_FRONTCOLOR);
  578.         IntToStr (Tile_Y,NUMBER);
  579.         DrawText (550,30,NUMBER,GLOBAL_FRONTCOLOR);
  580.         DrawText (570,30,")",GLOBAL_FRONTCOLOR);
  581.  
  582.         DrawLine (480,70,530,70,GLOBAL_FRONTCOLOR);
  583.         DrawLine (480,70,480,70+300,GLOBAL_FRONTCOLOR);
  584.         DrawLine (530,70,530,70+300,GLOBAL_FRONTCOLOR);
  585.         for (i=1;i<=6; i++) DrawLine (480,70+50*i,530,70+50*i,GLOBAL_FRONTCOLOR);
  586.         //Empty block
  587.         DrawLine (480+4,70+4,480+42,70+42,GLOBAL_FRONTCOLOR);
  588.         DrawLine (480+4,70+42,480+42,70+4,GLOBAL_FRONTCOLOR);
  589.         DrawBlock (480+4,70+4+50,GLOBAL_FRONTCOLOR);
  590.         DrawPit (480+7,70+4+100,GLOBAL_FRONTCOLOR);
  591.         DrawBatut (480+4,70+4+150,GLOBAL_FRONTCOLOR);
  592.         DrawFlag (480+8,70+4+200,GLOBAL_FRONTCOLOR);
  593.         DrawText (480+14,70+14+250,"f",GLOBAL_FRONTCOLOR);
  594.         DrawText (450,400,TILENAME [Tile_Type],GLOBAL_FRONTCOLOR);
  595.  
  596.         //Draw properties
  597.         DrawText (10,410,"q_properties",GLOBAL_FRONTCOLOR);
  598.         DrawText (10,430+20,"test level",GLOBAL_FRONTCOLOR);
  599.         DrawText (10,470,"start column <     >",GLOBAL_FRONTCOLOR);
  600.         IntToStr (GLOBAL_CHECKPOINT,NUMBER);
  601.         DrawText (270,470,NUMBER,GLOBAL_FRONTCOLOR);
  602.         DrawText (10,490,"reset level",GLOBAL_FRONTCOLOR);
  603.         DrawText (10,510,"save as 2d array (for developers)",GLOBAL_FRONTCOLOR);
  604.         DrawText (10,530,"hero sides <   >",GLOBAL_FRONTCOLOR);
  605.         IntToStr (LevelProps[CURRENT_LEVEL][2],NUMBER);
  606.         DrawText (230,530,NUMBER,GLOBAL_FRONTCOLOR);
  607.         DrawText (10,550,"back to menu",GLOBAL_FRONTCOLOR);
  608.  
  609.         if (Panel==0) {
  610.                 DrawLine ((Tile_X%10)*43,0,(Tile_X%10)*43,400,HeroColor);
  611.                 DrawLine ((Tile_X%10)*43+43,0,(Tile_X%10)*43+43,400,HeroColor);
  612.                 DrawLine (0,(Tile_Y%10)*43,440,(Tile_Y%10)*43,HeroColor);
  613.                 DrawLine (0,(Tile_Y%10)*43+43,440,(Tile_Y%10)*43+43,HeroColor);
  614.         }
  615.         if (Panel==1) {
  616.                 DrawText (450,10,"e_tools",HeroColor);
  617.                 DrawLine (480,70+Tile_Type*50,530,70+Tile_Type*50,HeroColor);
  618.                 DrawLine (480,70+Tile_Type*50,480,70+50+Tile_Type*50,HeroColor);
  619.                 DrawLine (480,70+Tile_Type*50+50,530,70+50+Tile_Type*50,HeroColor);
  620.                 DrawLine (530,70+Tile_Type*50,530,70+Tile_Type*50+50,HeroColor);
  621.                 DrawText (450,400,TILENAME [Tile_Type],HeroColor);
  622.         }
  623.         if (Panel==2) {
  624.                DrawText (10,410,"q_properties",HeroColor);
  625.                if (Q_SELECTED==0) DrawText (10,450,"test level",HeroColor);
  626.                if (Q_SELECTED==1) DrawText (10,470,"start column <     >",HeroColor);
  627.                if (Q_SELECTED==2) DrawText (10,490,"reset level",HeroColor);
  628.                if (Q_SELECTED==3) DrawText (10,510,"save as 2d array (for developers)",HeroColor);
  629.                if (Q_SELECTED==4) DrawText (10,530,"hero sides <   >",HeroColor);
  630.                if (Q_SELECTED==5) DrawText (10,550,"back to menu",HeroColor);
  631.         }
  632.  
  633.         for (i=0; i<10; i++) {
  634.                 for (j=0; j<9; j++) {
  635.                         int CurBlock=*(Levels[CURRENT_LEVEL]+j*LEVEL_MAXLEN+Tile_X-Tile_X%10+i);
  636.                         if (CurBlock==1) DrawBlock (43*i,43*j,GLOBAL_BLOCKCOLOR);
  637.                         if (CurBlock==2) DrawPit (43*i,43*j,GLOBAL_PITCOLOR);
  638.                         if (CurBlock==3) DrawBatut (43*i,43*j,GLOBAL_BATUTCOLOR);
  639.                         if (CurBlock==4) DrawFlag (43*i,43*j,GLOBAL_FLAGCOLOR);
  640.  
  641.                 }
  642.                 if (*(Levels[CURRENT_LEVEL]+0*LEVEL_MAXLEN+Tile_X-Tile_X%10+i)==5) {
  643.                         for (j=0; j<9;j++) {
  644.                                 DrawText (43*i+10,43*j+10,"f",GLOBAL_FRONTCOLOR);
  645.                         }
  646.                 }
  647.         }
  648.         if (Key==27) {
  649.                 GAME_TYPE=0;
  650.         }
  651. }
  652.  
  653. void Authors () {
  654.         if (THE_END_COUNT>0) THE_END_COUNT--;
  655.         DrawText (240,10+THE_END_COUNT,"the end",HeroColor);
  656.         DrawText (10,40+THE_END_COUNT,"dev team",HeroColor);
  657.         DrawText (10,60+THE_END_COUNT,"game director _ shimanskey eugene",GLOBAL_FRONTCOLOR);
  658.         DrawText (10,80+THE_END_COUNT,"level designer _ chuduk alexander", GLOBAL_FRONTCOLOR);
  659.         DrawText (10,100+THE_END_COUNT,"programmer _ shimanskey eugene", GLOBAL_FRONTCOLOR);
  660.         DrawText (10,120+THE_END_COUNT,"font designer _ chuduk alexander", GLOBAL_FRONTCOLOR);
  661.         DrawText (10,170+THE_END_COUNT,"this game is dedicated to our",GLOBAL_FRONTCOLOR);
  662.         DrawText (10,190+THE_END_COUNT,"relatives and friends",GLOBAL_FRONTCOLOR);
  663.         if (Key==27) {
  664.                 GAME_TYPE=0;
  665.                 THE_END_COUNT=600;
  666.         }
  667. }
  668.  
  669.  
  670. int main(int argc, char **argv) {
  671.         _ksys_get_screen_size (&ScreenX, &ScreenY);
  672.         OffsetX=ScreenX/2-Width/2;
  673.         OffsetY=ScreenY/2-Height/2;
  674.         draw_window();
  675.  
  676.         while (!0) {
  677.                 if (GAME_TYPE==1) {
  678.                 _ksys_delay(15-Max_Speed);
  679.                 }
  680.                 else {
  681.                 _ksys_delay(1);
  682.                 }
  683.                 Key=getKey();
  684.                 if (GAME_TYPE==-1) return 0;
  685.                 if (GAME_TYPE==0) MainMenu ();
  686.                 if (GAME_TYPE==1) GamePlay ();
  687.                 if (GAME_TYPE==2) ShowHelp ();
  688.                 if (GAME_TYPE==3) LevelEditor();
  689.                 if (GAME_TYPE==4) Authors();
  690.                 Update();
  691.  
  692.         }
  693. }