-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspawn.cpp
More file actions
49 lines (37 loc) · 912 Bytes
/
spawn.cpp
File metadata and controls
49 lines (37 loc) · 912 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
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "spawn.h"
#include "enemy.h"
#include "world.h"
#include "texturemanager.h"
Spawn::Spawn() : Entity()
{
pos.x = 50;
pos.y = 0;
frameSinceLastSpawn = 0;
spawnRate = 60;
sprite.setTexture(g_tex.getTexture(TextureManager::Objects));
sprite.setTextureRect(IntRect(416, 0, 32, 32));
}
Spawn::~Spawn()
{
}
void Spawn::frame()
{
if(frameSinceLastSpawn%spawnRate==0){
Enemy* created = new Enemy(pos + Pos(35, 0));
if(g_world.isFree(created->getRect(), nullptr))
g_world.addEntity(created);
else
delete created;
}
frameSinceLastSpawn++;
}
void Spawn::draw(){
sprite.setPosition(pos.x-16, pos.y-16);
g_window.draw(sprite);
}
bool Spawn::mustRemove() const {
return false;
}
IntRect Spawn::getRect() const{
return IntRect(pos.x-16, pos.y-16, 32, 32);
}