Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
ProjetProg2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pa
ProjetProg2
Commits
04ff12af
Commit
04ff12af
authored
Apr 10, 2019
by
pa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HUD support of key and coin
parent
2796c116
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
85 additions
and
37 deletions
+85
-37
data/room_0.dat
data/room_0.dat
+2
-0
headers/HUD.hpp
headers/HUD.hpp
+6
-3
headers/agent.hpp
headers/agent.hpp
+3
-2
headers/collectible.hpp
headers/collectible.hpp
+1
-1
headers/player.hpp
headers/player.hpp
+4
-0
headers/textureHolder.hpp
headers/textureHolder.hpp
+2
-1
res/coin.png
res/coin.png
+0
-0
res/key.png
res/key.png
+0
-0
res/void.png
res/void.png
+0
-0
source/HUD.cpp
source/HUD.cpp
+23
-23
source/agent.cpp
source/agent.cpp
+4
-0
source/alive.cpp
source/alive.cpp
+1
-1
source/collectible.cpp
source/collectible.cpp
+4
-0
source/game.cpp
source/game.cpp
+2
-0
source/player.cpp
source/player.cpp
+7
-1
source/room.cpp
source/room.cpp
+5
-1
source/textureHolder.cpp
source/textureHolder.cpp
+6
-0
source/world.cpp
source/world.cpp
+15
-4
No files found.
data/room_0.dat
View file @
04ff12af
0 0.5 0.5
6 0.25 0.5
16 0.75 0.5
18 0.5 0.25
19 0.5 0.75
headers/HUD.hpp
View file @
04ff12af
...
...
@@ -8,8 +8,12 @@
class
HUD
{
public
:
struct
Meter
{
int
cv
;
int
mv
;
Agent
::
Type
upType
,
downType
;
};
struct
HUD_data
{
int
HP
;
int
HP_max
;
int
poison_stack
;
int
poison_stack_max
;
Meter
*
meters
;
int
size
;
};
HUD
(
sf
::
RenderWindow
&
window
,
HUD_data
*
data
);
...
...
@@ -27,7 +31,6 @@ class HUD{
TextureHolder
mTextures
;
SceneNode
mRoot
;
SpriteNode
**
mHPs
;
SpriteNode
**
mPoisonStack
;
SpriteNode
***
mContent
;
HUD_data
*
mData
;
};
headers/agent.hpp
View file @
04ff12af
...
...
@@ -11,9 +11,10 @@ class Agent : public SceneNode{
public
:
enum
Type
{
Floor
,
qProjectile
,
tProjectile
,
Player
,
PlayerHit
,
Tower
,
SwordFloor
,
Sword_0
,
Sword_1
,
Sword_2
,
Sword_3
,
Sword_4
,
Sword_5
,
Doors
,
HP_full
,
HP_down
,
Poison
,
Void
SwordFloor
,
Sword_0
,
Sword_1
,
Sword_2
,
Sword_3
,
Sword_4
,
Sword_5
,
Doors
,
HP_full
,
HP_down
,
Poison
,
Void
,
Coin
,
Key
};
Textures
::
ID
toTextureID
(
Type
type
);
static
Textures
::
ID
toTextureID
(
Type
type
);
public
:
Agent
(
Type
type
,
TextureHolder
const
&
textures
);
...
...
headers/collectible.hpp
View file @
04ff12af
...
...
@@ -8,7 +8,7 @@
class
Collectible
:
public
Agent
{
public
:
enum
Type
{
Sword
,
Poison
,
Health
,
Dagger
};
enum
Type
{
Sword
,
Poison
,
Coin
,
Key
,
Health
,
Dagger
};
static
Agent
::
Type
typeOf
(
Type
type
);
static
Type
typeIn
(
Agent
::
Type
type
);
...
...
headers/player.hpp
View file @
04ff12af
...
...
@@ -28,6 +28,8 @@ public :
virtual
Category
::
Category
identify
()
const
{
return
Category
::
Player
;}
int
getPoisonStack
()
const
{
return
poison_stack
;}
int
getCoins
()
const
{
return
coin_stack
;}
int
getKeys
()
const
{
return
key_stack
;}
virtual
void
onCollideWith
(
SceneNode
&
collider
);
...
...
@@ -39,4 +41,6 @@ private :
sf
::
Time
mWCD
,
mWElapse
;
int
poison_stack
;
bool
unsing_poison
;
int
key_stack
;
bool
unsing_key
;
int
coin_stack
;
bool
unsing_coin
;
};
headers/textureHolder.hpp
View file @
04ff12af
...
...
@@ -9,7 +9,8 @@
namespace
Textures
{
enum
ID
{
Floor
,
qProjectile
,
tProjectile
,
Player
,
PlayerHit
,
Tower
,
Poison
,
SwordFloor
,
Sword_0
,
Sword_1
,
Sword_2
,
Sword_3
,
Sword_4
,
Sword_5
,
Doors
,
HP_full
,
HP_down
,
Void
SwordFloor
,
Sword_0
,
Sword_1
,
Sword_2
,
Sword_3
,
Sword_4
,
Sword_5
,
Doors
,
HP_full
,
HP_down
,
Void
,
Coin
,
Key
};
}
...
...
res/coin.png
0 → 100644
View file @
04ff12af
1.44 KB
res/key.png
0 → 100644
View file @
04ff12af
244 Bytes
res/void.png
View replaced file @
2796c116
View file @
04ff12af
184 Bytes
|
W:
|
H:
182 Bytes
|
W:
|
H:
2-up
Swipe
Onion skin
source/HUD.cpp
View file @
04ff12af
...
...
@@ -5,39 +5,39 @@
HUD
::
HUD
(
sf
::
RenderWindow
&
window
,
HUD
::
HUD_data
*
data
)
:
mWindow
(
window
),
mView
(
window
.
getDefaultView
()),
mBounds
(
0.
f
,
0.
f
,
mView
.
getSize
().
x
,
mView
.
getSize
().
y
),
mData
(
data
){
loadTextures
();
mHPs
=
new
SpriteNode
*
[
mData
->
HP_max
];
for
(
int
i
=
0
;
i
<
mData
->
HP_max
;
++
i
){
mHPs
[
i
]
=
new
SpriteNode
(
Agent
::
HP_full
,
mTextures
);
mRoot
.
attachChild
(
mHPs
[
i
]);
mHPs
[
i
]
->
move
(
32
*
i
+
16
,
16
);
}
mPoisonStack
=
new
SpriteNode
*
[
mData
->
poison_stack_max
];
for
(
int
i
=
0
;
i
<
mData
->
poison_stack_max
;
++
i
){
mPoisonStack
[
i
]
=
new
SpriteNode
(
Agent
::
Poison
,
mTextures
);
mRoot
.
attachChild
(
mPoisonStack
[
i
]);
mPoisonStack
[
i
]
->
move
(
16
*
i
+
8
,
32
+
8
);
}
loadTextures
();
mContent
=
new
SpriteNode
**
[
mData
->
size
];
for
(
int
i
=
0
;
i
<
mData
->
size
;
++
i
){
mContent
[
i
]
=
new
SpriteNode
*
[
mData
->
meters
[
i
].
mv
];
for
(
int
j
=
0
;
j
<
mData
->
meters
[
i
].
mv
;
++
j
){
mContent
[
i
][
j
]
=
new
SpriteNode
(
mData
->
meters
[
i
].
upType
,
mTextures
);
mRoot
.
attachChild
(
mContent
[
i
][
j
]);
mContent
[
i
][
j
]
->
move
(
32
*
j
+
16
,
32
*
i
+
16
);
}
}
}
void
HUD
::
loadTextures
(){
mTextures
.
load
(
Textures
::
HP_full
,
pathOfID
(
Textures
::
HP_full
));
mTextures
.
load
(
Textures
::
HP_down
,
pathOfID
(
Textures
::
HP_down
));
mTextures
.
load
(
Textures
::
Poison
,
pathOfID
(
Textures
::
Poison
));
mTextures
.
load
(
Textures
::
Void
,
pathOfID
(
Textures
::
Void
));
for
(
int
i
=
0
;
i
<
mData
->
size
;
++
i
){
mTextures
.
load
(
Agent
::
toTextureID
(
mData
->
meters
[
i
].
upType
),
pathOfID
(
Agent
::
toTextureID
(
mData
->
meters
[
i
].
upType
)));
mTextures
.
load
(
Agent
::
toTextureID
(
mData
->
meters
[
i
].
downType
),
pathOfID
(
Agent
::
toTextureID
(
mData
->
meters
[
i
].
downType
)));
}
}
void
HUD
::
draw
(){
mWindow
.
draw
(
mRoot
);
}
void
HUD
::
update
(
sf
::
Time
dt
){
for
(
int
i
=
0
;
i
<
mData
->
poison_stack
;
++
i
){
mPoisonStack
[
i
]
->
setType
(
Agent
::
Poison
);
}
for
(
int
i
=
mData
->
poison_stack
;
i
<
mData
->
poison_stack_max
;
++
i
){
mPoisonStack
[
i
]
->
setType
(
Agent
::
Void
);
for
(
int
i
=
0
;
i
<
mData
->
size
;
++
i
){
for
(
int
j
=
0
;
j
<
mData
->
meters
[
i
].
cv
;
++
j
)
mContent
[
i
][
j
]
->
setType
(
mData
->
meters
[
i
].
upType
);
for
(
int
j
=
mData
->
meters
[
i
].
cv
;
j
<
mData
->
meters
[
i
].
mv
;
++
j
)
mContent
[
i
][
j
]
->
setType
(
mData
->
meters
[
i
].
downType
);
}
mRoot
.
update
(
dt
);
}
...
...
source/agent.cpp
View file @
04ff12af
...
...
@@ -39,6 +39,10 @@ Textures::ID Agent::toTextureID(Agent::Type type){
return
Textures
::
ID
::
HP_down
;
case
Void
:
return
Textures
::
ID
::
Void
;
case
Key
:
return
Textures
::
ID
::
Key
;
case
Coin
:
return
Textures
::
ID
::
Coin
;
default
:
throw
std
::
logic_error
(
"Agent::toTextureID, non-exhaustive pattern-matching"
);
}
...
...
source/alive.cpp
View file @
04ff12af
#include "../headers/alive.hpp"
Alive
::
Alive
(
Agent
::
Type
type
,
TextureHolder
const
&
textures
,
int
HP
,
Entity
::
Side
side
)
:
Entity
(
type
,
textures
),
mHP
(
HP
),
mState
(
Normal
),
mSide
(
side
){}
:
Entity
(
type
,
textures
),
mHP
(
HP
),
mState
(
Normal
),
mSide
(
side
)
,
mPoisoned
(
false
)
{}
void
Alive
::
updateCurrent
(
sf
::
Time
dt
){
...
...
source/collectible.cpp
View file @
04ff12af
...
...
@@ -4,6 +4,8 @@ Agent::Type Collectible::typeOf(Collectible::Type type){
switch
(
type
){
case
Poison
:
return
Agent
::
Poison
;
case
Sword
:
return
Agent
::
SwordFloor
;
case
Key
:
return
Agent
::
Key
;
case
Coin
:
return
Agent
::
Coin
;
default
:
return
Agent
::
SwordFloor
;
}
}
...
...
@@ -12,6 +14,8 @@ Collectible::Type Collectible::typeIn(Agent::Type type){
switch
(
type
){
case
Agent
::
Poison
:
return
Poison
;
case
Agent
::
SwordFloor
:
return
Sword
;
case
Agent
::
Key
:
return
Key
;
case
Agent
::
Coin
:
return
Coin
;
default
:
return
Collectible
::
Sword
;
}
}
...
...
source/game.cpp
View file @
04ff12af
...
...
@@ -26,6 +26,8 @@ void Game::processEvents(){
break
;
}
}
if
(
sf
::
Keyboard
::
isKeyPressed
(
sf
::
Keyboard
::
LControl
)
&&
sf
::
Keyboard
::
isKeyPressed
(
sf
::
Keyboard
::
Q
))
mWindow
.
close
();
}
void
Game
::
update
(
sf
::
Time
deltaTime
){
...
...
source/player.cpp
View file @
04ff12af
...
...
@@ -15,7 +15,7 @@ Agent::Type Player::typeOfState(){
Player
::
Player
(
TextureHolder
const
&
textures
)
:
Alive
(
Agent
::
Player
,
textures
,
8
,
Entity
::
Player
),
mIsQAvailable
(
true
),
mIsWAvailable
(
true
),
mW
(
false
),
poison_stack
(
0
){
poison_stack
(
0
)
,
coin_stack
(
0
),
key_stack
(
0
)
{
mQCD
=
sf
::
seconds
(
8.
f
);
mWCD
=
sf
::
seconds
(
1.
f
);
}
...
...
@@ -90,6 +90,12 @@ void Player::onCollideWith(SceneNode& collider){
case
Collectible
::
Poison
:
++
poison_stack
;
break
;
case
Collectible
::
Coin
:
++
coin_stack
;
break
;
case
Collectible
::
Key
:
++
key_stack
;
break
;
}
break
;
}
...
...
source/room.cpp
View file @
04ff12af
...
...
@@ -26,6 +26,8 @@ void Room::loadTextures(){
mTextures
.
load
(
Textures
::
SwordFloor
,
pathOfID
(
Textures
::
SwordFloor
));
mTextures
.
load
(
Textures
::
Doors
,
pathOfID
(
Textures
::
Doors
));
mTextures
.
load
(
Textures
::
Poison
,
pathOfID
(
Textures
::
Poison
));
mTextures
.
load
(
Textures
::
Coin
,
pathOfID
(
Textures
::
Coin
));
mTextures
.
load
(
Textures
::
Key
,
pathOfID
(
Textures
::
Key
));
}
...
...
@@ -54,8 +56,10 @@ void Room::buildScene(std::string path){
mSceneLayers
[
Air
]
->
attachChild
(
ennemy
);
break
;
}
case
Agent
::
Poison
:{
case
Agent
::
Coin
:{
case
Agent
::
Poison
:
case
Agent
::
SwordFloor
:
case
Agent
::
Key
:
Collectible
*
sword
(
new
Collectible
(
mTextures
,
Collectible
::
typeIn
(
rType
)));
sword
->
setPosition
(
alpha_x
*
x
,
alpha_y
*
y
);
mSceneLayers
[
Air
]
->
attachChild
(
sword
);
...
...
source/textureHolder.cpp
View file @
04ff12af
...
...
@@ -90,6 +90,12 @@ std::string pathOfID(Textures::ID id){
case
Textures
::
Void
:
str
=
"res/void.png"
;
break
;
case
Textures
::
Key
:
str
=
"res/key.png"
;
break
;
case
Textures
::
Coin
:
str
=
"res/coin.png"
;
break
;
default
:
throw
std
::
logic_error
(
"TextureHolder::pathOfID, Non-exhaustive pattern-matching"
);
}
...
...
source/world.cpp
View file @
04ff12af
...
...
@@ -8,14 +8,25 @@ World::World(sf::RenderWindow& window)
mRoom
=
mCarte
.
checkIn
();
spawnPlayer
(
mRoom
);
mSceneGraph
.
attachChild
(
mRoom
);
mData
=
new
HUD
::
HUD_data
;
mData
->
HP
=
mData
->
HP_max
=
getPlayerHP
();
mData
->
poison_stack_max
=
10
;
mData
->
poison_stack
=
0
;
mData
->
size
=
4
;
mData
->
meters
=
new
HUD
::
Meter
[
mData
->
size
];
mData
->
meters
[
0
].
cv
=
mData
->
meters
[
0
].
mv
=
getPlayerHP
();
mData
->
meters
[
0
].
upType
=
Agent
::
HP_full
;
mData
->
meters
[
0
].
downType
=
Agent
::
HP_down
;
mData
->
meters
[
1
].
mv
=
10
;
mData
->
meters
[
1
].
cv
=
0
;
mData
->
meters
[
1
].
upType
=
Agent
::
Poison
;
mData
->
meters
[
1
].
downType
=
Agent
::
Void
;
mData
->
meters
[
2
].
mv
=
10
;
mData
->
meters
[
2
].
cv
=
0
;
mData
->
meters
[
2
].
upType
=
Agent
::
Coin
;
mData
->
meters
[
2
].
downType
=
Agent
::
Void
;
mData
->
meters
[
3
].
mv
=
10
;
mData
->
meters
[
3
].
cv
=
0
;
mData
->
meters
[
3
].
upType
=
Agent
::
Key
;
mData
->
meters
[
3
].
downType
=
Agent
::
Void
;
}
void
World
::
fillData
(){
mData
->
HP
=
getPlayerHP
();
mData
->
poison_stack
=
mPlayer
->
getPoisonStack
();
mData
->
meters
[
0
].
cv
=
getPlayerHP
();
mData
->
meters
[
1
].
cv
=
mPlayer
->
getPoisonStack
();
mData
->
meters
[
2
].
cv
=
mPlayer
->
getCoins
();
mData
->
meters
[
3
].
cv
=
mPlayer
->
getKeys
();
}
void
World
::
spawnPlayer
(
Room
*
room
){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment