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

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

enhanced test screen

File size: 4.9 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
36#include <caca.h>
37
38#include "core.h"
39#include "loldebug.h"
40
41using namespace std;
42using namespace lol;
43
44#include "neercs.h"
45#include "video/render.h"
46
47Neercs::Neercs()
48  : m_ready(false),
49    m_caca(caca_create_canvas(47, 32)),
50    m_render(new Render(m_caca)),
51    m_time(0.f)
52{
53    Ticker::Ref(m_render);
54}
55
56int Neercs::hex_color(float r, float g, float b)
57{
58return ((int)(r * 15.99f) << 8) | ((int)(g * 15.99f) << 4) | (int)(b * 15.99f);
59}
60
61void Neercs::TickGame(float seconds)
62{
63    WorldEntity::TickGame(seconds);
64
65    m_time += seconds;
66
67    /* draw something */
68    int bg_color = 0x222;
69    int w = caca_get_canvas_width(m_caca);
70    int h = caca_get_canvas_height(m_caca);
71
72    caca_set_color_argb(m_caca, 0xfff, bg_color);
73    caca_clear_canvas(m_caca);
74
75    caca_set_color_argb(m_caca, 0x444, bg_color);
76
77    int n1 = 8;
78    int n2 = 6;//w / n1 * h;
79
80    for(int i = 0; i < n1; i++)
81    {
82        for(int j = 0; j < n2; j++)
83        {
84            int p_x = i * w / n1 + w / (n1 * 2);
85            int p_y = j * h / n2 + h / (n2 * 2);
86            int r_w = w / (n1 * 2) + w / (n1 * 4) * lol::cos(m_time * 3 + M_PI / n1 * i) + h / (n2 * 4) * lol::sin(m_time * 2 + M_PI / n2 * j);
87            caca_fill_ellipse(m_caca, p_x, p_y, r_w, r_w, '%');
88        }
89    }
90
91    int radius = 12;
92
93    int x1 = w / 2 + radius * lol::cos(m_time * 2 - M_PI / 20);
94    int y1 = h / 2 + radius * lol::sin(m_time * 2 - M_PI / 20);
95    int x2 = w / 2 + radius * lol::cos(m_time * 2 + M_PI * 2 / 3 - M_PI / 20);
96    int y2 = h / 2 + radius * lol::sin(m_time * 2 + M_PI * 2 / 3 - M_PI / 20);
97    int x3 = w / 2 + radius * lol::cos(m_time * 2 + M_PI * 2 / 3 * 2 - M_PI / 20);
98    int y3 = h / 2 + radius * lol::sin(m_time * 2 + M_PI * 2 / 3 * 2 - M_PI / 20);
99    caca_set_color_argb(m_caca, 0x642, bg_color);
100    caca_draw_thin_line(m_caca, x1, y1, x2, y2);
101    caca_draw_thin_line(m_caca, x2, y2, x3, y3);
102    caca_draw_thin_line(m_caca, x3, y3, x1, y1);
103
104    x1 = w / 2 + radius * lol::cos(m_time * 2);
105    y1 = h / 2 + radius * lol::sin(m_time * 2);
106    x2 = w / 2 + radius * lol::cos(m_time * 2 + M_PI * 2 / 3);
107    y2 = h / 2 + radius * lol::sin(m_time * 2 + M_PI * 2 / 3);
108    x3 = w / 2 + radius * lol::cos(m_time * 2 + M_PI * 2 / 3 * 2);
109    y3 = h / 2 + radius * lol::sin(m_time * 2 + M_PI * 2 / 3 * 2);
110    caca_set_color_argb(m_caca, 0xea6, bg_color);
111    caca_draw_thin_line(m_caca, x1, y1, x2, y2);
112    caca_draw_thin_line(m_caca, x2, y2, x3, y3);
113    caca_draw_thin_line(m_caca, x3, y3, x1, y1);
114
115    int logo_x = -1;
116    int logo_y = h / 2 - 3;
117
118    caca_set_color_argb(m_caca, hex_color(0.5f + 0.25f * lol::cos(m_time * 3               ),0.5f,0.5f + 0.25f * lol::sin(m_time * 3               )), bg_color);
119    caca_put_str(m_caca, logo_x, logo_y    ," ___  __ _______ _______ _______  ._____ _______. ");
120    caca_set_color_argb(m_caca, hex_color(0.5f + 0.25f * 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);
121    caca_put_str(m_caca, logo_x, logo_y + 1, "|   \\|  Y   ____Y   ____Y  ___  \\/  .___Y   ___/  ");
122    caca_set_color_argb(m_caca, hex_color(0.5f + 0.25f * 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);
123    caca_put_str(m_caca, logo_x, logo_y + 2, "|  . °  >   ____>   ____>  .__  /  <_____\\____  \\ ");
124    caca_set_color_argb(m_caca, hex_color(0.5f + 0.25f * 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);
125    caca_put_str(m_caca, logo_x, logo_y + 3, "|__|\\___\\_______\\_______\\__|  \\_\\________________\\");
126    caca_set_color_argb(m_caca, 0xdef, bg_color);
127    caca_put_str(m_caca, logo_x + 7, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US!");
128
129    caca_set_color_ansi(m_caca, 0x666, bg_color);
130    caca_printf(m_caca, 1, h - 2, "W=%i H=%i", w, h);
131    caca_put_str(m_caca, w - 13, h - 2, "CACA RULEZ");
132}
133
134
135void Neercs::TickDraw(float seconds)
136{
137    WorldEntity::TickDraw(seconds);
138}
139
140Neercs::~Neercs()
141{
142    Ticker::Unref(m_render);
143}
144
145int main(int argc, char **argv)
146{
147    Application app("Neercs", ivec2(800, 600), 60.0f);
148
149#if defined _MSC_VER && !defined _XBOX
150    _chdir("..");
151#elif defined _WIN32 && !defined _XBOX
152    _chdir("../..");
153#endif
154
155    new Neercs();
156    new DebugFps(5, 15);
157    app.ShowPointer(false);
158
159    app.Run();
160
161    return EXIT_SUCCESS;
162}
163
Note: See TracBrowser for help on using the repository browser.