-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitem.cpp
More file actions
37 lines (30 loc) · 891 Bytes
/
item.cpp
File metadata and controls
37 lines (30 loc) · 891 Bytes
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
#include "item.h"
#include "texturemanager.h"
#include "world.h"
Item::Item() : Entity(){
pos.x = rand() % 500;
pos.y = rand() % 500;
sprite.setTexture(g_tex.getTexture(TextureManager::Objects));
sprite.setTextureRect(IntRect(0,0,16,16));
life = 1;
}
bool Item::mustRemove() const{return life <= 0;}
void Item::draw() {
sprite.setPosition(pos.x, pos.y);
g_window.draw(sprite);
}
void Item::frame(){
//check for a collision with a player. if so, have him reload, and remove the box
if(g_world.areaEffect(getRect(), [](Entity* e) {
if(e->getType() == Entity::Type_Player){
dynamic_cast<Player *>(e)->reload();
return true;
}
return false;
}))
life = 0;
}
Entity::Type Item::getType() const {return Type_Item;}
IntRect Item::getRect() const {
return IntRect(pos.x-8, pos.y-8, 16, 16);
}