1 | // |
---|
2 | // Neercs |
---|
3 | // |
---|
4 | // Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net> |
---|
5 | // |
---|
6 | |
---|
7 | #if defined HAVE_CONFIG_H |
---|
8 | # include "config.h" |
---|
9 | #endif |
---|
10 | |
---|
11 | #if defined _WIN32 |
---|
12 | # include <direct.h> |
---|
13 | #endif |
---|
14 | |
---|
15 | #if defined _XBOX |
---|
16 | # define _USE_MATH_DEFINES /* for M_PI */ |
---|
17 | # include <xtl.h> |
---|
18 | # undef near /* Fuck Microsoft */ |
---|
19 | # undef far /* Fuck Microsoft again */ |
---|
20 | #elif defined _WIN32 |
---|
21 | # define _USE_MATH_DEFINES /* for M_PI */ |
---|
22 | # define WIN32_LEAN_AND_MEAN |
---|
23 | # include <windows.h> |
---|
24 | # undef near /* Fuck Microsoft */ |
---|
25 | # undef far /* Fuck Microsoft again */ |
---|
26 | #else |
---|
27 | # include <cmath> |
---|
28 | #endif |
---|
29 | |
---|
30 | #include <time.h> |
---|
31 | #include <caca.h> |
---|
32 | |
---|
33 | #include "core.h" |
---|
34 | #include "loldebug.h" |
---|
35 | |
---|
36 | using namespace std; |
---|
37 | using namespace lol; |
---|
38 | |
---|
39 | #include "neercs.h" |
---|
40 | #include "video/render.h" |
---|
41 | |
---|
42 | #define USE_OLD_NEERCS 0 |
---|
43 | |
---|
44 | extern "C" |
---|
45 | { |
---|
46 | #include "old/neercs.h" |
---|
47 | } |
---|
48 | |
---|
49 | Neercs::Neercs(int argc, char **argv) |
---|
50 | : m_ready(false), |
---|
51 | m_caca(caca_create_canvas(10, 10)), |
---|
52 | m_render(new Render(m_caca)), |
---|
53 | m_time(0.f) |
---|
54 | { |
---|
55 | Ticker::Ref(m_render); |
---|
56 | |
---|
57 | #if USE_OLD_NEERCS |
---|
58 | m_buf = NULL; |
---|
59 | m_screen_list = init_neercs(argc, argv); |
---|
60 | if (!m_screen_list) |
---|
61 | exit(-1); |
---|
62 | m_screen_list->last_key_time = get_us(); |
---|
63 | #endif |
---|
64 | } |
---|
65 | |
---|
66 | int Neercs::hex_color(float r, float g, float b) |
---|
67 | { |
---|
68 | return ((int)(r * 15.99f) << 8) | ((int)(g * 15.99f) << 4) | (int)(b * 15.99f); |
---|
69 | } |
---|
70 | |
---|
71 | void Neercs::TickGame(float seconds) |
---|
72 | { |
---|
73 | WorldEntity::TickGame(seconds); |
---|
74 | |
---|
75 | #if USE_OLD_NEERCS |
---|
76 | mainloop_tick(&m_buf, m_screen_list); |
---|
77 | #endif |
---|
78 | |
---|
79 | m_time += seconds; |
---|
80 | |
---|
81 | /* draw something awesome */ |
---|
82 | int bg_color = 0x222; |
---|
83 | int w = caca_get_canvas_width(m_caca); |
---|
84 | int h = caca_get_canvas_height(m_caca); |
---|
85 | |
---|
86 | caca_set_color_argb(m_caca, 0xfff, bg_color); |
---|
87 | caca_clear_canvas(m_caca); |
---|
88 | |
---|
89 | caca_set_color_argb(m_caca, 0x545, bg_color); |
---|
90 | for(int i = 0; i < h; i++) |
---|
91 | { |
---|
92 | float a = M_PI / 180 * i * 16 + m_time * 4; |
---|
93 | float b = M_PI / 180 * i * 12; |
---|
94 | int x = w / 2 - 15 + h / 3 * lol::cos(a) + h / 4 * lol::sin(b); |
---|
95 | caca_put_str(m_caca, x, i, "LOL WUT! NEERCS SI TEH RULEZ!"); |
---|
96 | } |
---|
97 | |
---|
98 | caca_set_color_argb(m_caca, 0x444, bg_color); |
---|
99 | for(int i = 0; i < w; i++) |
---|
100 | { |
---|
101 | float a = m_time * 1 + M_PI / 180 * i * 8; |
---|
102 | float b = m_time * -2 + M_PI / 180 * i * 5; |
---|
103 | int y = h / 2 + h / 4 * lol::cos(a) + h / 4 * lol::sin(b); |
---|
104 | caca_set_color_argb(m_caca, hex_color(0.25f + 0.5f / w * i - 0.25f / h * y, 0.25f, 0.25f + 0.25f / w * i + 0.25f / h * y), bg_color); |
---|
105 | caca_draw_line(m_caca, i, y - 1, i, y + 1,'%'); |
---|
106 | } |
---|
107 | |
---|
108 | /* __ _________ ______ ______ ______ ______ |
---|
109 | / \/ / __ > __ > __ > ___// ___/ \x0a9 |
---|
110 | / / ____/ ____/ __ < <____\___ \ |
---|
111 | /__/\__/\_______________/ \________________\ */ |
---|
112 | |
---|
113 | int logo_x = (w - 46) / 2; |
---|
114 | int logo_y = h / 2 - 2;// + h / 4 * lol::cos(m_time * 2); |
---|
115 | |
---|
116 | caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 ), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 )), bg_color); |
---|
117 | caca_put_str(m_caca, logo_x + 3, logo_y ,"__ _________ ______ ______ ______ ______"); |
---|
118 | caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 + M_PI / 4 * 1), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 1)), bg_color); |
---|
119 | caca_put_str(m_caca, logo_x + 2, logo_y + 1, "/ \\/ / __ > __ > __ > ___// ___/"); |
---|
120 | caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 + M_PI / 4 * 2), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 2)), bg_color); |
---|
121 | caca_put_str(m_caca, logo_x + 1, logo_y + 2, "/ / ____/ ____/ __ < <____\\___ \\"); |
---|
122 | caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 + M_PI / 4 * 3), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 3)), bg_color); |
---|
123 | caca_put_str(m_caca, logo_x , logo_y + 3, "/__/\\__/\\_______________/ \\________________\\"); |
---|
124 | caca_set_color_argb(m_caca, 0xdef, bg_color); |
---|
125 | caca_put_str(m_caca, logo_x + 5, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US"); |
---|
126 | |
---|
127 | caca_set_color_argb(m_caca, 0x666, bg_color); |
---|
128 | caca_printf(m_caca, 2, h - 3, "W=%i", w); |
---|
129 | caca_printf(m_caca, 2, h - 2, "H=%i", h); |
---|
130 | |
---|
131 | caca_set_color_argb(m_caca, hex_color(0.6f + 0.4f * lol::cos(m_time * 2), 0.2f, 0.2f), bg_color); |
---|
132 | caca_put_str(m_caca, w - 12, h - 2, "CACA RULEZ"); |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | void Neercs::TickDraw(float seconds) |
---|
137 | { |
---|
138 | WorldEntity::TickDraw(seconds); |
---|
139 | } |
---|
140 | |
---|
141 | Neercs::~Neercs() |
---|
142 | { |
---|
143 | #if USE_OLD_NEERCS |
---|
144 | free(m_buf); |
---|
145 | free_screen_list(m_screen_list); |
---|
146 | #endif |
---|
147 | |
---|
148 | Ticker::Unref(m_render); |
---|
149 | } |
---|
150 | |
---|
151 | int main(int argc, char **argv) |
---|
152 | { |
---|
153 | Application app("Neercs", ivec2(800, 600), 60.0f); |
---|
154 | |
---|
155 | #if defined _MSC_VER && !defined _XBOX |
---|
156 | _chdir(".."); |
---|
157 | #elif defined _WIN32 && !defined _XBOX |
---|
158 | _chdir("../.."); |
---|
159 | #endif |
---|
160 | |
---|
161 | new Neercs(argc, argv); |
---|
162 | new DebugFps(2, 2); |
---|
163 | app.ShowPointer(false); |
---|
164 | |
---|
165 | app.Run(); |
---|
166 | |
---|
167 | return EXIT_SUCCESS; |
---|
168 | } |
---|
169 | |
---|