mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-06-29 07:58:30 +02:00
a4d7fc017c
This refactors the roomtext code to (1) not use ad-hoc objects and (2) not use a separate length-tracking variable to keep track of the actual amount of roomtext in a room. What I mean by ad-hoc object is, instead of formally creating a fully-fledged struct or class and storing one vector containing that object, this game instead hacks together an object by storing each attribute of an object in different vectors. In the case of roomtext, instead of making a Roomtext object that has attributes 'x', 'y', and 'text', the 'text' attribute of each is stored in the vector 'roomtext', the 'x' attribute of each is stored in the vector 'roomtextx', and the 'y' attribute of each is stored in the vector 'roomtexty'. It's only an object in the sense that you can grab the attributes of each roomtext by using the same index across all three vectors. This makes it somewhat annoying to maintain and deal with, like when I wanted add sub-tile positions to roomtext in VVVVVV: Community Edition. Instead of being able to add attributes to an already-existing formalized Roomtext object, I would instead have to add two more vectors, which is inelegant. Or I could refactor the whole system, which is what I decided to do instead. Furthermore, this removes the separate length-tracking variable 'roomtextnumlines', which makes the code much more easy to maintain and deal with, as the amount of roomtext is naturally tracked by C++ instead of us having to keep track of the actual amount of roomtext manually.
43 lines
641 B
C++
43 lines
641 B
C++
#ifndef OTHERLEVEL_H
|
|
#define OTHERLEVEL_H
|
|
|
|
#include "Game.h"
|
|
#include "Entity.h"
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
struct Roomtext
|
|
{
|
|
int x, y;
|
|
std::string text;
|
|
};
|
|
|
|
class otherlevelclass
|
|
{
|
|
public:
|
|
enum
|
|
{
|
|
BLOCK = 0,
|
|
TRIGGER,
|
|
DAMAGE,
|
|
DIRECTIONAL,
|
|
SAFE,
|
|
ACTIVITY
|
|
};
|
|
|
|
void addline(std::string t);
|
|
std::vector<std::string> loadlevel(int rx, int ry , Game& game, entityclass& obj);
|
|
|
|
std::string roomname;
|
|
|
|
int roomtileset;
|
|
int i;
|
|
|
|
// roomtext thing in other level
|
|
bool roomtexton;
|
|
std::vector<Roomtext> roomtext;
|
|
};
|
|
|
|
#endif /* OTHERLEVEL_H */
|