source: trunk/tools/neercs/neercs.cpp @ 1837

Last change on this file since 1837 was 1837, checked in by rez, 8 years ago

copper.lolfx added

File size: 5.8 KB
Line 
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
36using namespace std;
37using namespace lol;
38
39#include "neercs.h"
40#include "video/render.h"
41
42#define USE_OLD_NEERCS 0
43
44extern "C"
45{
46#include "old/neercs.h"
47}
48
49Neercs::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
66int 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
71void 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, 0xfff, 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  - 14 + w / 4 * lol::cos(a) + w / 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;
115
116    caca_set_color_argb(m_caca, 0x8ac, bg_color);
117    //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);
118    caca_put_str(m_caca, logo_x + 3, logo_y    ,"__  _________ ______ ______ ______ ______");
119    //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);
120    caca_put_str(m_caca, logo_x + 2, logo_y + 1, "/  \\/  /  __  >  __  >  __  >  ___//  ___/ \x0a9");
121    //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);
122    caca_put_str(m_caca, logo_x + 1, logo_y + 2, "/      /  ____/  ____/  __  <  <____\\___  \\");
123    //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);
124    caca_put_str(m_caca, logo_x    , logo_y + 3, "/__/\\__/\\_______________/  \\________________\\");
125    caca_set_color_argb(m_caca, 0xdef, bg_color);
126    caca_put_str(m_caca, logo_x + 5, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US");
127
128    caca_set_color_argb(m_caca, 0x666, bg_color);
129    caca_printf(m_caca, 2, h - 3, "W=%i", w);
130    caca_printf(m_caca, 2, h - 2, "H=%i", h);
131
132    caca_set_color_argb(m_caca, hex_color(0.6f + 0.4f * lol::cos(m_time * 2), 0.2f, 0.2f), bg_color);
133    caca_put_str(m_caca, w - 12, h - 2, "CACA RULEZ");
134
135/*
136  _______
137 /      /|
138/______/ |
139|      | |
140|  :D  | /
141|______|/
142*/
143
144    int lolcube_x = w / 2 - 5 + (w - 10) * lol::cos(m_time / 2);
145    int lolcube_y = h - 5 - abs ((h - 5) * lol::sin(m_time * 4));
146
147    caca_set_color_argb(m_caca, hex_color(0.75f + 0.25f * lol::sin(m_time * 2), 0.75f + 0.25f * lol::cos(m_time * 3), 0.75f + 0.25f * lol::sin(m_time * 5)), bg_color);
148    caca_put_str(m_caca, lolcube_x + 2, lolcube_y    , "_______");
149    caca_put_str(m_caca, lolcube_x + 1, lolcube_y + 1, "/      /|");
150    caca_put_str(m_caca, lolcube_x    , lolcube_y + 2, "/______/ |");
151    caca_put_str(m_caca, lolcube_x    , lolcube_y + 3, "|      | |");
152    caca_put_str(m_caca, lolcube_x    , lolcube_y + 4, "|  :D  | /");
153    caca_put_str(m_caca, lolcube_x    , lolcube_y + 5, "|______|/");
154
155    caca_set_color_argb(m_caca, 0xdef, bg_color);
156    caca_put_str(m_caca, 0, 0, "rez@lol:~/ sudo -s");
157    caca_put_str(m_caca, 0, 1, "[sudo] password for rez:");
158    caca_put_str(m_caca, 0, 2, "root@lol:~/ echo LOL");
159    caca_put_str(m_caca, 0, 3, "LOL");
160    caca_put_str(m_caca, 0, 4, "root@lol:~/");
161}
162
163
164void Neercs::TickDraw(float seconds)
165{
166    WorldEntity::TickDraw(seconds);
167}
168
169Neercs::~Neercs()
170{
171#if USE_OLD_NEERCS
172    free(m_buf);
173    free_screen_list(m_screen_list);
174#endif
175
176    Ticker::Unref(m_render);
177}
178
179int main(int argc, char **argv)
180{
181    Application app("Neercs", ivec2(800, 600), 60.0f);
182
183#if defined _MSC_VER && !defined _XBOX
184    _chdir("..");
185#elif defined _WIN32 && !defined _XBOX
186    _chdir("../..");
187#endif
188
189    new Neercs(argc, argv);
190    new DebugFps(2, 2);
191    app.ShowPointer(false);
192
193    app.Run();
194
195    return EXIT_SUCCESS;
196}
197
Note: See TracBrowser for help on using the repository browser.