Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

164 строки
4.9 KiB

  1. //
  2. // Neercs
  3. //
  4. // Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net>
  5. //
  6. #if defined HAVE_CONFIG_H
  7. # include "config.h"
  8. #endif
  9. #if defined _WIN32
  10. # include <direct.h>
  11. #endif
  12. #if defined _XBOX
  13. # define _USE_MATH_DEFINES /* for M_PI */
  14. # include <xtl.h>
  15. # undef near /* Fuck Microsoft */
  16. # undef far /* Fuck Microsoft again */
  17. #elif defined _WIN32
  18. # define _USE_MATH_DEFINES /* for M_PI */
  19. # define WIN32_LEAN_AND_MEAN
  20. # include <windows.h>
  21. # undef near /* Fuck Microsoft */
  22. # undef far /* Fuck Microsoft again */
  23. #else
  24. # include <cmath>
  25. #endif
  26. #if USE_SDL && defined __APPLE__
  27. # include <SDL_main.h>
  28. #endif
  29. #include <time.h>
  30. #include <caca.h>
  31. #include "core.h"
  32. #include "loldebug.h"
  33. using namespace std;
  34. using namespace lol;
  35. #include "neercs.h"
  36. #include "video/render.h"
  37. Neercs::Neercs()
  38. : m_ready(false),
  39. m_caca(caca_create_canvas(47, 32)),
  40. m_render(new Render(m_caca)),
  41. m_time(0.f)
  42. {
  43. Ticker::Ref(m_render);
  44. }
  45. int Neercs::hex_color(float r, float g, float b)
  46. {
  47. return ((int)(r * 15.99f) << 8) | ((int)(g * 15.99f) << 4) | (int)(b * 15.99f);
  48. }
  49. void Neercs::TickGame(float seconds)
  50. {
  51. WorldEntity::TickGame(seconds);
  52. m_time += seconds;
  53. /* draw something */
  54. int bg_color = 0x222;
  55. int w = caca_get_canvas_width(m_caca);
  56. int h = caca_get_canvas_height(m_caca);
  57. caca_set_color_argb(m_caca, 0xfff, bg_color);
  58. caca_clear_canvas(m_caca);
  59. caca_set_color_argb(m_caca, 0x444, bg_color);
  60. int n1 = 8;
  61. int n2 = 6;//w / n1 * h;
  62. for(int i = 0; i < n1; i++)
  63. {
  64. for(int j = 0; j < n2; j++)
  65. {
  66. int p_x = i * w / n1 + w / (n1 * 2);
  67. int p_y = j * h / n2 + h / (n2 * 2);
  68. 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);
  69. caca_fill_ellipse(m_caca, p_x, p_y, r_w, r_w, '%');
  70. }
  71. }
  72. int radius = 12;
  73. int x1 = w / 2 + radius * lol::cos(m_time * 2 - M_PI / 20);
  74. int y1 = h / 2 + radius * lol::sin(m_time * 2 - M_PI / 20);
  75. int x2 = w / 2 + radius * lol::cos(m_time * 2 + M_PI * 2 / 3 - M_PI / 20);
  76. int y2 = h / 2 + radius * lol::sin(m_time * 2 + M_PI * 2 / 3 - M_PI / 20);
  77. int x3 = w / 2 + radius * lol::cos(m_time * 2 + M_PI * 2 / 3 * 2 - M_PI / 20);
  78. int y3 = h / 2 + radius * lol::sin(m_time * 2 + M_PI * 2 / 3 * 2 - M_PI / 20);
  79. caca_set_color_argb(m_caca, 0x642, bg_color);
  80. caca_draw_thin_line(m_caca, x1, y1, x2, y2);
  81. caca_draw_thin_line(m_caca, x2, y2, x3, y3);
  82. caca_draw_thin_line(m_caca, x3, y3, x1, y1);
  83. x1 = w / 2 + radius * lol::cos(m_time * 2);
  84. y1 = h / 2 + radius * lol::sin(m_time * 2);
  85. x2 = w / 2 + radius * lol::cos(m_time * 2 + M_PI * 2 / 3);
  86. y2 = h / 2 + radius * lol::sin(m_time * 2 + M_PI * 2 / 3);
  87. x3 = w / 2 + radius * lol::cos(m_time * 2 + M_PI * 2 / 3 * 2);
  88. y3 = h / 2 + radius * lol::sin(m_time * 2 + M_PI * 2 / 3 * 2);
  89. caca_set_color_argb(m_caca, 0xea6, bg_color);
  90. caca_draw_thin_line(m_caca, x1, y1, x2, y2);
  91. caca_draw_thin_line(m_caca, x2, y2, x3, y3);
  92. caca_draw_thin_line(m_caca, x3, y3, x1, y1);
  93. int logo_x = -1;
  94. int logo_y = h / 2 - 3;
  95. 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);
  96. caca_put_str(m_caca, logo_x, logo_y ," ___ __ _______ _______ _______ ._____ _______. ");
  97. 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);
  98. caca_put_str(m_caca, logo_x, logo_y + 1, "| \\| Y ____Y ____Y ___ \\/ .___Y ___/ ");
  99. 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);
  100. caca_put_str(m_caca, logo_x, logo_y + 2, "| . ° > ____> ____> .__ / <_____\\____ \\ ");
  101. 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);
  102. caca_put_str(m_caca, logo_x, logo_y + 3, "|__|\\___\\_______\\_______\\__| \\_\\________________\\");
  103. caca_set_color_argb(m_caca, 0xdef, bg_color);
  104. caca_put_str(m_caca, logo_x + 7, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US!");
  105. caca_set_color_ansi(m_caca, 0x666, bg_color);
  106. caca_printf(m_caca, 1, h - 2, "W=%i H=%i", w, h);
  107. caca_put_str(m_caca, w - 13, h - 2, "CACA RULEZ");
  108. }
  109. void Neercs::TickDraw(float seconds)
  110. {
  111. WorldEntity::TickDraw(seconds);
  112. }
  113. Neercs::~Neercs()
  114. {
  115. Ticker::Unref(m_render);
  116. }
  117. int main(int argc, char **argv)
  118. {
  119. Application app("Neercs", ivec2(800, 600), 60.0f);
  120. #if defined _MSC_VER && !defined _XBOX
  121. _chdir("..");
  122. #elif defined _WIN32 && !defined _XBOX
  123. _chdir("../..");
  124. #endif
  125. new Neercs();
  126. new DebugFps(2, 2);
  127. app.ShowPointer(false);
  128. app.Run();
  129. return EXIT_SUCCESS;
  130. }