main title almost screen done

This commit is contained in:
Djalim Simaila 2022-01-09 00:10:37 +01:00
parent a2c9d40d4d
commit 6faffb7baf
7 changed files with 27 additions and 13 deletions

BIN
assets/logo.si2 Normal file

Binary file not shown.

BIN
assets/menu_background.si2 Normal file

Binary file not shown.

View File

@ -25,11 +25,13 @@ public:
* 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 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 logo{"assets/logo.si2"};
nsGui::Sprite gameBackground{"assets/game_background.si2"};
nsGui::Sprite menuBackground{"assets/menu_background.si2"};
nsGui::Sprite rightHand{"assets/hand_open.si2"};
nsGui::Sprite leftHand{MIRROR(rightHand)};
@ -49,7 +51,8 @@ public:
// TODO remove because unused ?
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 drawGameBackground() const;
void drawMenuBackground() const;
void drawFPS(unsigned fps) const;

View File

@ -76,8 +76,12 @@ void PixelManager::drawSprite(const Sprite& sprite, const Position& pos) const {
sprite.draw(window);
}
void PixelManager::drawBackground() const {
background.draw(window);
void PixelManager::drawGameBackground() const {
gameBackground.draw(window);
}
void PixelManager::drawMenuBackground() const {
menuBackground.draw(window);
}
unsigned PixelManager::getScreenHeight() const {

View File

@ -1,3 +1,5 @@
#include <chrono>
#include <thread>
#include <playMode.h>
#include "pixelManager.h"
#include "utils.h"
@ -15,6 +17,8 @@ void PixelManager::displayButton(const Position& baseVector,const string& text,n
void PixelManager::displayMenu(const Position& pos, Menu& currentMenu){
startFrame();
drawMenuBackground();
drawSprite(logo,Position(100,50));
size_t margin = 0;
size_t cpt = 0;
for(string& value : currentMenu.entries ){
@ -26,22 +30,25 @@ void PixelManager::displayMenu(const Position& pos, Menu& currentMenu){
}
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};
const unsigned xOffset = getScreenHeight() / 2;
const unsigned yOffset = getScreenWidth() / 2;
chrono::milliseconds waitTime = chrono::milliseconds(100);
while(true){
displayMenu(Position(100,100),initial);
// dessends
displayMenu(Position(350,0),initial);
// go down
if (window.isPressed({'s', false})){
++initial.currentValue;
if (initial.currentValue > initial.entries.size()) initial.currentValue = 0;
this_thread::sleep_for(waitTime);
}
// monte
if (window.isPressed({'z', false}))
// go up
if (window.isPressed({'z', false})){
if (initial.currentValue == 0) initial.currentValue = initial.entries.size()-1;
else --initial.currentValue;
this_thread::sleep_for(waitTime);
}
else if (window.isPressed({13, false})){
switch(initial.currentValue){
case 0:

View File

@ -5,7 +5,7 @@
* The more important stuff must be drawn last
*/
void Game::displayAll(unsigned fps) const {
pm.drawBackground();
pm.drawGameBackground();
for (unsigned i = 0; i < this->grid.size(); ++i){
for (unsigned j = 0; j < this->grid[i].size(); ++j){
Position vec(