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

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

core: switch the Win32/x64 binaries to the Windows subsystem so that they
do not open a console at startup.

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