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
f86ffafa
Commit
f86ffafa
authored
6 days ago
by
Сулимов Игорь Андреевич
Browse files
Options
Download
Patches
Plain Diff
Made GameState::render(); and partly GameState::event_handling();
parent
15cf5b94
main
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/Config.h
+3
-3
include/Config.h
include/States/GameState.h
+3
-3
include/States/GameState.h
source/States/GameState.cpp
+61
-0
source/States/GameState.cpp
with
67 additions
and
6 deletions
+67
-6
include/Config.h
+
3
−
3
View file @
f86ffafa
...
...
@@ -38,9 +38,9 @@ namespace config {
const
sf
::
Color
BUTTON_COLOR_SELECTION
{
255
,
180
,
180
};
const
sf
::
Color
BUTTON_COLOR_FRAME
{
0
,
0
,
0
};
const
sf
::
Color
SELECT_LEVEL_BACKGROUND_COLOR
{
230
,
230
,
230
};
//
const sf::Color GAME_COLOR_BACKGROUND_INGAME{ 230,230,230 };
//
const sf::Color GAME_COLOR_BACKGROUND_WIN{ 0, 255, 0 };
//
const sf::Color GAME_COLOR_BACKGROUND_LOST{ 255, 0, 0 };
const
sf
::
Color
GAME_COLOR_BACKGROUND_INGAME
{
230
,
230
,
230
};
const
sf
::
Color
GAME_COLOR_BACKGROUND_WIN
{
0
,
255
,
0
};
const
sf
::
Color
GAME_COLOR_BACKGROUND_LOST
{
255
,
0
,
0
};
const
sf
::
Color
GAME_COLOR_PACMAN
{
250
,
150
,
0
};
const
sf
::
Color
GAME_COLOR_ROOM
{
255
,
255
,
255
};
const
sf
::
Color
GAME_COLOR_WALL
{
0
,
0
,
0
};
...
...
This diff is collapsed.
Click to expand it.
include/States/GameState.h
+
3
−
3
View file @
f86ffafa
...
...
@@ -9,11 +9,11 @@ class GameState: public IState, public IWindowKeeper {
public:
void
set_maze
(
Maze
&&
maze
);
void
set_context
(
GameContext
&&
context
);
bool
do_step
()
override
{};
///@todo
bool
do_step
()
override
;
protected:
void
event_handling
()
override
{}
;
///@todo
void
event_handling
()
override
;
///@todo
void
update
()
override
{};
///@todo
void
render
()
override
{}
;
///@todo
void
render
()
override
;
///@todo
public
:
GameState
(
IStateManager
&
state_manager
,
const
sf
::
VideoMode
&
video_mode
,
const
std
::
string
&
window_title
);
...
...
This diff is collapsed.
Click to expand it.
source/States/GameState.cpp
+
61
−
0
View file @
f86ffafa
#include
"States/GameState.h"
#include
"States/SelectState.h"
GameState
::
GameState
(
IStateManager
&
state_manager
,
const
sf
::
VideoMode
&
video_mode
,
const
std
::
string
&
window_title
)
:
IWindowKeeper
(
video_mode
,
window_title
),
IState
(
state_manager
)
{}
...
...
@@ -9,4 +10,64 @@ void GameState::set_maze(Maze&& maze) {
void
GameState
::
set_context
(
GameContext
&&
context
)
{
m_context_manager
.
reset
(
std
::
move
(
context
));
}
bool
GameState
::
do_step
()
{
while
(
m_window
.
isOpen
())
{
event_handling
();
update
();
render
();
return
true
;
}
}
void
GameState
::
event_handling
()
{
sf
::
Event
event
;
while
(
m_window
.
pollEvent
(
event
))
{
if
(
event
.
type
==
sf
::
Event
::
Closed
)
{
m_state_manager
.
set_next_state
(
std
::
make_unique
<
SelectState
>
(
m_state_manager
,
config
::
SELECT_LEVEL_VIDEO_MODE
,
config
::
SELECT_LEVEL_TITLE
));
}
if
(
event
.
type
==
sf
::
Event
::
Resized
)
{
sf
::
View
view
=
m_window
.
getView
();
view
.
setSize
(
event
.
size
.
width
,
event
.
size
.
height
);
m_window
.
setView
(
view
);
}
// if (event.type == sf::Event::KeyPressed && m_context_manager.get_current_context().state == GameContext::INGAME) {
// process_key_pressed(event.key.code);
// break;
// }
// if (sf::Keyboard::isKeyPressed(sf::Keyboard::LControl) &&
// sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) {
// auto cur_state = m_context_manager.get_current_context().state;
// m_context_manager.restore_previous_context();
// if (cur_state) {
// m_state_sounds.first.stop();
// m_state_sounds.second.stop();
// m_ptr_music_player->play_music();
// }
// break;
// }
}
}
void
GameState
::
render
()
{
if
(
m_context_manager
.
get_current_context
().
state
==
GameContext
::
INGAME
)
{
m_window
.
clear
(
config
::
GAME_COLOR_BACKGROUND_INGAME
);
}
else
if
(
m_context_manager
.
get_current_context
().
state
==
GameContext
::
WIN
)
{
m_window
.
clear
(
config
::
GAME_COLOR_BACKGROUND_WIN
);
}
else
if
(
m_context_manager
.
get_current_context
().
state
==
GameContext
::
LOST
)
{
m_window
.
clear
(
config
::
GAME_COLOR_BACKGROUND_LOST
);
}
m_maze
.
draw_into
(
m_window
);
m_context_manager
.
get_current_context
().
pacman
.
draw_into
(
m_window
);
for
(
auto
&
obj
:
m_context_manager
.
get_current_context
().
static_objects
)
{
obj
->
draw_into
(
m_window
);
}
for
(
auto
&
obj
:
m_context_manager
.
get_current_context
().
dynamic_objects
)
{
obj
->
draw_into
(
m_window
);
}
m_window
.
display
();
}
\ No newline at end of file
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