Changeset ebe70f1 in mainline for uspace/app/tetris/shapes.c


Ignore:
Timestamp:
2009-06-09T11:10:31Z (16 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f3afd24
Parents:
080ad7f
Message:

slightly cleanup the horrible mess of tetris
introduce colors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tetris/shapes.c

    r080ad7f rebe70f1  
    3737
    3838/** @addtogroup tetris
    39  * @{ 
     39 * @{
    4040 */
    4141/** @file
     
    5151#include "tetris.h"
    5252
    53 #define TL      -B_COLS-1       /* top left */
    54 #define TC      -B_COLS         /* top center */
    55 #define TR      -B_COLS+1       /* top right */
    56 #define ML      -1              /* middle left */
    57 #define MR      1               /* middle right */
    58 #define BL      B_COLS-1        /* bottom left */
    59 #define BC      B_COLS          /* bottom center */
    60 #define BR      B_COLS+1        /* bottom right */
     53#define TL  (-B_COLS - 1)  /* top left */
     54#define TC  (-B_COLS)      /* top center */
     55#define TR  (-B_COLS + 1)  /* top right */
     56#define ML  -1             /* middle left */
     57#define MR  1              /* middle right */
     58#define BL  (B_COLS - 1)   /* bottom left */
     59#define BC  B_COLS         /* bottom center */
     60#define BR  (B_COLS + 1)   /* bottom right */
    6161
    6262const struct shape shapes[] = {
    63         /* 0*/  { 7,    7,      { TL, TC, MR } },
    64         /* 1*/  { 8,    8,      { TC, TR, ML } },
    65         /* 2*/  { 9,    11,     { ML, MR, BC } },
    66         /* 3*/  { 3,    3,      { TL, TC, ML } },
    67         /* 4*/  { 12,   14,     { ML, BL, MR } },
    68         /* 5*/  { 15,   17,     { ML, BR, MR } },
    69         /* 6*/  { 18,   18,     { ML, MR, 2  } }, /* sticks out */
    70         /* 7*/  { 0,    0,      { TC, ML, BL } },
    71         /* 8*/  { 1,    1,      { TC, MR, BR } },
    72         /* 9*/  { 10,   2,      { TC, MR, BC } },
    73         /*10*/  { 11,   9,      { TC, ML, MR } },
    74         /*11*/  { 2,    10,     { TC, ML, BC } },
    75         /*12*/  { 13,   4,      { TC, BC, BR } },
    76         /*13*/  { 14,   12,     { TR, ML, MR } },
    77         /*14*/  { 4,    13,     { TL, TC, BC } },
    78         /*15*/  { 16,   5,      { TR, TC, BC } },
    79         /*16*/  { 17,   15,     { TL, MR, ML } },
    80         /*17*/  { 5,    16,     { TC, BC, BL } },
    81         /*18*/  { 6,    6,      { TC, BC, 2*B_COLS } }/* sticks out */
     63        /*  0 */  {  7,  7, { TL, TC, MR }, 0xff042d},
     64        /*  1 */  {  8,  8, { TC, TR, ML }, 0xff9304},
     65        /*  2 */  {  9, 11, { ML, MR, BC }, 0xbeff04},
     66        /*  3 */  {  3,  3, { TL, TC, ML }, 0x63ff04},
     67        /*  4 */  { 12, 14, { ML, BL, MR }, 0xce04ff},
     68        /*  5 */  { 15, 17, { ML, BR, MR }, 0xff04cf},
     69        /*  6 */  { 18, 18, { ML, MR, 2  }, 0x7604ff}, /* sticks out */
     70        /*  7 */  {  0,  0, { TC, ML, BL }, 0xff042d},
     71        /*  8 */  {  1,  1, { TC, MR, BR }, 0xff9304},
     72        /*  9 */  { 10,  2, { TC, MR, BC }, 0xbeff04},
     73        /* 10 */  { 11,  9, { TC, ML, MR }, 0xbeff04},
     74        /* 11 */  {  2, 10, { TC, ML, BC }, 0xbeff04},
     75        /* 12 */  { 13,  4, { TC, BC, BR }, 0xce04ff},
     76        /* 13 */  { 14, 12, { TR, ML, MR }, 0xce04ff},
     77        /* 14 */  {  4, 13, { TL, TC, BC }, 0xce04ff},
     78        /* 15 */  { 16,  5, { TR, TC, BC }, 0xff04cf},
     79        /* 16 */  { 17, 15, { TL, MR, ML }, 0xff04cf},
     80        /* 17 */  {  5, 16, { TC, BC, BL }, 0xff04cf},
     81        /* 18 */  {  6,  6, { TC, BC, 2 * B_COLS }, 0x7604ff}  /* sticks out */
    8282};
    8383
     
    8686 * taking the current board into account.
    8787 */
    88 int
    89 fits_in(const struct shape *shape, int pos)
     88int fits_in(const struct shape *shape, int pos)
    9089{
    9190        int *o = shape->off;
    92 
    93         if (board[pos] || board[pos + *o++] || board[pos + *o++] ||
    94             board[pos + *o])
     91       
     92        if ((board[pos]) || (board[pos + *o++]) || (board[pos + *o++]) ||
     93            (board[pos + *o]))
    9594                return 0;
     95       
    9696        return 1;
    9797}
     
    101101 * if `onoff' is 1, and off if `onoff' is 0.
    102102 */
    103 void
    104 place(const struct shape *shape, int pos, int onoff)
     103void place(const struct shape *shape, int pos, int onoff)
    105104{
    106105        int *o = shape->off;
    107 
    108         board[pos] = onoff;
    109         board[pos + *o++] = onoff;
    110         board[pos + *o++] = onoff;
    111         board[pos + *o] = onoff;
     106       
     107        board[pos] = onoff ? shape->color : 0x000000;
     108        board[pos + *o++] = onoff ? shape->color : 0x000000;
     109        board[pos + *o++] = onoff ? shape->color : 0x000000;
     110        board[pos + *o] = onoff ? shape->color : 0x000000;
    112111}
    113112
    114113/** @}
    115114 */
    116 
Note: See TracChangeset for help on using the changeset viewer.