-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildingInstance.cpp
67 lines (55 loc) · 1.41 KB
/
buildingInstance.cpp
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
/*
Copyright (c) 2013 Auston Sterling
See license.txt for copying permission.
-----BuildingInstance Class Implementation-----
Auston Sterling
Implementation of the BuildingInstance class.
*/
#include "buildingInstance.h"
#ifndef _buildinginstance_cpp_
#define _buildinginstance_cpp_
//Default constructor
BuildingInstance::BuildingInstance() :
type_(NULL),
projectileTime_(0),
time_(0)
{}
//Regular constructor
BuildingInstance::BuildingInstance(Building* type) :
type_(type),
projectileTime_(0),
time_(0)
{}
//Progresses the building
void BuildingInstance::update()
{
//Find time since last call
if (time_ == 0) {time_ = SDL_GetTicks(); return;}
int currentTime = SDL_GetTicks();
int dt = currentTime - time_;
time_ = currentTime;
//Update projectileTime_ if the building exists
if (type_ != NULL)
{
projectileTime_ += dt;
//Do not allow projectileTime to store up extra shots
if (projectileTime_ > type_->cd()) projectileTime_ = type_->cd();
}
}
//Destroys the building
void BuildingInstance::destroy()
{
type_ = NULL;
projectileTime_ = 0;
time_ = 0;
}
//Fires a projectile. Here, this only reduces projectileTime_ appropriately
//Returns true if it completed successfully, false if not enough time has passed
bool BuildingInstance::fire()
{
if (!canFire()) return false;
projectileTime_ -= type_->cd();
return true;
}
#endif