-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjectManager.cpp
More file actions
68 lines (59 loc) · 1.67 KB
/
Copy pathobjectManager.cpp
File metadata and controls
68 lines (59 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "objectManager.h"
#include <string>
#include "spriteContainer.h"
#include "animContainer.h"
#include "player.h"
bool ObjectManager::addObject( int type, std::string file, int x, int y )
{
if( type == 1 )
{
std::shared_ptr<SpriteContainer> tempSprite( new SpriteContainer( file ) );
tempSprite->sprite.setPosition( x, y );
objects.push_back( tempSprite );
}
return true;
}
bool ObjectManager::addObject( int type, std::vector<std::string> files, std::vector<int> dels, int x, int y )
{
switch( type )
{
case 2:
{
std::shared_ptr<AnimContainer> tempAnim( new AnimContainer( files, dels ) );
tempAnim->sprite.setPosition( x, y );
objects.push_back( tempAnim );
break;
}
case 3:
{
std::shared_ptr<Player> tempPlayer( new Player( files, dels ) );
tempPlayer->sprite.setPosition( x, y );
objects.push_back( tempPlayer );
break;
}
default:
break;
}
return true;
}
bool ObjectManager::removeObject( int id )
{
return true;
}
void ObjectManager::sortX()
{
for( unsigned int i = 0; i < objects.size() - 1; i ++ )
{
if( objects[ i ]->sprite.getPosition().x > objects[ i + 1 ]->sprite.getPosition().x )
{
std::swap( objects[ i ], objects[ i + 1 ] );
for( int j = i; j > 0; j -- )
{
if( objects[ j ]->sprite.getPosition().x < objects[ j - 1 ]->sprite.getPosition().x )
{
std::swap( objects[ j ], objects[ j - 1 ] );
}
}
}
}
}