|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T s
Length: 2170 (0x87a) Types: TextFile Names: »shot.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/X/Roids/shot.c«
/* shot.c - handle movement, etc. of the shots. */ #include "roids.h" #define MAXSHOTS 20 typedef struct _ShotRec { double x, y; /* Location of this shot. */ double vx, vy; /* Velocity of this shot. */ int count; /* Countdown of life remaining to this shot. */ } ShotRec, *Shot; ShotRec shots[MAXSHOTS]; static int numshots; /* Number of shots currently flying. */ static int shotcount; /* Initial value for life countdown. */ static void PaintShot(shot, gc) Shot shot; GC gc; { AddLine(rint(shot->x), rint(shot->y), rint(shot->x - shot->vx), rint(shot->y - shot->vy), gc); } void PaintAllShots() { int i; for (i=0 ; i<numshots ; i++) PaintShot(shots + i, shotgc); } static void DestroyShot(i) int i; { PaintShot(shots + i, backgc); numshots--; shots[i] = shots[numshots]; } void MoveShots(closure, id) Opaque closure; XtIntervalId id; { int i; double newx, newy; Shot shot; if (closure != (Opaque) MoveShots) return; if (numshots > 0) shottimerid = XtAddTimeOut(shotwait, MoveShots, (Opaque) MoveShots); else shottimerid = NULL; for (i=0 ; i<numshots ; i++) { shot = shots + i; newx = shot->x + shot->vx; newy = shot->y + shot->vy; if (LineHitsRock(rint(shot->x - shot->vx), rint(shot->y - shot->vy), rint(newx), rint(newy)) || --(shot->count) == 0) { DestroyShot(i); i--; /* Ensures we don't skip moving a shot. */ } else { PaintShot(shot, backgc); shot->x = newx < 0 ? newx + gamewidth : (newx > gamewidth ? newx - gamewidth : newx); shot->y = newy < 0 ? newy + gameheight : (newy > gameheight ? newy - gameheight : newy); PaintShot(shot, shotgc); } } } void AddShot(x, y, vx, vy) double x, y, vx, vy; { Shot shot; if (numshots >= maxshots) return; shot = shots + numshots; numshots++; shot->x = x; shot->y = y; shot->vx = vx; shot->vy = vy; shot->count = shotcount; if (shottimerid == NULL) shottimerid = XtAddTimeOut(shotwait, MoveShots, (Opaque) MoveShots); } InitShot() { shottimerid = NULL; shotcount = shotduration / shotwait; numshots = 0; }