130 lines
5.6 KiB
C++
130 lines
5.6 KiB
C++
#include <playMode.h>
|
|
#include "pixelManager.h"
|
|
#include "utils.h"
|
|
#include "god.h"
|
|
|
|
using namespace nsShape;
|
|
|
|
|
|
PixelManager::PixelManager(MinGL& a) : window(a) {
|
|
window.initGlut();
|
|
window.initGraphic();
|
|
}
|
|
|
|
void PixelManager::drawInvaderA(const Position& baseVector, unsigned size, const RGBAcolor& color) const {
|
|
float scale = size/(float)100;
|
|
window << Circle(Position(50*scale, 50*scale)+baseVector, 50*scale, nsGraphics::KGray);
|
|
window << Triangle(Position(35*scale, 50*scale)+baseVector, Position(15*scale, 25*scale)+baseVector, Position(15*scale, 75*scale)+baseVector, nsGraphics::KBlack);
|
|
window << Triangle(Position(25*scale, 50*scale)+baseVector, Position(10*scale, 25*scale)+baseVector, Position(10*scale, 75*scale)+baseVector, nsGraphics::KGray);
|
|
window << Triangle(Position(65*scale, 50*scale)+baseVector, Position(85*scale, 25*scale)+baseVector, Position(85*scale, 75*scale)+baseVector, nsGraphics::KBlack);
|
|
window << Triangle(Position(75*scale, 50*scale)+baseVector, Position(90*scale, 25*scale)+baseVector, Position(90*scale, 75*scale)+baseVector, nsGraphics::KGray);
|
|
window << Rectangle(Position(35*scale, 65*scale)+baseVector, Position(65*scale, 72*scale)+baseVector, nsGraphics::KBlack);
|
|
}
|
|
|
|
void PixelManager::drawInvaderB(const Position& baseVector, unsigned size, const RGBAcolor& color) const {
|
|
float scale = size/(float)100;
|
|
window << Circle(Position(50*scale, 50*scale)+baseVector, 50*scale, nsGraphics::KRed);
|
|
window << Rectangle(Position(25*scale, 30*scale)+baseVector, Position(45*scale, 40*scale)+baseVector, nsGraphics::KBlack);
|
|
window << Rectangle(Position(55*scale, 30*scale)+baseVector, Position(75*scale, 40*scale)+baseVector, nsGraphics::KBlack);
|
|
window << Rectangle(Position(35*scale, 65*scale)+baseVector, Position(65*scale, 72*scale)+baseVector, nsGraphics::KBlack);
|
|
}
|
|
|
|
void PixelManager::drawInvaderC(const Position& baseVector, unsigned size, const RGBAcolor& color) const {
|
|
float scale = size/(float)100;
|
|
window << Circle(Position(50*scale, 50*scale)+baseVector, 50*scale, nsGraphics::KGreen);
|
|
window << Circle(Position(35*scale, 35*scale)+baseVector, 10*scale, nsGraphics::KBlack);
|
|
window << Circle(Position(65*scale, 35*scale)+baseVector, 10*scale, nsGraphics::KBlack);
|
|
window << Rectangle(Position(35*scale, 65*scale)+baseVector, Position(65*scale, 72*scale)+baseVector, nsGraphics::KBlack);
|
|
}
|
|
|
|
void PixelManager::drawPlayer(unsigned x, unsigned width, const nsGraphics::RGBAcolor& color) const {
|
|
width = width-10-10;
|
|
width = width/2;
|
|
window << Triangle(Position(0+x, 720), Position(5+x, 720), Position(5+x, 720-PLAYER_HEIGHT/2), color);
|
|
window << Rectangle(Position(5+x, 720), Position(5+width+x, 720-PLAYER_HEIGHT/2), color);
|
|
window << Rectangle(Position(5+width+x, 720), Position(15+width+x, 720-PLAYER_HEIGHT), color);
|
|
window << Rectangle(Position(15+width+x, 720), Position(15+width*2+x, 720-PLAYER_HEIGHT/2), color);
|
|
window << Triangle(Position(15+width*2+x, 720), Position(15+width*2+x, 720-PLAYER_HEIGHT/2), Position(20+width*2+x, 720), color);
|
|
window << Triangle(Position(5+x,720-PLAYER_HEIGHT/2), Position(5+width+x,720-PLAYER_HEIGHT/2), Position(5+width+x,720-PLAYER_HEIGHT*0.9), color);
|
|
window << Triangle(Position(15+width+x,720-PLAYER_HEIGHT/2), Position(15+width*2+x,720-PLAYER_HEIGHT/2), Position(15+width+x,720-PLAYER_HEIGHT*0.9), color);
|
|
}
|
|
|
|
void PixelManager::askPlayerNameMenu(playerID pID, string& name) const {
|
|
cout << "ask for player " << (pID+1) << endl;
|
|
name = "Thomas";
|
|
}
|
|
|
|
void PixelManager::drawMissile(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const {
|
|
window << Rectangle(baseVector, baseVector + Position(width, width * PROJ_LENGTH_FACTOR), color);
|
|
}
|
|
|
|
void PixelManager::drawTorpedo(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const {
|
|
window << Rectangle(baseVector, baseVector + Position(width, width * PROJ_LENGTH_FACTOR), color);
|
|
}
|
|
|
|
void PixelManager::drawSprite(const nsGui::Sprite& sprite, const Position& pos) const {
|
|
// see pixelManager.h for the explanation of this hack
|
|
const_cast<nsGui::Sprite&>(sprite).setPosition(pos);
|
|
sprite.draw(window);
|
|
}
|
|
|
|
void PixelManager::drawBackground() const {
|
|
background.draw(window);
|
|
}
|
|
|
|
unsigned PixelManager::getScreenHeight() const {
|
|
return window.getWindowSize().getY();
|
|
}
|
|
|
|
unsigned PixelManager::getScreenWidth() const {
|
|
return window.getWindowSize().getX();
|
|
}
|
|
|
|
void PixelManager::startFrame() const {
|
|
window.clearScreen();
|
|
}
|
|
|
|
void PixelManager::endFrame() const {
|
|
window.finishFrame();
|
|
}
|
|
|
|
void PixelManager::drawGodBench(int y) const {
|
|
window << Rectangle(Position(0, y), Position(getScreenWidth(), y+GOD_BENCH_SIZE), nsGraphics::KGray);
|
|
}
|
|
|
|
void PixelManager::drawGodRightHand(const Position& pos, bool closed) const {
|
|
if(closed){
|
|
drawSprite(rightHandClosed, pos);
|
|
}else{
|
|
drawSprite(rightHandOpen, pos);
|
|
}
|
|
}
|
|
|
|
void PixelManager::drawGodLeftHand(const Position& pos, bool closed) const {
|
|
if(closed){
|
|
drawSprite(leftHandClosed, pos);
|
|
}else{
|
|
drawSprite(leftHandOpen, pos);
|
|
}
|
|
}
|
|
|
|
void PixelManager::displayText(const Position& pos, const string& text,const nsGraphics::RGBAcolor& color) const {
|
|
window << nsGui::Text(pos, text, color);
|
|
}
|
|
|
|
void PixelManager::drawFPS(unsigned fps) const {
|
|
window << nsGui::Text(Position(getScreenWidth()-100, 10), "FPS : "+ to_string(fps), nsGraphics::KWhite);
|
|
}
|
|
|
|
vector<RGBAcolor>
|
|
PixelManager::mirrorData(const vector<nsGraphics::RGBAcolor>& inPixels, unsigned rowSize) {
|
|
vector<RGBAcolor> outPixels;
|
|
outPixels.reserve(inPixels.size());
|
|
|
|
for(unsigned i=0;i<inPixels.size();i+=rowSize){
|
|
for(unsigned j=0;j<rowSize;++j) {
|
|
outPixels.push_back(inPixels[i + rowSize - j - 1]);
|
|
}
|
|
}
|
|
return std::move(outPixels);
|
|
} |