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

Last change on this file since 1647 was 1647, checked in by sam, 8 years ago

build: hide the SDL_main.h inclusion in core.h, and only activate it
on Windows if using Visual Studio; if using MinGW, try to stick to the
original main() entry point.

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#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
42extern "C"
43{
44#include "old/neercs.h"
45}
46
47Neercs::Neercs(int argc, char **argv)
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, 0xa46, bg_color);
76    for(int i = 0; i < h; i++)
77    {
78        float a = M_PI / 180 * i * 16 + m_time * 4;
79        float b = M_PI / 180 * i * 12;
80        int x = w / 2  - 15 + h / 3 * lol::cos(a) + h / 4 * lol::sin(b);
81        caca_put_str(m_caca, x, i, "LOL WUT! NEERCS SI TEH RULEZ!");
82    }
83
84    caca_set_color_argb(m_caca, 0x444, bg_color);
85    for(int i = 0; i < w; i++)
86    {
87        float a = m_time * 1 + M_PI / 180 * i * 8;
88        float b = m_time * -2 + M_PI / 180 * i * 5;
89        int y = h / 2 + h / 4 * lol::cos(a) + h / 4 * lol::sin(b);
90        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);
91        caca_draw_line(m_caca, i, y - 1, i, y + 1,'%');
92    }
93
94/*
95.___  __ ______ ______ ______  ______ ______,
96 \° \|  /° __  \° __  \° __  \/° ___//° ___/
97 /   `  >  ____/  ____/  ,_  <_ <____\___  \
98/__/\___\______\______\__| \__/_____________\
99*/
100
101    int logo_x = (w - 45) / 2;
102    int logo_y = h / 2 - 2;
103
104    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);
105    caca_put_str(m_caca, logo_x, logo_y    ,".___  __ ______ ______ ______  ______ ______,");
106    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);
107    caca_put_str(m_caca, logo_x, logo_y + 1, " \\° \\|  /° __  \\° __  \\° __  \\/° ___//° ___/");
108    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);
109    caca_put_str(m_caca, logo_x, logo_y + 2, " /   `  >  ____/  ____/  ,_  <_ <____\\___  \\");
110    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);
111    caca_put_str(m_caca, logo_x, logo_y + 3, "/__/\\___\\______\\______\\__| \\__/_____________\\");
112    caca_set_color_argb(m_caca, 0xdef, bg_color);
113    caca_put_str(m_caca, logo_x + 5, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US");
114
115    caca_set_color_argb(m_caca, 0x666, bg_color);
116    caca_printf(m_caca, 2, h - 3, "W=%i", w);
117    caca_printf(m_caca, 2, h - 2, "H=%i", h);
118
119    caca_set_color_argb(m_caca, hex_color(0.6f + 0.4f * lol::cos(m_time * 2), 0.2f, 0.2f), bg_color);
120    caca_put_str(m_caca, w - 12, h - 2, "CACA RULEZ");
121}
122
123
124void Neercs::TickDraw(float seconds)
125{
126    WorldEntity::TickDraw(seconds);
127}
128
129Neercs::~Neercs()
130{
131    Ticker::Unref(m_render);
132}
133
134int main(int argc, char **argv)
135{
136    Application app("Neercs", ivec2(800, 600), 60.0f);
137
138#if defined _MSC_VER && !defined _XBOX
139    _chdir("..");
140#elif defined _WIN32 && !defined _XBOX
141    _chdir("../..");
142#endif
143
144    new Neercs(argc, argv);
145    new DebugFps(2, 2);
146    app.ShowPointer(false);
147
148    app.Run();
149
150    return EXIT_SUCCESS;
151}
152
Note: See TracBrowser for help on using the repository browser.