Annotation of researchv9/jtools/src/demo/asteroids/explode.c, revision 1.1

1.1     ! root        1: #include <jerq.h>
        !             2: #include "event.h"
        !             3: extern Bitmap *buildimage();
        !             4: extern Rectangle scaler();
        !             5: char expl4[]={
        !             6:        'R', -4, -4, 4+1, 4+1,
        !             7:        'p', 0, -1,
        !             8:        'p', 3, 0,
        !             9:        'p', 0, 0,
        !            10:        'p', 1, 3,
        !            11:        'p', 0, 0,
        !            12:        'p', 1, -1,
        !            13:        'p', 3, 0,
        !            14:        'p', 1, 0,
        !            15:        'p', 4, 1,
        !            16:        'p', 3, 2,
        !            17:        'p', 2, 0,
        !            18:        'p', -3, 0,
        !            19:        'p', -1, 3,
        !            20:        'p', 1, 0,
        !            21:        'p', -1, -1,
        !            22:        'p', 0, 1,
        !            23:        'p', 0, 0,
        !            24:        'p', 3, -1,
        !            25:        'p', 0, 0,
        !            26:        'p', 1, 3,
        !            27:        'p', 3, 1,
        !            28:        'p', -1, 1,
        !            29:        'p', 2, 3,
        !            30:        'p', 0, 3,
        !            31:        'p', 3, 2,
        !            32:        0};
        !            33: char expl8[]={
        !            34:        'R', -8, -8, 8+1, 8+1,
        !            35:        'p', -1, -3,
        !            36:        'p', 7, 1,
        !            37:        'p', -1, 0,
        !            38:        'p', 3, 7,
        !            39:        'p', 0, -1,
        !            40:        'p', 2, -3,
        !            41:        'p', 6, 0,
        !            42:        'p', 2, -1,
        !            43:        'p', 8, 3,
        !            44:        'p', 7, 5,
        !            45:        'p', 5, 0,
        !            46:        'p', -6, 1,
        !            47:        'p', -3, 7,
        !            48:        'p', 2, 0,
        !            49:        'p', -2, -3,
        !            50:        'p', 0, 3,
        !            51:        'p', 1, 1,
        !            52:        'p', 6, -3,
        !            53:        'p', 0, 0,
        !            54:        'p', 2, 6,
        !            55:        'p', 7, 2,
        !            56:        'p', -2, 2,
        !            57:        'p', 4, 6,
        !            58:        'p', -1, 6,
        !            59:        'p', 6, 4,
        !            60:        0};
        !            61: char expl12[]={
        !            62:        'R', -12, -12, 12+1, 12+1,
        !            63:        'p', -2, -4,
        !            64:        'p', 10, 2,
        !            65:        'p', -2, 1,
        !            66:        'p', 5, 11,
        !            67:        'p', 0, -2,
        !            68:        'p', 3, -5,
        !            69:        'p', 9, 1,
        !            70:        'p', 3, -2,
        !            71:        'p', 12, 4,
        !            72:        'p', 10, 8,
        !            73:        'p', 8, 0,
        !            74:        'p', -9, 2,
        !            75:        'p', -5, 11,
        !            76:        'p', 4, 0,
        !            77:        'p', -4, -4,
        !            78:        'p', 1, 5,
        !            79:        'p', 1, 2,
        !            80:        'p', 10, -5,
        !            81:        'p', 0, 0,
        !            82:        'p', 3, 9,
        !            83:        'p', 11, 3,
        !            84:        'p', -3, 3,
        !            85:        'p', 7, 9,
        !            86:        'p', -1, 9,
        !            87:        'p', 9, 6,
        !            88:        0};
        !            89: char expl16[]={
        !            90:        'R', -16, -16, 16+1, 16+1,
        !            91:        'p', -3, -6,
        !            92:        'p', 14, 3,
        !            93:        'p', -3, 1,
        !            94:        'p', 7, 14,
        !            95:        'p', 0, -3,
        !            96:        'p', 4, -7,
        !            97:        'p', 12, 1,
        !            98:        'p', 4, -3,
        !            99:        'p', 16, 6,
        !           100:        'p', 14, 10,
        !           101:        'p', 11, 0,
        !           102:        'p', -12, 3,
        !           103:        'p', -7, 14,
        !           104:        'p', 5, 1,
        !           105:        'p', -5, -6,
        !           106:        'p', 1, 7,
        !           107:        'p', 2, 3,
        !           108:        'p', 13, -7,
        !           109:        'p', 0, -1,
        !           110:        'p', 5, 12,
        !           111:        'p', 15, 5,
        !           112:        'p', -4, 4,
        !           113:        'p', 9, 12,
        !           114:        'p', -2, 12,
        !           115:        'p', 12, 8,
        !           116:        0};
        !           117: char expl20[]={
        !           118:        'R', -20, -20, 20+1, 20+1,
        !           119:        'p', -4, -8,
        !           120:        'p', 17, 4,
        !           121:        'p', -4, 2,
        !           122:        'p', 8, 18,
        !           123:        'p', 0, -4,
        !           124:        'p', 5, -9,
        !           125:        'p', 15, 2,
        !           126:        'p', 5, -4,
        !           127:        'p', 20, 8,
        !           128:        'p', 17, 13,
        !           129:        'p', 14, 0,
        !           130:        'p', -16, 4,
        !           131:        'p', -8, 18,
        !           132:        'p', 7, 1,
        !           133:        'p', -7, -8,
        !           134:        'p', 2, 8,
        !           135:        'p', 3, 4,
        !           136:        'p', 16, -9,
        !           137:        'p', 0, -1,
        !           138:        'p', 6, 15,
        !           139:        'p', 19, 6,
        !           140:        'p', -5, 5,
        !           141:        'p', 12, 16,
        !           142:        'p', -3, 15,
        !           143:        'p', 15, 11,
        !           144:        0};
        !           145: char expl25[]={
        !           146:        'R', -25, -25, 25+1, 25+1,
        !           147:        'p', -6, -10,
        !           148:        'p', 22, 6,
        !           149:        'p', -6, 3,
        !           150:        'p', 11, 23,
        !           151:        'p', -1, -6,
        !           152:        'p', 7, -12,
        !           153:        'p', 19, 3,
        !           154:        'p', 7, -6,
        !           155:        'p', 25, 10,
        !           156:        'p', 22, 17,
        !           157:        'p', 18, 0,
        !           158:        'p', -20, 5,
        !           159:        'p', -11, 23,
        !           160:        'p', 9, 2,
        !           161:        'p', -9, -10,
        !           162:        'p', 3, 11,
        !           163:        'p', 4, 6,
        !           164:        'p', 21, -12,
        !           165:        'p', 1, -2,
        !           166:        'p', 8, 19,
        !           167:        'p', 24, 8,
        !           168:        'p', -7, 7,
        !           169:        'p', 15, 20,
        !           170:        'p', -4, 19,
        !           171:        'p', 19, 14,
        !           172:        0};
        !           173: char *exim[]={
        !           174:        expl4, expl8, expl12, expl16, expl20, expl25, 0
        !           175: };
        !           176: #define        NIMAGE  (sizeof exim/sizeof (char *) -1)
        !           177: Bitmap *exseq[sizeof exim/sizeof (char *)];
        !           178: typedef struct{
        !           179:        Point   p;
        !           180:        char    image;
        !           181:        char    allocated;
        !           182: }Explosion;
        !           183: #define        NEXPL   16      /* known in event type */
        !           184: #define        EXPLTICKS       32
        !           185: Explosion ex[NEXPL];
        !           186: int    exadvance();
        !           187: initexplosion()
        !           188: {
        !           189:        register i;
        !           190:        for(i=0; i<NIMAGE; i++)
        !           191:                exseq[i]=buildimage(exim[i]);
        !           192:        for(i=0; i<NEXPL; i++)
        !           193:                ex[i].allocated=0;
        !           194: }
        !           195: exfree()
        !           196: {
        !           197:        register Bitmap **b;
        !           198:        for(b=exseq; b<&exseq[NIMAGE]; b++)
        !           199:                bfree(*b);
        !           200: }
        !           201: explode(p)
        !           202:        Point p;
        !           203: {
        !           204:        register i;
        !           205:        register Explosion *e;
        !           206:        for(i=0, e=ex; i<NEXPL; i++, e++)
        !           207:                if(e->allocated==0){
        !           208:                        if(addevent(newevent(), EXPLTICKS, exadvance, EEXPL|i)){
        !           209:                                e->p=p;
        !           210:                                e->allocated=1;
        !           211:                                e->image=0;
        !           212:                                exdraw(i);
        !           213:                        }
        !           214:                        break;
        !           215:                }
        !           216: }
        !           217: exdraw(i)
        !           218: {
        !           219:        register Bitmap *b=exseq[ex[i].image];
        !           220:        bitblt(b, b->rect, &display, add(transform(ex[i].p), b->rect.origin), F_XOR);
        !           221: }
        !           222: exadvance(x)
        !           223: {
        !           224:        register Explosion *e= &ex[x&=~EEXPL];
        !           225:        extern notdrawn;
        !           226:        exdraw(x);
        !           227:        if(++e->image >= NIMAGE){
        !           228:                e->allocated=0;
        !           229:                return 0;
        !           230:        }
        !           231:        exdraw(x);
        !           232:        --notdrawn;     /* minor kludge to keep time smooth */
        !           233:        return 1;
        !           234: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.