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

Last change on this file since 1634 was 1634, checked in by rez, 10 years ago

glsl letterbox and round corner & some new fancy animation!

File size: 4.1 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_draw_line(m_caca, i, y - 1, i, y + 1,'%');
90    }
91
92/*
93.___  __ ______ ______ ______  ______ ______,
94 \° \|  /° __  \° __  \° __  \/° ___//° ___/
95 /   `  >  ____/  ____/  ,_  <_ <____\___  \
96/__/\___\______\______\__| \__/_____________\
97*/
98
99    int logo_x = (w - 45) / 2;
100    int logo_y = h / 2 - 2;
101
102    caca_set_color_argb(m_caca, hex_color(0.5f + 0.375f * lol::cos(m_time * 3               ),0.5f,0.5f + 0.25f * lol::sin(m_time * 3               )), bg_color);
103    caca_put_str(m_caca, logo_x, logo_y    ,".___  __ ______ ______ ______  ______ ______,");
104    caca_set_color_argb(m_caca, hex_color(0.5f + 0.375f * 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);
105    caca_put_str(m_caca, logo_x, logo_y + 1, " \\° \\|  /° __  \\° __  \\° __  \\/° ___//° ___/");
106    caca_set_color_argb(m_caca, hex_color(0.5f + 0.375f * 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);
107    caca_put_str(m_caca, logo_x, logo_y + 2, " /   `  >  ____/  ____/  ,_  <_ <____\\___  \\");
108    caca_set_color_argb(m_caca, hex_color(0.5f + 0.375f * 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);
109    caca_put_str(m_caca, logo_x, logo_y + 3, "/__/\\___\\______\\______\\__| \\__/_____________\\");
110    caca_set_color_argb(m_caca, 0xdef, bg_color);
111    caca_put_str(m_caca, logo_x + 5, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US");
112
113    caca_set_color_argb(m_caca, 0x666, bg_color);
114    caca_put_str(m_caca, w - 10, h - 1, "CACA RULEZ");
115    caca_printf(m_caca, 0, h - 2, "W=%i", w);
116    caca_printf(m_caca, 0, h - 1, "H=%i", h);
117}
118
119
120void Neercs::TickDraw(float seconds)
121{
122    WorldEntity::TickDraw(seconds);
123}
124
125Neercs::~Neercs()
126{
127    Ticker::Unref(m_render);
128}
129
130int main(int argc, char **argv)
131{
132    Application app("Neercs", ivec2(800, 600), 60.0f);
133
134#if defined _MSC_VER && !defined _XBOX
135    _chdir("..");
136#elif defined _WIN32 && !defined _XBOX
137    _chdir("../..");
138#endif
139
140    new Neercs();
141    new DebugFps(2, 2);
142    app.ShowPointer(false);
143
144    app.Run();
145
146    return EXIT_SUCCESS;
147}
148
Note: See TracBrowser for help on using the repository browser.