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

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

updated border autoresize + canvas resize

File size: 5.2 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(10, 10)),
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/*
119.___  __ ______ ______ ______  ______ ______,
120 \° \|  /° __  \° __  \° __  \/° ___//° ___/
121 /   `  >  ____/  ____/  ,_  <  <____\___  \
122/__/\___\______\______\__| \__\_____________\
123*/
124
125    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);
126    caca_put_str(m_caca, logo_x, logo_y    ,".___  __ ______ ______ ______  ______ ______,");
127    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);
128    caca_put_str(m_caca, logo_x, logo_y + 1, " \\° \\|  /° __  \\° __  \\° __  \\/° ___//° ___/");
129    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);
130    caca_put_str(m_caca, logo_x, logo_y + 2, " /   `  >  ____/  ____/  ,_  <  <____\\___  \\");
131    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);
132    caca_put_str(m_caca, logo_x, logo_y + 3, "/__/\\___\\______\\______\\__| \\__\\_____________\\");
133    caca_set_color_argb(m_caca, 0xdef, bg_color);
134    caca_put_str(m_caca, logo_x + 5, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US");
135
136    caca_set_color_ansi(m_caca, 0x666, bg_color);
137    caca_printf(m_caca, 1, h - 2, "W=%i H=%i", w, h);
138    //caca_printf(m_caca, 1, h - 2, "2d ratio=%i*%i", ratio_2d.x, ratio_2d.y);
139    caca_put_str(m_caca, w - 13, h - 2, "CACA RULEZ");
140}
141
142
143void Neercs::TickDraw(float seconds)
144{
145    WorldEntity::TickDraw(seconds);
146}
147
148Neercs::~Neercs()
149{
150    Ticker::Unref(m_render);
151}
152
153int main(int argc, char **argv)
154{
155    Application app("Neercs", ivec2(800, 600), 60.0f);
156
157#if defined _MSC_VER && !defined _XBOX
158    _chdir("..");
159#elif defined _WIN32 && !defined _XBOX
160    _chdir("../..");
161#endif
162
163    new Neercs();
164    new DebugFps(2, 2);
165    app.ShowPointer(false);
166
167    app.Run();
168
169    return EXIT_SUCCESS;
170}
171
Note: See TracBrowser for help on using the repository browser.