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

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

testing things...

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#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, 0x444, bg_color);
75
76    int n = 16;
77    int radius = 48;
78    int speed = 1;
79    int z = 1;
80
81    for(int i = 0; i < n; i++)
82    {
83        //z -= speed;
84        int r = (radius - i * 4) / z;
85        int x1 = w / 2 + r * lol::cos(m_time * 2 - M_PI / 20);
86        int y1 = h / 2 + r * lol::sin(m_time * 2 - M_PI / 20);
87        int x2 = w / 2 + r * lol::cos(m_time * 2 + M_PI * 2 / 3 - M_PI / 20);
88        int y2 = h / 2 + r * lol::sin(m_time * 2 + M_PI * 2 / 3 - M_PI / 20);
89        int x3 = w / 2 + r * lol::cos(m_time * 2 + M_PI * 2 / 3 * 2 - M_PI / 20);
90        int y3 = h / 2 + r * lol::sin(m_time * 2 + M_PI * 2 / 3 * 2 - M_PI / 20);
91        caca_set_color_argb(m_caca, 0x642, bg_color);
92        caca_draw_thin_line(m_caca, x1, y1, x2, y2);
93        caca_draw_thin_line(m_caca, x2, y2, x3, y3);
94        caca_draw_thin_line(m_caca, x3, y3, x1, y1);
95    }
96
97/*
98.___  __ ______ ______ ______  ______ ______,
99 \° \|  /° __  \° __  \° __  \/° ___//° ___/
100 /   `  >  ____/  ____/  ,_  <  <____\___  \
101/__/\___\______\______\__| \__\_____________\
102*/
103
104    int logo_x = (w - 46) / 2;
105    int logo_y = h / 2 - 2;
106
107    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);
108    caca_put_str(m_caca, logo_x, logo_y    ,".___  __ ______ ______ ______  ______ ______,");
109    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);
110    caca_put_str(m_caca, logo_x, logo_y + 1, " \\° \\|  /° __  \\° __  \\° __  \\/° ___//° ___/");
111    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);
112    caca_put_str(m_caca, logo_x, logo_y + 2, " /   `  >  ____/  ____/  ,_  <  <____\\___  \\");
113    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);
114    caca_put_str(m_caca, logo_x, logo_y + 3, "/__/\\___\\______\\______\\__| \\__\\_____________\\");
115    caca_set_color_argb(m_caca, 0xdef, bg_color);
116    caca_put_str(m_caca, logo_x + 5, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US");
117
118    caca_set_color_ansi(m_caca, 0x666, bg_color);
119    caca_printf(m_caca, 1, h - 2, "W=%i H=%i", w, h);
120    //caca_printf(m_caca, 1, h - 2, "2d ratio=%i*%i", ratio_2d.x, ratio_2d.y);
121    caca_put_str(m_caca, w - 11, h - 2, "CACA RULEZ");
122}
123
124
125void Neercs::TickDraw(float seconds)
126{
127    WorldEntity::TickDraw(seconds);
128}
129
130Neercs::~Neercs()
131{
132    Ticker::Unref(m_render);
133}
134
135int main(int argc, char **argv)
136{
137    Application app("Neercs", ivec2(800, 600), 60.0f);
138
139#if defined _MSC_VER && !defined _XBOX
140    _chdir("..");
141#elif defined _WIN32 && !defined _XBOX
142    _chdir("../..");
143#endif
144
145    new Neercs();
146    new DebugFps(2, 2);
147    app.ShowPointer(false);
148
149    app.Run();
150
151    return EXIT_SUCCESS;
152}
153
Note: See TracBrowser for help on using the repository browser.