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
68689404
Commit
68689404
authored
Apr 09, 2019
by
pa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Did the collision not bad
parent
eff534b0
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
109 additions
and
46 deletions
+109
-46
Readme.md
Readme.md
+0
-3
headers/alive.hpp
headers/alive.hpp
+4
-1
headers/category.hpp
headers/category.hpp
+1
-1
headers/collectible.hpp
headers/collectible.hpp
+24
-0
headers/entity.hpp
headers/entity.hpp
+12
-9
headers/orbital.hpp
headers/orbital.hpp
+4
-3
headers/player.hpp
headers/player.hpp
+2
-0
headers/room.hpp
headers/room.hpp
+1
-0
headers/sceneNode.hpp
headers/sceneNode.hpp
+1
-0
source/alive.cpp
source/alive.cpp
+9
-2
source/collectible.cpp
source/collectible.cpp
+24
-0
source/ennemy.cpp
source/ennemy.cpp
+2
-2
source/orbital.cpp
source/orbital.cpp
+2
-3
source/player.cpp
source/player.cpp
+11
-2
source/room.cpp
source/room.cpp
+1
-2
source/sceneNode.cpp
source/sceneNode.cpp
+5
-1
source/world.cpp
source/world.cpp
+6
-17
No files found.
Readme.md
View file @
68689404
...
...
@@ -33,6 +33,3 @@
-
[ ] Different kinds of weapons
*
Limit to 2 weapons
-
[ ] Heals and consomable
headers/alive.hpp
View file @
68689404
...
...
@@ -15,7 +15,7 @@ public :
virtual
Agent
::
Type
typeOfState
();
public
:
Alive
(
Agent
::
Type
type
,
TextureHolder
const
&
Textures
,
int
HP
);
Alive
(
Agent
::
Type
type
,
TextureHolder
const
&
Textures
,
int
HP
,
Entity
::
Side
side
);
int
getHP
()
const
{
return
mHP
;}
State
getState
()
const
{
return
mState
;}
...
...
@@ -37,7 +37,10 @@ public :
virtual
Category
::
Category
identify
()
const
{
return
Category
::
Alive
;}
virtual
void
onCollideWith
(
SceneNode
&
collider
);
private
:
Entity
::
Side
mSide
;
State
mState
;
int
mHP
;
...
...
headers/category.hpp
View file @
68689404
...
...
@@ -2,6 +2,6 @@
namespace
Category
{
enum
Category
{
SceneNode
,
SpriteNode
,
Entity
,
Agent
,
Alive
,
Player
,
Ennemy
,
Orbital
,
Sword
,
Door
SceneNode
,
SpriteNode
,
Entity
,
Agent
,
Alive
,
Player
,
Ennemy
,
Orbital
,
Sword
,
Door
,
Collectible
};
}
headers/collectible.hpp
0 → 100644
View file @
68689404
#pragma once
#include <SFML/Graphics.hpp>
#include "textureHolder.hpp"
#include "category.hpp"
#include "agent.hpp"
class
Collectible
:
public
Agent
{
public
:
enum
Type
{
Sword
,
Poison
,
Health
,
Dagger
};
static
Agent
::
Type
typeOf
(
Type
type
);
static
Type
typeIn
(
Agent
::
Type
type
);
public
:
Collectible
(
TextureHolder
const
&
tex
,
Type
type
);
Type
getType
(){
return
mType
;}
virtual
Category
::
Category
identify
()
const
{
return
Category
::
Collectible
;}
virtual
void
onCollideWith
(
SceneNode
&
collider
);
private
:
Type
mType
;
};
headers/entity.hpp
View file @
68689404
...
...
@@ -6,18 +6,21 @@
class
Entity
:
public
Agent
{
public
:
Entity
(
Agent
::
Type
type
,
TextureHolder
const
&
textures
)
;
public
:
enum
Side
{
None
,
Player
,
Ennemy
}
;
void
setVelocity
(
sf
::
Vector2f
velocity
);
void
setVelocity
(
float
x
,
float
y
);
public:
Entity
(
Agent
::
Type
type
,
TextureHolder
const
&
textures
);
sf
::
Vector2f
&
getVelocity
();
void
setVelocity
(
sf
::
Vector2f
velocity
);
void
setVelocity
(
float
x
,
float
y
);
virtual
void
updateCurrent
(
sf
::
Time
dt
);
sf
::
Vector2f
&
getVelocity
(
);
virtual
Category
::
Category
identify
()
const
{
return
Category
::
Entity
;}
virtual
void
updateCurrent
(
sf
::
Time
dt
);
private:
sf
::
Vector2f
mVelocity
;
virtual
Category
::
Category
identify
()
const
{
return
Category
::
Entity
;}
private:
sf
::
Vector2f
mVelocity
;
};
headers/orbital.hpp
View file @
68689404
...
...
@@ -5,18 +5,19 @@
#include "entity.hpp"
#include "speedPatern.hpp"
#include "category.hpp"
#include "alive.hpp"
class
Orbital
:
public
Entity
{
public
:
Orbital
(
Agent
::
Type
type
,
TextureHolder
const
&
texture
,
SpeedPatern
*
spP
,
bool
ally
);
Orbital
(
Agent
::
Type
type
,
TextureHolder
const
&
texture
,
SpeedPatern
*
spP
,
Entity
::
Side
ally
);
virtual
void
updateCurrent
(
sf
::
Time
dt
);
virtual
Category
::
Category
identify
()
const
{
return
Category
::
Orbital
;}
virtual
bool
getOwner
()
const
{
return
mAlly
;
}
virtual
Entity
::
Side
getSide
()
const
{
return
Entity
::
None
;
}
private
:
bool
mAlly
;
Entity
::
Side
mSide
;
SpeedPatern
*
mSpeedPatern
;
sf
::
Time
mLifeSpan
;
};
headers/player.hpp
View file @
68689404
...
...
@@ -26,6 +26,8 @@ public :
virtual
Category
::
Category
identify
()
const
{
return
Category
::
Player
;}
virtual
void
onCollideWith
(
SceneNode
&
collider
);
private
:
bool
mIsQAvailable
;
sf
::
Time
mQCD
,
mQElapse
;
...
...
headers/room.hpp
View file @
68689404
...
...
@@ -8,6 +8,7 @@
#include "ennemy.hpp"
#include "player.hpp"
#include "door.hpp"
#include "collectible.hpp"
#include <fstream>
#include <sstream>
...
...
headers/sceneNode.hpp
View file @
68689404
...
...
@@ -39,6 +39,7 @@ public :
bool
collidesWith
(
SceneNode
&
node
)
const
;
void
checkNodeCollision
(
SceneNode
&
node
,
std
::
set
<
Pair
>&
target
);
void
checkSceneCollision
(
SceneNode
&
root
,
std
::
set
<
Pair
>&
target
);
virtual
void
onCollideWith
(
SceneNode
&
collider
);
private
:
std
::
vector
<
Ptr
>
mChildren
;
...
...
source/alive.cpp
View file @
68689404
#include "../headers/alive.hpp"
Alive
::
Alive
(
Agent
::
Type
type
,
TextureHolder
const
&
textures
,
int
HP
)
:
Entity
(
type
,
textures
),
mHP
(
HP
),
mState
(
Normal
){}
Alive
::
Alive
(
Agent
::
Type
type
,
TextureHolder
const
&
textures
,
int
HP
,
Entity
::
Side
side
)
:
Entity
(
type
,
textures
),
mHP
(
HP
),
mState
(
Normal
)
,
mSide
(
side
)
{}
void
Alive
::
updateCurrent
(
sf
::
Time
dt
){
...
...
@@ -78,3 +78,10 @@ void Alive::moveLeft(){
void
Alive
::
moveRight
(){
getVelocity
()
+=
sf
::
Vector2f
(
400.
f
,
0.
f
);
}
void
Alive
::
onCollideWith
(
SceneNode
&
collider
){
if
(
collider
.
identify
()
==
Category
::
Orbital
)
if
(
static_cast
<
Orbital
&>
(
collider
).
getSide
()
!=
mSide
){
hit
();
}
}
source/collectible.cpp
0 → 100644
View file @
68689404
#include "../headers/collectible.hpp"
Agent
::
Type
Collectible
::
typeOf
(
Collectible
::
Type
type
){
switch
(
type
){
default
:
return
Agent
::
SwordFloor
;
}
}
Collectible
::
Type
Collectible
::
typeIn
(
Agent
::
Type
type
){
switch
(
type
){
default
:
return
Collectible
::
Sword
;
}
}
Collectible
::
Collectible
(
TextureHolder
const
&
tex
,
Collectible
::
Type
type
)
:
Agent
(
typeOf
(
type
),
tex
),
mType
(
type
)
{}
void
Collectible
::
onCollideWith
(
SceneNode
&
collider
){
switch
(
collider
.
identify
()){
case
Category
::
Player
:
stageForRemoval
();
break
;
}
}
source/ennemy.cpp
View file @
68689404
#include "../headers/ennemy.hpp"
Ennemy
::
Ennemy
(
TextureHolder
const
&
textures
)
:
Alive
(
Agent
::
Tower
,
textures
,
2
),
mIsQ
(
true
),
mIsW
(
true
){
Ennemy
::
Ennemy
(
TextureHolder
const
&
textures
)
:
Alive
(
Agent
::
Tower
,
textures
,
2
,
Entity
::
Ennemy
),
mIsQ
(
true
),
mIsW
(
true
){
mQCD
=
sf
::
seconds
(
4.
f
);
markForReset
();
}
...
...
@@ -22,7 +22,7 @@ void Ennemy::q_spell(float sense){
sf
::
Transform
transform
;
transform
.
rotate
(
120.
f
);
for
(
int
i
=
0
;
i
<
3
;
++
i
){
Orbital
*
orb
=
new
Orbital
(
Agent
::
tProjectile
,
getTexHolder
(),
new
HellSpeedPatern
(
positionSetter
,
sense
*
94.
f
,
1.005
f
),
false
);
new
HellSpeedPatern
(
positionSetter
,
sense
*
94.
f
,
1.005
f
),
Entity
::
Ennemy
);
orb
->
setPosition
(
positionSetter
);
attachChild
(
orb
);
positionSetter
=
transform
.
transformPoint
(
positionSetter
);
...
...
source/orbital.cpp
View file @
68689404
#include "../headers/orbital.hpp"
#include <iostream>
Orbital
::
Orbital
(
Agent
::
Type
type
,
TextureHolder
const
&
textures
,
SpeedPatern
*
spP
,
bool
ally
)
:
Entity
(
type
,
textures
),
mSpeedPatern
(
spP
),
mLifeSpan
(
sf
::
seconds
(
15.
f
)),
m
Ally
(
ally
){
Orbital
::
Orbital
(
Agent
::
Type
type
,
TextureHolder
const
&
textures
,
SpeedPatern
*
spP
,
Entity
::
Side
ally
)
:
Entity
(
type
,
textures
),
mSpeedPatern
(
spP
),
mLifeSpan
(
sf
::
seconds
(
15.
f
)),
m
Side
(
ally
){
}
void
Orbital
::
updateCurrent
(
sf
::
Time
dt
){
...
...
source/player.cpp
View file @
68689404
...
...
@@ -14,7 +14,7 @@ Agent::Type Player::typeOfState(){
}
Player
::
Player
(
TextureHolder
const
&
textures
)
:
Alive
(
Agent
::
Player
,
textures
,
8
),
mIsQAvailable
(
true
),
mIsWAvailable
(
true
),
mW
(
false
){
:
Alive
(
Agent
::
Player
,
textures
,
8
,
Entity
::
Player
),
mIsQAvailable
(
true
),
mIsWAvailable
(
true
),
mW
(
false
){
mQCD
=
sf
::
seconds
(
8.
f
);
mWCD
=
sf
::
seconds
(
1.
f
);
}
...
...
@@ -27,7 +27,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
),
true
);
RotationSpeedPatern
(
positionSetter
,
540.
f
),
Entity
::
Player
);
orb
->
setPosition
(
positionSetter
);
attachChild
(
orb
);
positionSetter
=
transform
.
transformPoint
(
positionSetter
);
...
...
@@ -75,3 +75,12 @@ void Player::keyBindings(){
if
(
sf
::
Keyboard
::
isKeyPressed
(
sf
::
Keyboard
::
S
))
w_spell
(
1
);
if
(
sf
::
Keyboard
::
isKeyPressed
(
sf
::
Keyboard
::
D
))
w_spell
(
0
);
}
void
Player
::
onCollideWith
(
SceneNode
&
collider
){
switch
(
collider
.
identify
()){
case
Category
::
Collectible
:
giveSword
();
break
;
}
Alive
::
onCollideWith
(
collider
);
}
source/room.cpp
View file @
68689404
#include "../headers/room.hpp"
#include "../headers/door.hpp"
Room
::
Room
(
TextureHolder
&
textures
,
sf
::
IntRect
&
bounds
)
...
...
@@ -55,7 +54,7 @@ void Room::buildScene(std::string path){
break
;
}
case
Agent
::
SwordFloor
:{
Agent
*
sword
(
new
Agent
(
rType
,
mTextures
));
Collectible
*
sword
(
new
Collectible
(
mTextures
,
Collectible
::
typeIn
(
rType
)
));
sword
->
setPosition
(
alpha_x
*
x
,
alpha_y
*
y
);
mSceneLayers
[
Air
]
->
attachChild
(
sword
);
break
;
...
...
source/sceneNode.cpp
View file @
68689404
...
...
@@ -11,7 +11,7 @@ SceneNode::~SceneNode(){
void
SceneNode
::
reset
(){
if
(
isMarkForReset
){
//
for(auto& child : mChildren) delete child;
for
(
auto
&
child
:
mChildren
)
delete
child
;
mChildren
.
clear
();
}
else
{
...
...
@@ -106,3 +106,7 @@ void SceneNode::checkSceneCollision(SceneNode& root, std::set<Pair>& target){
for
(
auto
&
child
:
root
.
mChildren
)
checkSceneCollision
(
*
child
,
target
);
}
void
SceneNode
::
onCollideWith
(
SceneNode
&
collider
){
return
;
}
source/world.cpp
View file @
68689404
...
...
@@ -36,6 +36,7 @@ void World::update(sf::Time dt){
mSceneGraph
.
update
(
dt
);
mSceneGraph
.
removeWrecks
(
bounds
);
checkCollision
();
fillData
();
}
void
World
::
checkCollision
(){
...
...
@@ -43,25 +44,13 @@ void World::checkCollision(){
mSceneGraph
.
checkSceneCollision
(
mSceneGraph
,
stack
);
for
(
auto
&
pair
:
stack
){
if
(
pair
.
first
->
identify
()
==
Category
::
Player
&&
pair
.
second
->
identify
()
==
Category
::
Orbital
&&
!
static_cast
<
Orbital
&>
(
*
pair
.
second
).
getOwner
()){
static_cast
<
Player
&>
(
*
pair
.
first
).
hit
();
pair
.
second
->
stageForRemoval
();
fillData
();
}
if
(
pair
.
first
->
identify
()
==
Category
::
Agent
&&
static_cast
<
Agent
&>
(
*
pair
.
first
).
getType
()
==
Agent
::
SwordFloor
&&
pair
.
second
->
identify
()
==
Category
::
Player
){
static_cast
<
Player
&>
(
*
pair
.
second
).
giveSword
();
pair
.
first
->
stageForRemoval
();
}
pair
.
first
->
onCollideWith
(
*
pair
.
second
);
pair
.
second
->
onCollideWith
(
*
pair
.
first
);
}
for
(
auto
&
pair
:
stack
){
if
(
pair
.
first
->
identify
()
==
Category
::
Ennemy
&&
pair
.
second
->
identify
()
==
Category
::
Sword
){
static_cast
<
Player
&>
(
*
pair
.
first
).
hit
();
}
if
(
pair
.
first
->
identify
()
==
Category
::
Ennemy
&&
pair
.
second
->
identify
()
==
Category
::
Orbital
&&
static_cast
<
Orbital
&>
(
*
pair
.
second
).
getOwner
()){
static_cast
<
Player
&>
(
*
pair
.
first
).
hit
();
}
if
(
pair
.
first
->
identify
()
==
Category
::
Orbital
&&
pair
.
second
->
identify
()
==
Category
::
Orbital
&&
static_cast
<
Orbital
&>
(
*
pair
.
first
).
getOwner
()
!=
static_cast
<
Orbital
&>
(
*
pair
.
second
).
getOwner
()){
pair
.
first
->
stageForRemoval
();
pair
.
second
->
stageForRemoval
();
}
if
(
pair
.
first
->
identify
()
==
Category
::
Player
&&
pair
.
second
->
identify
()
==
Category
::
Door
){
mPlayer
=
static_cast
<
Player
*>
(
mRoom
->
detachPlayer
(
*
mPlayer
));
Room
*
room
=
static_cast
<
Room
*>
(
mSceneGraph
.
detachChild
(
*
mRoom
));
...
...
@@ -73,5 +62,5 @@ void World::checkCollision(){
mRoom
->
attachPlayer
(
mPlayer
);
mSceneGraph
.
attachChild
(
mRoom
);
}
}
}
}
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