/* :ts=8 bk=0 * If you liked "Boing!", there's a better than even chance you'll like this. * * Leo L. Schwab 8608.6 */ #include #include #include #include #define REV 0L #define FRAMES 6 #define SPRHEIGHT 16 #define WORDSPERSPR (2 * SPRHEIGHT + 4) #define MAXX (640-32) #define MAXY (200-16) #define MAGIC1 33 #define MAGIC2 21 #define ever (;;) extern UWORD ballmask[], ball0[]; extern void *OpenLibrary(), *OpenWindow(), *AllocMem(), *GetMsg(), *ViewPortAddress(); extern long GetSprite(), VBeamPos(); struct NewWindow windef = { 0, 15, 300, 10, -1, -1, CLOSEWINDOW, WINDOWCLOSE | WINDOWDEPTH | WINDOWDRAG | ACTIVATE, NULL, NULL, (UBYTE *) "One moment....", NULL, NULL, 0, 0, 0, 0, WBENCHSCREEN }; /* Doing it this way is faster than saying (i+offset) % 6 */ UBYTE idx[] = { 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4 }; struct SimpleSprite spr[FRAMES]; struct Window *win; struct ViewPort *vp; UWORD *sprbuf; UWORD *sprites[FRAMES]; int vx[FRAMES], vy[FRAMES]; void *GfxBase, *IntuitionBase; main () { int i, offset = 0, flag = 0; void *msg; openstuff (); setupsprites (); rnd ((short) -VBeamPos()); /* Plant a seed */ for (i=0; i>\273\273 ", "Oing!"); for ever { /* * WaitTOF()'s presence way up here is significant. I used * have it down by the ChangeSprite() loop, but it flickered. * When it's up here, I get just the right amount of delay * after top-of-frame so that nothing glitches. */ WaitTOF (); if (msg = GetMsg (win -> UserPort)) { ReplyMsg (msg); closestuff (); return; } for (i=0; i MAXX) { /* spr.x is unsigned, so we have to cheat */ spr[i].x = (spr[i].x & 0x8000) ? 0 : MAXX; vx[i] = -vx[i]; } /* The shift by 2 is to slow vertical motion a bit */ if ((spr[i].y += (vy[i] >> 2)) > MAXY) { spr[i].y = MAXY; vx[i] = rnd (MAGIC2) - MAGIC2 / 2; vy[i] = -rnd (MAGIC1) - 5; } vy[i]++; /* Gravity */ } for (i=0; i UserPort); } else puts (str); closestuff (); exit (100); } /* * The following code segment was lifted (nearly) intact from the Alpha-9 * 1.2 README disk. Thanks to Jim Mackraz for the code, and also for * drawing all those ball sprites. */ setupsprites () { UWORD *cw; /* current position in buffer of sprite images */ UWORD *maskp; /* current position in ballmask */ UWORD *ballp; /* current position in ball0 data */ int frame, scan; if (!(sprbuf = AllocMem (2L * WORDSPERSPR * FRAMES, MEMF_CHIP))) die ("Can't allocate sprite buffer."); cw = sprbuf; /* current position at top of buffer */ ballp = ball0; /* ... top of data to be interleaved */ for (frame=0; frame