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

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

glsl letterbox and round corner & some new fancy animation!

File size: 4.3 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#if USE_SDL && defined __APPLE__
31#   include <SDL_main.h>
32#endif
33
34#include <time.h>
35#include <caca.h>
36
37#include "core.h"
38#include "loldebug.h"
39
40using namespace std;
41using namespace lol;
42
43#include "neercs.h"
44#include "video/render.h"
45
46Neercs::Neercs()
47  : m_ready(false),
48    m_caca(caca_create_canvas(10, 10)),
49    m_render(new Render(m_caca)),
50    m_time(0.f)
51{
52    Ticker::Ref(m_render);
53}
54
55int Neercs::hex_color(float r, float g, float b)
56{
57return ((int)(r * 15.99f) << 8) | ((int)(g * 15.99f) << 4) | (int)(b * 15.99f);
58}
59
60void Neercs::TickGame(float seconds)
61{
62    WorldEntity::TickGame(seconds);
63
64    m_time += seconds;
65
66    /* draw something */
67    int bg_color = 0x222;
68    int w = caca_get_canvas_width(m_caca);
69    int h = caca_get_canvas_height(m_caca);
70
71    caca_set_color_argb(m_caca, 0xfff, bg_color);
72    caca_clear_canvas(m_caca);
73
74    caca_set_color_argb(m_caca, 0x234, bg_color);
75    for(int i = 0; i < h; i++)
76    {
77        float a = M_PI / 180 * i * 16 + m_time * 4;
78        float b = M_PI / 180 * i * 12;
79        int x = w / 2  - 15 + h / 3 * lol::cos(a) + h / 4 * lol::sin(b);
80        caca_put_str(m_caca, x, i, "LOL WUT! NEERCS SI TEH RULEZ!");
81    }
82
83    caca_set_color_argb(m_caca, 0x444, bg_color);
84    for(int i = 0; i < w; i++)
85    {
86        float a = m_time * 1 + M_PI / 180 * i * 8;
87        float b = m_time * -2 + M_PI / 180 * i * 5;
88        int y = h / 2 + h / 4 * lol::cos(a) + h / 4 * lol::sin(b);
89        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);
90        caca_draw_line(m_caca, i, y - 1, i, y + 1,'%');
91    }
92
93/*
94.___  __ ______ ______ ______  ______ ______,
95 \° \|  /° __  \° __  \° __  \/° ___//° ___/
96 /   `  >  ____/  ____/  ,_  <_ <____\___  \
97/__/\___\______\______\__| \__/_____________\
98*/
99
100    int logo_x = (w - 45) / 2;
101    int logo_y = h / 2 - 2;
102
103    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);
104    caca_put_str(m_caca, logo_x, logo_y    ,".___  __ ______ ______ ______  ______ ______,");
105    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);
106    caca_put_str(m_caca, logo_x, logo_y + 1, " \\° \\|  /° __  \\° __  \\° __  \\/° ___//° ___/");
107    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);
108    caca_put_str(m_caca, logo_x, logo_y + 2, " /   `  >  ____/  ____/  ,_  <_ <____\\___  \\");
109    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);
110    caca_put_str(m_caca, logo_x, logo_y + 3, "/__/\\___\\______\\______\\__| \\__/_____________\\");
111    caca_set_color_argb(m_caca, 0xdef, bg_color);
112    caca_put_str(m_caca, logo_x + 5, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US");
113
114    caca_set_color_argb(m_caca, 0x666, bg_color);
115    caca_printf(m_caca, 2, h - 3, "W=%i", w);
116    caca_printf(m_caca, 2, h - 2, "H=%i", h);
117
118    caca_set_color_argb(m_caca, hex_color(0.6f + 0.4f * lol::cos(m_time * 2), 0.125f, 0.125f), bg_color);
119    caca_put_str(m_caca, w - 12, h - 2, "CACA RULEZ");
120}
121
122
123void Neercs::TickDraw(float seconds)
124{
125    WorldEntity::TickDraw(seconds);
126}
127
128Neercs::~Neercs()
129{
130    Ticker::Unref(m_render);
131}
132
133int main(int argc, char **argv)
134{
135    Application app("Neercs", ivec2(800, 600), 60.0f);
136
137#if defined _MSC_VER && !defined _XBOX
138    _chdir("..");
139#elif defined _WIN32 && !defined _XBOX
140    _chdir("../..");
141#endif
142
143    new Neercs();
144    new DebugFps(2, 2);
145    app.ShowPointer(false);
146
147    app.Run();
148
149    return EXIT_SUCCESS;
150}
151
Note: See TracBrowser for help on using the repository browser.