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
1c1d2f70
Commit
1c1d2f70
authored
Apr 10, 2019
by
pa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a damageable class
parent
a434bb42
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
88 additions
and
24 deletions
+88
-24
data/room_0.dat
data/room_0.dat
+1
-0
headers/alive.hpp
headers/alive.hpp
+4
-1
headers/category.hpp
headers/category.hpp
+1
-1
headers/damageable.hpp
headers/damageable.hpp
+18
-0
headers/orbital.hpp
headers/orbital.hpp
+6
-3
headers/player.hpp
headers/player.hpp
+3
-0
headers/sword.hpp
headers/sword.hpp
+3
-3
source/alive.cpp
source/alive.cpp
+13
-5
source/damageable.cpp
source/damageable.cpp
+6
-0
source/ennemy.cpp
source/ennemy.cpp
+2
-1
source/orbital.cpp
source/orbital.cpp
+10
-2
source/player.cpp
source/player.cpp
+15
-4
source/room.cpp
source/room.cpp
+3
-1
source/sword.cpp
source/sword.cpp
+3
-2
source/textureHolder.cpp
source/textureHolder.cpp
+0
-1
No files found.
data/room_0.dat
View file @
1c1d2f70
0 0.5 0.5
6 0.25 0.5
16 0.75 0.5
headers/alive.hpp
View file @
1c1d2f70
...
...
@@ -32,7 +32,7 @@ public :
void
unlock
();
bool
isLocked
()
const
{
return
mLock
;}
void
hit
();
void
hit
(
bool
poisonous
=
false
);
void
hitAnimation
(
sf
::
Time
dt
);
virtual
Category
::
Category
identify
()
const
{
return
Category
::
Alive
;}
...
...
@@ -49,4 +49,7 @@ private :
bool
mLock
;
sf
::
Time
mLockTime
;
bool
mPoisoned
;
sf
::
Time
mPoisonTime
;
};
headers/category.hpp
View file @
1c1d2f70
...
...
@@ -2,6 +2,6 @@
namespace
Category
{
enum
Category
{
SceneNode
,
SpriteNode
,
Entity
,
Agent
,
Alive
,
Player
,
Ennemy
,
Orbital
,
Sword
,
Door
,
Collectible
SceneNode
,
SpriteNode
,
Entity
,
Agent
,
Alive
,
Player
,
Ennemy
,
Orbital
,
Sword
,
Door
,
Collectible
,
Damageable
};
}
headers/damageable.hpp
0 → 100644
View file @
1c1d2f70
#pragma once
#include "entity.hpp"
#include "category.hpp"
class
Damageable
:
public
Entity
{
public
:
Damageable
(
Agent
::
Type
type
,
TextureHolder
const
&
tex
,
int
dmg
=
1
,
bool
poisonous
=
false
);
virtual
Category
::
Category
identify
()
const
{
return
Category
::
Damageable
;}
bool
isPoisonous
()
const
{
return
mPoisonous
;}
int
getDMG
()
const
{
return
mDMG
;}
private
:
int
mDMG
;
bool
mPoisonous
;
};
headers/orbital.hpp
View file @
1c1d2f70
...
...
@@ -2,20 +2,23 @@
#include <iostream>
#include <SFML/Graphics.hpp>
#include "
entity
.hpp"
#include "
damageable
.hpp"
#include "speedPatern.hpp"
#include "category.hpp"
#include "alive.hpp"
class
Orbital
:
public
Entity
{
class
Orbital
:
public
Damageable
{
public
:
Orbital
(
Agent
::
Type
type
,
TextureHolder
const
&
texture
,
SpeedPatern
*
spP
,
Entity
::
Side
ally
);
Orbital
(
Agent
::
Type
type
,
TextureHolder
const
&
texture
,
SpeedPatern
*
spP
,
Entity
::
Side
ally
,
bool
poisonous
=
false
);
virtual
void
updateCurrent
(
sf
::
Time
dt
);
virtual
Category
::
Category
identify
()
const
{
return
Category
::
Orbital
;}
virtual
Entity
::
Side
getSide
()
const
{
return
Entity
::
None
;
}
virtual
void
onCollideWith
(
SceneNode
&
node
);
private
:
Entity
::
Side
mSide
;
SpeedPatern
*
mSpeedPatern
;
...
...
headers/player.hpp
View file @
1c1d2f70
...
...
@@ -5,6 +5,7 @@
#include "alive.hpp"
#include "category.hpp"
#include "sword.hpp"
#include "collectible.hpp"
class
Player
:
public
Alive
{
...
...
@@ -34,4 +35,6 @@ private :
bool
mIsWAvailable
,
mW
;
sf
::
Time
mWCD
,
mWElapse
;
int
poison_stack
;
bool
unsing_poison
;
};
headers/sword.hpp
View file @
1c1d2f70
#pragma once
#include <SFML/Graphics.hpp>
#include "
agent
.hpp"
#include "
damageable
.hpp"
#include "category.hpp"
#include <iostream>
class
Sword
:
public
Agent
{
class
Sword
:
public
Damageable
{
public
:
enum
State
{
Increasing
,
Decreading
};
Sword
(
TextureHolder
const
&
textures
);
Sword
(
TextureHolder
const
&
textures
,
bool
poisonous
=
false
);
virtual
void
updateCurrent
(
sf
::
Time
dt
);
...
...
source/alive.cpp
View file @
1c1d2f70
...
...
@@ -5,6 +5,11 @@ Alive::Alive(Agent::Type type, TextureHolder const& textures, int HP, Entity::Si
void
Alive
::
updateCurrent
(
sf
::
Time
dt
){
if
(
mPoisoned
)
mPoisonTime
-=
dt
;
if
(
mPoisoned
&&
mPoisonTime
.
asSeconds
()
<=
0.
f
){
hit
();
mPoisonTime
=
sf
::
seconds
(
1.
f
);
}
if
(
!
isLocked
()){
act
(
dt
);
hitAnimation
(
dt
);
...
...
@@ -36,7 +41,9 @@ Agent::Type Alive::typeOfState(){
return
Agent
::
Player
;
}
void
Alive
::
hit
(){
void
Alive
::
hit
(
bool
poisonous
){
if
(
poisonous
&&
!
mPoisoned
)
mPoisonTime
=
sf
::
seconds
(
1.
f
);
mPoisoned
=
mPoisoned
||
poisonous
;
if
(
!
mLock
){
--
mHP
;
lock
(
sf
::
milliseconds
(
500.
f
));
...
...
@@ -80,8 +87,9 @@ void Alive::moveRight(){
}
void
Alive
::
onCollideWith
(
SceneNode
&
collider
){
if
(
collider
.
identify
()
==
Category
::
Orbital
)
if
(
static_cast
<
Orbital
&>
(
collider
).
getSide
()
!=
mSide
){
hit
();
}
switch
(
collider
.
identify
()){
case
Category
::
Orbital
:
if
(
static_cast
<
Orbital
&>
(
collider
).
getSide
()
!=
mSide
)
hit
(
static_cast
<
Orbital
&>
(
collider
).
isPoisonous
());
}
}
source/damageable.cpp
0 → 100644
View file @
1c1d2f70
#include "../headers/damageable.hpp"
Damageable
::
Damageable
(
Agent
::
Type
type
,
TextureHolder
const
&
tex
,
int
dmg
,
bool
poisonous
)
:
Entity
(
type
,
tex
),
mDMG
(
dmg
),
mPoisonous
(
poisonous
)
{}
source/ennemy.cpp
View file @
1c1d2f70
#include "../headers/ennemy.hpp"
Ennemy
::
Ennemy
(
TextureHolder
const
&
textures
)
:
Alive
(
Agent
::
Tower
,
textures
,
2
,
Entity
::
Ennemy
),
mIsQ
(
true
),
mIsW
(
true
){
Ennemy
::
Ennemy
(
TextureHolder
const
&
textures
)
:
Alive
(
Agent
::
Tower
,
textures
,
1
2
,
Entity
::
Ennemy
),
mIsQ
(
true
),
mIsW
(
true
){
mQCD
=
sf
::
seconds
(
4.
f
);
markForReset
();
}
...
...
@@ -55,6 +55,7 @@ void Ennemy::onCollideWith(SceneNode& collider){
hit
();
break
;
}
Alive
::
onCollideWith
(
collider
);
}
...
...
source/orbital.cpp
View file @
1c1d2f70
#include "../headers/orbital.hpp"
Orbital
::
Orbital
(
Agent
::
Type
type
,
TextureHolder
const
&
textures
,
SpeedPatern
*
spP
,
Entity
::
Side
ally
)
:
Entity
(
type
,
texture
s
),
mSpeedPatern
(
spP
),
mLifeSpan
(
sf
::
seconds
(
15.
f
)),
mSide
(
ally
){
Orbital
::
Orbital
(
Agent
::
Type
type
,
TextureHolder
const
&
textures
,
SpeedPatern
*
spP
,
Entity
::
Side
ally
,
bool
poisonous
)
:
Damageable
(
type
,
textures
,
1
,
poisonou
s
),
mSpeedPatern
(
spP
),
mLifeSpan
(
sf
::
seconds
(
15.
f
)),
mSide
(
ally
){
}
void
Orbital
::
updateCurrent
(
sf
::
Time
dt
){
...
...
@@ -13,3 +13,11 @@ void Orbital::updateCurrent(sf::Time dt){
setVelocity
(
mSpeedPatern
->
getVelocity
());
Entity
::
updateCurrent
(
dt
);
}
void
Orbital
::
onCollideWith
(
SceneNode
&
node
){
switch
(
node
.
identify
()){
case
Category
::
Player
:
case
Category
::
Ennemy
:
stageForRemoval
();
break
;
}
}
source/player.cpp
View file @
1c1d2f70
...
...
@@ -14,7 +14,8 @@ Agent::Type Player::typeOfState(){
}
Player
::
Player
(
TextureHolder
const
&
textures
)
:
Alive
(
Agent
::
Player
,
textures
,
8
,
Entity
::
Player
),
mIsQAvailable
(
true
),
mIsWAvailable
(
true
),
mW
(
false
){
:
Alive
(
Agent
::
Player
,
textures
,
8
,
Entity
::
Player
),
mIsQAvailable
(
true
),
mIsWAvailable
(
true
),
mW
(
false
),
poison_stack
(
0
){
mQCD
=
sf
::
seconds
(
8.
f
);
mWCD
=
sf
::
seconds
(
1.
f
);
}
...
...
@@ -27,7 +28,7 @@ void Player::q_spell(){
sf
::
Transform
transform
;
transform
.
rotate
(
120.
f
);
for
(
int
i
=
0
;
i
<
3
;
++
i
){
Orbital
*
orb
=
new
Orbital
(
Agent
::
qProjectile
,
getTexHolder
(),
new
RotationSpeedPatern
(
positionSetter
,
540.
f
),
Entity
::
Player
);
RotationSpeedPatern
(
positionSetter
,
540.
f
),
Entity
::
Player
,
unsing_poison
);
orb
->
setPosition
(
positionSetter
);
attachChild
(
orb
);
positionSetter
=
transform
.
transformPoint
(
positionSetter
);
...
...
@@ -39,7 +40,7 @@ void Player::w_spell(int dir){
if
(
mIsWAvailable
&&
mW
){
mIsWAvailable
=
false
;
Sword
*
sword
=
new
Sword
(
getTexHolder
()
)
;
Sword
*
sword
=
new
Sword
(
getTexHolder
()
,
unsing_poison
);
unsing_poison
=
false
;
sword
->
rotate
(
dir
*
90.
f
);
attachChild
(
sword
);
}
...
...
@@ -74,12 +75,22 @@ void Player::keyBindings(){
if
(
sf
::
Keyboard
::
isKeyPressed
(
sf
::
Keyboard
::
Q
))
w_spell
(
2
);
if
(
sf
::
Keyboard
::
isKeyPressed
(
sf
::
Keyboard
::
S
))
w_spell
(
1
);
if
(
sf
::
Keyboard
::
isKeyPressed
(
sf
::
Keyboard
::
D
))
w_spell
(
0
);
if
(
sf
::
Keyboard
::
isKeyPressed
(
sf
::
Keyboard
::
E
)
&&
!
unsing_poison
&&
poison_stack
>
0
){
unsing_poison
=
true
;
--
poison_stack
;
}
}
void
Player
::
onCollideWith
(
SceneNode
&
collider
){
switch
(
collider
.
identify
()){
case
Category
::
Collectible
:
giveSword
();
switch
(
static_cast
<
Collectible
&>
(
collider
).
getType
()){
case
Collectible
::
Sword
:
giveSword
();
break
;
case
Collectible
::
Poison
:
++
poison_stack
;
break
;
}
break
;
}
Alive
::
onCollideWith
(
collider
);
...
...
source/room.cpp
View file @
1c1d2f70
...
...
@@ -25,6 +25,7 @@ void Room::loadTextures(){
mTextures
.
load
(
Textures
::
Sword_5
,
pathOfID
(
Textures
::
Sword_5
));
mTextures
.
load
(
Textures
::
SwordFloor
,
pathOfID
(
Textures
::
SwordFloor
));
mTextures
.
load
(
Textures
::
Doors
,
pathOfID
(
Textures
::
Doors
));
mTextures
.
load
(
Textures
::
Poison
,
pathOfID
(
Textures
::
Poison
));
}
...
...
@@ -53,7 +54,8 @@ void Room::buildScene(std::string path){
mSceneLayers
[
Air
]
->
attachChild
(
ennemy
);
break
;
}
case
Agent
::
SwordFloor
:{
case
Agent
::
Poison
:{
case
Agent
::
SwordFloor
:
Collectible
*
sword
(
new
Collectible
(
mTextures
,
Collectible
::
typeIn
(
rType
)));
sword
->
setPosition
(
alpha_x
*
x
,
alpha_y
*
y
);
mSceneLayers
[
Air
]
->
attachChild
(
sword
);
...
...
source/sword.cpp
View file @
1c1d2f70
#include "../headers/sword.hpp"
Sword
::
Sword
(
TextureHolder
const
&
mTextures
)
:
Agent
(
Agent
::
Sword_1
,
mTextures
),
mAnimationTime
(
sf
::
milliseconds
(
80.
f
)),
mIsIncreasing
(
true
){
Sword
::
Sword
(
TextureHolder
const
&
mTextures
,
bool
poisonous
)
:
Damageable
(
Agent
::
Sword_1
,
mTextures
,
1
,
poisonous
),
mAnimationTime
(
sf
::
milliseconds
(
80.
f
)),
mIsIncreasing
(
true
){
getSprite
().
setOrigin
(
20.
f
,
20.
f
);
}
...
...
source/textureHolder.cpp
View file @
1c1d2f70
...
...
@@ -10,7 +10,6 @@ void RessourceHolder<Ressource,Identifier>::load(Identifier id, const std::strin
throw
std
::
runtime_error
(
"RessourceHolder::load - Failed to load "
+
filename
);
auto
inserted
=
mRessourceMap
.
insert
(
std
::
make_pair
(
id
,
std
::
move
(
res
)));
//if(!inserted.second) throw std::logic_error("TextureHolder::load - Failed to insert " + filename);
return
;
}
...
...
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