-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntroView.cpp
More file actions
156 lines (135 loc) · 4.72 KB
/
IntroView.cpp
File metadata and controls
156 lines (135 loc) · 4.72 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// IntroView.cpp
// TankGame
//
// Created by Jacob Gonzalez on 11/04/2015.
// Copyright (c) 2015 Jacob Gonzalez. All rights reserved.
//
#include "IntroView.h"
#include "TextureTools.h"
#include "ConsoleTools.h"
#include "Point.h"
#include "Terrain.h"
#include <cstdlib>
void IntroView::_init()
{
player1 = "";
player2 = "";
_position = Point<int>::zero();
_size = ConsoleTools::get_terminal_size();
// title
Sprite *header = new Sprite(TextureTools::get_texture("title"));
// adjust positions for unicode text
header->set_position(Point<int>(get_size().x/2 - header->get_size().x/4 - 6, 2));
header->set_size(Point<int>(header->get_size().x, header->get_size().y));
header->set_fcolor(ConsoleTools::magneta);
header->tag = 1;
add_child(header);
// copyright
Sprite *copyright = new Sprite("Copyright © Jacob Gonzalez (a1687803) 2015");
copyright->set_position(Point<int>(get_size().x/2 - copyright->get_size().x/2,
get_size().y - 1));
copyright->set_fcolor(ConsoleTools::green);
add_child(copyright);
// vs_text. not adding to view for can be on stack
_vs_text = Sprite(TextureTools::get_texture("vs"));
_vs_text.set_position(Point<int>(get_size().x/2 - _vs_text.get_size().x/4 + 2,
get_size().y/2 - _vs_text.get_size().y/2));
_vs_text.set_fcolor(ConsoleTools::yellow);
// loading string
_load_num_string = "";
}
void IntroView::update(int t)
{
// get player's name's after sometime
if (t == 20 && player1 == "" && player2 == "")
{
ConsoleTools::set_cursor(0, get_size().y/2);
ConsoleTools::clear_line();
// get player 1
ConsoleTools::set_cursor(get_size().x/2 - StringTools::string_width("Name of Player 1")/2, get_size().y/3);
ConsoleTools::set_fcolor(ConsoleTools::white);
printf("Name of Player 1");
ConsoleTools::move_cursor(ConsoleTools::down, 2);
ConsoleTools::move_cursor(ConsoleTools::left, StringTools::string_width("Name of Player 1"));
ConsoleTools::set_fcolor(ConsoleTools::red);
player1 = ConsoleTools::get_line();
ConsoleTools::play_music("beep.wav");
// get player 2
ConsoleTools::set_cursor(get_size().x/2 - StringTools::string_width("Name of Player 2")/2, 2*get_size().y/3);
ConsoleTools::set_fcolor(ConsoleTools::white);
printf("Name of Player 2");
ConsoleTools::move_cursor(ConsoleTools::down, 2);
ConsoleTools::move_cursor(ConsoleTools::left, StringTools::string_width("Name of Player 2"));
ConsoleTools::set_fcolor(ConsoleTools::blue);
player2 = ConsoleTools::get_line();
ConsoleTools::play_music("beep.wav");
// write to replay file
if (ConsoleTools::replay == false)
{
std::ofstream file("replay.txt", std::ios::app);
file << player1 << std::endl << player2 << std::endl;
file.close();
}
}
else if (t < 20 && t % 4 == 0)
{
// increment the loader
if (_load_num_string == "")
{
_load_num_string = ".";
}
else if (_load_num_string == ".")
{
_load_num_string = "..";
}
else if (_load_num_string == "..")
{
_load_num_string = "...";
}
else if (_load_num_string == "...")
{
_load_num_string = "";
}
}
else if (t > 60)
{
_should_remove_from_parent = true;
}
// update children
View::update(t);
}
void IntroView::draw()
{
// draw rain
if (tag == 1)
{
for (int i = 0; i < get_size().x; i+=5)
{
ConsoleTools::set_fcolor(ConsoleTools::cyan);
ConsoleTools::set_cursor(Point<int>(i, rand() % get_size().y));
printf("|");
}
}
if (player1 != "" && player2 != "")
{
// draw player vs info
ConsoleTools::set_cursor(get_size().x/2 - StringTools::string_width(player1)/2, get_size().y/3);
ConsoleTools::set_fcolor(ConsoleTools::red);
printf("%s", player1.c_str());
_vs_text.draw();
ConsoleTools::set_cursor(get_size().x/2 - StringTools::string_width(player2)/2, 2*get_size().y/3);
ConsoleTools::set_fcolor(ConsoleTools::blue);
printf("%s", player2.c_str());
}
else
{
// draw the loading text
ConsoleTools::set_cursor(get_size().x/2 - (18 + StringTools::string_width(_load_num_string))/2, get_size().y/2);
ConsoleTools::set_fcolor(ConsoleTools::yellow);
ConsoleTools::clear_line();
printf("Pretending to load%s", _load_num_string.c_str());
}
// draw children
View::draw();
}