changement de nom des fichier entityDraw et menuDraw
This commit is contained in:
		
							parent
							
								
									0692b91ffc
								
							
						
					
					
						commit
						e1e1af4e7e
					
				
							
								
								
									
										130
									
								
								src/drawEntity.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										130
									
								
								src/drawEntity.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,130 @@ | ||||
| #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); | ||||
| } | ||||
							
								
								
									
										64
									
								
								src/drawMenu.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								src/drawMenu.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,64 @@ | ||||
| #include <playMode.h> | ||||
| #include "pixelManager.h" | ||||
| #include "utils.h" | ||||
| #include "god.h" | ||||
| #include "mingl/shape/rectangle.h" | ||||
| 
 | ||||
| using namespace nsShape; | ||||
| using namespace nsGraphics; | ||||
| 
 | ||||
| void PixelManager::displayButton(const Position& baseVector,const string& text,nsGraphics::RGBAcolor& color){ | ||||
|     window << Rectangle(Position(190, 430)+baseVector, Position(310, 465)+baseVector,  KGray); | ||||
| 	window << Rectangle(Position(188, 428)+baseVector, Position(312, 467)+baseVector,  KBlack); | ||||
|     window << nsGui::Text(Vec2D(200, 450)+baseVector, text, color); | ||||
| } | ||||
| 
 | ||||
| void PixelManager::displayMenu(const Position& pos, Menu& currentMenu){ | ||||
| 	startFrame(); | ||||
| 	size_t margin = 0; | ||||
| 	size_t cpt = 0; | ||||
| 	for(auto& value : currentMenu.entries ){ | ||||
| 		displayButton(Position(0,0+margin)+ pos, value, (currentMenu.currentValue == cpt) ? currentMenu.selectedColor : currentMenu.unSelectedColor ); | ||||
| 		++cpt; | ||||
| 		margin += 50; | ||||
| 	} | ||||
| 	endFrame(); | ||||
| } | ||||
| 
 | ||||
| PlayMode PixelManager::showInitialMenu(){ | ||||
| 	//return PlayMode::SINGLE; // will remove
 | ||||
| 	vector<string> entries {"single player","multi player (local)","EXIT"}; | ||||
| 	Menu initial {entries,0,nsGraphics::KRed,nsGraphics::KWhite}; | ||||
| 	while(true){ | ||||
| 		displayMenu(Position(100,100),initial);	 | ||||
| 		// dessends	
 | ||||
| 		if (window.isPressed({'s', false})){ | ||||
| 			++initial.currentValue; | ||||
| 			if (initial.currentValue > initial.entries.size()) initial.currentValue = 0; | ||||
| 		} | ||||
| 		// monte
 | ||||
| 		if (window.isPressed({'z', false}))  | ||||
| 			if (initial.currentValue == 0) initial.currentValue = initial.entries.size()-1; | ||||
| 			else --initial.currentValue; | ||||
| 
 | ||||
| 		 | ||||
| 		else if (window.isPressed({13, false})){ | ||||
| 			switch(initial.currentValue){ | ||||
| 				case 0: | ||||
| 					return PlayMode::SINGLE; | ||||
| 				case 1: | ||||
| 					return PlayMode::TWO_LOCAL; | ||||
| 				case 2: | ||||
| 					return PlayMode::EXIT; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| bool PixelManager::showDeathMenu() const { | ||||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user