Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Сулимов Игорь Андреевич
Pac-Man
Commits
15cf5b94
Commit
15cf5b94
authored
6 days ago
by
Сулимов Игорь Андреевич
Browse files
Options
Download
Patches
Plain Diff
Finally FIXED BUGS and it WORKS
parent
20497752
main
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
source/Draw/Button.cpp
+2
-1
source/Draw/Button.cpp
source/Draw/Menu.cpp
+37
-73
source/Draw/Menu.cpp
with
39 additions
and
74 deletions
+39
-74
source/Draw/Button.cpp
+
2
−
1
View file @
15cf5b94
...
...
@@ -12,12 +12,13 @@ Button::Button() {
void
Button
::
set
(
const
sf
::
Vector2f
&
pos
,
const
sf
::
Vector2f
&
button_size
,
const
std
::
string
&
text
,
size_t
font_size
,
std
::
unique_ptr
<
ISelectCommand
>
ptr_command
)
{
m_rectangle
.
setOrigin
(
m_rectangle
.
getSize
()
/
2.
f
);
m_rectangle
.
setSize
(
button_size
);
m_rectangle
.
setOrigin
(
m_rectangle
.
getSize
()
/
2.
f
);
m_rectangle
.
setPosition
(
pos
);
m_text
.
setString
(
text
);
auto
bounds
=
m_text
.
getLocalBounds
();
m_text
.
setOrigin
(
bounds
.
left
+
bounds
.
width
/
2.0
f
,
bounds
.
top
+
bounds
.
height
/
2.0
f
);
m_text
.
setPosition
(
pos
);
m_ptr_command
=
std
::
move
(
ptr_command
);
}
...
...
This diff is collapsed.
Click to expand it.
source/Draw/Menu.cpp
+
37
−
73
View file @
15cf5b94
...
...
@@ -5,83 +5,47 @@
#include
"Commands/ExitCommand.h"
//Menu::Menu(IStateManager& state_manager) {
// sf::Vector2f starting_position(config::SELECT_LEVEL_VIDEO_MODE.width / 4.f,
// config::SELECT_LEVEL_VIDEO_MODE.height / 5.f);
//
// auto easy_director = std::make_unique<GameBuilderDirector>(
// std::make_unique<SimpleBuilder>(
// config::GAME_VIDEO_MODE.width, config::GAME_VIDEO_MODE.height,
// config::ROOM_SIZE),
// config::GAME_VIDEO_MODE,
// config::EASY_GAME_TITLE,
// config::EASY_GAME_ENEMY_RATIO);
//
// auto medium_director = std::make_unique<GameBuilderDirector>(
// std::make_unique<SimpleBuilder>(
// config::GAME_VIDEO_MODE.width, config::GAME_VIDEO_MODE.height,
// config::ROOM_SIZE),
// config::GAME_VIDEO_MODE,
// config::MEDIUM_GAME_TITLE,
// config::MEDIUM_GAME_ENEMY_RATIO);
//
// auto hard_director = std::make_unique<GameBuilderDirector>(
// std::make_unique<ComplexBuilder>(
// config::GAME_VIDEO_MODE.width, config::GAME_VIDEO_MODE.height,
// config::ROOM_SIZE),
// config::GAME_VIDEO_MODE,
// config::HARD_GAME_TITLE,
// config::HARD_GAME_ENEMY_RATIO);
//
// auto easy_command = std::make_unique<GameCommand>(state_manager, std::move(easy_director));
// auto medium_command = std::make_unique<GameCommand>(state_manager, std::move(medium_director));
// auto hard_command = std::make_unique<GameCommand>(state_manager, std::move(hard_director));
// auto exit_command = std::make_unique<ExitCommand>(state_manager);
// m_buttons[0].set(sf::Vector2f{ starting_position.x, 2*starting_position.y}, config::BUTTON_SIZE, config::BUTTON_TEXT_EASY, config::BUTTON_FONT_SIZE, std::move(easy_command));
// m_buttons[1].set(sf::Vector2f{ starting_position.x, 3*starting_position.y}, config::BUTTON_SIZE, config::BUTTON_TEXT_MEDIUM, config::BUTTON_FONT_SIZE, std::move(medium_command));
// m_buttons[2].set(sf::Vector2f{ starting_position.x, 4*starting_position.y}, config::BUTTON_SIZE, config::BUTTON_TEXT_HARD, config::BUTTON_FONT_SIZE, std::move(hard_command));
// m_buttons[3].set(sf::Vector2f{ starting_position.x, 5*starting_position.y}, config::BUTTON_SIZE, config::BUTTON_TEXT_EXIT, config::BUTTON_FONT_SIZE, std::move(exit_command));
//}
Menu
::
Menu
(
IStateManager
&
state_manager
)
{
float
select_screen_width
=
config
::
SELECT_LEVEL_VIDEO_MODE
.
width
;
float
select_screen_height
=
config
::
SELECT_LEVEL_VIDEO_MODE
.
height
;
float
game_screen_width
=
config
::
GAME_VIDEO_MODE
.
width
;
float
game_screen_height
=
config
::
GAME_VIDEO_MODE
.
height
;
auto
ptr_director_simple
=
std
::
make_unique
<
GameBuilderDirector
>
(
std
::
make_unique
<
SimpleBuilder
>
(
game_screen_width
,
game_screen_height
,
config
::
ROOM_SIZE
),
config
::
GAME_VIDEO_MODE
,
config
::
EASY_GAME_TITLE
,
config
::
EASY_GAME_ENEMY_RATIO
);
auto
ptr_director_medium
=
std
::
make_unique
<
GameBuilderDirector
>
(
std
::
make_unique
<
SimpleBuilder
>
(
game_screen_width
,
game_screen_height
,
config
::
ROOM_SIZE
),
config
::
GAME_VIDEO_MODE
,
config
::
MEDIUM_GAME_TITLE
,
config
::
MEDIUM_GAME_ENEMY_RATIO
);
auto
ptr_director_hard
=
std
::
make_unique
<
GameBuilderDirector
>
(
std
::
make_unique
<
ComplexBuilder
>
(
game_screen_width
,
game_screen_height
,
config
::
ROOM_SIZE
),
config
::
GAME_VIDEO_MODE
,
config
::
HARD_GAME_TITLE
,
config
::
HARD_GAME_ENEMY_RATIO
);
float
button_pos_x
=
select_screen_width
/
2.
f
;
float
button_pos_y
=
select_screen_height
/
5.
f
;
m_buttons
.
at
(
0
).
set
({
button_pos_x
,
button_pos_y
},
config
::
BUTTON_SIZE
,
config
::
BUTTON_TEXT_EASY
,
config
::
BUTTON_FONT_SIZE
,
std
::
make_unique
<
GameCommand
>
(
state_manager
,
std
::
move
(
ptr_director_simple
)));
m_buttons
.
at
(
1
).
set
({
button_pos_x
,
2
*
button_pos_y
},
config
::
BUTTON_SIZE
,
config
::
BUTTON_TEXT_MEDIUM
,
config
::
BUTTON_FONT_SIZE
,
std
::
make_unique
<
GameCommand
>
(
state_manager
,
std
::
move
(
ptr_director_medium
)));
m_buttons
.
at
(
2
).
set
({
button_pos_x
,
3
*
button_pos_y
},
config
::
BUTTON_SIZE
,
config
::
BUTTON_TEXT_HARD
,
config
::
BUTTON_FONT_SIZE
,
std
::
make_unique
<
GameCommand
>
(
state_manager
,
std
::
move
(
ptr_director_hard
)));
m_buttons
.
at
(
3
).
set
({
button_pos_x
,
4
*
button_pos_y
},
config
::
BUTTON_SIZE
,
config
::
BUTTON_TEXT_EXIT
,
config
::
BUTTON_FONT_SIZE
,
std
::
make_unique
<
ExitCommand
>
(
state_manager
));
sf
::
Vector2f
starting_position
(
config
::
SELECT_LEVEL_VIDEO_MODE
.
width
/
2.
f
,
config
::
SELECT_LEVEL_VIDEO_MODE
.
height
/
5.
f
);
auto
easy_director
=
std
::
make_unique
<
GameBuilderDirector
>
(
std
::
make_unique
<
SimpleBuilder
>
(
config
::
GAME_VIDEO_MODE
.
width
,
config
::
GAME_VIDEO_MODE
.
height
,
config
::
ROOM_SIZE
),
config
::
GAME_VIDEO_MODE
,
config
::
EASY_GAME_TITLE
,
config
::
EASY_GAME_ENEMY_RATIO
);
auto
medium_director
=
std
::
make_unique
<
GameBuilderDirector
>
(
std
::
make_unique
<
SimpleBuilder
>
(
config
::
GAME_VIDEO_MODE
.
width
,
config
::
GAME_VIDEO_MODE
.
height
,
config
::
ROOM_SIZE
),
config
::
GAME_VIDEO_MODE
,
config
::
MEDIUM_GAME_TITLE
,
config
::
MEDIUM_GAME_ENEMY_RATIO
);
auto
hard_director
=
std
::
make_unique
<
GameBuilderDirector
>
(
std
::
make_unique
<
ComplexBuilder
>
(
config
::
GAME_VIDEO_MODE
.
width
,
config
::
GAME_VIDEO_MODE
.
height
,
config
::
ROOM_SIZE
),
config
::
GAME_VIDEO_MODE
,
config
::
HARD_GAME_TITLE
,
config
::
HARD_GAME_ENEMY_RATIO
);
auto
easy_command
=
std
::
make_unique
<
GameCommand
>
(
state_manager
,
std
::
move
(
easy_director
));
auto
medium_command
=
std
::
make_unique
<
GameCommand
>
(
state_manager
,
std
::
move
(
medium_director
));
auto
hard_command
=
std
::
make_unique
<
GameCommand
>
(
state_manager
,
std
::
move
(
hard_director
));
auto
exit_command
=
std
::
make_unique
<
ExitCommand
>
(
state_manager
);
m_buttons
[
0
].
set
(
sf
::
Vector2f
{
starting_position
.
x
,
starting_position
.
y
},
config
::
BUTTON_SIZE
,
config
::
BUTTON_TEXT_EASY
,
config
::
BUTTON_FONT_SIZE
,
std
::
move
(
easy_command
));
m_buttons
[
1
].
set
(
sf
::
Vector2f
{
starting_position
.
x
,
2
*
starting_position
.
y
},
config
::
BUTTON_SIZE
,
config
::
BUTTON_TEXT_MEDIUM
,
config
::
BUTTON_FONT_SIZE
,
std
::
move
(
medium_command
));
m_buttons
[
2
].
set
(
sf
::
Vector2f
{
starting_position
.
x
,
3
*
starting_position
.
y
},
config
::
BUTTON_SIZE
,
config
::
BUTTON_TEXT_HARD
,
config
::
BUTTON_FONT_SIZE
,
std
::
move
(
hard_command
));
m_buttons
[
3
].
set
(
sf
::
Vector2f
{
starting_position
.
x
,
4
*
starting_position
.
y
},
config
::
BUTTON_SIZE
,
config
::
BUTTON_TEXT_EXIT
,
config
::
BUTTON_FONT_SIZE
,
std
::
move
(
exit_command
));
}
void
Menu
::
draw_into
(
sf
::
RenderWindow
&
window
)
const
{
for
(
const
Button
&
ptr_
button
:
m_buttons
)
ptr_
button
.
draw_into
(
window
);
for
(
const
Button
&
button
:
m_buttons
)
button
.
draw_into
(
window
);
}
void
Menu
::
process_mouse
(
sf
::
Vector2f
pos
,
bool
is_pressed
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets