Skip to content

Commit

Permalink
zzz, custom damage smoke particle, default text particle value #712
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Aug 30, 2024
1 parent f88cb93 commit 543d369
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 18 deletions.
12 changes: 10 additions & 2 deletions data/.wolf3d/N3Ddata.cdogscpn/map_objects.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,11 @@
"TicksPerFrame": 60
},
"Health": 0,
"DrawBelow": true
"DrawBelow": true,
"DamageSmoke": {
"Particle": "zzz",
"HealthThreshold": 1.0
}
},
{
"Name": "goat_sleep",
Expand All @@ -307,7 +311,11 @@
"TicksPerFrame": 60
},
"Health": 0,
"DrawBelow": true
"DrawBelow": true,
"DamageSmoke": {
"Particle": "zzz",
"HealthThreshold": 1.0
}
}
]
}
14 changes: 14 additions & 0 deletions data/.wolf3d/N3Ddata.cdogscpn/particles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Version": 3,
"Particles": [
{
"Name": "zzz",
"Type": "Text",
"Text": {
"Value": "z"
},
"Range": 40,
"GravityFactor": -0.1
}
]
}
6 changes: 5 additions & 1 deletion src/cdogs/emitter.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2016-2017, 2019 Cong Xu
Copyright (c) 2016-2017, 2019, 2024 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -71,6 +71,10 @@ void EmitterStart(Emitter *em, const AddParticle *data)
}
e.u.AddParticle.DZ = RAND_FLOAT(em->minDZ, em->maxDZ);
e.u.AddParticle.Spin = RAND_DOUBLE(em->minRotation, em->maxRotation);
if (strlen(e.u.AddParticle.Text) == 0 && em->p->Type == PARTICLE_TEXT)
{
strcpy(e.u.AddParticle.Text, em->p->u.Text.Value);
}
GameEventsEnqueue(&gGameEvents, e);
}

Expand Down
8 changes: 7 additions & 1 deletion src/cdogs/map_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
This file incorporates work covered by the following copyright and
permission notice:
Copyright (c) 2014, 2016-2017, 2019, 2021 Cong Xu
Copyright (c) 2014, 2016-2017, 2019, 2021, 2024 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -441,6 +441,11 @@ static bool TryLoadMapObject(MapObject *m, json_t *node, const int version)
json_t *dSmokeNode = json_find_first_label(node, "DamageSmoke");
if (dSmokeNode != NULL && dSmokeNode->child != NULL)
{
LoadStr(&m->DamageSmoke.ParticleClass, dSmokeNode->child, "Particle");
if (m->DamageSmoke.ParticleClass == NULL)
{
CSTRDUP(m->DamageSmoke.ParticleClass, "smoke_big");
}
LoadFloat(
&m->DamageSmoke.HealthThreshold, dSmokeNode->child,
"HealthThreshold");
Expand Down Expand Up @@ -558,6 +563,7 @@ void MapObjectsClear(CArray *classes)
CFREE(c->Wreck.MO);
CFREE(c->Wreck.Bullet);
CFREE(c->FootstepSound);
CFREE(c->DamageSmoke.ParticleClass);
CArrayTerminate(&c->DestroyGuns);
CArrayTerminate(&c->DestroySpawn);
}
Expand Down
3 changes: 2 additions & 1 deletion src/cdogs/map_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
This file incorporates work covered by the following copyright and
permission notice:
Copyright (c) 2013-2019, 2021 Cong Xu
Copyright (c) 2013-2019, 2021, 2024 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -119,6 +119,7 @@ typedef struct
} u;
CArray DestroySpawn; // of MapObjectDestroySpawn
struct {
char *ParticleClass;
float HealthThreshold; // Smoke if map object damaged below this ratio
} DamageSmoke;
} MapObject;
Expand Down
4 changes: 2 additions & 2 deletions src/cdogs/objs.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
This file incorporates work covered by the following copyright and
permission notice:
Copyright (c) 2013-2021 Cong Xu
Copyright (c) 2013-2021, 2024 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -498,7 +498,7 @@ void ObjAdd(const NMapObjectAdd amo)
o->thing.CPicFunc = MapObjectDraw;
MapTryMoveThing(&gMap, &o->thing, NetToVec2(amo.Pos));
EmitterInit(
&o->damageSmoke, StrParticleClass(&gParticleClasses, "smoke_big"),
&o->damageSmoke, StrParticleClass(&gParticleClasses, o->Class->DamageSmoke.ParticleClass),
svec2_zero(), -0.05f, 0.05f, 3, 3, 0, 0, 20);
o->isInUse = true;
LOG(LM_MAIN, LL_DEBUG,
Expand Down
37 changes: 28 additions & 9 deletions src/cdogs/particle.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2014-2017, 2019-2021 Cong Xu
Copyright (c) 2014-2017, 2019-2021, 2024 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -39,7 +39,7 @@ ParticleClasses gParticleClasses;
CArray gParticles;
#define MAX_PARTICLES 4096

#define VERSION 2
#define VERSION 3

// Particles get darker when below this height
#define PARTICLE_DARKEN_Z BULLET_Z
Expand Down Expand Up @@ -170,13 +170,32 @@ static void LoadParticleClass(
CPicLoadJSON(&c->u.Pic, json_find_first_label(node, "Pic")->child);
break;
case PARTICLE_TEXT:
c->u.TextColor = colorWhite;
tmp = NULL;
LoadStr(&tmp, node, "TextMask");
if (tmp != NULL)
c->u.Text.Mask = colorWhite;
if (version <= 2)
{
c->u.TextColor = StrColor(tmp);
CFREE(tmp)
tmp = NULL;
LoadStr(&tmp, node, "TextMask");
if (tmp != NULL)
{
c->u.Text.Mask = StrColor(tmp);
}
CFREE(tmp);
}
else
{
if (json_find_first_label(node, "Text"))
{
json_t *text = json_find_first_label(node, "Text")->child;
tmp = NULL;
LoadStr(&tmp, text, "Mask");
if (tmp != NULL)
{
c->u.Text.Mask = StrColor(tmp);
}
CFREE(tmp);

LoadStr(&c->u.Text.Value, text, "Value");
}
}
break;
default:
Expand Down Expand Up @@ -545,7 +564,7 @@ static void DrawParticle(const struct vec2i pos, const ThingDrawFuncData *data)
case PARTICLE_TEXT: {
FontOpts opts = FontOptsNew();
opts.HAlign = ALIGN_CENTER;
opts.Mask = p->Class->u.TextColor;
opts.Mask = p->Class->u.Text.Mask;
FontStrOpt(
p->u.Text, svec2i(pos.x, pos.y - (int)(p->Z / Z_FACTOR)), opts);
break;
Expand Down
8 changes: 6 additions & 2 deletions src/cdogs/particle.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2014-2015, 2017-2019, 2021 Cong Xu
Copyright (c) 2014-2015, 2017-2019, 2021, 2024 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -46,7 +46,11 @@ typedef struct
union
{
CPic Pic;
color_t TextColor;
struct
{
char *Value;
color_t Mask;
} Text;
} u;
// -1 is infinite range
int RangeLow;
Expand Down

0 comments on commit 543d369

Please sign in to comment.