SuperSpaceInvaderTurboApoca.../headers/pixelManager.h
2022-01-06 15:20:37 +01:00

78 lines
2.9 KiB
C++

#ifndef GUARD_PIXELMANAGER_H
#define GUARD_PIXELMANAGER_H
#include <string>
#include "mingl/mingl.h"
#include "mingl/shape/line.h"
#include "mingl/shape/triangle.h"
#include "mingl/shape/rectangle.h"
#include "mingl/shape/circle.h"
#include "mingl/gui/sprite.h"
#include "mingl/gui/text.h"
#include "utils.h"
#include "playMode.h"
#include "menu.h"
using namespace std;
#define MIRROR(SP) mirrorData((SP).getPixelData(), (SP).getRowSize()), (SP).getRowSize()
class PixelManager{
public:
MinGL& window;
/*
* Sprites are not const because for some reason the texture is associated with coordinates,
* and we have no way to dissociate them...
* So the objects are constantly updated with new coordinates as they need to be drawn
* We used {} insead of {} for the constructor because the () makes the compiler think we declare methods
*
* (We could copy them every time, but I feel like copying image data every frame isn't great)
*/
nsGui::Sprite background{"assets/bg.si2"};
nsGui::Sprite rightHandOpen{"assets/hand_open.si2"};
nsGui::Sprite rightHandClosed{"assets/hand_closed.si2"};
nsGui::Sprite leftHandOpen{MIRROR(rightHandOpen)};
nsGui::Sprite leftHandClosed{MIRROR(rightHandClosed)};
explicit PixelManager(MinGL&);
void drawInvaderA(const Position& baseVector, unsigned size, const RGBAcolor& color) const;
void drawInvaderB(const Position& baseVector, unsigned size, const RGBAcolor& color) const;
void drawInvaderC(const Position& baseVector, unsigned size, const RGBAcolor& color) const;
void drawPlayer(unsigned x, unsigned width, const nsGraphics::RGBAcolor& color) const;
void drawMissile(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const;
void drawTorpedo(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const;
void drawSprite(const nsGui::Sprite& sprite, const Position& pos) const;
void displayButton(const Position& baseVector,const string& text,nsGraphics::RGBAcolor& color);
void displayText(const Position& pos, const string& text,const nsGraphics::RGBAcolor& color = nsGraphics::KWhite) const;
void displayMenu(const Position& pos, Menu& currentMenu);
void drawBackground() const;
void drawFPS(unsigned fps) const;
PlayMode showInitialMenu();
bool showDeathMenu() const;
unsigned getScreenHeight() const;
unsigned getScreenWidth() const;
void startFrame() const;
void endFrame() const;
void askPlayerNameMenu(playerID pID, string& name) const;
// y will be negative sometimes, so not unsigned
void drawGodBench(int y) const;
void drawGodRightHand(const Position& pos, bool closed= false) const;
void drawGodLeftHand(const Position& pos, bool closed= false) const;
private:
// Explanation for choices :
// non reference output : I don't think we have another choice than a std::move() here
vector<RGBAcolor> mirrorData(const vector<RGBAcolor>& inPixels, unsigned rowSize);
};
#endif