Skip to content

Commit

Permalink
Add rocket sprites for heatseeker (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Jun 12, 2014
1 parent 63f8b04 commit 4f425bf
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 29 deletions.
Binary file added graphics/rockets_7x7.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/cdogs/blit.c
Expand Up @@ -135,7 +135,8 @@ void BlitOld(int x, int y, PicPaletted *pic, void *table, int mode)
}
}

void BlitPicHighlight(GraphicsDevice *g, Pic *pic, Vec2i pos, color_t color)
void BlitPicHighlight(
GraphicsDevice *g, const Pic *pic, const Vec2i pos, const color_t color)
{
// Draw highlight around the picture
int i;
Expand Down Expand Up @@ -249,7 +250,7 @@ void BlitBackground(
}
}

void Blit(GraphicsDevice *device, Pic *pic, Vec2i pos)
void Blit(GraphicsDevice *device, const Pic *pic, Vec2i pos)
{
Uint32 *current = pic->Data;
pos = Vec2iAdd(pos, pic->offset);
Expand Down
5 changes: 3 additions & 2 deletions src/cdogs/blit.h
Expand Up @@ -66,7 +66,7 @@ void BlitOld(int x, int y, PicPaletted *pic, void *table, int mode);
void BlitBackground(
GraphicsDevice *device,
const Pic *pic, Vec2i pos, const HSV *tint, const bool isTransparent);
void Blit(GraphicsDevice *device, Pic *pic, Vec2i pos);
void Blit(GraphicsDevice *device, const Pic *pic, Vec2i pos);
void BlitMasked(
GraphicsDevice *device,
const Pic *pic,
Expand All @@ -75,7 +75,8 @@ void BlitMasked(
int isTransparent);
void BlitBlend(
GraphicsDevice *g, const Pic *pic, Vec2i pos, const color_t blend);
void BlitPicHighlight(GraphicsDevice *g, Pic *pic, Vec2i pos, color_t color);
void BlitPicHighlight(
GraphicsDevice *g, const Pic *pic, const Vec2i pos, const color_t color);
/* DrawPic - simply draws a rectangular picture to screen. I do not
* remember if this is the one that ignores zero source-pixels or not, but
* that much should be obvious.
Expand Down
40 changes: 25 additions & 15 deletions src/cdogs/bullet_class.c
Expand Up @@ -134,7 +134,7 @@ static void DrawMolotov(Vec2i pos, TileItemDrawFuncData *data)
PicManagerGetOldPic(&gPicManager, pic->picIndex));
}

static Pic *GetFlame(int id)
static const Pic *GetFlame(int id, Vec2i *offset)
{
TMobileObject *obj = CArrayGet(&gMobObjs, id);
CASSERT(obj->isInUse, "Cannot draw non-existent mobobj");
Expand All @@ -143,22 +143,35 @@ static Pic *GetFlame(int id)
obj->state.frame = rand();
}
const TOffsetPic *pic = &cFlamePics[obj->state.frame & 3];
Pic *p = PicManagerGetFromOld(&gPicManager, pic->picIndex);
p->offset.x = pic->dx;
p->offset.y = pic->dy - obj->z;
return p;
offset->x = pic->dx;
offset->y = pic->dy - obj->z;
return PicManagerGetFromOld(&gPicManager, pic->picIndex);
}

static Pic *GetBeam(int id)
static const Pic *GetBeam(int id, Vec2i *offset)
{
const TMobileObject *obj = CArrayGet(&gMobObjs, id);
CASSERT(obj->isInUse, "Cannot draw non-existent mobobj");
// Calculate direction based on velocity
const direction_e dir = RadiansToDirection(Vec2iToRadians(obj->vel));
const TOffsetPic *pic = &cBeamPics[obj->state.Beam][dir];
Pic *p = PicManagerGetFromOld(&gPicManager, pic->picIndex);
p->offset.x = pic->dx;
p->offset.y = pic->dy - obj->z;
const Pic *p;
// TODO: don't use SpriteName, don't use MuzzleFlash
if (obj->tileItem.drawData.u.MuzzleFlash.SpriteName)
{
p = PicManagerGetSprite(
&gPicManager,
obj->tileItem.drawData.u.MuzzleFlash.SpriteName,
dir);
offset->x = -p->size.x / 2;
offset->y = -p->size.y / 2 - obj->z;
}
else
{
const TOffsetPic *pic = &cBeamPics[obj->bulletClass->Beam][dir];
p = PicManagerGetFromOld(&gPicManager, pic->picIndex);
offset->x = pic->dx;
offset->y = pic->dy - obj->z;
}
return p;
}

Expand Down Expand Up @@ -855,10 +868,8 @@ void BulletInitialize(void)

b = &gBulletClasses[BULLET_HEATSEEKER];
b->Name = "heatseeker";
b->DrawFunc = (TileItemDrawFunc)DrawBullet;
b->DrawData.u.Bullet.Ofspic = OFSPIC_SNIPERBULLET;
b->DrawData.u.Bullet.UseMask = true;
b->DrawData.u.Bullet.Mask = colorRed;
b->GetPicFunc = GetBeam;
b->DrawData.u.MuzzleFlash.SpriteName = "rockets";
b->SpeedLow = b->SpeedHigh = 512;
b->RangeLow = b->RangeHigh = 60;
b->Power = 20;
Expand Down Expand Up @@ -1115,7 +1126,6 @@ void AddBulletDirectional(
TMobileObject *obj = CArrayGet(&gMobObjs, MobObjAdd(pos, player));
obj->vel = GetFullVectorsForRadians(dir2radians[dir]);
SetBulletProps(obj, z, type, flags);
obj->state.Beam = obj->bulletClass->Beam;
}

void BulletAdd(
Expand Down
13 changes: 9 additions & 4 deletions src/cdogs/draw.c
Expand Up @@ -243,7 +243,9 @@ static void DrawDebris(DrawBuffer *b, Vec2i offset)
t->x - b->xTop + offset.x, t->y - b->yTop + offset.y);
if (t->getPicFunc)
{
Blit(&gGraphicsDevice, t->getPicFunc(t->id), pos);
Vec2i offset;
const Pic *pic = t->getPicFunc(t->id, &offset);
Blit(&gGraphicsDevice, pic, Vec2iAdd(pos, offset));
}
else
{
Expand Down Expand Up @@ -302,7 +304,9 @@ static void DrawWallsAndThings(DrawBuffer *b, Vec2i offset)
t->x - b->xTop + offset.x, t->y - b->yTop + offset.y);
if (t->getPicFunc)
{
Blit(&gGraphicsDevice, t->getPicFunc(t->id), picPos);
Vec2i offset;
const Pic *pic = t->getPicFunc(t->id, &offset);
Blit(&gGraphicsDevice, pic, Vec2iAdd(picPos, offset));
}
else if (t->getActorPicsFunc)
{
Expand Down Expand Up @@ -433,8 +437,9 @@ static void DrawObjectiveHighlight(
color.a = (Uint8)alphaUnscaled;
if (ti->getPicFunc != NULL)
{
BlitPicHighlight(
&gGraphicsDevice, ti->getPicFunc(ti->id), pos, color);
Vec2i offset;
const Pic *pic = ti->getPicFunc(ti->id, &offset);
BlitPicHighlight(&gGraphicsDevice, pic, Vec2iAdd(pos, offset), color);
}
else if (ti->getActorPicsFunc != NULL)
{
Expand Down
7 changes: 4 additions & 3 deletions src/cdogs/objs.c
Expand Up @@ -76,7 +76,7 @@ CArray gMobObjs;

// Draw functions

Pic *GetObjectPic(int id)
const Pic *GetObjectPic(const int id, Vec2i *offset)
{
const TObject *obj = CArrayGet(&gObjs, id);

Expand All @@ -95,16 +95,17 @@ Pic *GetObjectPic(int id)
{
return NULL;
}
pic->offset = Vec2iScaleDiv(pic->size, -2);
*offset = Vec2iScaleDiv(pic->size, -2);
}
else if (pic == NULL)
{
// Default old pic
pic = PicManagerGetFromOld(&gPicManager, ofpic->picIndex);
*offset = pic->offset;
}
if (ofpic != NULL)
{
pic->offset = Vec2iNew(ofpic->dx, ofpic->dy);
*offset = Vec2iNew(ofpic->dx, ofpic->dy);
}
return pic;
}
Expand Down
2 changes: 0 additions & 2 deletions src/cdogs/objs.h
Expand Up @@ -140,8 +140,6 @@ typedef struct MobileObject
union
{
int frame;
// For beam bullets; which beam pic to use
BeamPic Beam;
} state;
int range;
int flags;
Expand Down
2 changes: 1 addition & 1 deletion src/cdogs/tile.h
Expand Up @@ -96,7 +96,7 @@ typedef enum
#define OBJECTIVE_SHIFT 3


typedef Pic *(*TileItemGetPicFunc)(int);
typedef const Pic *(*TileItemGetPicFunc)(int, Vec2i *);

// For actor drawing
typedef struct
Expand Down

0 comments on commit 4f425bf

Please sign in to comment.