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
Ушкова Диана Петровна
Pacman
Commits
5814ac6b
Commit
5814ac6b
authored
2 months ago
by
Ушкова Диана Петровна
Browse files
Options
Download
Patches
Plain Diff
this version doesn't work
parent
391ad6aa
main
ui_disagn
1 merge request
!1
created menu
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
CMakeLists.txt
+1
-0
CMakeLists.txt
config/config.h
+2
-1
config/config.h
source/application/Drawable/Button/button.cpp
+2
-2
source/application/Drawable/Button/button.cpp
source/application/Drawable/Menu/menu.cpp
+16
-4
source/application/Drawable/Menu/menu.cpp
source/application/State/IState.cpp
+5
-8
source/application/State/IState.cpp
source/application/State/IState.h
+4
-0
source/application/State/IState.h
source/application/app/app.cpp
+1
-1
source/application/app/app.cpp
with
31 additions
and
16 deletions
+31
-16
CMakeLists.txt
+
1
−
0
View file @
5814ac6b
...
...
@@ -18,6 +18,7 @@ add_executable(pacman source/main.cpp
source/application/Drawable/Menu/menu.cpp
)
target_link_libraries
(
pacman PRIVATE sfml-window sfml-graphics sfml-system
)
target_compile_definitions
(
pacman PRIVATE ASSETS_PATH=
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/assets/"
)
#target_include_directories(pacman PUBLIC
# ${CMAKE_SOURCE_DIR}/source/application
# ${CMAKE_SOURCE_DIR}/source/application/Event
...
...
This diff is collapsed.
Click to expand it.
config/config.h
+
2
−
1
View file @
5814ac6b
...
...
@@ -7,9 +7,10 @@ namespace config {
// Меню:
const
sf
::
Vector2f
BUTTON_SIZE
=
{
250
,
100
};
const
size_t
BUTTON_FONT_SIZE
=
static_cast
<
size_t
>
(
BUTTON_SIZE
.
y
/
1.5
f
);
const
float
BUTTON_FRAME_THICKNESS
=
2.0
f
;
const
char
FONT_FILE
[]
=
"Calibri
-Light
.ttf"
;
const
char
FONT_FILE
[]
=
"Calibri.ttf"
;
const
char
SELECT_LEVEL_TITLE
[]
=
"Select Level"
;
const
sf
::
VideoMode
SELECT_LEVEL_VIDEO_MODE
{
400
,
600
};
const
std
::
vector
<
std
::
string
>
BUTTON_TEXT
=
{
"Easy"
,
"Medium"
,
"Hard"
,
"Exit"
};
const
char
BUTTON_TEXT_EASY
[]
=
"Easy"
;
const
char
BUTTON_TEXT_MEDIUM
[]
=
"Medium"
;
const
char
BUTTON_TEXT_HARD
[]
=
"Hard"
;
...
...
This diff is collapsed.
Click to expand it.
source/application/Drawable/Button/button.cpp
+
2
−
2
View file @
5814ac6b
#include
"button.h"
#include
"config.h"
#include
"
../../../../config/
config.h"
#include
"../Font/font.h"
void
Button
::
set
(
sf
::
Vector2f
pos
,
sf
::
Vector2f
button_size
,
...
...
@@ -13,7 +13,7 @@ void Button::set(sf::Vector2f pos, sf::Vector2f button_size,
m_text
=
sf
::
Text
(
text
,
MyFont
::
Instance
(),
font_size
);
m_text
.
setFillColor
(
config
::
BUTTON_COLOR_TEXT
);
m_text
.
setPosition
(
pos
);
//
m_ptr_command = std::move(ptr_command);
m_ptr_command
=
std
::
move
(
ptr_command
);
}
void
Button
::
select
()
{
...
...
This diff is collapsed.
Click to expand it.
source/application/Drawable/Menu/menu.cpp
+
16
−
4
View file @
5814ac6b
#include
"menu.h"
#include
"config.h"
//#include "Select Command/ISelectCommand.h"
#include
"../../../../config/config.h"
#include
<memory>
Menu
::
Menu
(
IStateManager
&
state_manager
)
{
for
(
Button
&
ptr_button
:
m_buttons
)
{
ptr_button
.
set
(
sf
::
Vector2f
(
100
,
120
),
size_t
button_number
=
&
ptr_button
-
&
m_buttons
[
0
];
ptr_button
.
set
(
sf
::
Vector2f
(
100
,
120
+
button_number
*
120
),
config
::
BUTTON_SIZE
,
config
::
BUTTON_TEXT
_EASY
,
config
::
BUTTON_TEXT
[
button_number
]
,
config
::
BUTTON_FONT_SIZE
,
std
::
make_unique
<
ExitCommand
>
(
state_manager
));
}
}
void
Menu
::
draw_into
(
sf
::
RenderWindow
&
window
)
const
{
for
(
const
Button
&
ptr_button
:
m_buttons
)
ptr_button
.
draw_into
(
window
);
}
void
Menu
::
process_mouse
(
const
sf
::
Vector2f
pos
,
bool
is_pressed
)
{
for
(
Button
&
ptr_button
:
m_buttons
)
{
if
(
ptr_button
.
is_position_in
(
pos
))
{
ptr_button
.
select
();
if
(
is_pressed
)
ptr_button
.
push
();
}
else
ptr_button
.
unselect
();
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
source/application/State/IState.cpp
+
5
−
8
View file @
5814ac6b
#include
"IState.h"
#include
"config.h"
#include
"
../../../config/
config.h"
#include
<iostream>
...
...
@@ -11,25 +11,22 @@ SelectState::SelectState(IStateManager& state_manager,
void
SelectState
::
event_handling
()
{
sf
::
Event
event
;
while
(
m_window
.
pollEvent
(
event
))
{
if
(
sf
::
Event
::
Closed
)
{
m_state_manager
.
set_next_state
(
std
::
make_unique
<
ExitState
>
(
m_state_manager
));
break
;
}
if
(
event
.
type
==
sf
::
Event
::
Closed
)
{
m_window
.
close
();}
}
}
void
SelectState
::
update
()
{
const
sf
::
Vector2f
pos
=
m_window
.
mapPixelToCoords
(
sf
::
Mouse
::
getPosition
(
m_window
));
if
(
sf
::
Mouse
::
isButtonPressed
(
sf
::
Mouse
::
Left
))
{
m_menu
.
process_mouse
(
true
,
pos
);
m_menu
.
process_mouse
(
pos
,
true
);
return
;
}
m_menu
.
process_mouse
(
false
,
pos
);
m_menu
.
process_mouse
(
pos
,
false
);
}
void
SelectState
::
render
()
{
m_window
.
clear
(
config
::
SELECT_LEVEL_BACKGROUND_COLOR
);
m_menu
.
draw_into
(
m_window
);
m_window
.
display
();
}
...
...
This diff is collapsed.
Click to expand it.
source/application/State/IState.h
+
4
−
0
View file @
5814ac6b
...
...
@@ -26,6 +26,10 @@ private:
struct
GameState
:
IState
,
IWindowKeeper
{
GameState
(
IStateManager
&
state_manager
,
const
sf
::
VideoMode
&
video_mode
,
const
std
::
string
&
window_title
);
void
event_handling
()
override
;
void
update
()
override
;
void
render
()
override
;
bool
do_step
()
override
;
};
struct
ExitState
:
IState
{
...
...
This diff is collapsed.
Click to expand it.
source/application/app/app.cpp
+
1
−
1
View file @
5814ac6b
#include
"app.h"
#include
"config.h"
#include
"
../../../config/
config.h"
Application
::
Application
()
:
m_ptr_state_current
(
std
::
make_unique
<
SelectState
>
(
*
this
,
...
...
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