-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSprite.cpp
78 lines (67 loc) · 1.51 KB
/
Sprite.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
68
69
70
71
72
73
74
75
76
77
78
//
// Sprite.cpp
// TankGame
//
// Created by Jacob Gonzalez on 4/05/2015.
// Copyright (c) 2015 Jacob Gonzalez. All rights reserved.
//
#include "Sprite.h"
#include "StringTools.h"
// : get/set _fcolor :
ConsoleTools::Color Sprite::get_fcolor() const
{
return _fcolor;
}
void Sprite::set_fcolor(ConsoleTools::Color color)
{
_fcolor = color;
}
// : get/set _bcolor :
ConsoleTools::Color Sprite::get_bcolor() const
{
return _bcolor;
}
void Sprite::set_bcolor(ConsoleTools::Color color)
{
_bcolor = color;
}
// : getter/setter for _texture :
std::string Sprite::get_texture() const
{
return _texture;
}
void Sprite::set_texture(std::string characters)
{
_texture = characters;
}
void Sprite::update(int t)
{
View::update(t);
}
// : draw funtion for all child views :
void Sprite::draw()
{
vstring lines = StringTools::split(get_texture(), "\n");
for (int i = 0; i < lines.get_count(); ++i)
{
// draw relative to parent
Point<int> parent_pos;
if (get_parent() != 0)
{
parent_pos = get_parent()->get_position();
}
else
{
parent_pos = Point<int>::zero();
}
// set position
ConsoleTools::set_cursor(parent_pos.x + get_position().x, parent_pos.y + get_position().y + i);
// set color
ConsoleTools::set_color(get_fcolor(), get_bcolor());
// draw
printf("%s\n", lines[i].c_str());
// end color
ConsoleTools::end_color();
}
View::draw();
}