You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

112 lines
2.5 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 commes 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 "common.h"
  17. cucul_canvas_t *heart_sprite;
  18. cucul_canvas_t *gem_sprite;
  19. void init_bonus(game *g, bonus *bo)
  20. {
  21. cucul_buffer_t *b;
  22. int i;
  23. for(i = 0; i < BONUS; i++)
  24. {
  25. bo->type[i] = BONUS_NONE;
  26. }
  27. b = cucul_load_file("data/bonheart.caca");
  28. heart_sprite = cucul_import_canvas(b, "");
  29. cucul_free_buffer(b);
  30. b = cucul_load_file("data/bongem.caca");
  31. gem_sprite = cucul_import_canvas(b, "");
  32. cucul_free_buffer(b);
  33. }
  34. void draw_bonus(game *g, bonus *bo)
  35. {
  36. int i;
  37. for(i = 0; i < BONUS; i++)
  38. {
  39. switch(bo->type[i])
  40. {
  41. case BONUS_GREEN:
  42. cucul_set_canvas_frame(gem_sprite, (bo->n[i]/2 % 3) ? 0 : 1);
  43. cucul_blit(g->cv, bo->x[i], bo->y[i], gem_sprite, NULL);
  44. break;
  45. case BONUS_LIFE:
  46. cucul_set_canvas_frame(heart_sprite, (bo->n[i] % 3) ? 0 : 1);
  47. cucul_blit(g->cv, bo->x[i], bo->y[i], heart_sprite, NULL);
  48. break;
  49. case BONUS_NONE:
  50. break;
  51. }
  52. }
  53. }
  54. void update_bonus(game *g, bonus *bo)
  55. {
  56. int i;
  57. for(i = 0; i < BONUS; i++)
  58. {
  59. switch(bo->type[i])
  60. {
  61. case BONUS_GREEN:
  62. bo->n[i]++;
  63. bo->y[i]++;
  64. if(bo->y[i] > g->h)
  65. {
  66. bo->type[i] = BONUS_NONE;
  67. }
  68. break;
  69. case BONUS_LIFE:
  70. bo->n[i]++;
  71. bo->y[i]++;
  72. if(bo->y[i] > g->h)
  73. {
  74. bo->type[i] = BONUS_NONE;
  75. }
  76. break;
  77. case BONUS_NONE:
  78. break;
  79. }
  80. }
  81. }
  82. void add_bonus(game *g, bonus *bo, int x, int y, int type)
  83. {
  84. int i;
  85. for(i = 0; i < BONUS; i++)
  86. {
  87. if(bo->type[i] == BONUS_NONE)
  88. {
  89. bo->type[i] = type;
  90. bo->x[i] = x;
  91. bo->y[i] = y;
  92. bo->n[i] = 0;
  93. break;
  94. }
  95. }
  96. }