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
labs
Laba_3
pacman
Compare revisions
a6d6f3f69048516ab8d6e0452fccc0292729e53b...ec81d7042d4ab639d3b4fd63a2427e723c541586
Source
labs/laba_3/pacman
Select target project
ec81d7042d4ab639d3b4fd63a2427e723c541586
Select Git revision
Branches
main
..
..
...
Target
labs/laba_3/pacman
Select target project
labs/laba_3/pacman
a6d6f3f69048516ab8d6e0452fccc0292729e53b
Select Git revision
Branches
main
Compare
Swap revisions
Commits (2)
created ultimate skill with video
· 6e9737f0
Авдеев Евгений Владимирович
authored
3 weeks ago
6e9737f0
fixed pacman texture for each direction
· ec81d704
Авдеев Евгений Владимирович
authored
3 weeks ago
ec81d704
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
source/Draw/Texture.cpp
+23
-2
source/Draw/Texture.cpp
source/Draw/Texture.h
+2
-2
source/Draw/Texture.h
source/Event/IGameEvent.cpp
+38
-2
source/Event/IGameEvent.cpp
source/Event/IGameEvent.h
+11
-0
source/Event/IGameEvent.h
source/Game/Pacman.cpp
+10
-6
source/Game/Pacman.cpp
source/Game/Pacman.h
+3
-2
source/Game/Pacman.h
source/Maze/Maze.cpp
+7
-4
source/Maze/Maze.cpp
source/Maze/Maze.h
+1
-1
source/Maze/Maze.h
source/State/States.cpp
+12
-2
source/State/States.cpp
with
107 additions
and
21 deletions
+107
-21
source/Draw/Texture.cpp
View file @
ec81d704
#include
"Texture.h"
PacmanTexture
::
PacmanTexture
()
{
if
(
!
m_tex
.
loadFromFile
(
std
::
string
(
TEXTURE_PATH
)
+
"pacman.png"
))
throw
std
::
runtime_error
(
"Can't added Texture for Pacman"
);
if
(
!
m_right
.
loadFromFile
(
std
::
string
(
TEXTURE_PATH
)
+
"pacman.png"
))
throw
std
::
runtime_error
(
"Can't added Texture for pacman"
);
if
(
!
m_down
.
loadFromFile
(
std
::
string
(
TEXTURE_PATH
)
+
"pacman_down.png"
))
throw
std
::
runtime_error
(
"Can't added Texture for pacman"
);
if
(
!
m_left
.
loadFromFile
(
std
::
string
(
TEXTURE_PATH
)
+
"pacman_left.png"
))
throw
std
::
runtime_error
(
"Can't added Texture for pacman"
);
if
(
!
m_up
.
loadFromFile
(
std
::
string
(
TEXTURE_PATH
)
+
"pacman_up.png"
))
throw
std
::
runtime_error
(
"Can't added Texture for pacman"
);
}
sf
::
Texture
&
PacmanTexture
::
get_texture
()
{
switch
(
m_dir
)
{
case
Direction
::
UP
:
return
m_up
;
case
Direction
::
DOWN
:
return
m_down
;
case
Direction
::
RIGHT
:
return
m_right
;
case
Direction
::
LEFT
:
return
m_left
;
}
}
EnemyTexture
::
EnemyTexture
()
{
if
(
!
m_tex
.
loadFromFile
(
std
::
string
(
TEXTURE_PATH
)
+
"spider.png"
))
throw
std
::
runtime_error
(
"Can't added Texture for Enemy"
);
...
...
This diff is collapsed.
Click to expand it.
source/Draw/Texture.h
View file @
ec81d704
...
...
@@ -18,9 +18,9 @@ protected:
class
PacmanTexture
:
public
Texture
{
public:
static
PacmanTexture
&
Instance
()
{
static
PacmanTexture
tex
;
return
tex
;
}
sf
::
Texture
&
get_texture
()
override
{
return
m_tex
;
}
sf
::
Texture
&
get_texture
()
override
;
private
:
sf
::
Texture
m_
tex
;
sf
::
Texture
m_
up
,
m_right
,
m_down
,
m_left
;
PacmanTexture
();
};
...
...
This diff is collapsed.
Click to expand it.
source/Event/IGameEvent.cpp
View file @
ec81d704
#include
"IGameEvent.h"
#include
<opencv2/opencv.hpp>
#include
<iostream>
#include
"../Context/Context.h"
#include
"../Game/IEntity.h"
//DELETESTATIC
DeleteStaticEntity
::
DeleteStaticEntity
(
std
::
unique_ptr
<
IStaticEntity
>
ptr
)
:
m_ptr_entity
(
std
::
move
(
ptr
))
{}
void
DeleteStaticEntity
::
handle
(
GameContext
&
context
)
const
{
...
...
@@ -41,8 +42,43 @@ void Potion_take::handle(GameContext& context) const{
for
(
auto
it
=
context
.
static_obj
.
begin
();
it
!=
context
.
static_obj
.
end
();
++
it
)
{
if
(
m_ptr_entity
==
(
*
it
))
{
context
.
static_obj
.
erase
(
it
);
context
.
m_bar
.
regen_MP
(
5
0
);
context
.
m_bar
.
regen_MP
(
2
5
);
return
;
}
}
}
Ultimate
::
Ultimate
(){
set_sound
(
&
UltimateSound
::
Instance
());
m_sound
.
setBuffer
(
m_ptr_sound
->
get_sound
());
}
static
void
kill_all
(
GameContext
&
context
)
{
context
.
dynamic_obj
.
clear
();
}
void
Ultimate
::
handle
(
GameContext
&
context
)
const
{
//m_sound.play();
cv
::
VideoCapture
cap
(
std
::
string
(
VIDEO_PATH
)
+
"ultimate.mp4"
);
//
if
(
!
cap
.
isOpened
())
{
std
::
cerr
<<
"ERROR!!!!!!!!!!!!!!!!!
\n
"
<<
std
::
endl
;
}
cv
::
Mat
frame
;
cv
::
namedWindow
(
""
,
cv
::
WINDOW_NORMAL
);
//
cv
::
resizeWindow
(
""
,
1200
,
800
);
bool
flag
=
true
;
while
(
true
)
{
cap
>>
frame
;
//
if
(
frame
.
empty
())
break
;
// ,
if
(
flag
)
{
kill_all
(
context
);
}
cv
::
imshow
(
""
,
frame
);
if
(
cv
::
waitKey
(
30
)
==
27
)
break
;
// ESC
}
cap
.
release
();
cv
::
destroyAllWindows
();
}
This diff is collapsed.
Click to expand it.
source/Event/IGameEvent.h
View file @
ec81d704
#pragma once
#include
<memory>
#include
"Sound.h"
class
GameContext
;
class
IStaticEntity
;
class
IDynamicEntity
;
...
...
@@ -44,3 +46,12 @@ public:
void
handle
(
GameContext
&
context
)
const
override
;
};
class
Ultimate
:
public
IGameEvent
{
public:
Ultimate
();
void
handle
(
GameContext
&
context
)
const
override
;
void
set_sound
(
MySound
*
ptr_sound
)
{
m_ptr_sound
=
ptr_sound
;
}
private
:
MySound
*
m_ptr_sound
;
mutable
sf
::
Sound
m_sound
;
};
This diff is collapsed.
Click to expand it.
source/Game/Pacman.cpp
View file @
ec81d704
...
...
@@ -2,6 +2,7 @@
#include
<iostream>
#include
"../Config/Config.h"
Pacman
::
Pacman
()
{
m_clock
.
restart
();
set_texture
(
&
PacmanTexture
::
Instance
());
}
...
...
@@ -17,10 +18,12 @@ void Pacman::spell(){
}
}
void
Pacman
::
ultimate
(){
if
(
m_mp
>=
100
)
{
m_mp
-=
100
;
std
::
unique_ptr
<
IGameEvent
>
Pacman
::
ultimate
(){
if
(
m_mp
>=
300
)
{
m_mp
-=
300
;
return
std
::
make_unique
<
Ultimate
>
();
}
return
{};
}
void
Pacman
::
draw_into
(
sf
::
RenderWindow
&
window
)
const
{
...
...
@@ -35,6 +38,7 @@ void Pacman::draw_into(sf::RenderWindow& window) const {
}
void
Pacman
::
prepare_for_drawing
()
{
m_ptr_tex
->
set_dir
(
m_dir
);
m_sprite
.
setTexture
(
m_ptr_tex
->
get_texture
());
m_sprite
.
setScale
(
0.07
,
0.07
);
m_sprite
.
setPosition
(
m_ptr_room
->
get_position
()
+
sf
::
Vector2f
(
-
20
,
-
20
));
...
...
@@ -49,7 +53,7 @@ std::unique_ptr<IGameEvent> Pacman::visit(Food* ptr_food) {
std
::
unique_ptr
<
IGameEvent
>
Pacman
::
visit
(
MPpotion
*
ptr_food
)
{
if
(
ptr_food
->
get_location
()
!=
this
->
get_location
())
return
{};
m_mp
+=
5
0
;
m_mp
+=
2
5
;
return
std
::
make_unique
<
Potion_take
>
(
std
::
move
(
std
::
unique_ptr
<
MPpotion
>
(
ptr_food
)));
}
...
...
@@ -60,8 +64,9 @@ std::unique_ptr<IGameEvent> Fireball::visit(Enemy* ptr_enemy){
}
std
::
unique_ptr
<
IGameEvent
>
Pacman
::
visit
(
Enemy
*
ptr_enemy
)
{
if
(
ptr_enemy
->
get_location
()
!=
this
->
get_location
()
)
if
(
ptr_enemy
->
get_location
()
!=
this
->
get_location
()
||
m_clock
.
getElapsedTime
().
asSeconds
()
<
5
)
{
return
{};
}
return
std
::
make_unique
<
LostGame
>
();
}
...
...
@@ -73,7 +78,6 @@ Fireball::Fireball(Direction direction, Room* room) {
}
void
Fireball
::
draw_into
(
sf
::
RenderWindow
&
window
)
const
{
//std::cout << "x = " << m_sprite.getPosition().x << "; y = " << m_sprite.getPosition().y << '\n';
window
.
draw
(
m_sprite
);
}
...
...
This diff is collapsed.
Click to expand it.
source/Game/Pacman.h
View file @
ec81d704
...
...
@@ -25,7 +25,7 @@ public:
Pacman
();
void
move
(
Direction
direction
);
void
spell
();
void
ultimate
();
std
::
unique_ptr
<
IGameEvent
>
ultimate
();
void
draw_into
(
sf
::
RenderWindow
&
window
)
const
override
;
void
prepare_for_drawing
()
override
;
std
::
unique_ptr
<
IGameEvent
>
visit
(
Food
*
ptr_food
)
override
;
...
...
@@ -35,9 +35,10 @@ public:
std
::
vector
<
Fireball
>
m_spells
;
private
:
mutable
float
m_mp
=
config
::
PACMAN_START_MP
;
Direction
m_dir
;
Direction
m_dir
=
Direction
::
RIGHT
;
sf
::
Sprite
m_sprite
;
Texture
*
m_ptr_tex
;
sf
::
Clock
m_clock
;
};
...
...
This diff is collapsed.
Click to expand it.
source/Maze/Maze.cpp
View file @
ec81d704
...
...
@@ -136,19 +136,22 @@ void Wall::enter(IEntity* entity) {
MPbar
::
MPbar
(){
m_back
.
setSize
(
config
::
BAR_SIZE
);
m_back
.
setFillColor
(
sf
::
Color
(
50
,
50
,
50
));
m_back
.
setPosition
(
0
,
0
);
m_back
.
setOrigin
(
config
::
BAR_SIZE
.
x
/
2.0
f
,
config
::
BAR_SIZE
.
y
/
2.0
f
);
m_back
.
setPosition
(
config
::
GAME_VIDEO_MODE
.
width
/
2.0
f
,
1
);
float
percentage
=
m_cur_mp
/
m_max_mp
;
m_bar
.
setSize
(
sf
::
Vector2f
(
m_back
.
getSize
().
x
*
percentage
,
m_back
.
getSize
().
y
));
m_bar
.
setFillColor
(
sf
::
Color
(
0
,
0
,
255
));
// MP
m_bar
.
setPosition
(
0
,
0
);
m_bar
.
setFillColor
(
sf
::
Color
(
0
,
0
,
255
));
m_bar
.
setOrigin
(
config
::
BAR_SIZE
.
x
/
2.0
f
,
config
::
BAR_SIZE
.
y
/
2.0
f
);
m_bar
.
setPosition
(
config
::
GAME_VIDEO_MODE
.
width
/
2.0
f
,
1
);
m_text
.
setFont
(
MyFont
::
Instance
());
m_text
.
setString
(
std
::
to_string
((
size_t
)(
m_cur_mp
))
+
"/"
+
std
::
to_string
((
size_t
)
m_max_mp
));
m_text
.
setCharacterSize
(
0.90
*
15.0
f
);
m_text
.
setLetterSpacing
(
1
);
auto
textRect
=
m_text
.
getLocalBounds
();
m_text
.
setPosition
(
0
,
0
);
m_text
.
setOrigin
(
textRect
.
width
/
2.0
f
,
textRect
.
height
/
2.0
f
);
m_text
.
setPosition
(
m_back
.
getPosition
().
x
,
m_back
.
getPosition
().
y
);
m_text
.
setFillColor
(
config
::
BUTTON_COLOR_TEXT
);
m_text
.
setOutlineColor
(
config
::
BUTTON_COLOR_FRAME
);
m_text
.
setOutlineThickness
(
config
::
BUTTON_FRAME_THICKNESS
);
...
...
This diff is collapsed.
Click to expand it.
source/Maze/Maze.h
View file @
ec81d704
...
...
@@ -83,8 +83,8 @@ public:
void
use_MP
(
float
mp
);
void
regen_MP
(
float
mp
);
void
update
();
private:
float
m_cur_mp
=
config
::
PACMAN_START_MP
;
private:
float
m_max_mp
=
config
::
PACMAN_MAX_MP
;
sf
::
RectangleShape
m_back
;
sf
::
RectangleShape
m_bar
;
...
...
This diff is collapsed.
Click to expand it.
source/State/States.cpp
View file @
ec81d704
...
...
@@ -34,8 +34,18 @@ void GameState::event_handling() {
}
if
(
event
.
type
==
sf
::
Event
::
KeyPressed
&&
event
.
key
.
code
==
sf
::
Keyboard
::
Space
)
{
m_context_manager
.
save_context
();
m_context_manager
.
get_context
().
pacman
.
spell
();
m_context_manager
.
get_context
().
m_bar
.
use_MP
(
50
);
if
(
m_context_manager
.
get_context
().
m_bar
.
m_cur_mp
>=
50
)
{
m_context_manager
.
get_context
().
pacman
.
spell
();
m_context_manager
.
get_context
().
m_bar
.
use_MP
(
50
);
}
}
if
(
event
.
type
==
sf
::
Event
::
KeyPressed
&&
event
.
key
.
code
==
sf
::
Keyboard
::
E
)
{
m_context_manager
.
save_context
();
if
(
m_context_manager
.
get_context
().
m_bar
.
m_cur_mp
==
300
)
{
m_events
.
emplace_back
(
m_context_manager
.
get_context
().
pacman
.
ultimate
());
m_context_manager
.
get_context
().
m_bar
.
use_MP
(
300
);
}
}
if
(
event
.
type
==
sf
::
Event
::
KeyPressed
&&
m_context_manager
.
get_context
().
state
==
GameContext
::
INGAME
)
{
process_key_pressed
(
event
.
key
.
code
);
...
...
This diff is collapsed.
Click to expand it.
Menu
Explore
Projects
Groups
Topics
Snippets