1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 10:09:43 +01:00

Modify how enemy colors are set

While the last commit was an attempt at making colors be set better,
this one should help more. Basically, things that emitters emit now
copy the emitter's color. That means, if you change the color of the
emitter, what it emits will change as well. This means we don't have
to worry about setting the colour ourselves, just the enemy type.

`set_enemy_colour` is now called BEFORE setting the type, so the type's
color will override the room color. This is what we want -- in the
future there might be custom enemy types, and if you specify a specific
color, you probably want that color to be used.

But wait, don't the types usable in levels have their colors set? Well,
this commit also duplicates the editor enemy types and sets their
colors to `-1` so they'll use the room's color instead, or more
accurately, they'll use the color they had previously, which was the
room's enemy color.

With this system, old levels which use main game enemies will have the
correct colors -- the colors stored in their enemy types. And if it
becomes possible to make custom enemy types, if someone makes an
emitter which uses the room's color (by passing in color `-1`), the
enemies which it emits will use the room's color as well, since it will
copy what the emitter itself uses.

All of that just to say: colors are now handled a bit more sanely.
This commit is contained in:
AllyTally 2023-09-02 13:04:41 -03:00 committed by NyakoFox
parent 333524533d
commit 5409f0715f
2 changed files with 71 additions and 59 deletions

View file

@ -134,6 +134,18 @@ void entityclass::add_default_types(void)
{ {
EnemyType* type; EnemyType* type;
// Copies for the editor, without the color set:
create_type("custom_square", 78, -1, 1, 16, 16);
create_type("custom_circle", 88, -1, 1, 16, 16);
create_type("custom_disc", 36, -1, 1, 16, 16);
create_type("custom_glitch", 164, -1, 1, 16, 16);
create_type("custom_coin", 68, -1, 1, 16, 16);
create_type("custom_cross", 48, -1, 5, 16, 16);
create_type("custom_triangle", 176, -1, 1, 16, 16);
create_type("custom_ice", 168, -1, 1, 16, 16);
create_type("custom_heart", 112, -1, 5, 16, 16);
create_type("custom_broken_heart", 114, -1, 5, 16, 16);
create_type("square", 78, 7, 1, 16, 16); // Vibrating String Problem create_type("square", 78, 7, 1, 16, 16); // Vibrating String Problem
create_type("circle", 88, 11, 1, 16, 16); // Kids His Age Bounce create_type("circle", 88, 11, 1, 16, 16); // Kids His Age Bounce
create_type("disc", 36, 8, 1, 16, 16); // Security Sweep create_type("disc", 36, 8, 1, 16, 16); // Security Sweep
@ -302,27 +314,27 @@ const char* entityclass::legacy_id_to_entity(const int id)
switch (id) switch (id)
{ {
case 0: case 0:
return "square"; return "custom_square";
case 1: case 1:
return "circle"; return "custom_circle";
case 2: case 2:
return "disc"; return "custom_disc";
case 3: case 3:
return "glitch"; return "custom_glitch";
case 4: case 4:
return "coin"; return "custom_coin";
case 5: case 5:
return "cross"; return "custom_cross";
case 6: case 6:
return "triangle"; return "custom_triangle";
case 7: case 7:
return "ice"; return "custom_ice";
case 8: case 8:
return "heart"; return "custom_heart";
case 9: case 9:
return "broken_heart"; return "custom_broken_heart";
default: default:
return "square"; return "custom_square";
} }
} }
@ -432,10 +444,11 @@ void entityclass::set_enemy_colour(entclass* entity)
break; break;
} }
} }
else }
{
/* Okay, so we're not in a custom level. void entityclass::correct_emitter_colours(entclass* entity)
* Most colors are stored in the enemy type themselves, {
/* Most colors are stored in the enemy type themselves,
* because each enemy is pretty much only in a single room. * because each enemy is pretty much only in a single room.
* There's some special cases, though, like LIES and factory clouds, * There's some special cases, though, like LIES and factory clouds,
* so let's correct their colors to match the rooms. * so let's correct their colors to match the rooms.
@ -461,7 +474,6 @@ void entityclass::set_enemy_colour(entclass* entity)
entity->colour = 8; entity->colour = 8;
break; break;
} }
}
} }
void entityclass::resetallflags(void) void entityclass::resetallflags(void)
@ -1689,12 +1701,12 @@ entclass* entityclass::createentity(int xp, int yp, int t, int meta1, int meta2,
if (game.roomy == 111 && (game.roomx >= 113 && game.roomx <= 117)) if (game.roomy == 111 && (game.roomx >= 113 && game.roomx <= 117))
{ {
entity.setenemy(0); entity.setenemy(0);
set_enemy_colour(&entity); correct_emitter_colours(&entity);
} }
else if (game.roomx == 113 && (game.roomy <= 110 && game.roomy >= 108)) else if (game.roomx == 113 && (game.roomy <= 110 && game.roomy >= 108))
{ {
entity.setenemy(1); entity.setenemy(1);
set_enemy_colour(&entity); correct_emitter_colours(&entity);
} }
else else
{ {
@ -2430,7 +2442,6 @@ entclass* entityclass::createentity(int xp, int yp, int t, int meta1, int meta2,
const char* type = legacy_id_to_entity(customenemy); const char* type = legacy_id_to_entity(customenemy);
set_enemy_type(&entity, type); set_enemy_type(&entity, type);
set_enemy_colour(&entity); set_enemy_colour(&entity);
break;
} }
case 100: // Invalid enemy, but gets treated as a teleporter case 100: // Invalid enemy, but gets treated as a teleporter
entity.type = EntityType_TELEPORTER; entity.type = EntityType_TELEPORTER;
@ -2669,7 +2680,7 @@ bool entityclass::updateentities( int i )
{ {
entclass* entity = createentity(entities[i].xp+28, entities[i].yp, 1, 10, -1); entclass* entity = createentity(entities[i].xp+28, entities[i].yp, 1, 10, -1);
set_enemy_type(entity, "lies"); set_enemy_type(entity, "lies");
set_enemy_colour(entity); entity->colour = entities[i].colour;
entities[i].state = 1; entities[i].state = 1;
entities[i].statedelay = 12; entities[i].statedelay = 12;
} }
@ -2706,7 +2717,7 @@ bool entityclass::updateentities( int i )
{ {
entclass* entity = createentity(entities[i].xp, entities[i].yp, 1, 12, -1); entclass* entity = createentity(entities[i].xp, entities[i].yp, 1, 12, -1);
set_enemy_type(entity, "factory_clouds"); set_enemy_type(entity, "factory_clouds");
set_enemy_colour(entity); entity->colour = entities[i].colour;
entities[i].state = 1; entities[i].state = 1;
entities[i].statedelay = 16; entities[i].statedelay = 16;
} }

View file

@ -70,6 +70,7 @@ public:
const char* legacy_id_to_entity(int id); const char* legacy_id_to_entity(int id);
void set_enemy_type(entclass* entity, const char* type); void set_enemy_type(entclass* entity, const char* type);
void set_enemy_colour(entclass* entity); void set_enemy_colour(entclass* entity);
void correct_emitter_colours(entclass* entity);
void resetallflags(void); void resetallflags(void);