-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilding.cpp
More file actions
76 lines (67 loc) · 1.65 KB
/
building.cpp
File metadata and controls
76 lines (67 loc) · 1.65 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
69
70
71
72
73
74
75
76
/*
Copyright (c) 2013 Auston Sterling
See license.txt for copying permission.
-----Building Class Definition-----
Auston Sterling
austonst@gmail.com
Contains the definition for the Building class, for use in "Galcon"
*/
#include "building.h"
#ifndef _building_cpp_
#define _building_cpp_
//Default constructor, won't do much
Building::Building()
{
effect_ = "none";
}
//Regular constructor
//The inputted SDL_Surface will be copied away and does not have to be maintained
Building::Building(SDL_Surface* surf, SDL_Surface* consSurf, std::string effect):
image_(RotationCache(surf, NUM_BUILDING_ROTATIONS)),
constructionImage_(RotationCache(consSurf, NUM_BUILDING_ROTATIONS)),
effect_(effect),
buildtime_(1000),
cd_(2000),
range_(1000)
{
}
//Displays the building to the given coordinates
void Building::display(Vec2f pos, float angle, SDL_Surface* screen, bool complete)
{
//Blit it
SDL_Rect outrect;
outrect.x = pos.x();
outrect.y = pos.y();
if (complete)
{
SDL_BlitSurface(image_.rotation(angle), NULL, screen, &outrect);
}
else
{
SDL_BlitSurface(constructionImage_.rotation(angle), NULL, screen, &outrect);
}
}
//Returns either the unrotated image if no args, or the rotation at the given angle
SDL_Surface* Building::rotation(float angle, bool complete)
{
//Complete
if (complete)
{
//No args, or uninformed user
if (angle < 0)
{
return image_.rotation(0);
}
return image_.rotation(angle);
}
else
{
//No args, or uninformed user
if (angle < 0)
{
return constructionImage_.rotation(0);
}
return constructionImage_.rotation(angle);
}
}
#endif