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
Commits
ec81d704
Commit
ec81d704
authored
2 weeks ago
by
Авдеев Евгений Владимирович
Browse files
Options
Download
Patches
Plain Diff
fixed pacman texture for each direction
parent
6e9737f0
main
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 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
+1
-1
source/Event/IGameEvent.cpp
source/Game/Pacman.cpp
+4
-2
source/Game/Pacman.cpp
source/Game/Pacman.h
+2
-1
source/Game/Pacman.h
with
32 additions
and
8 deletions
+32
-8
source/Draw/Texture.cpp
+
23
−
2
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
+
2
−
2
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
+
1
−
1
View file @
ec81d704
...
...
@@ -58,7 +58,7 @@ static void kill_all(GameContext& context) {
}
void
Ultimate
::
handle
(
GameContext
&
context
)
const
{
m_sound
.
play
();
//
m_sound.play();
cv
::
VideoCapture
cap
(
std
::
string
(
VIDEO_PATH
)
+
"ultimate.mp4"
);
//
if
(
!
cap
.
isOpened
())
{
...
...
This diff is collapsed.
Click to expand it.
source/Game/Pacman.cpp
+
4
−
2
View file @
ec81d704
...
...
@@ -2,6 +2,7 @@
#include
<iostream>
#include
"../Config/Config.h"
Pacman
::
Pacman
()
{
m_clock
.
restart
();
set_texture
(
&
PacmanTexture
::
Instance
());
}
...
...
@@ -37,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
));
...
...
@@ -62,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
>
();
}
...
...
@@ -75,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
+
2
−
1
View file @
ec81d704
...
...
@@ -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.
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