?login_element?

Subversion Repositories NedoOS

Rev

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

  1. //#define __SDCC_z80
  2. #include <evo.h>
  3. #include "resources.h"
  4. #include "map.h"
  5. #include <math.h>
  6. static u8 save_output_x;
  7. static u8 output_x;
  8. static u8 output_y;
  9. static u8 keys[40];
  10. struct room2 *curroom;
  11. static u8 noredraw;
  12. void fade_to_black(void)
  13. {
  14.         u8 a;
  15.         for(a=4;a>0;a--)
  16.         {
  17.                 pal_bright(a-1);
  18.                 delay(2);
  19.                 swap_screen();
  20.         }
  21. }
  22. void fade_from_black(void)
  23. {
  24.         u8 a;
  25.         for(a=0;a<=3;a++)
  26.         {
  27.                 pal_bright(a);
  28.                 delay(2);
  29.                 swap_screen();
  30.         }
  31. }
  32. void put_char(u8 n)
  33. {
  34.  if(n>=' ') draw_tile(output_x,output_y,n-' ');
  35.  
  36.   ++output_x;
  37.  
  38.   if(output_x==39||n=='\n')
  39.   {
  40.     output_x=save_output_x;
  41.    
  42.     ++output_y;
  43.    
  44.     if(output_y==24) output_y=1;
  45.   }
  46. }
  47. void put_str(u8* str)
  48. {
  49.  
  50.   u8 i;
  51.   //output_x=1;
  52.   //output_y=1;
  53.   //pal_select(PAL_FONT);
  54.   select_image(IMG_FONT);
  55.   save_output_x=output_x;
  56.   while(1)
  57.   {
  58.     i=*str++;
  59.  
  60.     if(!i) break;
  61.  
  62.     put_char(i);
  63.   }
  64. }
  65. struct room2 *ge_room(u8 num)
  66. {
  67.         if(num==0)return &l34;
  68.         if(num==1)return &l33;
  69.         if(num==2)return &l36;
  70.         if(num==3)return &l35;
  71.         if(num==4)return &l32;
  72.         if(num==5)return &l31;
  73.         if(num==6)return &l37;
  74.         if(num==7)return &l39;
  75.         if(num==8)return &l310;
  76.         if(num==9)return &l21;
  77.         if(num==10)return &l22;
  78.         if(num==11)return &l23;
  79.         if(num==12)return &l25;
  80.         if(num==13)return &l24;
  81.         if(num==14)return &l210;
  82.         if(num==15)return &l26;
  83.         if(num==16)return &l27;
  84.         if(num==17)return &l29;
  85.         if(num==18)return &l28;
  86.         if(num==19)return &l11;
  87.         if(num==20)return &l17;
  88.         if(num==21)return &l19;
  89.         if(num==22)return &l18;
  90.         if(num==23)return &l12;
  91.         if(num==24)return &l13;
  92.         if(num==25)return &l15;
  93.         if(num==26)return &l14;
  94.         if(num==27)return &l16;
  95.         if(num==28)return &l38;
  96.         if(num==29)return &l41;
  97.         if(num==30)return &l01;
  98.         return &l34;
  99. }
  100. /*void print_tile(u8 x,u8 y,u8 tilenum,u8 tw,u8 tmw,u8 mask)
  101. {
  102.   u8 a,b,c,d;
  103.   //select_image(IMG_TILES);
  104.   for(a=0;a<tw;a++)
  105.   {
  106.     for(b=0;b<tw;b++)
  107.     {
  108.       d=(tilenum/(tmw/tw));
  109.       c=(d*tw)*tmw+(tilenum-d*(tmw/tw))*tw;
  110.       //+a+b*tmw
  111.       if(mask!=1) draw_tile(x+a,y+b,(tilenum-d*(tmw/tw))*tw+(d*tw)*tmw+a+b*tmw);
  112.       else
  113.       {
  114.         color_key(13);
  115.         draw_tile_key(x+a,y+b,(tilenum-d*(tmw/tw))*tw+(d*tw)*tmw+a+b*tmw);
  116.       }
  117.        
  118.      
  119.     }
  120.   }
  121. }*/
  122. void print_tile(u8 x,u8 y,u16 tilenum,u8 tw,u8 tmw,u8 mask)
  123. {
  124.   u16 c,d,tn;
  125.   u8 a,b,xt,xend;
  126.   //select_image(IMG_TILES);
  127.   if(tw==1)
  128.   {
  129.     tn = tilenum;
  130.     c = tilenum;
  131.   }
  132.   else
  133.   {
  134.     if ( (tw==2) && (tmw == 32))
  135.     {
  136.         d = (tilenum & 0xfff0) << 2;
  137. //        ptile_d = ptile_d << 2;
  138.         c = d + ((tilenum & 0x0f) << 1);
  139.         tn = c;
  140.     }
  141.     else
  142.     {
  143.       d=(tilenum/(tmw/tw));
  144.       c=(d*tw)*tmw+(tilenum-d*(tmw/tw))*tw;
  145.       tn = c;
  146.     }
  147.   }
  148. if(mask!=1)
  149.   for(a=0;a<tw;a++)
  150.   {
  151.     xt = x;
  152.         xend = xt+tw;
  153.     //for(b=0;b<tw;b++)
  154.         do
  155.     {
  156.       draw_tile(xt,y,tn);
  157.           tn++;
  158.       xt++;
  159.     }while(xt < xend);
  160.     y++;
  161.     c+=tmw;
  162.     tn = c;
  163.   }
  164. else //mask==1
  165. {
  166.   color_key(13);
  167.   for(a=0;a<tw;a++)
  168.   {
  169.     xt = x;
  170.         xend = xt+tw;
  171.     //for(b=0;b<tw;b++)
  172.         do
  173.     {
  174.       draw_tile_key(xt,y,tn);
  175.           tn++;
  176.       xt++;
  177.     }while(xt < xend);
  178.     y++;
  179.     c+=tmw;
  180.     tn = c;
  181.   }
  182. } //else
  183. }
  184. void draw_room(struct room2 *rm)
  185. {
  186.   i16 x,xx,yy,y,b;
  187.   i16 a;
  188.   i16 curelem;
  189.   clear_screen(1);
  190.   x=rm->l;
  191.   y=rm->t;
  192.   xx=x;
  193.   yy=y;
  194.   select_image(IMG_TILES);
  195.   if(rm->count_l1_elements>0)
  196.   {
  197.           for(a=0;a<rm->count_l1_elements*2;a+=2)
  198.           {
  199.                 curelem=rm->l1_elements[a];
  200.                 for(b=0;b<rm->l1_elements[a+1];b++)
  201.                 {
  202.                   if (curelem>0)print_tile(xx*2,yy*2,curelem-1,2,32,0);
  203.                   xx++;
  204.                   if(xx>20)
  205.                   {
  206.                         xx=x;
  207.                         yy++;
  208.                   }
  209.                 }
  210.           }
  211.          }
  212.         if(rm->count_l1_elements==0 && rm->l1_elements[0]==0)
  213.         {
  214.                 draw_image(0,0,IMG_ROOF);
  215.         }
  216.         if(rm->count_l1_elements==0 && rm->l1_elements[0]==1)
  217.         {
  218.                 draw_image(0,0,IMG_BASEMENT);
  219.         }
  220.           select_image(IMG_SEC_LAY);
  221.          
  222.           for(a=0;a<rm->count_l2_elements;a++)
  223.           {
  224.                 curelem=rm->l2_elements[a*3]-1;
  225.                 print_tile(rm->l2_elements[a*3+1]*2,rm->l2_elements[a*3+2]*2,curelem,2,32,1);
  226.           }
  227.           select_image(IMG_OBJECTS);
  228.           for(a=rm->count_triggers-1;a>=0;a--)
  229.           {
  230.                 if(rm->triggers[a].picture_unactived>0 ||rm->triggers[a].picture_actived>0)
  231.                 {
  232.                         if(rm->triggers[a].actived==1 && rm->triggers[a].picture_actived>0)
  233.                         {
  234.                                 print_tile(rm->triggers[a].x*2,rm->triggers[a].y*2,rm->triggers[a].picture_actived-1,2,2,1);
  235.                         }
  236.                         else if(rm->triggers[a].actived==0 && rm->triggers[a].picture_unactived>0)
  237.                         {
  238.                                 print_tile(rm->triggers[a].x*2,rm->triggers[a].y*2,rm->triggers[a].picture_unactived-1,2,2,1);
  239.                         }
  240.                 }
  241.           }
  242.  
  243.  
  244. }
  245. void draw_text(struct room2 *rm,struct text *txt)
  246. {
  247.         int a,b,c;
  248.         sprites_stop();
  249.         txt->x=20-(txt->w/2)-1;
  250.         txt->y=12-(txt->h/2)-1;
  251.         for(c=0;c<txt->count_phrases;c++)
  252.         {
  253.                 sample_play(SMP_SWITCH);
  254.                 output_x=txt->x;
  255.                 output_y=txt->y;
  256.                 put_str("╔");
  257.                 output_x=txt->x+txt->w;
  258.                 output_y=txt->y;
  259.                 put_str("╗");
  260.                 output_x=txt->x;
  261.                 output_y=txt->y+txt->h;
  262.                 put_str("╚");
  263.                 output_x=txt->x+txt->w;
  264.                 output_y=txt->y+txt->h;
  265.                 put_str("╝");
  266.                 output_x=txt->x+1;
  267.                 output_y=txt->y;
  268.                 for(a=txt->x+1;a<txt->x+txt->w;a++)
  269.                 {
  270.                         put_str("═");
  271.                 }
  272.                 output_x=txt->x+1;
  273.                 output_y=txt->y+txt->h;
  274.                 for(a=txt->x+1;a<txt->x+txt->w;a++)
  275.                 {
  276.                         put_str("═");
  277.                 }
  278.                 output_x=txt->x;
  279.                 output_y=txt->y+1;
  280.                 for(a=txt->y+1;a<txt->y+txt->h;a++)
  281.                 {
  282.                         output_x=txt->x;
  283.                         output_y=a;
  284.                         put_str("║");
  285.                 }
  286.                 output_x=txt->x+txt->w;
  287.                 output_y=txt->y+1;
  288.                 for(a=txt->y+1;a<txt->y+txt->h;a++)
  289.                 {
  290.                         output_x=txt->x+txt->w;
  291.                         output_y=a;
  292.                         put_str("║");
  293.                 }
  294.                
  295.                 for(b=txt->y+1;b<txt->y+txt->h;b++)
  296.                 {
  297.                         output_x=txt->x+1;
  298.                         output_y=b;
  299.                         for(a=txt->x+1;a<txt->x+txt->w;a++)
  300.                         {
  301.                                 put_str(" ");
  302.                         }
  303.                 }
  304.                 output_x=txt->x+txt->w-1;
  305.                 output_y=txt->y+txt->h;
  306.                 put_str("░");
  307.                 output_x=txt->x+1;
  308.                 output_y=txt->y+1;
  309.                 put_str(txt->text[c]);
  310.                 swap_screen();
  311.                 delay(10);
  312.                 while(joystick()==0) vsync(); //for joystick
  313.                
  314.         }
  315.         if (noredraw!=2)        draw_room(rm);
  316.         swap_screen();
  317.         sprites_start();
  318.         delay(15);
  319. }
  320.  
  321. void title(void)
  322. {
  323.        
  324.         music_play(MUS_DIAMOND);
  325.         sprites_stop();
  326.         pal_select(PAL_TITLE);
  327.         draw_image(0,0,IMG_TITLE);
  328.         swap_screen();
  329.         fade_from_black();
  330.         while(joystick()==0) vsync(); //for joystick
  331.         music_stop(); //bug fixed
  332.         sample_play(SMP_BELL);
  333.         fade_to_black();
  334.         clear_screen(1);
  335.         swap_screen();
  336.         clear_screen(1);
  337.         swap_screen();
  338.         sprites_start();
  339. }
  340. void game_begin( character *james)
  341. {
  342.   u8 a,b;
  343.   noredraw=1;
  344.   border(1);
  345.   james->x=50;
  346.   james->y=80;
  347.   james->napr=1;
  348.   james->frame=0;
  349.   james->count_items=0;
  350.   pal_bright(BRIGHT_MIN);
  351.   pal_select(PAL_TILES);
  352.   pal_bright(BRIGHT_MID);
  353.   for(a=0;a<=30;a++)
  354.  {
  355.         curroom=ge_room(a);
  356.         for(b=0;b<(curroom)->count_triggers;b++)
  357.         {
  358.                 (curroom)->triggers[b].actived=1;
  359.                 if((curroom)->triggers[b].act_walkable==1)(curroom)->triggers[b].walkable=0;
  360.         }
  361.  }
  362.  
  363.   curroom=ge_room(0);
  364.   draw_text(curroom,&intro);
  365.   color_key(30);
  366.   /*james->count_items=2;
  367.   james->inventory[0]=21;
  368.   james->inventory[1]=20;*/
  369.   draw_room(curroom);
  370.   swap_screen();
  371.   draw_room(curroom);
  372.  
  373.  
  374.   sprites_start();
  375.   draw_text(curroom,(struct text *)texts[0]);                     //------------------потом вернуть
  376. }
  377.  
  378.  
  379.  
  380. //-----------------------------------------------------------------
  381. u8 check_distance(struct room2 *rm,u8 tox,u8 toy)
  382. {
  383.   i16 a,c,d,e;
  384.   u8 b;
  385.   b=1;
  386.   toy+=16;
  387.  
  388.  
  389.         for(a=0;a<rm->count_triggers;a++)
  390.         {
  391.                 for(d=0;d<rm->triggers[a].w;d++)
  392.                 {
  393.                         for(e=0;e<rm->triggers[a].h;e++)
  394.                         {
  395.                                 c=sqrtf(((tox-(rm->triggers[a].x+d)*8)*(tox-(rm->triggers[a].x+d)*8))+(toy-(rm->triggers[a].y+e)*16)*(toy-(rm->triggers[a].y+e)*16));
  396.                                 if(c<=20&&rm->triggers[a].actived==1&&rm->triggers[a].item_needed!=0)
  397.                                 {
  398.                                        
  399.                                         b=a+5;
  400.                                         a=rm->count_triggers+1;
  401.                                         e=rm->triggers[a].h+1;
  402.                                         d=rm->triggers[a].w+1;
  403.                                 }
  404.                         }
  405.                 }
  406.         }
  407.  
  408.  
  409.   return b;
  410. }
  411. u8 on_trig(struct room2 *rm,u8 x,u8 trg,u8 tox,u8 toy)
  412. {
  413.   u8 a,b;
  414.   b=1;
  415.   toy+=32;
  416.   tox+=4;
  417.  
  418.           for(a=0;a<rm->count_triggers;a++)
  419.           {
  420.  
  421.                 if(rm->triggers[a].actived==1)
  422.                 {
  423.                         if((((tox-2>=(rm->triggers[a].x-1)*8)||(tox>=(rm->triggers[a].x-1)*8))&&(toy>=(rm->triggers[a].y-1)*16)&&((tox-2<=((rm->triggers[a].x+1)*8+rm->triggers[a].w*8))||(tox<=((rm->triggers[a].x+1)*8+rm->triggers[a].w)))&&(toy<=((rm->triggers[a].y+2)*16+rm->triggers[a].h*16))))
  424.                         {
  425.                                 b=a+5;
  426.                         }
  427.                 }
  428.          }
  429.  
  430.   return b;
  431. }
  432. u8 check_walkness(struct room2 *rm,u8 x,u8 trg,u8 tox,u8 toy)
  433. {
  434.   u8 a,b;
  435.   b=1;
  436.   toy+=32;
  437.   tox+=4;
  438.   if (trg==0)
  439.   {
  440.           for(a=0;a<rm->count_walk_elements*4;a+=4)
  441.           {
  442.  
  443.                         if(((tox-2>=rm->walk_elements[a]*8)||(tox>=rm->walk_elements[a]*8))&&(toy>=rm->walk_elements[a+1]*16)&&((tox-2<=(rm->walk_elements[a]*8+rm->walk_elements[a+2]*8))||(tox<=(rm->walk_elements[a]*8+rm->walk_elements[a+2]*8)))&&(toy<=(rm->walk_elements[a+1]*16+rm->walk_elements[a+3]*16)))
  444.                         {
  445.                                 b=0;
  446.                         }
  447.           }
  448.           for(a=0;a<rm->count_triggers;a++)
  449.           {
  450.                         if((rm->triggers[a].walkable==0)&&(((tox-2>=rm->triggers[a].x*8)||(tox>=rm->triggers[a].x*8))&&(toy>=rm->triggers[a].y*16)&&((tox-2<=(rm->triggers[a].x*8+rm->triggers[a].w*8))||(tox<=(rm->triggers[a].x+rm->triggers[a].w)))&&(toy<=(rm->triggers[a].y*16+rm->triggers[a].h*16))))
  451.                         {
  452.                                 b=0;
  453.                         }
  454.           }
  455.  }
  456.  
  457.   if (trg==1)
  458.   {
  459.           for(a=0;a<rm->count_triggers;a++)
  460.           {
  461.  
  462.                 if(rm->triggers[a].actived==1&&rm->triggers[a].walkable==1)
  463.                 {
  464.                         if((((tox-2>=rm->triggers[a].x*8)||(tox>=rm->triggers[a].x*8))&&(toy>=rm->triggers[a].y*16)&&((tox-2<=(rm->triggers[a].x*8+rm->triggers[a].w*8))||(tox<=(rm->triggers[a].x+rm->triggers[a].w)))&&(toy<=(rm->triggers[a].y*16+rm->triggers[a].h*16))))
  465.                         {
  466.                                 b=a+5;
  467.                         }
  468.                 }
  469.          }
  470.  }
  471.  
  472.   return b;
  473. }
  474. void activate_trigger(struct room2 *rm,character *chr,struct room2 **rooms,struct room2 **curroom,u8 triggernum,u8 fire)//fire так же является номером предмета. если 0-наступил. 1- жмякнул действие 2 и более предмет
  475. {
  476.         u8 a,b,c;
  477.         if(rm->triggers[triggernum].actived==1)
  478.         {
  479.                 if(rm->triggers[triggernum].item_needed==fire)
  480.                 {
  481.                         //put_str("correct");
  482.                         if(rm->triggers[triggernum].disabling==1)
  483.                         {
  484.                                 rm->triggers[triggernum].actived=0;
  485.                                 draw_room(rm);
  486.                                
  487.                         }
  488.                         if(fire>1)
  489.                         {
  490.                                 for(a=0;a<chr->count_items;a++)
  491.                                 {
  492.                                         if (chr->inventory[a]==fire)
  493.                                         {
  494.                                                 for(b=a;b<chr->count_items;b++)
  495.                                                 {
  496.                                                         chr->inventory[b]=chr->inventory[b+1];
  497.                                                 }
  498.                                                 a=chr->count_items;
  499.                                                 chr->count_items--;
  500.                                         }
  501.                                 }
  502.                         }
  503.                         if(rm->triggers[triggernum].item_or_teleport==1)
  504.                         {
  505.                                 //fade_to_black();
  506.                                 pal_bright(0);
  507.                                 *curroom=ge_room(rm->triggers[triggernum].room_or_item_number);
  508.                                 //*curroom=rooms[];
  509.                                 chr->x=rm->triggers[triggernum].x_exit*8;
  510.                                 chr->y=rm->triggers[triggernum].y_exit*16-20;
  511.                                 select_image(IMG_TILES);
  512.                                 sprites_stop();
  513.                                 clear_screen(1);
  514.                                 draw_room(*curroom);
  515.                                 swap_screen();
  516.                                 //clear_screen(1);
  517.                                 //draw_room(*curroom);
  518.                                 //sample_play(SMP_DOOR);
  519.                                 sprites_start();
  520.                                 //fade_from_black();
  521.                                 pal_bright(3);
  522.                         }
  523.                         if(rm->triggers[triggernum].item_or_teleport==2)
  524.                         {
  525.                                 c=0;
  526.                                 for(b=0;b<chr->count_items;b++)
  527.                                 {      
  528.                                         if(chr->inventory[0]==rm->triggers[triggernum].room_or_item_number)c=1;
  529.                                 }
  530.                                 if(c==0)
  531.                                 {                              
  532.                                         chr->inventory[chr->count_items]=rm->triggers[triggernum].room_or_item_number;
  533.                                         chr->count_items++;
  534.                                 }
  535.                         }
  536.                         if(rm->triggers[triggernum].item_or_teleport==5)//попался к глубоководным
  537.                         {
  538.                                 sprites_stop();
  539.                                 pal_select(PAL_DEEP_ONE);
  540.                                 draw_image(0,0,IMG_DEEP_ONE);
  541.                                 swap_screen();
  542.                                 draw_image(0,0,IMG_DEEP_ONE);
  543.                                 swap_screen();
  544.                                 sample_play(SMP_DEEPONE);
  545.                                 delay(25);
  546.                                 clear_screen(2);
  547.                                 swap_screen();
  548.                                 draw_image(0,0,IMG_SCRATCH1);
  549.                                 swap_screen();
  550.                                 draw_image(0,0,IMG_SCRATCH1);
  551.                                 swap_screen();
  552.                                 sample_play(SMP_SLASH);
  553.                                 delay(25);
  554.                                 clear_screen(2);
  555.                                 swap_screen();
  556.                                 draw_image(0,0,IMG_SCRATCH2);
  557.                                 swap_screen();
  558.                                 draw_image(0,0,IMG_SCRATCH2);
  559.                                 swap_screen();
  560.                                 sample_play(SMP_SLASH);
  561.                                 delay(25);
  562.                                 for(a=4;a>0;a--)
  563.                                 {
  564.                                         pal_bright(a-1);
  565.                                         delay(10);
  566.                                         swap_screen();
  567.                                 }
  568.                                 delay(150);
  569.                                 border(0);
  570.                                 pal_bright(3);
  571.                                 pal_select(PAL_GAMEOVER);
  572.                                 draw_image(0,0,IMG_GAMEOVER);
  573.                                 swap_screen();
  574.                                 while(joystick()==0) vsync(); //for joystick
  575.                                 sprites_start();
  576.                                 border(1);
  577.                                 clear_screen(1);
  578.                                 title();
  579.                                 game_begin(chr);
  580.                         }
  581.                         if(rm->triggers[triggernum].item_or_teleport==6)//конец
  582.                         {
  583.                                 sprites_stop();
  584.                                 pal_select(PAL_WIN);
  585.                                 draw_image(0,0,IMG_WIN);
  586.                                 swap_screen();
  587.                                 draw_image(0,0,IMG_WIN);
  588.                                 swap_screen();
  589.                                 delay(150);
  590.                                 noredraw=2;
  591.                                 draw_text(rm,&end);
  592.                                 noredraw=1;
  593.                                 sprites_start();
  594.                                 border(1);
  595.                                 clear_screen(1);
  596.                                 fade_to_black();
  597.                                 title();
  598.                                 game_begin(chr);
  599.                         }
  600.  
  601.                         if(rm->triggers[triggernum].text_active!=0)
  602.                         {
  603.                                 draw_text(rm,(struct text *)texts[rm->triggers[triggernum].text_active-1]);
  604.                         }
  605.                         if(rm->triggers[triggernum].act_walkable==1 )rm->triggers[triggernum].walkable=1-rm->triggers[triggernum].walkable;
  606.                 }
  607.                 else
  608.                 {
  609.                        
  610.                         if(rm->triggers[triggernum].text_wrong!=0 && fire!=0)
  611.                         {
  612.                                 draw_text(rm,(struct text *)texts[rm->triggers[triggernum].text_wrong-1]);
  613.                         }
  614.                 }
  615.                
  616.                
  617.                
  618.                
  619.                 if(rm->triggers[triggernum].text_touch!=0 && rm->triggers[triggernum].text_touch_sayed==0)
  620.                 {
  621.                         draw_text(rm,(struct text *)texts[rm->triggers[triggernum].text_touch-1]);
  622.                         rm->triggers[triggernum].text_touch_sayed=1;
  623.                 }
  624.         }
  625. }
  626. u8 check_triggers(struct room2 *rm,character *chr,struct room2 **rooms,struct room2 **curroom,u8 fire)
  627. {
  628.         u8 a,b;
  629.         u8 str[3];
  630.         //for(a=0;a<rm->count_triggers;a++)
  631.         //{
  632.                 b=check_walkness(rm,0,1,chr->x,chr->y);
  633.                 if(b>1)
  634.                 {
  635.                         activate_trigger(rm,chr,rooms,curroom,b-5,fire);
  636.                 }
  637.                 else if(fire>0)
  638.                 {
  639.                        
  640.                         b=check_distance(rm,chr->x,chr->y);
  641.                         output_x=0;
  642.                         if(b>1)
  643.                         {
  644.                                 //draw_text(rm,&testtxt);
  645.                                 activate_trigger(rm,chr,rooms,curroom,b-5,fire);
  646.                         }
  647.                 }
  648.         //}
  649.         return 1;
  650. }
  651. void redraw_inventory(u8 length,u8 curpos,character *chr)
  652. {
  653.         u8 a,b,c,x;
  654.         x=3;
  655.         select_image(IMG_ITEMS);
  656.         if(chr->count_items==0)
  657.         {
  658.                 for(a=0;a<length;a++)
  659.                 {
  660.                         print_tile(x+a*4+a,3,0,4,4,1);
  661.                 }
  662.         }
  663.         else
  664.         {
  665.                 output_x=5;
  666.                 output_y=10;
  667.                 //for(a=3;a<length+3;a++)
  668.                 for(a=0;a<length;a++)
  669.                 {
  670.                         c=3;
  671.                         if (chr->count_items<3)c=1;
  672.                         b=chr->inventory[(curpos+a+chr->count_items-c)%chr->count_items];
  673.                         print_tile(x+(a)*4+(a),3,items[b-2]->imgnum,4,4,1);
  674.                 }
  675.                 b=(curpos+3)%chr->count_items;
  676.                 put_str(items[chr->inventory[curpos]-2]->name);
  677.                
  678.         }
  679. }
  680. u8 inventory(struct room2 *rm,character* chr)
  681. {
  682.         u8 a,b,c;
  683.         u8 exit;
  684.         exit=0;
  685.         c=0;
  686.         a=1;
  687.         b=0;
  688.         sprites_stop();
  689.         draw_image(0,0,IMG_INVENTORY);
  690.         redraw_inventory(7,b,chr);
  691.         swap_screen();
  692.         //keyboard(keys);
  693.        
  694.        
  695.         while(exit==0)
  696.         {
  697.                 vsync(); //for joystick
  698.                 keyboard(keys);
  699.                 if (keys[KEY_ENTER]==KEY_DOWN)
  700.                 {
  701.                         exit=1;
  702.                         if(chr->count_items>0)
  703.                         {
  704.                                 c=chr->inventory[b];
  705.                         }
  706.                         else
  707.                         {
  708.                                 c=0;
  709.                         }
  710.                         //return(b+1);
  711.                 }
  712.                 if(joystick()!=0)
  713.                 {
  714.                         if(joystick()==JOY_LEFT)
  715.                         {
  716.                                 if(b==0)b=chr->count_items;
  717.                                 b--;
  718.                                 draw_image(0,0,IMG_INVENTORY);
  719.                                 redraw_inventory(7,b,chr);
  720.                                 sample_play(SMP_INVENTORY);
  721.                                 swap_screen();
  722.                         }
  723.                         if(joystick()==JOY_RIGHT)
  724.                         {
  725.                                 b++;
  726.                                 if(b==chr->count_items)b=0;
  727.                                 draw_image(0,0,IMG_INVENTORY);
  728.                                 redraw_inventory(7,b,chr);
  729.                                 sample_play(SMP_INVENTORY);
  730.                                 swap_screen();
  731.                         }
  732.                 }
  733.         }
  734.         pal_bright(0);
  735.         draw_room(rm);
  736.         swap_screen();
  737.         draw_room(rm);
  738.         sprites_start();
  739.         fade_from_black();
  740.         return c;
  741. }
  742. void main(void)
  743. {
  744.  
  745.   static u8 i;
  746.   static u8 xx,yy,a,b,c;
  747.   static u8 palette[16];
  748.  
  749.   character james;
  750.   //struct room2 rm;
  751.   struct room2 *rooms[16];
  752.  
  753.   //rm.l1_elements=m1_l1_elements;
  754.   title();
  755.  
  756.   border(1);
  757.   curroom=ge_room(0);
  758.   music_play(MUS_DIAMOND2);
  759.   game_begin(&james);
  760. /*for(a=0;a<57;a++)
  761.   {
  762.         draw_text(curroom,texts[a]);
  763.   }*/
  764.   c=0;
  765.  
  766.   while(1)
  767.   {
  768.         b=on_trig(curroom,james.x,0,james.x+1,james.y);
  769.         if(b!=1)        set_sprite(2,curroom->triggers[b-5].x*8,curroom->triggers[b-5].y*16,48);
  770.         else set_sprite(2,3,3,49);
  771.   //vsync(); //for joystick
  772.   if(joystick()==JOY_LEFT && james.x>0)
  773.   {
  774.         //if(on_trig(curroom,james.x,0,james.x+1,james.y)!=1)   set_sprite(2,3,3,48);
  775.         //b=on_trig(curroom,james.x,0,james.x+1,james.y);
  776.         //if(b!=1)      set_sprite(2,curroom->triggers[b-5].x*8,curroom->triggers[b-5].y*16,48);
  777.         //else set_sprite(2,3,3,49);
  778.     if(check_walkness(curroom,james.x,0,james.x-1,james.y)==1)james.x--;
  779.     james.frame++;
  780.     if(james.frame>=32)james.frame=0;
  781.     james.napr=3;
  782.         check_triggers(curroom,&james,rooms,&curroom,0);
  783.   }
  784.   if(joystick()==JOY_RIGHT&& james.x<(150))
  785.   {
  786.  
  787.     //james.x++;
  788.         //b=on_trig(curroom,james.x,0,james.x+1,james.y);
  789.         //if(b!=1)      set_sprite(2,curroom->triggers[b-5].x*8,curroom->triggers[b-5].y*16,48);
  790.         //else set_sprite(2,3,3,49);
  791.     if(check_walkness(curroom,james.x,0,james.x+1,james.y)==1)james.x++;
  792.     james.frame++;
  793.     if(james.frame>=32)james.frame=0;
  794.     james.napr=1;
  795.         check_triggers(curroom,&james,rooms,&curroom,0);
  796.   }
  797.   if(joystick()==JOY_UP&& james.y>0)
  798.   {
  799.  
  800.     //if(on_trig(curroom,james.x,0,james.x+1,james.y)!=1)       set_sprite(2,3,3,48);
  801.         //b=on_trig(curroom,james.x,0,james.x+1,james.y);
  802.         //if(b!=1)      set_sprite(2,curroom->triggers[b-5].x*8,curroom->triggers[b-5].y*16,48);
  803.         //else set_sprite(2,3,3,49);
  804.     if(check_walkness(curroom,james.x,0,james.x,james.y-1)==1)james.y--;
  805.     james.frame++;
  806.     if(james.frame>=30)james.frame=0;
  807.     james.napr=4;
  808.         check_triggers(curroom,&james,rooms,&curroom,0);
  809.   }
  810.   if(joystick()==JOY_DOWN&&james.y<184)
  811.   {
  812.     //if(on_trig(curroom,james.x,0,james.x+1,james.y)!=1)       set_sprite(2,3,3,48);
  813.         //b=on_trig(curroom,james.x,0,james.x+1,james.y);
  814.         //if(b!=1)      set_sprite(2,curroom->triggers[b-5].x*8,curroom->triggers[b-5].y*16,48);
  815.         //else set_sprite(2,3,3,49);
  816.     if(check_walkness(curroom,james.x,0,james.x,james.y+1)==1)james.y++;
  817.     james.frame++;
  818.     if(james.frame>=30)james.frame=0;
  819.     james.napr=2;
  820.         check_triggers(curroom,&james,rooms,&curroom,0);
  821.   }
  822.   if(joystick()==JOY_FIRE)
  823.   {
  824.         check_triggers(curroom,&james,rooms,&curroom,1);
  825.        
  826.   }
  827.   keyboard(keys);
  828.   if(keys[KEY_ENTER]==KEY_DOWN)
  829.   {
  830.         a=inventory(curroom,&james);
  831.         if(a!=0)
  832.         {
  833.                 check_triggers(curroom,&james,rooms,&curroom,a);
  834.         }
  835.   }
  836.   if(james.napr==1)
  837.   {
  838.     set_sprite(0,james.x,james.y,16+james.frame/4);
  839.     set_sprite(1,james.x,james.y+16,24+james.frame/4);
  840.   }
  841.   if(james.napr==3)
  842.   {
  843.     set_sprite(0,james.x,james.y,32+james.frame/4);
  844.     set_sprite(1,james.x,james.y+16,40+james.frame/4);
  845.   }
  846.   if(james.napr==2)
  847.   {
  848.     set_sprite(0,james.x,james.y,4+james.frame/10);
  849.     set_sprite(1,james.x,james.y+16,12+james.frame/10);
  850.   }
  851.   if(james.napr==4)
  852.   {
  853.     set_sprite(0,james.x,james.y,1+james.frame/10);
  854.     set_sprite(1,james.x,james.y+16,9+james.frame/10);
  855.   }
  856.  
  857.   swap_screen();
  858.   }
  859. }
  860.