-
Notifications
You must be signed in to change notification settings - Fork 0
/
textrender.cpp
135 lines (113 loc) · 2.65 KB
/
textrender.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "textrender.h"
#include <iostream>
#ifdef DEBUG
#include "sam.h"
#include "dan.h"
#include "manager.h"
#include <stdexcept>
#include <string>
#endif // DEBUG
static const Ball * bll = nullptr;
static const Player * lplr = nullptr;
static const Player * rplr = nullptr;
void RenderInterface::draw() const
{
}
TextRender::TextRender()
{
}
TextRender::~TextRender()
{
}
void TextRender::init()
{
mgr = &(Manager::getSingleton());
mgr->setStep(1.0 / 60.0);
mgr->addPlayer("left", "DanThePlayer").init(Vector2D(-1.0), Vector2D(), 0.2, 0.05, 0.5, 0.5);
mgr->addPlayer("right", "SamThePlayer").init(Vector2D(), Vector2D(1.0), 0.2, 0.05, 0.5, 0.5);
mgr->addBlock("leftPlate", "left") = Block(Vector2D(-1.0), Vector2D());
mgr->addBlock("rightPlate", "right") = Block(Vector2D(), Vector2D(1.0));
mgr->addNet("lwall") = Block(-1.0, 0.0, -1.0, 1.0);
mgr->addNet("rwall") = Block( 1.0, 0.0, 1.0, 1.0);
mgr->addNet("twall") = Block(-1.0, 1.0, 1.0, 1.0);
mgr->addNet("net") = Block( 0.0, 0.0, 0.0, 0.5);
bll =
&(mgr->addBall("ball") = Ball(
Vector2D(-1.0, 0.0),
Vector2D(1.0, 1.0),
Vector2D(-0.5, 0.5),
Vector2D())
); // TODO: Ball initialization
// bll = &(mgr->addBall("ball") = Ball()); // TODO: Ball initialization
lplr = &(mgr->getPlayer("left"));
rplr = &(mgr->getPlayer("right"));
}
void TextRender::start()
{
RenderMachine::start();
}
void TextRender::beforeUpdate()
{
}
void TextRender::update()
{
mgr->nextFrame();
std::cout
<< "left: " << lplr->get_pos().x
<< "\tright: " << rplr->Movable::get_pos().x
<< "\tball: ( " << bll->get_pos().x << ", " << bll->get_pos().y << " )"
<< std::endl;
}
void TextRender::afterUpdate()
{
typedef Manager::Status St;
Manager::State const & st = Manager::getState();
switch(st.currentStatus) {
case St::OK:
std::cout << "Stats is [ OK ]" << std::endl;
break;
case St::ATTACK:
std::cout << *(st.playerName) << " player pushed ball" << std::endl;
break;
default:
// Do nithing
break;
}
}
void TextRender::stop()
{
Manager::State const & st = Manager::getState();
std::cout << "Game Over. The "
<< (st.playerName ? *(st.playerName) : "[not defined]")
<< " wasn't able to prevent "
<< (st.ballName ? *(st.ballName) : "[not defined]")
<< " to touch the "
<< (st.blockName ? *(st.blockName) : "[not defined]")
<< "." << std::endl;
}
/*
void Block::draw() const
{
}
void SamThePlayer::draw() const
{
}
*/
/*
void Ball::draw() const
{
}
*/
#ifdef DEBUG
int main ()
{
try {
TextRender tr;
tr.init();
tr.start();
} catch(std::logic_error & e) {
std::cerr << "Error occured: " << e.what() << std::endl;
}
return 0;
}
#endif