This commit is contained in:
Nyako 2024-04-15 21:56:54 -03:00 committed by GitHub
commit 757408648b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 124 additions and 5 deletions

View File

@ -956,6 +956,23 @@ int customlevelclass::findtrinket(int t)
return 0; return 0;
} }
int customlevelclass::findcoin(int t)
{
int coins = 0;
for (int i = 0; i < (int) customentities.size(); i++)
{
if (i == t)
{
return coins;
}
if (customentities[i].t == 8)
{
coins++;
}
}
return 0;
}
int customlevelclass::findcrewmate(int t) int customlevelclass::findcrewmate(int t)
{ {
int ttrinket=0; int ttrinket=0;
@ -1961,6 +1978,19 @@ int customlevelclass::numtrinkets(void)
return temp; return temp;
} }
int customlevelclass::numcoins(void)
{
int temp = 0;
for (size_t i = 0; i < customentities.size(); i++)
{
if (customentities[i].t == 8 && inbounds(&customentities[i]))
{
temp++;
}
}
return temp;
}
int customlevelclass::numcrewmates(void) int customlevelclass::numcrewmates(void)
{ {
int temp = 0; int temp = 0;

View File

@ -142,6 +142,7 @@ public:
void generatecustomminimap(void); void generatecustomminimap(void);
int findtrinket(int t); int findtrinket(int t);
int findcoin(int t);
int findcrewmate(int t); int findcrewmate(int t);
int findwarptoken(int t); int findwarptoken(int t);
void findstartpoint(void); void findstartpoint(void);
@ -155,6 +156,7 @@ public:
static const int numrooms = maxwidth * maxheight; static const int numrooms = maxwidth * maxheight;
int contents[40 * 30 * numrooms]; int contents[40 * 30 * numrooms];
int numtrinkets(void); int numtrinkets(void);
int numcoins(void);
int numcrewmates(void); int numcrewmates(void);
RoomProperty roomproperties[numrooms]; //Maxwidth*maxheight RoomProperty roomproperties[numrooms]; //Maxwidth*maxheight

View File

@ -48,6 +48,7 @@ editorclass::editorclass(void)
register_tool(EditorTool_WARP_LINES, "Warp Lines", "I", SDLK_i, false); register_tool(EditorTool_WARP_LINES, "Warp Lines", "I", SDLK_i, false);
register_tool(EditorTool_CREWMATES, "Crewmates", "O", SDLK_o, false); register_tool(EditorTool_CREWMATES, "Crewmates", "O", SDLK_o, false);
register_tool(EditorTool_START_POINT, "Start Point", "P", SDLK_p, false); register_tool(EditorTool_START_POINT, "Start Point", "P", SDLK_p, false);
register_tool(EditorTool_COINS, "Coins", "^2", SDLK_2, true);
static const short basic[] = { static const short basic[] = {
121, 121, 121, 121, 121, 121, 121, 160, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 160, 121, 121, 121, 121, 121, 121, 121,
@ -993,6 +994,10 @@ static void draw_entities(void)
font::print(PR_FONT_8X8, x, y, "////", 255 - help.glow, 255 - help.glow, 255 - help.glow); font::print(PR_FONT_8X8, x, y, "////", 255 - help.glow, 255 - help.glow, 255 - help.glow);
graphics.draw_rect(x, y, 32, 8, graphics.getRGB(255, 255, 255)); graphics.draw_rect(x, y, 32, 8, graphics.getRGB(255, 255, 255));
break; break;
case 8: // Coins
graphics.draw_grid_tile(graphics.grphx.im_tiles_white, 48, x, y, 8, 8, graphics.huetilegetcol());
graphics.draw_rect(x, y, 8, 8, graphics.getRGB(255, 164, 164));
break;
case 9: // Shiny Trinkets case 9: // Shiny Trinkets
graphics.draw_sprite(x, y, 22, 196, 196, 196); graphics.draw_sprite(x, y, 22, 196, 196, 196);
graphics.draw_rect(x, y, 16, 16, graphics.getRGB(255, 164, 164)); graphics.draw_rect(x, y, 16, 16, graphics.getRGB(255, 164, 164));
@ -1350,6 +1355,7 @@ static void draw_cursor(void)
case EditorTool_GRAVITY_LINES: case EditorTool_GRAVITY_LINES:
case EditorTool_ROOMTEXT: case EditorTool_ROOMTEXT:
case EditorTool_SCRIPTS: case EditorTool_SCRIPTS:
case EditorTool_COINS:
// 1x1 // 1x1
graphics.draw_rect(x, y, 8, 8, blue); graphics.draw_rect(x, y, 8, 8, blue);
break; break;
@ -1757,6 +1763,12 @@ void editorclass::draw_tool(EditorTools tool, int x, int y)
case EditorTool_START_POINT: case EditorTool_START_POINT:
graphics.draw_sprite(x, y, 184, graphics.col_crewcyan); graphics.draw_sprite(x, y, 184, graphics.col_crewcyan);
break; break;
case EditorTool_COINS:
graphics.draw_grid_tile(graphics.grphx.im_tiles_white, 48, x, y - 1, 8, 8, graphics.getRGB(255, 255, 0));
graphics.draw_grid_tile(graphics.grphx.im_tiles_white, 48, x + 9, y - 1, 8, 8, graphics.getRGB(255, 255, 0));
graphics.draw_grid_tile(graphics.grphx.im_tiles_white, 48, x, y + 8, 8, 8, graphics.getRGB(255, 255, 0));
graphics.draw_grid_tile(graphics.grphx.im_tiles_white, 48, x + 9, y + 8, 8, 8, graphics.getRGB(255, 255, 0));
break;
default: default:
break; break;
} }
@ -2462,6 +2474,9 @@ void editorclass::entity_clicked(const int index)
} }
break; break;
} }
case 8:
lclickdelay = 0;
break;
case 10: case 10:
// Checkpoints // Checkpoints
// If it's not textured as a checkpoint, then just leave it be // If it's not textured as a checkpoint, then just leave it be
@ -2645,6 +2660,9 @@ void editorclass::tool_place()
add_entity(levx, levy, tilex, tiley, 16, 0); add_entity(levx, levy, tilex, tiley, 16, 0);
lclickdelay = 1; lclickdelay = 1;
break; break;
case EditorTool_COINS:
add_entity(levx, levy, tilex, tiley, 8);
break;
default: default:
break; break;
} }

View File

@ -49,6 +49,7 @@ enum EditorTools
EditorTool_WARP_LINES, EditorTool_WARP_LINES,
EditorTool_CREWMATES, EditorTool_CREWMATES,
EditorTool_START_POINT, EditorTool_START_POINT,
EditorTool_COINS,
NUM_EditorTools NUM_EditorTools
}; };

View File

@ -1524,7 +1524,7 @@ void entityclass::createentity(int xp, int yp, int t, int meta1, int meta2, int
//Check if it's already been collected //Check if it's already been collected
entity.para = meta1; entity.para = meta1;
if (!INBOUNDS_ARR(meta1, collect) || collect[meta1]) return; if (coincollect.find(meta1) != coincollect.end()) return;
break; break;
case 9: //Something Shiny case 9: //Something Shiny
entity.rule = 3; entity.rule = 3;
@ -2657,10 +2657,7 @@ bool entityclass::updateentities( int i )
if (entities[i].state == 1) if (entities[i].state == 1)
{ {
music.playef(Sound_COIN); music.playef(Sound_COIN);
if (INBOUNDS_ARR(entities[i].para, collect)) coincollect.insert(entities[i].para);
{
collect[(int) entities[i].para] = true;
}
return disableentity(i); return disableentity(i);
} }

View File

@ -2,6 +2,7 @@
#define ENTITY_H #define ENTITY_H
#include <SDL.h> #include <SDL.h>
#include <set>
#include <string> #include <string>
#include <vector> #include <vector>
@ -175,6 +176,7 @@ public:
std::vector<blockclass> blocks; std::vector<blockclass> blocks;
bool flags[100]; bool flags[100];
bool collect[100]; bool collect[100];
std::set<int> coincollect;
bool customcollect[100]; bool customcollect[100];
int platformtile; int platformtile;

View File

@ -477,6 +477,23 @@ void Game::deletecustomlevelstats(void)
} }
} }
#define LOAD_SET_RENAME(SET_NAME, DEST) \
if (SDL_strcmp(pKey, #SET_NAME) == 0 && pText[0] != '\0') \
{ \
/* We're loading in 32-bit integers. If we need more than 16 chars,
* something is seriously wrong */ \
char buffer[16]; \
size_t start = 0; \
size_t i = 0; \
\
while (next_split_s(buffer, sizeof(buffer), &start, pText, ',')) \
{ \
DEST.insert(help.Int(buffer)); \
++i; \
} \
}
#define LOAD_ARRAY_RENAME(ARRAY_NAME, DEST) \ #define LOAD_ARRAY_RENAME(ARRAY_NAME, DEST) \
if (SDL_strcmp(pKey, #ARRAY_NAME) == 0 && pText[0] != '\0') \ if (SDL_strcmp(pKey, #ARRAY_NAME) == 0 && pText[0] != '\0') \
{ \ { \
@ -5747,6 +5764,8 @@ void Game::customloadquick(const std::string& savfile)
LOAD_ARRAY_RENAME(collect, obj.collect) LOAD_ARRAY_RENAME(collect, obj.collect)
LOAD_SET_RENAME(coincollect, obj.coincollect)
LOAD_ARRAY_RENAME(customcollect, obj.customcollect) LOAD_ARRAY_RENAME(customcollect, obj.customcollect)
if (SDL_strcmp(pKey, "finalmode") == 0) if (SDL_strcmp(pKey, "finalmode") == 0)
@ -6262,6 +6281,16 @@ bool Game::customsavequick(const std::string& savfile)
} }
xml::update_tag(msgs, "collect", collect.c_str()); xml::update_tag(msgs, "collect", collect.c_str());
std::string coincollect;
std::set<int>::iterator iterator = obj.coincollect.begin();
while (iterator != obj.coincollect.end()) {
{
coincollect += help.String(*iterator) + ",";
iterator++;
}
}
xml::update_tag(msgs, "coincollect", coincollect.c_str());
std::string customcollect; std::string customcollect;
for(size_t i = 0; i < SDL_arraysize(obj.customcollect); i++ ) for(size_t i = 0; i < SDL_arraysize(obj.customcollect); i++ )
{ {
@ -7528,6 +7557,11 @@ int Game::trinkets(void)
return temp; return temp;
} }
int Game::coins(void)
{
return (int) obj.coincollect.size();
}
int Game::crewmates(void) int Game::crewmates(void)
{ {
int temp = 0; int temp = 0;

View File

@ -483,6 +483,7 @@ public:
int deathseq, lifeseq; int deathseq, lifeseq;
int trinkets(void); int trinkets(void);
int coins(void);
int crewmates(void); int crewmates(void);
int savepoint, teleportxpos; int savepoint, teleportxpos;
bool teleport; bool teleport;

View File

@ -1865,6 +1865,9 @@ void mapclass::loadlevel(int rx, int ry)
case 3: // Disappearing platforms case 3: // Disappearing platforms
obj.createentity(ex, ey, 3); obj.createentity(ex, ey, 3);
break; break;
case 8: // Coins
obj.createentity(ex, ey, 8, cl.findcoin(edi));
break;
case 9: // Trinkets case 9: // Trinkets
obj.createentity(ex, ey, 9, cl.findtrinket(edi)); obj.createentity(ex, ey, 9, cl.findtrinket(edi));
break; break;

View File

@ -2390,6 +2390,26 @@ void gamerender(void)
); );
} }
bool show_coins = game.coins() > 0;
#ifndef NO_CUSTOM_LEVELS
show_coins = show_coins || (map.custommode && (cl.numcoins() > 0));
#endif
if (show_coins) {
int color = 255 - help.glow / 2;
font::print(PR_BOR | PR_RIGHT, 304, 231, help.String(game.coins()), color, color, 196);
if (!graphics.notextoutline) {
graphics.draw_grid_tile(graphics.grphx.im_tiles_white, 48, 310, 230, 8, 8, graphics.getRGB(0, 0, 0));
graphics.draw_grid_tile(graphics.grphx.im_tiles_white, 48, 312, 230, 8, 8, graphics.getRGB(0, 0, 0));
graphics.draw_grid_tile(graphics.grphx.im_tiles_white, 48, 311, 229, 8, 8, graphics.getRGB(0, 0, 0));
graphics.draw_grid_tile(graphics.grphx.im_tiles_white, 48, 311, 231, 8, 8, graphics.getRGB(0, 0, 0));
}
graphics.draw_grid_tile(graphics.grphx.im_tiles_white, 48, 311, 230, 8, 8, graphics.getRGB(color, color, 196));
}
if (map.roomtexton) if (map.roomtexton)
{ {
//Draw room text! //Draw room text!

View File

@ -1290,6 +1290,14 @@ void scriptclass::run(void)
position--; position--;
} }
} }
else if (words[0] == "ifcoins")
{
if (game.coins() >= ss_toi(words[1]))
{
load("custom_" + raw_words[2]);
position--;
}
}
else if (words[0] == "hidecoordinates") else if (words[0] == "hidecoordinates")
{ {
map.setexplored(ss_toi(words[1]), ss_toi(words[2]), false); map.setexplored(ss_toi(words[1]), ss_toi(words[2]), false);
@ -1437,6 +1445,7 @@ void scriptclass::run(void)
obj.collect[i] = false; obj.collect[i] = false;
obj.customcollect[i] = false; obj.customcollect[i] = false;
} }
obj.coincollect.clear();
game.deathcounts = 0; game.deathcounts = 0;
game.advancetext = false; game.advancetext = false;
game.hascontrol = true; game.hascontrol = true;
@ -3239,6 +3248,8 @@ void scriptclass::hardreset(void)
SDL_memset(obj.customcollect, false, sizeof(obj.customcollect)); SDL_memset(obj.customcollect, false, sizeof(obj.customcollect));
i = 100; //previously a for-loop iterating over collect/customcollect set this to 100 i = 100; //previously a for-loop iterating over collect/customcollect set this to 100
obj.coincollect.clear();
int theplayer = obj.getplayer(); int theplayer = obj.getplayer();
if (INBOUNDS_VEC(theplayer, obj.entities)){ if (INBOUNDS_VEC(theplayer, obj.entities)){
obj.entities[theplayer].tile = 0; obj.entities[theplayer].tile = 0;