?login_element?

Subversion Repositories NedoOS

Rev

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

  1. // Jias jias - Este es como el subaquatic, que lleva en desarrollo tanto
  2. // tiempo que el cєdigo de aquэ abajo da miedo miedor.
  3.  
  4. #include "splib.h"
  5.  
  6. /* Extern pointers for the graphic definitions: */
  7.  
  8. #include "resources.h"
  9. #include "fases.h"
  10. #include "sprites.h"
  11.  
  12. #define MAXCURBRIGHT (4*3)
  13.  
  14. /* Game constants */
  15.  
  16. #define CANAL_FX        1       // Canal por el que suenan los efectos de sonido
  17.  
  18. /* masks for joystick functions */
  19.  
  20. #define sp_START                0x0100
  21. #define sp_FIRE                 0x0080
  22. #define sp_RIGHT                0x0008
  23. #define sp_LEFT                 0x0004
  24. #define sp_DOWN                 0x0002
  25. #define sp_UP                   0x0001
  26.  
  27. i8 play;
  28. u8 curbright;
  29.  
  30. /* Import sp_ClipStruct */
  31.  
  32. struct sp_Rect *sp_ClipStruct;
  33.  
  34. struct sp_Rect spritesClipValues;
  35. struct sp_Rect *spritesClip;
  36.  
  37. /* Manage keys and joystick at the same time: */
  38. u8 keys[255];
  39.  
  40. u16 joyfunc(void)
  41. {
  42.     u16 i;
  43.     i16 res;
  44.  
  45.     i=joystick();
  46.         keyboard(keys);
  47.  
  48.     res=0;
  49.     if(i&JOY_LEFT)  res|=sp_LEFT;
  50.     if(i&JOY_RIGHT) res|=sp_RIGHT;
  51.     if(i&JOY_UP)    res|=sp_UP;
  52.     if(i&JOY_DOWN)  res|=sp_DOWN;
  53.     if(i&JOY_FIRE)      res|=sp_FIRE;
  54.     if(keys[KEY_ENTER]==KEY_DOWN)       res|=sp_START;
  55.  
  56.     return res^0xffff;
  57. }
  58.  
  59. /* Data types */
  60.  
  61. typedef struct {
  62.     i16 x, y;
  63.     i16 vx, vy;
  64.     i8 g, ax, rx;
  65.     u8 salto, cont_salto;
  66.     u8 saltando;
  67.     u16 frame, subframe, facing;
  68.     u8 estado;
  69.     u8 ct_estado;
  70.     u16 ground,nojump;
  71. } INERCIA;
  72.  
  73. #define EST_NORMAL       0
  74. #define EST_NUDE         1
  75. #define EST_PARP         2
  76. #define EST_MUR          4
  77. #define EST_EXIT         8
  78. #define EST_EXIT_LEFT   16
  79. #define EST_EXIT_RIGHT  32
  80.  
  81. INERCIA player;
  82.  
  83. i8 pantalla;
  84. i8 visitados [55];
  85. i8 lives;
  86.  
  87.  
  88. // Estructura de datos para los objetos mєviles:
  89. typedef struct {
  90.     u8 x, y;
  91.     i8 vx, vy;
  92.     u8 t1, t2;
  93.     i16 rx, ry;
  94.     u16 current_frame, next_frame;
  95.     i8 tipo;
  96. } MOVILES;
  97.  
  98. MOVILES moviles[3];
  99. struct sp_SS *sp_moviles [3];
  100.  
  101. // Almacena las monedas del nivel actual
  102.  
  103. typedef struct {
  104.     u16 type;
  105.     u16 x,y;
  106.     struct sp_SS *sp;
  107. } MONEDA;
  108.  
  109. MONEDA monedas[10];
  110. u8 num_monedas;
  111.  
  112. // Para ahorrar IFs...
  113. const u16 enem_frames [8] = {
  114.     wolfi_1a,       wolfi_1a,
  115.     franki_1a,      franki_1a,
  116.     vampi_1a,       vampi_1a,
  117.     fanti_l_1a,     fanti_r_1a
  118. };
  119.  
  120. i8 flag1, flag2;
  121. u8 playing;
  122. i8 level;
  123.  
  124. // Espacio para guardar 12 bloques de fondo.
  125. u8 tile_buffer01 [8];
  126.  
  127. u8 j, x, y, xx, yy, xt, yt;
  128. i8 i;
  129. i8 fantact;
  130. struct sp_SS *sp_prueba;
  131. i8 *timer;
  132. u8 *wyz_music_flag;
  133. u8 *allpurposepuntero;
  134. u8 maincounter;
  135. u8 n_pant;
  136. u16 total_score;
  137. u16 total_coins;
  138. i8 time8;
  139. u8 xcami, ycami;
  140. struct sp_Rect rectangulo;
  141. u8 prueba[8];
  142. i8 bonus1, bonus2;
  143.  
  144. i8 vidaextra;
  145.  
  146. u16 rand_seed;
  147.  
  148. u16 cheat;
  149. u16 monedas_frame;
  150.  
  151. const u16 monedas_anim[]={
  152.     coin_1a,coin_1a+DSPR*1,coin_1a+DSPR*2,coin_1a+DSPR*2,coin_1a+DSPR*1,coin_1a,coin_1a+DSPR*3,coin_1a+DSPR*4,coin_1a+DSPR*4,coin_1a+DSPR*3
  153. };
  154. //#define monedas_frames 10
  155. #define monedas_frames (sizeof(monedas_anim)/sizeof(u16))
  156.  
  157. const u16 monedas_take_anim[]={
  158.     coin_1a,coin_1a+DSPR*1,coin_1a+DSPR*2,coin_1a+DSPR*4,coin_1a+DSPR*5,coin_1a+DSPR*6,coin_1a+DSPR*7,coin_1a+DSPR*8,coin_1a+DSPR*9,coin_1a+DSPR*10
  159. };
  160.  
  161. const u16 player_anim[]={
  162.     uwol_r_1a,uwol_r_2a,uwol_r_3a,uwol_r_2a,
  163.     uwol_l_1a,uwol_l_2a,uwol_l_3a,uwol_l_2a,
  164.     uwolpelot_r_1a,uwolpelot_r_2a,uwolpelot_r_3a,uwolpelot_r_2a,
  165.     uwolpelot_l_1a,uwolpelot_l_2a,uwolpelot_l_3a,uwolpelot_l_2a
  166. };
  167.  
  168. const u8 level_number[]={
  169. 1,
  170. 1,2,
  171. 1,2,3,
  172. 1,2,3,4,
  173. 1,2,3,4,5,
  174. 1,2,3,4,5,6,
  175. 1,2,3,4,5,6,7,
  176. 1,2,3,4,5,6,7,8,
  177. 1,2,3,4,5,6,7,8,9,
  178. 1,2,3,4,5,6,7,8,9,10
  179. };
  180.  
  181. struct sp_SS *arrow_l;
  182. struct sp_SS *arrow_r;
  183.  
  184.  
  185. #define SPTW 4/7//2/3
  186.  
  187. /*
  188. //packed screens data
  189.  
  190. extern const u8 mojon_data[];
  191. extern const u8 credits_data[];
  192. extern const u8 title_data[];
  193. extern const u8 gover_data[];
  194. extern const u8 finbad_data[];
  195. extern const u8 fingoo_data[];
  196. extern const u8 finend_data[];
  197. extern u16 warp_palette[];
  198. */
  199.  
  200. //music data
  201. #define SONG_MENU MUS_MENU
  202. #define SONG_PIRAMIDE MUS_PIRAMIDE
  203. #define SONG_ZONA1 MUS_ZONA1
  204. #define SONG_ZONA2 MUS_ZONA2
  205. #define SONG_ZONA3 MUS_ZONA3
  206. #define SONG_ZONA4 MUS_ZONA4
  207. #define SONG_FANTASMA MUS_FANTASMA
  208. #define SONG_GAMEOVER MUS_GAMEOVER
  209. #define SONG_ENDINGKO MUS_ENDINGKO
  210. #define SONG_ENDINGOK MUS_ENDINGOK
  211. /*
  212. extern const u8 menu_data[];
  213. extern const u8 piramide_data[];
  214. extern const u8 zona1_data[];
  215. extern const u8 zona2_data[];
  216. extern const u8 zona3_data[];
  217. extern const u8 zona4_data[];
  218. extern const u8 fantasma_data[];
  219. extern const u8 gameover_data[];
  220. extern const u8 endingko_data[];
  221. extern const u8 endingok_data[];
  222. */
  223.  
  224. // Pelotingui o vestido:
  225.  
  226. u8 rand () {
  227.     rand_seed*=31421;
  228.     rand_seed+=6927;
  229.     return (u8)rand_seed;
  230. }
  231.  
  232. void wyz_play_sound (u8 fx_number, u8 fx_channel)
  233. {
  234.     if (!play)
  235.         return;
  236.  
  237.         //psgfx_play(fx_number);
  238.         sfx_play(fx_number+SFX_NONAME001,5/*volume -7..+7*/);
  239. }
  240.  
  241. //void wyz_play_music (const u8 *data)
  242. void wyz_play_music (u8 songnum)
  243. {
  244.     if (!play)
  245.         return;
  246.  
  247. /*    tfc_play(FALSE);
  248.     tfc_init(data);
  249.     tfc_play(TRUE);*/
  250.         music_play(songnum);
  251. }
  252.  
  253. void wyz_stop_sound ()
  254. {
  255.     if (!play)
  256.         return;
  257.  
  258.     //tfc_play(FALSE);
  259.         music_stop();
  260. }
  261.  
  262. /* Auxiliary functions */
  263.  
  264. void todo_a_negro () {
  265.     i16 i,j;
  266.  
  267.     for(i=0;i<24;i++)
  268.     {
  269.         for(j=0;j<32;j++) sp_AttrSet(j,i,0);
  270.     }
  271. }
  272.  
  273. /* fade into a given palette */
  274.  
  275. //void fade_into(u16 *palette)
  276. void fade_into()
  277. {
  278.        
  279.         pal_bright(BRIGHT_MIN+(curbright/4));
  280.         //pal_bright(BRIGHT_MIN+3);
  281.         if(curbright<MAXCURBRIGHT) curbright++;
  282. }
  283.  
  284. void fade_out ()
  285. {
  286.     //fade_screen(TRUE);
  287.         for(i=0;i<4;++i)
  288.         {
  289.                 pal_bright(BRIGHT_MID-i);
  290.                 for(j=0;j<4;++j) vsync();
  291.         }
  292.     todo_a_negro();
  293. }
  294.  
  295. //void fade_screen(u16 out)
  296. void fade_screen()
  297. {
  298.     u16 i;
  299.  
  300.         curbright=0;
  301.  
  302.         for(i=0;i<16;i++)
  303.         {
  304.                 fade_into();
  305.                 vsync();
  306.         }
  307. }
  308.  
  309. //void unpack_RAM3 (const u8 *data)
  310. void view_image (u8 image)
  311. {
  312.         pal_bright(BRIGHT_MIN);
  313.         pal_select(image);
  314.  
  315.     //unpack_screen(data);
  316.         draw_image(0,0,image);
  317.         swap_screen();
  318.         fade_screen();
  319. }
  320.  
  321. /* Game functions */
  322.  
  323. void draw_lives (i8 lives) {
  324.     sp_PrintAtInv (0, 6, 71, 99);
  325.     sp_PrintAtInv (0, 7, vidaextra && (player.estado & EST_PARP) && (player.ct_estado & 1) ? 71 : 69, 89 + (lives / 10));
  326.     sp_PrintAtInv (0, 8, vidaextra && (player.estado & EST_PARP) && (player.ct_estado & 1) ? 71 :69, 89 + (lives % 10));
  327. }
  328.  
  329. void draw_score (u8 score) {
  330.     sp_PrintAtInv (0, 24, 71, 99);
  331.     sp_PrintAtInv (0, 25, 69, 89 + (score / 100));
  332.     sp_PrintAtInv (0, 26, 69, 89 + (score % 100) / 10);
  333.     sp_PrintAtInv (0, 27, 69, 89 + (score % 10));
  334. }
  335.  
  336. void draw_total_score (i8 y,i8 x,u16 total_score) {
  337.     sp_PrintAtInv (y, x+0, 4, 106);
  338.     sp_PrintAtInv (y, x+1, 4, 107);
  339.     sp_PrintAtInv (y, x+2, 4, 108);
  340.     sp_PrintAtInv (y, x+3, 4, 109);
  341.     sp_PrintAtInv (y, x+4, 4, 103);
  342.     sp_PrintAtInv (y, x+5, 7, 99);
  343.     sp_PrintAtInv (y, x+6, 5, 89 + total_score / 10000);
  344.     sp_PrintAtInv (y, x+7, 5, 89 + (total_score % 10000) / 1000);
  345.     sp_PrintAtInv (y, x+8, 5, 89 + (total_score % 1000) / 100);
  346.     sp_PrintAtInv (y, x+9, 5, 89 + (total_score % 100) / 10);
  347.     sp_PrintAtInv (y, x+10, 5, 89 + (total_score % 10));
  348. }
  349.  
  350. void draw_time (i8 time) {
  351.     sp_PrintAtInv (0, 12, 68, 100);
  352.     sp_PrintAtInv (0, 13, 68, 101);
  353.     sp_PrintAtInv (0, 14, 68, 102);
  354.     sp_PrintAtInv (0, 15, 68, 103);
  355.     sp_PrintAtInv (0, 16, 71, 99);
  356.     sp_PrintAtInv (0, 17, 69, 89 + (time / 100));
  357.     sp_PrintAtInv (0, 18, 69, 89 + (time % 100) / 10);
  358.     sp_PrintAtInv (0, 19, 69, 89 + (time % 10));
  359. }
  360.  
  361. void draw_level (i8 y,i8 x,i8 level,u16 n_pant) {
  362.     sp_PrintAtInv (y,x+0, 4, 104);
  363.     sp_PrintAtInv (y,x+1, 4, 103);
  364.     sp_PrintAtInv (y,x+2, 4, 105);
  365.     sp_PrintAtInv (y,x+3, 4, 103);
  366.     sp_PrintAtInv (y,x+4, 4, 104);
  367.     if(level>=10)
  368.     {
  369.         sp_PrintAtInv (y,x+5, 5, 90);
  370.         x++;
  371.     }
  372.     sp_PrintAtInv (y,x+5, 5, 89 + (level % 10));
  373.     sp_PrintAtInv (y,x+6, 5, 84);
  374.     if(level_number[n_pant]>=10)
  375.     {
  376.         sp_PrintAtInv (y,x+7, 5, 90);
  377.         x++;
  378.     }
  379.     sp_PrintAtInv (y,x+7, 5, 89 + (level_number[n_pant] % 10));
  380. }
  381.  
  382. u16 collision_v(u16 x,u16 y,u16 h)
  383. {
  384.     u16 i;
  385.  
  386.     h--;
  387.     h=((y+h)>>3)-(y>>3)+1;
  388.  
  389.     for(i=0;i<h;i++)
  390.     {
  391.         if(sp_AttrGet(x>>3,y>>3)>63) return TRUE;
  392.         y+=8;
  393.     }
  394.  
  395.     return FALSE;
  396. }
  397.  
  398. u16 collision_h(u16 x,u16 y,u16 w)
  399. {
  400.     u16 i;
  401.  
  402.     w--;
  403.     w=((x+w)>>3)-(x>>3)+1;
  404.  
  405.     for(i=0;i<w;i++)
  406.     {
  407.         if(sp_AttrGet(x>>3,y>>3)>63) return TRUE;
  408.         x+=8;
  409.     }
  410.  
  411.     return FALSE;
  412. }
  413.  
  414. void move (u16 i) {
  415.     u8 xx, yy;
  416.     u8 x, y;
  417.     u16 off;
  418.  
  419.     /* Primera prueba del motor de movimiento de inercia para z88dk/splib2
  420.        Vamos a ver si esto no explota tє */
  421.  
  422.     /* Por partes. Primero el movimiento vertical. La ecuaciєn de movimien-
  423.        to viene a ser, en cada ciclo:
  424.  
  425.        1.- vy = vy + g
  426.        2.- y = y + vy
  427.  
  428.        O sea la velocidad afectada por la gravedad.
  429.        Para no colarnos con los nmeros, ponemos limitadores:
  430.     */
  431.  
  432.     if (player.vy < 512*SPTW/*256*/)
  433.         player.vy += player.g;
  434.     else
  435.         player.vy = 512*SPTW/*256*/;
  436.  
  437.     player.y += player.vy;
  438.     if (player.y < 0)
  439.         player.y = 0;
  440.  
  441.     /* El problema es que no es tan fсcil... Hay que ver si no nos chocamos.
  442.        Si esto pasa, hay que "recular" hasta el borde del obstсculo.
  443.  
  444.        Por eso miramos el signo de vy, para que los cсlculos sean mсs sencillos.
  445.        De paso vamos a precalcular un par de cosas para que esto vaya mсs rсpido.
  446.     */
  447.  
  448.     x = player.x >> 6;              // dividimos entre 64 para pixels, y luego entre 8 para tiles.
  449.     y = player.y >> 6;
  450.     xx = x >> 3;
  451.     yy = y >> 3;
  452.  
  453.     if (player.vy < 0) {            // estamos ascendiendo
  454.         if (player.y >= 1024)
  455.             if(collision_h(x+2,y+4,16-4)) {
  456.                 // paramos y ajustamos:
  457.                 player.y = player.y-player.vy;
  458.                 player.vy = 0;
  459.             }
  460.         player.ground=FALSE;
  461.     } else if (player.vy > 0) {     // estamos descendiendo
  462.         if(collision_h(x+2,y+16,16-4))
  463.         {
  464.             // paramos y ajustamos:
  465.             player.vy = 0;
  466.             player.y = yy << 9;
  467.             if(!player.ground)
  468.             {
  469.                 player.ground=TRUE;
  470.                 player.nojump=TRUE;
  471.                 wyz_play_sound (0, CANAL_FX);
  472.             }
  473.         }
  474.         else
  475.         {
  476.             player.ground=FALSE;
  477.         }
  478.     }
  479.  
  480.     /* Salto: El salto se reduce a dar un valor negativo a vy. Esta es la forma mсs
  481.        sencilla. Sin embargo, para mсs control, usamos el tipo de salto "mario bros".
  482.        Para ello, en cada pulsaciєn dejaremos decrementar vy hasta un mэnimo, y de-
  483.        tectando que no se vuelva a pulsar cuando estemos en el aire. Juego de banderas ;)
  484.     */
  485.  
  486.     if ( !player.nojump && (i & sp_FIRE) == 0 && player.vy == 0 && player.saltando == 0 && player.ground) {
  487.         player.saltando = 1;
  488.         player.cont_salto = 0;
  489.         wyz_play_sound (7, CANAL_FX);
  490.  
  491.         // Para que el inicio del salto sea mсs potente: (a veces conviene):
  492.         // player.vy -= (player.salto << 1);
  493.     }
  494.  
  495.     if ( (i & sp_FIRE) == 0 && player.saltando ) {
  496.         player.vy -= (player.salto + 48*SPTW/*16*/ - (player.cont_salto>>1));
  497.         if (player.vy < -256/*128*/) player.vy = -256/*128*/;
  498.  
  499.         player.cont_salto ++;
  500.         if (player.cont_salto == 6/*8*/)
  501.             player.saltando = 0;
  502.     }
  503.  
  504.     if ( (i & sp_FIRE) != 0)
  505.         {
  506.             player.saltando = 0;
  507.             player.nojump=FALSE;
  508.         }
  509.  
  510.     // ------ ok con el movimiento vertical.
  511.  
  512.     /* Movimiento horizontal:
  513.  
  514.        Mientras se pulse una tecla de direcciєn,
  515.  
  516.        x = x + vx
  517.        vx = vx + ax
  518.  
  519.        Si no se pulsa nada:
  520.  
  521.        x = x + vx
  522.        vx = vx - rx
  523.     */
  524.  
  525.     if ( ! ((i & sp_LEFT) == 0 || (i & sp_RIGHT) == 0))
  526.         {
  527.         if (player.vx > 0) {
  528.             player.vx -= player.rx;
  529.             if (player.vx < 0)
  530.                 player.vx = 0;
  531.         } else if (player.vx < 0) {
  532.             player.vx += player.rx;
  533.             if (player.vx > 0)
  534.                 player.vx = 0;
  535.         }
  536.         }
  537.  
  538.     if ((i & sp_LEFT) == 0)
  539.         {
  540.         if (player.vx > -192*SPTW) {
  541.             player.facing = 0;
  542.             player.vx -= player.ax;
  543.         }
  544.         }
  545.  
  546.     if ((i & sp_RIGHT) == 0)
  547.         {
  548.         if (player.vx < 192*SPTW) {
  549.             player.vx += player.ax;
  550.             player.facing = 1;
  551.         }
  552.         }
  553.  
  554.     player.x = player.x + player.vx;
  555.  
  556.     /* Ahora, como antes, vemos si nos chocamos con algo, y en ese caso
  557.        paramos y reculamos */
  558.  
  559.     y = player.y >> 6;
  560.     x = player.x >> 6;
  561.     yy = y >> 3;
  562.     xx = x >> 3;
  563.  
  564.     if (player.y >= 512/*1024*/)
  565.         {
  566.         if (player.vx < 0) {
  567.             if(collision_v(x+2,y+4,16-4)) {
  568.                 // paramos y ajustamos:
  569.                 player.x = player.x-player.vx;
  570.                 player.vx = 0;
  571.             }
  572.         } else {
  573.             if(collision_v(x+16-2,y+4,16-4)) {
  574.                 // paramos y ajustamos:
  575.                 player.x = player.x-player.vx;
  576.                 player.vx = 0;
  577.             }
  578.         }
  579.         }
  580.  
  581.     // Calculamos el frame que hay que poner:
  582.  
  583.     if(player.vx!=0) player.subframe++;
  584.     off=(player.subframe>>1)&3;
  585.     if(player.facing==0) off+=4;
  586.     if(player.estado&EST_NUDE) off+=8;
  587.     player.frame=player_anim[off];
  588.  
  589.     // Wrap around
  590.  
  591.     if (player.x <= 1088)
  592.         player.x = 14270;
  593.  
  594.     if (player.x >= 14272)      player.x = 1090;
  595.  
  596.     // Morir en un pit
  597.  
  598.     if (player.y > 10752) {
  599.         player.frame = uwolmuete_1a;
  600.         player.estado |= EST_MUR;
  601.         player.vy = - 7*SPTW * (player.salto);
  602.         player.y = 10750;
  603.         lives --;
  604.         if (lives >= 0) draw_lives (lives);
  605.         wyz_play_sound(11, CANAL_FX);
  606.     }
  607.  
  608.     // Saliendo de la fase
  609.  
  610.     if (!(i & sp_DOWN))
  611.         {
  612.         if ( player.estado & EST_EXIT ) {
  613.             if ( player.x > 2204 && player.x < 2880 )
  614.                 player.estado |= EST_EXIT_LEFT;
  615.             if ( player.x > 12480 && player.x < 13120 )
  616.                 player.estado |= EST_EXIT_RIGHT;
  617.         }
  618.         }
  619. }
  620.  
  621. void death_sequence () {
  622.     if (player.vy < 1024*SPTW/*256*/)
  623.         player.vy += player.g;
  624.     else
  625.         player.vy = 1024*SPTW/*256*/;
  626.  
  627.     player.y += player.vy;
  628.  
  629.     // Esto acaba cuando el jugador sale de la pantalla:
  630.  
  631.     if (player.y > 11264) {
  632.         player.estado = EST_PARP;
  633.         player.x = 32 << 6;
  634.         player.y = 144 << 6;
  635.         player.vx = player.vy = 0;
  636.         player.ct_estado = 32*3/2;                      // Tiempo de inmunidad.
  637.         flag1 = 3;
  638.         playing = 0;
  639.     }
  640. }
  641.  
  642. void draw_minitile(i8 y, i8 x, u8 c, u8 tile)
  643. {
  644.         if(x<28&&y<22) sp_PrintAtInv (y, x, c, tile);
  645. }
  646.  
  647. void draw_tile4 (i8 x, i8 y, u8 c, u8 tile, u8 off) {
  648.     draw_minitile( off + y,    off + x,    c, tile);
  649.     draw_minitile( off + y,   (off^1) + x, c, tile + 1);
  650.     draw_minitile((off^1) + y, off + x,    c, tile + 2);
  651.     draw_minitile((off^1) + y,(off^1) + x, c, tile + 3);
  652. }
  653.  
  654. void draw_screen (u16 r_pant) {
  655.     /* Esta funciєn lee del array de pantallas y pinta la pantalla que
  656.        se le pasa en el argumento.
  657.     */
  658.  
  659.     struct sp_Rect rectangulo;
  660.     i8 x,y;
  661.     i8 l,n,v,t1,t2,t;
  662.     u16 i,j,n_pant;
  663.     u8 bd_atr, bd_pap, bd_ink;
  664.  
  665.     // Sэ, amigos, somos unos trampucheros. No hay 55 pantallas. Hay 45
  666.     // y se repiten 10.
  667.  
  668.     n_pant = r_pant % 45;
  669.  
  670.     // Quщ malos somos.
  671.  
  672.     // Calculamos el atributo de fondo correctamente de forma que INK > PAPER
  673.     // si esto no ocurre (puede pasar en las fases repetidas), se cambia.
  674.  
  675.     bd_atr = (level == 10) + (fases[n_pant].descriptor & 63);
  676.     bd_ink = bd_atr & 7;
  677.     bd_pap = bd_atr >> 3;
  678.     if (bd_ink < bd_pap) {
  679.         i = bd_pap;
  680.         bd_pap = bd_ink;
  681.         bd_ink = i;
  682.     }
  683.     bd_atr = bd_ink + (bd_pap << 3);
  684.  
  685.     // Ea, ahora el Anju se queda contento :-P
  686.  
  687.     // Calculamos el tile de fondo seg·n la altura:
  688.     if (level < 4)
  689.         t = 1;
  690.     else if (level < 7)
  691.         t = 5;
  692.     else if (level < 9)
  693.         t = 9;
  694.     else
  695.         t = 13;
  696.  
  697.     // Primero el fondo
  698.     for (y = 0; y < 10; y++)
  699.         for (x = 0; x < 12; x++) {
  700.             draw_tile4 (4 + (x<<1), 2 + (y<<1), bd_atr, t,0);
  701.         }
  702.  
  703.     // Objetos
  704.     for (i = 0; i < 10; i ++) {
  705.         if (fases[n_pant].obj[i] != 0) {
  706.             x = (u8) (fases[n_pant].obj[i] >> 12) & 15;
  707.             y = (u8) (fases[n_pant].obj[i] >> 8) & 15;
  708.             l = (u8) (fases[n_pant].obj[i] >> 4) & 15;
  709.             n = (u8) (fases[n_pant].obj[i] >> 1) & 7;
  710.  
  711.             if ( (fases[n_pant].obj[i] & 1) == 0 ) {
  712.                 // plataforma horizontal
  713.                 for (j = x; j < x + l; j ++)
  714.                     draw_tile4 (5 + (j<<1), 3 + (y<<1), bd_atr, 16 + t,1);
  715.                 for (j = x; j < x + l; j ++)
  716.                     draw_tile4 (4 + (j<<1), 2 + (y<<1), 64, 49 + (n<<2),0);
  717.             } else {
  718.                 // plataforma vertical
  719.                 for (j = y; j < y + l; j ++)
  720.                     draw_tile4 (5 + (x<<1), 3 + (j<<1), bd_atr, 16 + t,1);
  721.                 for (j = y; j < y + l; j ++)
  722.                     draw_tile4 (4 + (x<<1), 2 + (j<<1), 64, 49 + (n<<2),0);
  723.             }
  724.         }
  725.     }
  726.  
  727.     // Monedas:
  728.     // Act 20091201 :: Sєlo pintamos monedas si la habitaciєn NO ha sido visitada :-)
  729.  
  730.     if (!visitados [r_pant]) {
  731.         num_monedas = 0;
  732.  
  733.         rectangulo.width = rectangulo.height = 2;
  734.  
  735.         for ( i = 0; i < 10; i ++) {
  736.         //fases [n_pant].coin [i] = i;
  737.             // Primero copiamos los valores en nuestra estructura
  738.             monedas [i].type = fases [n_pant].coin [i]?1:0;
  739.  
  740.             if (fases [n_pant].coin [i] != 0) {
  741.                 // Y ahora dibujamos
  742.                 x = (u8) (fases [n_pant].coin [i] >> 4);
  743.                 y = (u8) (fases [n_pant].coin [i] & 15);
  744.                 monedas[i].x=(4+(x<<1))<<3;
  745.                 monedas[i].y=(2+(y<<1))<<3;
  746.  
  747.                 monedas[i].sp=sp_CreateSpr (sp_MASK_SPRITE, 3, 0, 1, TRANSPARENT);
  748.                 sp_MoveSprAbs (monedas[i].sp, spritesClip, coin_1a, 2+(y<<1), 4+(x<<1), 0, 0);
  749.  
  750.                 num_monedas ++;
  751.             }
  752.         }
  753.     }
  754.  
  755.     // Cargamos ahora los objetos mєviles
  756.     for (i = 0; i < 3; i ++) {
  757.         if (fases [n_pant].movil [i] == 0)      // Enemigo desactivado.
  758.             moviles [i].tipo = -1;
  759.         else {
  760.             v = (u8) (fases [n_pant].movil [i] & 1);
  761.             n = (u8) (fases [n_pant].movil [i] >> 1) & 7;
  762.             y = (u8) (fases [n_pant].movil [i] >> 4) & 15;
  763.             t1 = (u8) (fases [n_pant].movil [i] >> 12) & 15;
  764.             t2 = (u8) (fases [n_pant].movil [i] >> 8) & 15;
  765.  
  766.  
  767.             moviles [i].x = moviles [i].t1 = 32 + (t1 << 4);
  768.             moviles [i].t2 = 32 + (t2 << 4);
  769.             moviles [i].y = 16 + (y << 4);
  770.             moviles [i].vx = v*SPTW + 1;
  771.             moviles [i].tipo = n;
  772.  
  773.             if (n != 3)
  774.                 moviles [i].next_frame = enem_frames [ 1 + (n << 1) ];
  775.             moviles[i].current_frame=moviles[i].next_frame;
  776.  
  777.             sp_MoveSprAbs (sp_moviles [i], spritesClip, moviles[i].current_frame, 0,0,0,0);
  778.         }
  779.     }
  780.  
  781.     for(i=0;i<24;i++)
  782.     {
  783.         sp_AttrSet(2,i,sp_AttrGet(26,i));
  784.         sp_AttrSet(3,i,sp_AttrGet(27,i));
  785.         sp_AttrSet(28,i,sp_AttrGet(2,i));
  786.         sp_AttrSet(29,i,sp_AttrGet(3,i));
  787.     }
  788. }
  789.  
  790. i8 abs8 (i8 x) {
  791.     return x < 0 ? -x : x;
  792. }
  793.  
  794. void move_moviles () {
  795.     // Esto mueve los tres mєviles (en caso de estar definidos, o sea, con tipo != 0
  796.  
  797.     u8 i;
  798.  
  799.     for (i = 0; i < 3; i ++)
  800.         if ( moviles [i].tipo == 3) {
  801.             // Fanty
  802.             if (player.x > moviles [i].rx && moviles [i].vx < 100/*120*/*SPTW) {
  803.                 moviles [i].vx +=4*SPTW;
  804.                 moviles [i].next_frame = enem_frames [ 1 + (moviles [i].tipo << 1) ];
  805.             } else if (player.x < moviles [i].rx && moviles [i].vx > -100/*120*/*SPTW) {
  806.                 moviles [i].vx -=4*SPTW;
  807.                 moviles [i].next_frame = enem_frames [ moviles [i].tipo << 1 ];
  808.             }
  809.  
  810.             if (player.y > moviles [i].ry && moviles [i].vy < 100/*120*/*SPTW)
  811.                 moviles [i].vy +=4*SPTW;
  812.             else if (player.y < moviles [i].ry && moviles [i].vy > -100/*120*/*SPTW)
  813.                 moviles [i].vy -=4*SPTW;
  814.  
  815.             moviles [i].rx += moviles [i].vx;
  816.             moviles [i].ry += moviles [i].vy;
  817.     // Wrap around
  818.  
  819.     if (moviles [i].rx <= 1088) moviles [i].rx = 14270;
  820.     if (moviles [i].rx >= 14272) moviles [i].rx = 1090;
  821.  
  822.             moviles [i].x = (u8) (moviles [i].rx >> 6);
  823.             moviles [i].y = (u8) (moviles [i].ry >> 6);
  824.         } else if ( moviles [i].tipo > -1 && !( player.estado & EST_EXIT )) {
  825.             // Franky o Vampy o Wolfi
  826.             moviles [i].x += moviles [i].vx;
  827.             if ( moviles [i].x <= moviles [i].t1) {
  828.                 moviles [i].vx = abs8 (moviles [i].vx);
  829.                 moviles [i].next_frame = enem_frames [ 1 + (moviles [i].tipo << 1) ];
  830.             }
  831.  
  832.             if ( moviles [i].x >= moviles [i].t2) {
  833.                 moviles [i].vx = -abs8 (moviles [i].vx);
  834.                 moviles [i].next_frame = enem_frames [ moviles [i].tipo << 1 ];
  835.             }
  836.         }
  837. }
  838.  
  839. u8 game (u8 n_pant) {
  840.     u8 salida;
  841.     u8 aux;
  842.     u8 fade;
  843.     u16 i,j,idx;
  844.     u16 type;
  845.     u16 pause,pause_cnt;
  846.     u16 arrow_yoff;
  847.        
  848.         u8 curtime,oldtime,logictime,logicframe;
  849.         oldtime = time()-1;
  850.        
  851.     salida=0;
  852.     flag1 = 0;
  853.     idx=0;
  854.  
  855.     player.x = 32 << 6;
  856.     player.y = 144 << 6;
  857.     player.vy = 0;
  858.     player.g = 32*SPTW; //8;
  859.     player.vx = 0;
  860.     player.ax = 24*SPTW; //8;
  861.     player.rx = 32*SPTW; //8;
  862.     player.salto = 64*SPTW;
  863.     player.cont_salto = 1;
  864.     player.saltando = 0;
  865.     player.frame = 0;
  866.     player.subframe = 0;
  867.     player.facing = 1;
  868.     player.estado = EST_NORMAL;
  869.     player.ct_estado = 0;
  870.     player.ground=TRUE;
  871.     player.nojump=FALSE;
  872.  
  873.     todo_a_negro ();
  874.  
  875.     //sp_DelAllSpr();
  876.         clear_screen(0);
  877.         swap_screen();
  878.         clear_screen(0);
  879.         swap_screen();
  880.         set_sprite(0/*i*/,0,0,SPRITE_END);
  881.         sprites_start(); //яЁш ЁрчЁх°╕ээ√ї ёяЁрщЄрї ртЄюьрЄшўхёъш т√яюыэ хЄё  ъюяшЁютрэшх т√тюфшьющ уЁрЇшъш т фтр ¤ъЁрэр
  882.        
  883.         curbright=0;
  884.         pal_bright(BRIGHT_MIN);
  885.         pal_select(PAL_TILES);
  886.  
  887.     draw_screen (n_pant);
  888.     sp_UpdateNow();
  889.  
  890.     time8 = num_monedas * 8/3;//2;
  891.  
  892.     draw_lives (lives);
  893.     draw_time (time8);
  894.     draw_level (23,4,level,n_pant);
  895.     draw_score (total_coins);
  896.     draw_total_score (23,17,total_score);
  897.  
  898.     sp_PrintAtInv(0,5,71,110);
  899.     sp_PrintAtInv(0,23,71,111);
  900.  
  901.     maincounter = 0;
  902.     playing = 1;
  903.     fantact = 0;
  904.     vidaextra = 0;
  905.  
  906.     player.frame = uwol_r_2a;
  907.  
  908.     // Calculamos el tile de fondo seg·n la altura:
  909.     if (level < 4)
  910.         //wyz_play_music (zona1_data);
  911.         wyz_play_music (SONG_ZONA1);
  912.     else if (level < 7)
  913.         //wyz_play_music (zona2_data);
  914.         wyz_play_music (SONG_ZONA2);
  915.     else if (level < 9)
  916.         //wyz_play_music (zona3_data);
  917.         wyz_play_music (SONG_ZONA3);
  918.     else
  919.         //wyz_play_music (zona4_data);
  920.         wyz_play_music (SONG_ZONA4);
  921.  
  922.     // Si la habitaciєn ya fue visitada, mostramos las salidas y al fantasmilla.
  923.     if (visitados [n_pant]) {
  924.         num_monedas = 0;
  925.         time8 = 0;
  926.     }
  927.  
  928.     monedas_frame=0;
  929.  
  930.     //sp_SetSpriteClip(spritesClip);
  931.     fade=0;
  932.     pause=FALSE;
  933.     pause_cnt=25;
  934.     arrow_yoff=0;
  935.  
  936.         sp_MoveSprAbs(arrow_l,spritesClip,arrow_1a,0,0,0,0);
  937.         sp_MoveSprAbs(arrow_r,spritesClip,arrow_1a,0,0,0,0);
  938.  
  939.     while (playing) {
  940.         maincounter ++;     // Como es un u8, irс siempre de 0 a 255, con ciclos potencias de 2.
  941.  
  942.         //if(fade==2) fade_screen(FALSE);
  943.         //if(fade<10) fade++;
  944.                 if(pause_cnt) pause_cnt--;
  945.  
  946.         //fade_into(needed_pal);
  947.                 if(!pause) fade_into();
  948.                 if (curbright>MAXCURBRIGHT) curbright = MAXCURBRIGHT; //схыюЄр юЄ тч Єш  ьюэхЄюъ Єюы№ъю эр 1 ЇЁхщь, яюЄюь єсшЁрхЄё 
  949.                
  950.         j = joyfunc(); // Leemos del teclado
  951.        
  952.         if((j^0xffff)&sp_START)
  953.         {
  954.                 if(!pause_cnt)
  955.                 {
  956.                         pause^=TRUE;
  957.                         pause_cnt=25;
  958.                         wyz_play_sound( 7, CANAL_FX );
  959.                         if(pause) //тїюфшь т ярєчє
  960.                         {
  961.                                         /*for(i=0;i<64;i++)
  962.                                         {
  963.                                                 j=(((needed_pal[i]&0x0f00)>>8)+((needed_pal[i]&0x00f0)>>4)+((needed_pal[i]&0x000f)))/3;
  964.                                                 needed_pal[i]=j|(j<<4)|(j<<8);
  965.                                         }*/
  966.                                         curbright=4;
  967.                                         pal_bright(BRIGHT_MIN+1/*curbright/4*/);
  968.                         }
  969.                         else //т√їюфшь шч ярєч√
  970.                         {
  971.                                 //fade_screen(FALSE); //sets target palette to default and fades in
  972.                         }
  973.                 }
  974.         }
  975.        
  976.         if(pause)
  977.         {
  978.                 vsync();
  979.                         //update_palette();
  980.                 continue;
  981.         }
  982.  
  983.         if ( !(maincounter & 31)) {
  984.             if (time8 > 0) {
  985.                 time8 --;
  986.                 draw_time (time8);
  987.             } else {
  988.                 // бCuando se acaba el tiempo sale el fanti!
  989.                 if (time8 == 0) {
  990.                     wyz_stop_sound ();
  991.                                         //wyz_play_music (fantasma_data);
  992.                                         wyz_play_music (SONG_FANTASMA);
  993.  
  994.                     time8 --;
  995.  
  996.                     // Lєgica: buscamos el primer enemigo "vacэo". De no haberlo,
  997.                     // se sustituye el ·ltimo enemigo por fanti.
  998.  
  999.                     idx = 2;
  1000.  
  1001.                     for ( i = 0; i < 3; i ++)
  1002.                         if (moviles [i].tipo == -1) {
  1003.                             idx = i;
  1004.                             moviles [idx].x = 127;
  1005.                             moviles [idx].y = 87;
  1006.                         }
  1007.  
  1008.                     // Borramos el sprite:
  1009.                     sp_MoveSprAbs (sp_moviles [idx], spritesClip, 0,0,0,0,0);
  1010.                     sp_DeleteSpr (sp_moviles [idx]);
  1011.                     moviles [idx].rx = moviles[idx].x << 6;
  1012.                     moviles [idx].ry = moviles[idx].y << 6;
  1013.  
  1014.                     // Creamos a fanti:
  1015.                     sp_moviles [idx] = sp_CreateSpr(sp_MASK_SPRITE, 3, fanti_r_1a, 2, TRANSPARENT);
  1016.  
  1017.                     fantact = 1;
  1018.  
  1019.                     //sp_MoveSprAbs (sp_moviles [idx], spritesClip, 0, moviles [idx].y >> 3, moviles [idx].x >> 3, moviles [idx].x & 7, moviles [idx].y & 7);
  1020.                     moviles [idx].current_frame = moviles [idx].next_frame = fanti_r_1a;
  1021.                     moviles [idx].tipo = 3;
  1022.  
  1023.                     // бlisto!
  1024.                 }
  1025.             }
  1026.         }
  1027.  
  1028.         sp_UpdateNow();
  1029.  
  1030.         /* Move sprites */
  1031.         curtime = time();
  1032.         logictime = curtime-oldtime;
  1033.         oldtime = curtime;
  1034.         for (logicframe = 0 ; logicframe < logictime; logicframe++)
  1035.         {
  1036.                
  1037.         if ( !(player.estado & EST_MUR) )
  1038.             move (j);
  1039.         else {
  1040.             salida = 2;
  1041.             death_sequence ();
  1042.         }
  1043.  
  1044.         move_moviles ();
  1045.  
  1046.         x = player.x >> 6;
  1047.         y = player.y >> 6;
  1048.  
  1049.         /* Collisions & game mechanics: */
  1050.  
  1051.         if ( player.estado & EST_PARP ) {
  1052.             // Duraciєn de la inmunidad:
  1053.             player.ct_estado --;
  1054.             if (player.ct_estado == 0) {
  1055.                 player.estado = player.estado & (~EST_PARP);
  1056.                 vidaextra = 0;
  1057.             }
  1058.         }
  1059.  
  1060.         if ( !( player.estado & EST_PARP ) && !( player.estado & EST_MUR ) &&!cheat)        // Colisiєn con enemigos:
  1061.             for ( i = 0; i < 3; i ++ )
  1062.                 if ( moviles [i].tipo > -1 && ( !( player.estado & EST_EXIT ) || (fantact && i == idx) )  ) {
  1063.                     if (y >= moviles [i].y - 14 && y <= moviles [i].y + 14 && x >= moviles [i].x - 14 && x <= moviles [i].x + 14) {
  1064.                         if ( !(player.estado & EST_NUDE) ) {
  1065.                             player.estado |= EST_NUDE;
  1066.                             player.estado |= EST_PARP;                  // Parpadeamos inmunes.
  1067.                             player.ct_estado = 32*3/2;                      // Tiempo de inmunidad.
  1068.  
  1069.                             if (time8 >= 0) {
  1070.                                 do {
  1071.                                     xcami = 32 + ((rand () % 12) << 4);
  1072.                                     ycami = 16 + ((1 + (rand () % 8)) << 4);
  1073.                                 } while ( sp_AttrGet ( xcami >> 3, ycami >> 3) > 63 );
  1074.  
  1075.                                 rectangulo.row_coord = ycami >> 3;
  1076.                                 rectangulo.col_coord = xcami >> 3;
  1077.                                 sp_GetTiles ( &rectangulo, tile_buffer01 );
  1078.                                 draw_tile4 (xcami >> 3, ycami >> 3, 22, 85,0);
  1079.                             } else {
  1080.                                 xcami = ycami = 0;
  1081.                             }
  1082.  
  1083.                             // El jugador "rebota" una poca.
  1084.                             player.vy = - 4*SPTW * (player.salto);
  1085.                             player.vx = ((player.x >> 6) - moviles [i].x) * (16*SPTW);
  1086.                         } else {
  1087.                             player.vy = - 7 * (player.salto);
  1088.                             lives --;
  1089.  
  1090.                             if (lives >= 0)
  1091.                                 draw_lives (lives);
  1092.  
  1093.                             player.estado |= EST_MUR;
  1094.                             player.frame = uwolmuete_1a;
  1095.                         }
  1096.                         wyz_play_sound (1, CANAL_FX);
  1097.                         moviles [i].vx =- moviles [i].vx;           // El enemigo se da media vuelta.
  1098.                     }
  1099.                 }
  1100.  
  1101.         if ( player.estado & EST_NUDE )     // Colisiєn con la camiseta
  1102.             if (y >= ycami - 14 && y <= ycami + 15 && x >= xcami - 15 && x <= xcami + 15) {
  1103.                 wyz_play_sound (3, CANAL_FX);
  1104.                 total_score += 15;
  1105.                 draw_total_score (23,17,total_score);
  1106.  
  1107.                 player.estado &= (~EST_NUDE);
  1108.                 player.estado |= EST_PARP;
  1109.                 player.ct_estado = 32*3/2;
  1110.  
  1111.                 //draw_tile4 (xcami >> 3, ycami >> 3, fases[n_pant].descriptor & 63, 1 + (fases[n_pant].descriptor >> 4));
  1112.                 rectangulo.row_coord = ycami >> 3;
  1113.                 rectangulo.col_coord = xcami >> 3;
  1114.                 sp_PutTiles ( &rectangulo, tile_buffer01 );
  1115.             }
  1116.  
  1117.         // Vemos si colisionamos con alguna moneda.
  1118.         for (i = 0; i < 10; i ++)
  1119.             if (monedas [i].type != 0) {
  1120.                 xx=monedas[i].x;
  1121.                 yy=monedas[i].y;
  1122.                 type=monedas[i].type==1?monedas_anim[monedas_frame]:monedas_take_anim[(monedas[i].type-2)/2];
  1123.  
  1124.                 sp_MoveSprAbs(monedas[i].sp,spritesClip,type,yy>>3,xx>>3,xx&7,yy&7);
  1125.  
  1126.                 if(monedas[i].type>1)
  1127.                 {
  1128.                     monedas[i].type++;
  1129.                     if(monedas[i].type<12) monedas[i].y-=2; else monedas[i].y+=2;
  1130.                     if(monedas[i].type>20)
  1131.                     {
  1132.                         monedas [i].type = 0;
  1133.                         sp_DeleteSpr(monedas[i].sp);
  1134.                         monedas[i].sp=NULL;
  1135.                     }
  1136.                 }
  1137.                 else
  1138.                 {
  1139.                     if (y >= yy - 10 && y <= yy + 10 && x >= xx - 10 && x <= xx + 10) {
  1140.                         wyz_play_sound (5, CANAL_FX);
  1141.  
  1142.                         monedas [i].type = 2;
  1143.                         num_monedas --;
  1144.                         total_coins ++;
  1145.                         draw_score (total_coins);
  1146.                         total_score ++;
  1147.                         draw_total_score (23,17,total_score);
  1148.                     }
  1149.                 }
  1150.             }
  1151.  
  1152.         if(!(maincounter&3))
  1153.         {
  1154.             monedas_frame=(monedas_frame+1)%monedas_frames;
  1155.         }
  1156.  
  1157.         if(player.estado&EST_EXIT)
  1158.         {
  1159.                 if ( sp_AttrGet ( 5, 19) < 64 && sp_AttrGet ( 6, 19) < 64)
  1160.                 {
  1161.                         sp_MoveSprAbs(arrow_l,spritesClip,arrow_1a,18,5,0,arrow_yoff);
  1162.                 }
  1163.                 if ( sp_AttrGet (25, 19) < 64 && sp_AttrGet (26, 19) < 64)
  1164.                 {
  1165.                         sp_MoveSprAbs(arrow_r,spritesClip,arrow_1a,18,25,0,arrow_yoff);
  1166.                 }
  1167.                 if(!(maincounter&3))
  1168.                 {
  1169.                         arrow_yoff++;
  1170.                         if(arrow_yoff>=3) arrow_yoff=0;
  1171.                 }
  1172.         }
  1173.        
  1174.         if(num_monedas==0) {
  1175.             // Si se acaban las monedas, presentamos las salidas.
  1176.             if ( !(player.estado & EST_EXIT) ) {
  1177.                 if ( sp_AttrGet ( 5, 19) < 64 && sp_AttrGet ( 6, 19) < 64)
  1178.                     draw_tile4 ( 5, 20, 86, level < 10 ? 113 : 123 ,0);
  1179.                 if ( sp_AttrGet (25, 19) < 64 && sp_AttrGet (26, 19) < 64)
  1180.                     draw_tile4 (25, 20, 86, level < 10 ? 117 : 123 ,0);
  1181.  
  1182.                 player.estado |= EST_EXIT;
  1183.  
  1184.                 if(salida!=2)
  1185.                 {
  1186.                     //for(i=0;i<64;i++) screen_pal[i]=0xffff;
  1187.                                         curbright = 6*4; //all white for one frame
  1188.                     wyz_play_sound (9, CANAL_FX);
  1189.                 }
  1190.  
  1191.                 // бSaca a todo el mundo de aquэ!
  1192.                 for ( i = 0; i < 3; i ++ )
  1193.                     if (!fantact || i != idx)
  1194.                         sp_MoveSprAbs (sp_moviles [i], spritesClip, 0, 0,0,0,0);
  1195.             }
  1196.         }
  1197.  
  1198.         // Retardo para quitar cafeэna cuando no hay bishos.
  1199.         if ( player.estado & EST_EXIT )
  1200.             for (i = 0; i < 126; i ++)
  1201.                 xt ++;
  1202.  
  1203.         // Salir IZQ/DER
  1204.         if ( player.estado & EST_EXIT_LEFT ) {
  1205.             salida = 0;
  1206.             playing = 0;
  1207.         } else if ( player.estado & EST_EXIT_RIGHT ) {
  1208.             salida = 1;
  1209.             playing = 0;
  1210.         }
  1211.  
  1212.         // Vidas extra a los 1000 y a los 2500
  1213.         aux = 0;
  1214.         if (total_score >= 1000 && !bonus1) {
  1215.             aux = 1;
  1216.             bonus1 = 1;
  1217.         }
  1218.         if (total_score >= 2500 && !bonus2) {
  1219.             aux = 1;
  1220.             bonus2 = 1;
  1221.         }
  1222.         if (aux) {
  1223.             player.estado |= EST_PARP;
  1224.             if(lives<99) lives ++;
  1225.             vidaextra = 1;
  1226.             player.ct_estado = 32*3/2;
  1227.             wyz_play_sound (3, CANAL_FX);
  1228.         }
  1229.         if (vidaextra)
  1230.             draw_lives (lives);
  1231.         } //logicframe loop
  1232.         /* Render */
  1233.  
  1234.         if ( !(player.estado & EST_PARP) || !(maincounter & 1) )
  1235.             sp_MoveSprAbs (sp_prueba, spritesClip, player.frame, y >> 3, x >> 3, x & 7, y & 7);
  1236.         else
  1237.             sp_MoveSprAbs (sp_prueba, spritesClip, player.frame, 0,0,0,0);  // Parpadeo :o)
  1238.  
  1239.         if ( !(player.estado & EST_EXIT) )
  1240.             for ( i = 0; i < 3; i ++ )
  1241.                 if ( moviles [i].tipo > -1) {
  1242.                     sp_MoveSprAbs (sp_moviles [i], spritesClip, moviles [i].current_frame, moviles
  1243. [i].y >> 3, moviles [i].x >> 3, moviles [i].x & 7, moviles [i].y & 7);
  1244.                     moviles [i].current_frame = moviles [i].next_frame;
  1245.                 }
  1246.  
  1247.         if ( (player.estado & EST_EXIT) && fantact) {
  1248.             sp_MoveSprAbs (sp_moviles [idx], spritesClip, moviles [idx].current_frame, moviles
  1249. [idx].y >> 3, moviles [idx].x >> 3, moviles [idx].x & 7, moviles [idx].y & 7);
  1250.             moviles [idx].current_frame = moviles [idx].next_frame;
  1251.         }
  1252.     }
  1253.  
  1254.     wyz_stop_sound ();
  1255.  
  1256.     fade_out ();
  1257.  
  1258.     for(i=0;i<10;i++) sp_DeleteSpr(monedas[i].sp);
  1259.  
  1260.     //sp_SetSpriteClip(NULL);
  1261.     sp_HideAllSpr();
  1262.  
  1263.     todo_a_negro ();
  1264.  
  1265.     if (fantact) {
  1266.         // Al carao fanti.
  1267.         sp_MoveSprAbs (sp_moviles [idx], spritesClip, 0,0,0,0,0);
  1268.         sp_DeleteSpr (sp_moviles [idx]);
  1269.  
  1270.         // Creamos sprite normal:
  1271.         sp_moviles [idx] = sp_CreateSpr(sp_MASK_SPRITE, 2, wolfi_1a, 2, TRANSPARENT);
  1272.  
  1273.         moviles [idx].current_frame = wolfi_1a;
  1274.     }
  1275.  
  1276.     // Tenemos que sacar los sprites del viewport
  1277.  
  1278.     sp_MoveSprAbs (sp_prueba, spritesClip, 0,0,0,0,0);
  1279.     if ( (player.estado & EST_EXIT) && fantact)
  1280.         sp_MoveSprAbs (sp_moviles [idx], spritesClip, 0,0,0,0,0);
  1281.  
  1282.     if ( flag1 == 0 || flag1 == 1 )
  1283.         total_score += (100 + 5 * time8);
  1284.  
  1285.     for (i = 0; i < 3; i ++)
  1286.         sp_MoveSprAbs (sp_moviles [i], spritesClip, 0, 0,0,0,0);
  1287.  
  1288.     if (lives < 0)
  1289.         salida = 3;
  1290.  
  1291.         sprites_stop();
  1292.  
  1293.     return salida;
  1294. }
  1295.  
  1296. void piramide (i8 npant) {
  1297.     u8 l;
  1298.     i8 c;
  1299.     u8 sx,sy;
  1300.     u16 i,fade;
  1301.  
  1302.     //wyz_play_music (piramide_data);
  1303.     wyz_play_music (SONG_PIRAMIDE);
  1304.  
  1305.     // Pintamos todo:
  1306.     //sp_ClearRect(sp_ClipStruct, 0, ' ', sp_CR_TILES);
  1307.     //sp_DelAllSpr();
  1308.         clear_screen(0);
  1309.         swap_screen();
  1310.         clear_screen(0);
  1311.         swap_screen();
  1312.         set_sprite(0/*i*/,0,0,SPRITE_END);
  1313.         sprites_start(); //яЁш ЁрчЁх°╕ээ√ї ёяЁрщЄрї ртЄюьрЄшўхёъш т√яюыэ хЄё  ъюяшЁютрэшх т√тюфшьющ уЁрЇшъш т фтр ¤ъЁрэр
  1314.        
  1315.         curbright=0;
  1316.         pal_bright(BRIGHT_MIN);
  1317.         pal_select(PAL_TILES);
  1318.        
  1319.     draw_level(2,level<10?12:11,level,n_pant);
  1320.  
  1321.  
  1322.     // Pirсmide
  1323.     j = 16;
  1324.     y = 5;
  1325.     l = 0;
  1326.     sx=0;
  1327.     sy=0;
  1328.  
  1329.     for (i = 0; i < 55; i ++) {
  1330.         if (i == l * (l + 1) / 2) {
  1331.             j --;
  1332.             x = j;
  1333.             y ++;
  1334.             l ++;
  1335.         }
  1336.  
  1337.         if (n_pant == i)
  1338.             {
  1339.                 c = 121+6;
  1340.                 sx=x;
  1341.                 sy=y;
  1342.             }
  1343.         else
  1344.             {
  1345.                 if (visitados [i])
  1346.                     c = 121+6;
  1347.                 else
  1348.                     c = 121;
  1349.             }
  1350.  
  1351.         sp_PrintAtInv (y,   x,   0,c);
  1352.         sp_PrintAtInv (y,   x+1, 0,c+1);
  1353.         sp_PrintAtInv (y,   x+2, 0,83);
  1354.         sp_PrintAtInv (y+1, x,   0,81);
  1355.         sp_PrintAtInv (y+1, x+1, 0,81);
  1356.         sp_PrintAtInv (y+1, x+2, 0,82);
  1357.  
  1358.         x += 2;
  1359.     }
  1360.  
  1361.     // Info stats
  1362.     sp_PrintAtInv (19, 10, 4, 106);
  1363.     sp_PrintAtInv (19, 11, 4, 107);
  1364.     sp_PrintAtInv (19, 12, 4, 108);
  1365.     sp_PrintAtInv (19, 13, 4, 109);
  1366.     sp_PrintAtInv (19, 14, 4, 103);
  1367.     sp_PrintAtInv (19, 15, 7, 99);
  1368.     sp_PrintAtInv (19, 16, 5, 89 + total_score / 10000);
  1369.     sp_PrintAtInv (19, 17, 5, 89 + (total_score % 10000) / 1000);
  1370.     sp_PrintAtInv (19, 18, 5, 89 + (total_score % 1000) / 100);
  1371.     sp_PrintAtInv (19, 19, 5, 89 + (total_score % 100) / 10);
  1372.     sp_PrintAtInv (19, 20, 5, 89 + (total_score % 10));
  1373.  
  1374.     sp_PrintAtInv (19, 4, 71, 110);
  1375.     sp_PrintAtInv (19, 5, 71, 99);
  1376.     sp_PrintAtInv (19, 6, 69, 89 + (lives / 10));
  1377.     sp_PrintAtInv (19, 7, 69, 89 + (lives % 10));
  1378.  
  1379.     sp_PrintAtInv (19, 24, 71, 111);
  1380.     sp_PrintAtInv (19, 25, 71, 99);
  1381.     sp_PrintAtInv (19, 26, 69, 89 + (total_coins / 100));
  1382.     sp_PrintAtInv (19, 27, 69, 89 + (total_coins % 100) / 10);
  1383.     sp_PrintAtInv (19, 28, 69, 89 + (total_coins % 10));
  1384.  
  1385.     j=0;
  1386.     fade=TRUE;
  1387.        
  1388.         swap_screen();
  1389.  
  1390.     // Esperamos a que se pulse alguna tecla de control
  1391.     do {
  1392.         sp_MoveSprAbs (sp_prueba, spritesClip, arrow_1a, sy-2, sx, 0, 4+(j>>2));
  1393.         sp_UpdateNow();
  1394.         if(fade)
  1395.         {
  1396.             //fade_screen(FALSE); //sets target palette to default and fades in
  1397.             fade_screen(); //palette is already default
  1398.             fade=FALSE;
  1399.         }
  1400.         j=(j+1)%12;
  1401.         i = joyfunc()^0xffff;
  1402.     } while ( !(i & (sp_FIRE|sp_START)));
  1403.  
  1404.     wyz_stop_sound ();
  1405.     wyz_play_sound(7, CANAL_FX);
  1406.  
  1407.     // Bonito
  1408.     fade_out ();
  1409.  
  1410.         sprites_stop();
  1411. }
  1412.  
  1413. i8 espera_activa (i16 espera) {
  1414.  
  1415.     // jL
  1416.  
  1417.     // Esta funciєn espera un rato o hasta que se pulse una tecla.
  1418.     // Si se pulsa una tecla, devuelve 0
  1419.  
  1420.     // Esta funciєn sєlo funciona en Spectrum.
  1421.     // en CPC no hay una interrupciєn cada 20ms, asэn que esto no
  1422.     // sirve "pa nс".
  1423.  
  1424.     i8 res = 1;
  1425.     if(espera<0)
  1426.     {
  1427.         espera=-espera;
  1428.         res=2;
  1429.     }
  1430.  
  1431.  
  1432.     while(espera>0)
  1433.     {
  1434.         vsync();
  1435.                 //update_palette();
  1436.                
  1437.         if ( ((joyfunc()^0xffff) & (sp_FIRE|sp_START)) && (res==1))
  1438.             {
  1439.                 res = 0;
  1440.                 break;
  1441.             }
  1442.         espera--;
  1443.     }
  1444.  
  1445.     return res;
  1446. }
  1447.  
  1448. /* Main */
  1449.  
  1450. void uwol_preinit_variables(void)
  1451. {
  1452.     play=0;
  1453.     playing=1;
  1454.     maincounter=0;
  1455. }
  1456.  
  1457. void uwolmain (void) {
  1458.     u16 i,j;
  1459.     i8 fl, show;
  1460.     //const u8 *scraddrr3;
  1461.         u8 scrnum;
  1462.     //const u8 *song;
  1463.         u8 songnum;
  1464.     u16 prevkey;
  1465.         u16 keycnt;
  1466.     const u16 seq[]={sp_UP,sp_UP,sp_DOWN,sp_DOWN,sp_LEFT,sp_RIGHT,sp_LEFT,sp_RIGHT};
  1467.     //const u8 *mus[]={menu_data,piramide_data,zona1_data,zona2_data,zona3_data,zona4_data,fantasma_data,gameover_data,endingko_data,endingok_data};
  1468.     u8 mus[]={SONG_MENU,SONG_PIRAMIDE,SONG_ZONA1,SONG_ZONA2,SONG_ZONA3,SONG_ZONA4,SONG_FANTASMA,SONG_GAMEOVER,SONG_ENDINGKO,SONG_ENDINGOK};
  1469.     u16 m,s;
  1470.  
  1471.     rectangulo.width = 2;
  1472.         rectangulo.height = 2;
  1473.  
  1474.     //scraddrr3=NULL;
  1475.         scrnum=0;
  1476.     //song=NULL;
  1477.         songnum=0;
  1478.  
  1479.     play = 1;
  1480.  
  1481.     /* Clip structure -- define it as small as possible! */
  1482.  
  1483.     spritesClipValues.row_coord = 2;
  1484.     spritesClipValues.col_coord = 4;
  1485.     spritesClipValues.height = 20;
  1486.     spritesClipValues.width = 24;
  1487.     spritesClip = &spritesClipValues;
  1488.  
  1489.     /* Create sprites */
  1490.  
  1491.     sp_prueba = sp_CreateSpr (sp_MASK_SPRITE, 3, uwol_r_2a, 1, TRANSPARENT);
  1492.  
  1493.     for ( i = 0; i < 3; i ++) {
  1494.         sp_moviles [i] = sp_CreateSpr(sp_MASK_SPRITE, 2, wolfi_1a, 2, TRANSPARENT);
  1495.         moviles [i].current_frame = wolfi_1a;
  1496.     }
  1497.  
  1498.         arrow_l=sp_CreateSpr(sp_MASK_SPRITE, 3, arrow_1a, 2, TRANSPARENT);
  1499.         arrow_r=sp_CreateSpr(sp_MASK_SPRITE, 3, arrow_1a, 2, TRANSPARENT);
  1500.  
  1501.     // Pochintro:
  1502.  
  1503.     //unpack_RAM3 (mojon_data);
  1504.         view_image(IMG_MOJON);
  1505.  
  1506.     wyz_play_sound (7, CANAL_FX);
  1507.     espera_activa (200);
  1508.     fade_out ();
  1509.  
  1510.     //unpack_RAM3 (credits_data);
  1511.         view_image(IMG_CREDITS);
  1512.     wyz_play_sound (7, CANAL_FX);
  1513.     espera_activa (500);
  1514.     fade_out ();
  1515.  
  1516.     cheat=FALSE;
  1517.  
  1518.     while (1) {
  1519.  
  1520.         // Aquэ tэtulo
  1521.  
  1522.         //unpack_RAM3 (title_data);
  1523.                 pal_bright(BRIGHT_MIN);
  1524.                 //pal_select(IMG_TITLE4WARP0);
  1525.                 draw_image(0,0,IMG_TITLE4WARP);
  1526.                 swap_screen();
  1527.                 view_image(IMG_TITLE4WARP_);
  1528.         //wyz_play_music (menu_data);
  1529.         wyz_play_music (SONG_MENU);
  1530.         j=0;
  1531.         prevkey=0;
  1532.         keycnt=0;
  1533.  
  1534.         while(1) //title warp and entering cheat code, fire or start to continue
  1535.         {
  1536.                         /*for(i=0;i<15;i++)
  1537.                         {
  1538.                                 screen_pal[i+49]=warp_palette[((i+j)%15)+1];
  1539.                                 needed_pal[i+49]=screen_pal[i+49];
  1540.                         }*/
  1541.                        
  1542.             //fade_into(needed_pal);
  1543.  
  1544.                         pal_select(PAL_TITLE4WARP0+((j>>1)&3));
  1545.             //vsync();
  1546.                         swap_screen();
  1547.                         //update_palette();
  1548.                
  1549.             j++;
  1550.             /*if((j%48)==0||(j%48)==24)
  1551.                         {
  1552.                                 vram_fill(PLANE_A_ADR+25*32*2,256+23*32+PALETTE_NUM(2),32,(j%48)==0?1:0);
  1553.                         }*/
  1554.  
  1555.             rand();
  1556.  
  1557.             i=joyfunc()^0xffff;
  1558.             if(!i) prevkey=0;
  1559.             if(prevkey) i=0;
  1560.             if(i&&!prevkey) prevkey=1;
  1561.  
  1562.             if(i)
  1563.             {
  1564.                 if(i&seq[keycnt]) keycnt++; else keycnt=0;
  1565.                 if(keycnt>=8)
  1566.                 {
  1567.                     cheat^=TRUE;
  1568.                     wyz_play_sound(5, CANAL_FX);
  1569.                     keycnt=0;
  1570.                 }
  1571.             }
  1572.             if(i&(sp_FIRE|sp_START)) break;
  1573.         }
  1574.         wyz_play_sound(10, CANAL_FX);
  1575.         wyz_stop_sound ();
  1576.         fade_out ();
  1577.         //vram_fill(PLANE_B_ADR,0,32*28,0);
  1578.                 //sp_ClearRect(sp_ClipStruct, 0, ' ', sp_CR_TILES);
  1579.                 clear_screen(0);
  1580.                 swap_screen();
  1581.                 clear_screen(0);
  1582.                 swap_screen();
  1583.  
  1584.                 select_image(IMG_TILES);
  1585.                
  1586.         if(!(joyfunc()&(sp_UP|sp_FIRE)))
  1587.         {
  1588.             //vram_fill(PLANE_A_ADR,0,32*28,0);
  1589.             //fade_screen(FALSE);
  1590.                         pal_bright(BRIGHT_MIN);
  1591.                         pal_select(PAL_TILES);
  1592.                         fade_screen();
  1593.  
  1594.             m=0;
  1595.             s=0;
  1596.             j=0;
  1597.             prevkey=0;
  1598.  
  1599.             while(1)
  1600.             {
  1601.                 vsync();
  1602.                                
  1603.                 //draw_tile(13,13,1);
  1604.                                
  1605.                 sp_PrintAtInv(11,12,0,!j?111:112);
  1606.                 sp_PrintAtInv(11,14,0,106);
  1607.                 sp_PrintAtInv(11,16,0,89+(s/10));
  1608.                 sp_PrintAtInv(11,17,0,89+(s%10));
  1609.                 sp_PrintAtInv(12,12,0,j==1?111:112);
  1610.                 sp_PrintAtInv(12,14,0,102);
  1611.                 sp_PrintAtInv(12,16,0,89+(m/10));
  1612.                 sp_PrintAtInv(12,17,0,89+(m%10));
  1613.  
  1614.                 i=joyfunc()^0xffff;
  1615.                 if(!i) prevkey=0;
  1616.                 if(prevkey) i=0;
  1617.                 if(i&&!prevkey) prevkey=1;
  1618.  
  1619.                 if(i&sp_LEFT)
  1620.                 {
  1621.                     if(!j&&s>0) s--;
  1622.                     if( j&&m>0) m--;
  1623.                 }
  1624.                 if(i&sp_RIGHT)
  1625.                 {
  1626.                     if(!j&&s<11) s++;
  1627.                     if( j&&m<10)  m++;
  1628.                 }
  1629.                 if(i&sp_UP)   j=0;
  1630.                 if(i&sp_DOWN) j=1;
  1631.                 if(i&sp_FIRE)
  1632.                 {
  1633.                     if(!j)
  1634.                     {
  1635.                         wyz_play_sound(s, CANAL_FX);
  1636.                     }
  1637.                     else
  1638.                     {
  1639.                         if(!m) wyz_stop_sound(); else wyz_play_music(mus[m-1]);
  1640.                     }
  1641.                 }
  1642.                                 swap_screen();
  1643.             }
  1644.         }
  1645.  
  1646.         // Empezamos
  1647.         n_pant = 0;
  1648.         level = 1;
  1649.         total_score = 0;
  1650.         total_coins = 0;
  1651.         lives = cheat?99:3;
  1652.         flag1 = 0;
  1653.         fl = 0;
  1654.         bonus1 = 0;
  1655.         bonus2 = 0;
  1656.  
  1657.         // player.estado = 0;
  1658.  
  1659.         for (i = 0; i < 55; i ++ )
  1660.             visitados [i] = 0;
  1661.  
  1662.         while (fl < 3) {
  1663.             piramide (n_pant);
  1664.             fl = game (n_pant);
  1665.  
  1666.             show = 0;
  1667.  
  1668.             if (fl == 0) {
  1669.                 visitados [n_pant] = 1;     // Marcamos como visitada la pantalla act.
  1670.                 n_pant = n_pant + level;
  1671.                 level ++;
  1672.             } else if (fl == 1) {
  1673.                 visitados [n_pant] = 1;     // Marcamos como visitada la pantalla act.
  1674.                 n_pant = n_pant + level + 1;
  1675.                 level ++;
  1676.             } else if (fl == 3) {
  1677.                 //scraddrr3 = gover_data; // Game over.
  1678.                                 scrnum = IMG_GOVER;
  1679.                 show = 1;
  1680.                 //song = gameover_data;
  1681.                                 songnum = SONG_GAMEOVER;
  1682.             }
  1683.  
  1684.             if (level == 11) {
  1685.                 // Salimos de la pirсmide, vamos a calcular si salimos de verdad o no.
  1686.                 if (total_coins < 256) {
  1687.                     //scraddrr3 = finbad_data; // Fin bad
  1688.                                         scrnum = IMG_FINBAD;
  1689.                     n_pant = 0;
  1690.                     level = 1;
  1691.                     show = 1;
  1692.                     //song = endingko_data;
  1693.                                         songnum = SONG_ENDINGKO;
  1694.                 } else {
  1695.                     fl = 4;
  1696.                     //scraddrr3 = fingoo_data; // Fin good
  1697.                                         scrnum = IMG_FINGOO;
  1698.                     show = 1;
  1699.                     //song = endingok_data;
  1700.                                         songnum = SONG_ENDINGOK;
  1701.                 }
  1702.             }
  1703.  
  1704.                         curbright = 0;
  1705.                         pal_bright(BRIGHT_MIN);
  1706.                         pal_select(PAL_TILES);
  1707.                        
  1708.             if (show) {
  1709.                 //unpack_RAM3 (scraddrr3);
  1710.                 view_image(scrnum);
  1711.                                 //wyz_play_music (song);
  1712.                                 wyz_play_music (songnum);
  1713.  
  1714.                 if(fl==3)
  1715.                 {
  1716.                     draw_total_score(15,10,total_score);
  1717.                     for(i=0;i<16;i++)
  1718.                     {
  1719.                                                 //fade_into(needed_pal);
  1720.                                                 fade_into();
  1721.                                                 vsync();
  1722.                                                 //update_palette();
  1723.                     }
  1724.                 }
  1725.  
  1726.                 espera_activa (fl == 3 ? -250 : 1500);
  1727.                 if (fl != 4) wyz_stop_sound ();
  1728.  
  1729.                 fade_out ();
  1730.                 //vram_fill(PLANE_B_ADR,0,32*28,0);
  1731.             }
  1732.         }
  1733.  
  1734.         if (fl == 4) {
  1735.             // The end!
  1736.             //unpack_RAM3 (finend_data);
  1737.                         view_image(IMG_FINEND);
  1738.             wyz_play_sound (7, CANAL_FX);
  1739.             espera_activa (1500);
  1740.             wyz_stop_sound ();
  1741.             fade_out ();
  1742.         }
  1743.     }
  1744. }
  1745.  
  1746. /*
  1747.  
  1748. Scary Monsters (And Super Creeps)
  1749. David Bowie
  1750.  
  1751. She had an horror of rooms
  1752. she was tired - you can't hide beat
  1753. When I looked in her eyes they were blue but nobody home
  1754.  
  1755. She could've been a killer
  1756. if she didn't walk the way she do, and she do
  1757. She opened strange doors that we'd never close again
  1758.  
  1759. She began to wail
  1760. jealousies scream
  1761. Waiting at the light - know what I mean
  1762.  
  1763. [CHORUS (twice)]
  1764. Scary monsters, super creeps
  1765. Keep me running, running scared
  1766.  
  1767. She asked me to stay
  1768. and I stole her room
  1769. She asked for my love
  1770. and I gave her a dangerous mind
  1771. Now she's stupid in the street
  1772. and she can't socialise
  1773. Well I love the little girl
  1774. and I'll love her till the day she dies
  1775.  
  1776. She wails
  1777. Jimmy's guitar sound
  1778. jealousies scream
  1779. Waiting at the light know what I mean
  1780.  
  1781. [CHORUS (twice)]
  1782.  
  1783. [CHORUS (twice)]
  1784.  
  1785. Run, Run, Run [ad lib]
  1786.  
  1787. */
  1788.