84 lines
2.4 KiB

  1. /*
  2. * ttyvaders Textmode shoot'em up
  3. * Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This program is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. #include "config.h"
  15. #include <stdlib.h>
  16. #include <math.h>
  17. #include <unistd.h>
  18. #include "common.h"
  19. void intro(game *g)
  20. {
  21. caca_event_t ev;
  22. caca_canvas_t *foo_sprite;
  23. caca_canvas_t *bar_sprite;
  24. caca_canvas_t *baz_sprite;
  25. caca_buffer_t *b;
  26. int frame = 0;
  27. b = caca_load_file("data/foofight.caca");
  28. foo_sprite = caca_import_canvas(b, "");
  29. caca_free_buffer(b);
  30. b = caca_load_file("data/barfight.caca");
  31. bar_sprite = caca_import_canvas(b, "");
  32. caca_free_buffer(b);
  33. b = caca_load_file("data/bazfight.caca");
  34. baz_sprite = caca_import_canvas(b, "");
  35. caca_free_buffer(b);
  36. while(caca_get_event(g->dp, CACA_EVENT_KEY_PRESS, &ev, 0) == 0)
  37. {
  38. int i, xo, yo, x[5], y[5];
  39. frame++;
  40. caca_clear_canvas(g->cv);
  41. xo = caca_get_canvas_width(g->cv) / 2;
  42. yo = caca_get_canvas_height(g->cv) / 2;
  43. caca_set_color(g->cv, CACA_COLOR_RED, CACA_COLOR_BLACK);
  44. caca_fill_ellipse(g->cv, xo, yo, 16, 8, "#");
  45. caca_set_color(g->cv, CACA_COLOR_GREEN, CACA_COLOR_BLACK);
  46. caca_draw_thin_ellipse(g->cv, xo, yo, 16, 8);
  47. for(i = 0; i < 4; i ++)
  48. {
  49. x[i] = xo + 0.5 + 12 * cos(0.05 * frame + i * M_PI / 2);
  50. y[i] = yo + 0.5 + 6 * sin(0.05 * frame + i * M_PI / 2);
  51. }
  52. x[4] = x[0];
  53. y[4] = y[0];
  54. caca_set_color(g->cv, CACA_COLOR_BLACK, CACA_COLOR_BLACK);
  55. caca_fill_triangle(g->cv, x[0], y[0], x[1], y[1], x[2], y[2], " ");
  56. caca_fill_triangle(g->cv, x[0], y[0], x[3], y[3], x[2], y[2], " ");
  57. caca_draw_line(g->cv, x[0], y[0], x[2], y[2], " ");
  58. caca_set_color(g->cv, CACA_COLOR_GREEN, CACA_COLOR_BLACK);
  59. caca_draw_thin_polyline(g->cv, x, y, 4);
  60. caca_set_canvas_frame(foo_sprite, frame % 5);
  61. caca_blit(g->cv, xo, yo, foo_sprite, NULL);
  62. caca_refresh_display(g->dp);
  63. usleep(40000);
  64. }
  65. }