1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
|
/*
Copyright notice:
This is mine. I'm only letting you use it. Period. Feel free to rip off
any of the code you see fit, but have the courtesy to give me credit.
Otherwise great hairy beasties will rip your eyes out and eat your flesh
when you least expect it.
Jonny Goldman <jonathan@think.com>
Wed May 8 1991
*/
/* shot.c - handle movement, etc. of the shots. */
#include "vaders.h"
extern int paused;
#define MAXSHOTS 1
#define MAXVSHOTS 6
#define SHOTSIZE (8*scale)
typedef struct _ShotRec {
int x, y; /* Location of this shot. */
} ShotRec, *Shot;
ShotRec shots[MAXSHOTS], vshots[MAXVSHOTS];
XImage *vshot_image[2];
static int tick = 0;
int numshots; /* Number of shots currently flying. */
int numvshots; /* Number of shots currently flying. */
static void PaintShot(shot, gc)
Shot shot;
GC gc;
{
AddLine(shot->x, shot->y,
shot->x, shot->y + SHOTSIZE, gc);
}
static void PaintVshot(vshot, gc)
Shot vshot;
GC gc;
{
XPutImage(dpy, gamewindow, gc, vshot_image[tick],
0, 0, vshot->x, vshot->y, vshot_image[tick]->width, vshot_image[tick]->height);
}
void PaintAllShots()
{
int i;
for (i=0 ; i<numshots ; i++)
PaintShot(shots + i, shotgc);
for (i=0 ; i<numvshots ; i++)
PaintVshot(vshots + i, vshotgc);
}
static void DestroyShot(i)
int i;
{
PaintShot(shots + i, backgc);
numshots--;
shots[i] = shots[numshots];
}
static void DestroyVshot(i)
int i;
{
PaintVshot(vshots + i, backgc);
numvshots--;
vshots[i] = vshots[numvshots];
}
/*ARGSUSED*/
void MoveShots(closure, id)
Opaque closure;
XtIntervalId id;
{
int i, x, y, newy;
Shot shot;
if (closure != (Opaque) MoveShots) return;
if (!paused) {
if (numshots > 0)
shottimerid = XtAddTimeOut(shotwait, MoveShots, (Opaque) MoveShots);
else
shottimerid = 0;
for (i=0 ; i<numshots ; i++) {
shot = shots + i;
newy = shot->y - SHOTSIZE/2;
x = shot->x;
y = shot->y;
if (ShotHitsVader(x, y)
|| ShotHitsSpacer(x, y)
|| ShotHitsBuilding(x, y)
|| y < 0) {
DestroyShot(i);
i--; /* Ensures we don't skip moving a shot. */
} else {
PaintShot(shot, backgc);
shot->y = newy;
PaintShot(shot, shotgc);
}
}
}
}
Boolean VshotHitsShot(x, y)
int x, y;
{
int i, dx, dy;
Shot shot;
for (i=0; i<numshots; i++) {
shot = shots + i;
dx = shot->x;
dy = shot->y;
if(dx >= x && dx < x+vshot_image[tick]->width
&& dy >= y && dy < y+vshot_image[tick]->height) {
DestroyShot(i);
return TRUE;
}
}
return FALSE;
}
/*ARGSUSED*/
void MoveVshots(closure, id)
Opaque closure;
XtIntervalId id;
{
int i, x, y, newy;
Shot vshot;
if (closure != (Opaque) MoveVshots) return;
if (!paused) {
if (numvshots > 0)
vshottimerid = XtAddTimeOut(vshotwait, MoveVshots, (Opaque) MoveVshots);
else
vshottimerid = 0;
for (i=0 ; i<numvshots ; i++) {
vshot = vshots + i;
newy = vshot->y + 2*scale;
x = vshot->x;
y = vshot->y;
if (y>gameheight ||
VshotHitsShot(x, y) ||
ShotHitsBase(x,y) ||
ShotHitsBuilding(x,y)) {
DestroyVshot(i);
i--; /* Ensures we don't skip moving a shot. */
} else {
PaintVshot(vshot, backgc);
tick = tick ? 0 : 1;
vshot->y = newy;
PaintVshot(vshot, vshotgc);
tick = tick ? 0 : 1;
}
}
tick = tick ? 0 : 1;
}
}
void AddShot(x, y)
int x, y;
{
Shot shot;
if (numshots >= maxshots) return;
shot = shots + numshots;
numshots++;
shot->x = x;
shot->y = y-SHOTSIZE;
PaintShot(shot, shotgc);
if (shottimerid == 0)
shottimerid = XtAddTimeOut(shotwait, MoveShots, (Opaque) MoveShots);
}
void AddVshot(x, y)
int x, y;
{
Shot shot;
if (numvshots >= maxvshots) return;
shot = vshots + numvshots;
numvshots++;
shot->x = x;
shot->y = y;
PaintVshot(shot, vshotgc);
if (vshottimerid == 0)
vshottimerid = XtAddTimeOut(shotwait, MoveVshots, (Opaque) MoveVshots);
}
#include "sperma1.bit"
#include "sperma2.bit"
#include "spermb1.bit"
#include "spermb2.bit"
int ReadVshotImages()
{
vshot_image[0] = XCreateImage(dpy,
DefaultVisual(dpy, DefaultScreen(dpy)),
1,
XYBitmap,
0,
(scale == 1) ? sperma1_bits : sperma2_bits,
(scale == 1) ? sperma1_width : sperma2_width,
(scale == 1) ? sperma1_height : sperma2_height,
8, 0);
vshot_image[0]->bitmap_bit_order = LSBFirst;
vshot_image[0]->byte_order = LSBFirst;
vshot_image[1] = XCreateImage(dpy,
DefaultVisual(dpy, DefaultScreen(dpy)),
1,
XYBitmap,
0,
(scale == 1) ? spermb1_bits : spermb2_bits,
(scale == 1) ? spermb1_width : spermb2_width,
(scale == 1) ? spermb1_height : spermb2_height,
8, 0);
vshot_image[1]->bitmap_bit_order = LSBFirst;
vshot_image[1]->byte_order = LSBFirst;
return BitmapSuccess;
}
void InitShot()
{
shottimerid = 0;
numshots = 0;
vshottimerid = 0;
numvshots = 0;
if( ReadVshotImages() != BitmapSuccess) {
fprintf(stderr, _("Error reading vshot images.\n"));
exit(20);
}
}
void AddLine(fromx, fromy, tox, toy, gc)
int fromx, fromy, tox, toy;
GC gc;
{
XDrawLine(dpy, gamewindow, gc, fromx, fromy, tox, toy);
}
|