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
33152a28
Commit
33152a28
authored
1 week ago
by
Сулимов Игорь Андреевич
Browse files
Options
Download
Patches
Plain Diff
Almost finished
parent
8067d964
main
No related merge requests found
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
assets/EnemyTexture.png
+0
-0
assets/EnemyTexture.png
assets/PacmanTexture.png
+0
-0
assets/PacmanTexture.png
include/Config.h
+3
-0
include/Config.h
include/Draw/Textures/EnemyTexture.h
+1
-3
include/Draw/Textures/EnemyTexture.h
include/Draw/Textures/FoodTexture.h
+3
-5
include/Draw/Textures/FoodTexture.h
include/Draw/Textures/PacmanTexture.h
+0
-3
include/Draw/Textures/PacmanTexture.h
include/Draw/Textures/Texture.h
+2
-1
include/Draw/Textures/Texture.h
include/MazeContent/Entities/Pacman.h
+11
-1
include/MazeContent/Entities/Pacman.h
source/Draw/Texture/EnemyTexture.cpp
+11
-1
source/Draw/Texture/EnemyTexture.cpp
source/Draw/Texture/FoodTexture.cpp
+11
-1
source/Draw/Texture/FoodTexture.cpp
source/Draw/Texture/PacmanTexture.cpp
+1
-5
source/Draw/Texture/PacmanTexture.cpp
source/MazeContent/Entities/Pacman.cpp
+29
-5
source/MazeContent/Entities/Pacman.cpp
source/States/GameState.cpp
+9
-0
source/States/GameState.cpp
with
81 additions
and
25 deletions
+81
-25
assets/EnemyTexture.png
0 → 100644
+
0
−
0
View file @
33152a28
174 KB
This diff is collapsed.
Click to expand it.
assets/PacmanTexture.png
0 → 100644
+
0
−
0
View file @
33152a28
206 KB
This diff is collapsed.
Click to expand it.
include/Config.h
+
3
−
0
View file @
33152a28
...
...
@@ -16,6 +16,9 @@ namespace config {
const
char
FONT_FILE_VARIANT_1
[]
=
"android2.ttf"
;
const
char
FONT_FILE_VARIANT_2
[]
=
"Oxygene1_RUS_by_KanycTa.ttf"
;
const
char
FONT_FILE
[]
=
"Font Over.otf"
;
const
char
PACMAN_TEXTURE_FILE
[]
=
"PacmanTexture.png"
;
const
char
ENEMY_TEXTURE_FILE
[]
=
"EnemyTexture.png"
;
const
char
FOOD_TEXTURE_FILE
[]
=
"FoodTexture.png"
;
const
char
SELECT_LEVEL_TITLE
[]
=
"Select Level"
;
const
sf
::
VideoMode
SELECT_LEVEL_VIDEO_MODE
{
400
,
600
};
const
char
BUTTON_TEXT_EASY
[]
=
"Easy"
;
...
...
This diff is collapsed.
Click to expand it.
include/Draw/Textures/EnemyTexture.h
+
1
−
3
View file @
33152a28
...
...
@@ -4,9 +4,7 @@
class
EnemyTexture
:
public
Texture
{
public:
static
EnemyTexture
&
Instance
()
{
static
EnemyTexture
tex
;
return
tex
;
}
sf
::
Texture
&
get_texture
()
override
{
return
m_texture
;
}
static
EnemyTexture
&
Instance
();
private:
sf
::
Texture
m_texture
;
EnemyTexture
();
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
include/Draw/Textures/FoodTexture.h
+
3
−
5
View file @
33152a28
...
...
@@ -2,11 +2,9 @@
#include
"Texture.h"
class
Food
:
public
Texture
{
class
Food
Texture
:
public
Texture
{
public:
static
Food
&
Instance
()
{
static
Food
m_texture
;
return
m_texutre
;
}
sf
::
Texture
&
get_texture
()
override
{
return
m_texture
;
}
static
FoodTexture
&
Instance
();
private:
sf
::
Texture
m_texture
;
Food
();
FoodTexture
();
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
include/Draw/Textures/PacmanTexture.h
+
0
−
3
View file @
33152a28
...
...
@@ -5,9 +5,6 @@
class
PacmanTexture
:
public
Texture
{
public:
static
PacmanTexture
&
Instance
();
sf
::
Texture
&
get_texture
()
const
noexcept
override
;
private:
PacmanTexture
();
private:
sf
::
Texture
m_texture
;
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
include/Draw/Textures/Texture.h
+
2
−
1
View file @
33152a28
...
...
@@ -6,7 +6,7 @@
class
Texture
{
public:
virtual
sf
::
Texture
&
get_texture
()
const
noexcept
=
0
;
const
sf
::
Texture
&
get_texture
()
const
noexcept
{
return
m_texture
;
}
void
set_direction
(
config
::
Direction
dir
)
{
m_direction
=
dir
;
}
public
:
Texture
(
const
Texture
&
tex
)
=
delete
;
...
...
@@ -15,4 +15,5 @@ protected:
Texture
()
=
default
;
protected
:
config
::
Direction
m_direction
=
config
::
Direction
::
RIGHT
;
sf
::
Texture
m_texture
;
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
include/MazeContent/Entities/Pacman.h
+
11
−
1
View file @
33152a28
...
...
@@ -3,6 +3,8 @@
#include
"IEntity.h"
#include
<Visit/IVisitor.h>
#include
"Draw/Textures/PacmanTexture.h"
class
Pacman
:
public
IEntity
,
public
IVisitor
{
public:
void
prepare_for_drawing
()
override
;
...
...
@@ -10,8 +12,16 @@ public:
void
move
(
Room
::
Direction
direction
);
std
::
unique_ptr
<
IGameEvent
>
visit
(
Food
*
ptr_food
)
override
;
std
::
unique_ptr
<
IGameEvent
>
visit
(
Enemy
*
ptr_enemy
)
override
;
void
next_animation
();
private:
void
set_texture
(
Texture
*
ptr_texture
);
public:
Pacman
();
public:
sf
::
Clock
m_clock
;
config
::
Direction
m_direction
=
config
::
RIGHT
;
private:
sf
::
CircleShape
m_circle
;
sf
::
Sprite
m_sprite
;
Texture
*
m_ptr_texture
;
inline
static
const
size_t
m_rect_count
=
2
;
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
source/Draw/Texture/EnemyTexture.cpp
+
11
−
1
View file @
33152a28
#include
"Draw/Textures/EnemyTexture.h"
\ No newline at end of file
#include
"Draw/Textures/EnemyTexture.h"
EnemyTexture
::
EnemyTexture
()
{
if
(
!
m_texture
.
loadFromFile
(
ASSETS_PATH
+
std
::
string
(
config
::
ENEMY_TEXTURE_FILE
)))
throw
std
::
runtime_error
(
"Could not open the PacmanTexture file!"
);
}
EnemyTexture
&
EnemyTexture
::
Instance
()
{
static
EnemyTexture
instance
;
return
instance
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
source/Draw/Texture/FoodTexture.cpp
+
11
−
1
View file @
33152a28
#include
"Draw/Textures/FoodTexture.h"
\ No newline at end of file
#include
"Draw/Textures/FoodTexture.h"
FoodTexture
::
FoodTexture
()
{
if
(
!
m_texture
.
loadFromFile
(
ASSETS_PATH
+
std
::
string
(
config
::
FOOD_TEXTURE_FILE
)))
throw
std
::
runtime_error
(
"Could not open the PacmanTexture file!"
);
}
FoodTexture
&
FoodTexture
::
Instance
()
{
static
FoodTexture
instance
;
return
instance
;
}
This diff is collapsed.
Click to expand it.
source/Draw/Texture/PacmanTexture.cpp
+
1
−
5
View file @
33152a28
#include
"Draw/Textures/PacmanTexture.h"
PacmanTexture
::
PacmanTexture
()
{
if
(
!
m_texture
.
loadFromFile
(
ASSETS_PATH
+
std
::
string
(
config
::
FONT
_FILE
)))
if
(
!
m_texture
.
loadFromFile
(
ASSETS_PATH
+
std
::
string
(
config
::
PACMAN_TEXTURE
_FILE
)))
throw
std
::
runtime_error
(
"Could not open the PacmanTexture file!"
);
}
...
...
@@ -9,7 +9,3 @@ PacmanTexture& PacmanTexture::Instance() {
static
PacmanTexture
instance
;
return
instance
;
}
sf
::
Texture
&
PacmanTexture
::
get_texture
()
const
noexcept
{
return
m_texture
;
}
This diff is collapsed.
Click to expand it.
source/MazeContent/Entities/Pacman.cpp
+
29
−
5
View file @
33152a28
...
...
@@ -5,17 +5,41 @@
#include
"MazeContent/Entities/StaticEntities/Food.h"
#include
"MazeContent/Entities/DynamicEntities/Enemy.h"
Pacman
::
Pacman
()
:
m_circle
(
config
::
GAME_PACMAN_SIZE
/
2
)
{
m_circle
.
setOrigin
(
m_circle
.
getRadius
(),
m_circle
.
getRadius
());
m_circle
.
setFillColor
(
config
::
GAME_COLOR_PACMAN
);
Pacman
::
Pacman
()
{
set_texture
(
&
PacmanTexture
::
Instance
());
}
void
Pacman
::
set_texture
(
Texture
*
ptr_texture
)
{
m_ptr_texture
=
ptr_texture
;
}
void
Pacman
::
prepare_for_drawing
()
{
m_circle
.
setPosition
(
m_ptr_room
->
get_position
());
m_sprite
.
setTexture
(
m_ptr_texture
->
get_texture
());
if
(
m_direction
==
config
::
RIGHT
)
{
m_sprite
.
setTextureRect
(
sf
::
IntRect
(
0
,
0
,
m_ptr_texture
->
get_texture
().
getSize
().
x
/
m_rect_count
,
(
m_ptr_texture
->
get_texture
().
getSize
().
y
-
2
)
/
4
));
}
else
if
(
m_direction
==
config
::
DOWN
)
{
m_sprite
.
setTextureRect
(
sf
::
IntRect
(
0
,
(
m_ptr_texture
->
get_texture
().
getSize
().
y
-
2
)
/
(
4
),
m_ptr_texture
->
get_texture
().
getSize
().
x
/
m_rect_count
,
(
m_ptr_texture
->
get_texture
().
getSize
().
y
-
2
)
/
(
4
)));
}
else
if
(
m_direction
==
config
::
LEFT
)
{
m_sprite
.
setTextureRect
(
sf
::
IntRect
(
0
,
(
m_ptr_texture
->
get_texture
().
getSize
().
y
-
2
)
/
(
m_rect_count
),
m_ptr_texture
->
get_texture
().
getSize
().
x
/
m_rect_count
,
(
m_ptr_texture
->
get_texture
().
getSize
().
y
-
2
)
/
4
));
}
else
if
(
m_direction
==
config
::
UP
)
{
m_sprite
.
setTextureRect
(
sf
::
IntRect
(
0
,
3
*
(
m_ptr_texture
->
get_texture
().
getSize
().
y
-
2
)
/
(
2
*
m_rect_count
),
m_ptr_texture
->
get_texture
().
getSize
().
x
/
m_rect_count
,
(
m_ptr_texture
->
get_texture
().
getSize
().
y
-
2
)));
}
m_sprite
.
setPosition
(
m_ptr_room
->
get_position
()
+
sf
::
Vector2f
(
-
20
,
-
20
));
m_sprite
.
setScale
(
0.25
,
0.25
);
}
void
Pacman
::
next_animation
()
{
sf
::
IntRect
rect
=
m_sprite
.
getTextureRect
();
rect
.
left
=
((
rect
.
left
/
(
rect
.
width
)
+
1
)
%
m_rect_count
)
*
rect
.
width
;
m_sprite
.
setTextureRect
(
rect
);
}
void
Pacman
::
draw_into
(
sf
::
RenderWindow
&
window
)
const
{
window
.
draw
(
m_
circl
e
);
window
.
draw
(
m_
sprit
e
);
}
void
Pacman
::
move
(
Room
::
Direction
direction
)
{
...
...
This diff is collapsed.
Click to expand it.
source/States/GameState.cpp
+
9
−
0
View file @
33152a28
...
...
@@ -26,18 +26,22 @@ bool GameState::do_step() {
void
GameState
::
process_key_pressed
(
sf
::
Keyboard
::
Key
key
)
{
if
(
key
==
config
::
KEY_LEFT
)
{
m_context_manager
.
save_current_context
();
m_context_manager
.
get_current_context
().
pacman
.
m_direction
=
config
::
LEFT
;
m_context_manager
.
get_current_context
().
pacman
.
move
(
Room
::
LEFT
);
}
else
if
(
key
==
config
::
KEY_RIGHT
)
{
m_context_manager
.
save_current_context
();
m_context_manager
.
get_current_context
().
pacman
.
m_direction
=
config
::
RIGHT
;
m_context_manager
.
get_current_context
().
pacman
.
move
(
Room
::
RIGHT
);
}
else
if
(
key
==
config
::
KEY_UP
)
{
m_context_manager
.
save_current_context
();
m_context_manager
.
get_current_context
().
pacman
.
m_direction
=
config
::
UP
;
m_context_manager
.
get_current_context
().
pacman
.
move
(
Room
::
UP
);
}
else
if
(
key
==
config
::
KEY_DOWN
)
{
m_context_manager
.
save_current_context
();
m_context_manager
.
get_current_context
().
pacman
.
m_direction
=
config
::
DOWN
;
m_context_manager
.
get_current_context
().
pacman
.
move
(
Room
::
DOWN
);
}
}
...
...
@@ -96,6 +100,11 @@ void GameState::update() {
process_entities_interactions
(
&
m_context_manager
.
get_current_context
().
pacman
);
if
(
!
m_context_manager
.
get_current_context
().
static_objects
.
size
())
m_context_manager
.
get_current_context
().
state
=
GameContext
::
WIN
;
auto
miliseconds
=
static_cast
<
size_t
>
(
m_context_manager
.
get_current_context
().
pacman
.
m_clock
.
getElapsedTime
().
asMilliseconds
());
if
(
miliseconds
<
200
)
return
;
m_context_manager
.
get_current_context
().
pacman
.
next_animation
();
m_context_manager
.
get_current_context
().
pacman
.
m_clock
.
restart
();
}
void
GameState
::
render
()
{
...
...
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