nsnake
Classic snake game for the terminal
Loading...
Searching...
No Matches
LayoutMainMenu.cpp
1#include <Display/Layouts/LayoutMainMenu.hpp>
2#include <Engine/Graphics/Colors.hpp>
3#include <Engine/Graphics/Ncurses.hpp>
4#include <Engine/EngineGlobals.hpp>
5#include <Engine/Helpers/Utils.hpp>
6#include <States/GameStateMainMenu.hpp>
7#include <Display/Animations/AnimationSnakes.hpp>
8#include <Display/Animations/AnimationFire.hpp>
9#include <Display/Animations/AnimationWater.hpp>
10#include <Display/Animations/AnimationGameOfLife.hpp>
11
12#include <iostream>
13
14LayoutMainMenu::LayoutMainMenu(int width, int height, GameStateMainMenu* state):
15 Layout(width, height),
16 state(state),
17 logo(NULL),
18 menu(NULL),
19 animationwin(NULL),
20 animation(NULL)
21{
22 this->windowsInit();
23}
24LayoutMainMenu::~LayoutMainMenu()
25{
26 this->windowsExit();
27}
28void LayoutMainMenu::windowsInit()
29{
30 Layout::windowsInit();
31
32 // LOGO
33 this->logo = new Window(this->main,
34 0, 0,
35 56, 7);
36 this->logo->borders(Window::BORDER_NONE);
37
38 // MENU
39 this->menu = new Window(this->main,
40 55, 0,
41 24, WINDOW_FILL);
42
43 this->menu->setTitle("Main Menu");
44 this->menu->refresh();
45
46 // ANIMATION
47 this->animationwin = new Window(this->main,
48 0,
49 this->logo->getH(),
50 this->logo->getW(),
51 this->main->getH() - this->logo->getH() - 1);
52
53 this->animationwin->borders(Window::BORDER_NONE);
54
55 // Deciding randomly the type of the Animation
56 switch(Utils::Random::between(0, 3))
57 {
58 case 0:
59 this->animation = new AnimationWater(this->animationwin);
60 break;
61
62 case 1:
63 this->animation = new AnimationSnakes(this->animationwin);
64 break;
65
66 case 2:
67 this->animation = new AnimationGameOfLife(this->animationwin);
68 break;
69
70 default:
71 this->animation = new AnimationFire(this->animationwin);
72 break;
73 }
74 this->animation->load();
75}
76void LayoutMainMenu::windowsExit()
77{
78 SAFE_DELETE(this->menu);
79 SAFE_DELETE(this->logo);
80 SAFE_DELETE(this->animationwin);
81 SAFE_DELETE(this->animation);
82
83 Layout::windowsExit();
84}
85void LayoutMainMenu::draw(Menu* menu)
86{
87 this->animation->update();
88
89 this->main->clear();
90
91 this->animation->draw();
92
93 this->logo->clear();
94 this->logo->print(Utils::String::split(" __ _ _______ __ _ _______ ___ _ _______\n"
95 "| | | || || | | || _ || | | || |\n"
96 "| |_| || _____|| |_| || |_| || |_| || ___|\n"
97 "| || |_____ | || || _|| |___ \n"
98 "| _ ||_____ || _ || || |_ | ___|\n"
99 "| | | | _____| || | | || _ || _ || |___ \n"
100 "|_| |__||_______||_| |__||__| |__||___| |_||_______|", '\n'),
101 0,
102 0,
103 Colors::pair("green", "default", true));
104
105 this->logo->refresh();
106
107 // Yay!
108 this->menu->clear();
109
110 menu->draw(this->menu);
111
112 this->menu->refresh();
113
114 this->main->refresh();
115
116 // NCURSES NEEDS THIS
117 refresh();
118}
119
Rules and behavior of the Fire animation.
Rules and behavior of the GameOfLife animation.
Rules and behavior of the Fire animation.
Rules and behavior of the Water animation.
void draw(Menu *menu)
Shows the Main Menu screen, along with drawing menu.
Animation * animation
Cure thing at the main menu.