| [36] | 1 | /* |
|---|
| [1456] | 2 | * ttyvaders Textmode shoot'em up |
|---|
| 3 | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> |
|---|
| 4 | * All Rights Reserved |
|---|
| [36] | 5 | * |
|---|
| [1456] | 6 | * $Id$ |
|---|
| [36] | 7 | * |
|---|
| [1460] | 8 | * This program is free software. It comes without any warranty, to |
|---|
| [1456] | 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. |
|---|
| [36] | 13 | */ |
|---|
| [20] | 14 | |
|---|
| [110] | 15 | #include "config.h" |
|---|
| 16 | |
|---|
| [20] | 17 | #include <stdlib.h> |
|---|
| 18 | |
|---|
| 19 | #include "common.h" |
|---|
| 20 | |
|---|
| [2990] | 21 | caca_canvas_t *heart_sprite; |
|---|
| 22 | caca_canvas_t *gem_sprite; |
|---|
| [122] | 23 | |
|---|
| [88] | 24 | void init_bonus(game *g, bonus *bo) |
|---|
| [20] | 25 | { |
|---|
| [2990] | 26 | caca_buffer_t *b; |
|---|
| [20] | 27 | int i; |
|---|
| 28 | |
|---|
| [88] | 29 | for(i = 0; i < BONUS; i++) |
|---|
| [20] | 30 | { |
|---|
| 31 | bo->type[i] = BONUS_NONE; |
|---|
| 32 | } |
|---|
| [122] | 33 | |
|---|
| [2990] | 34 | b = caca_load_file("data/bonheart.caca"); |
|---|
| 35 | heart_sprite = caca_import_canvas(b, ""); |
|---|
| 36 | caca_free_buffer(b); |
|---|
| [1057] | 37 | |
|---|
| [2990] | 38 | b = caca_load_file("data/bongem.caca"); |
|---|
| 39 | gem_sprite = caca_import_canvas(b, ""); |
|---|
| 40 | caca_free_buffer(b); |
|---|
| [20] | 41 | } |
|---|
| 42 | |
|---|
| [88] | 43 | void draw_bonus(game *g, bonus *bo) |
|---|
| [20] | 44 | { |
|---|
| 45 | int i; |
|---|
| 46 | |
|---|
| [88] | 47 | for(i = 0; i < BONUS; i++) |
|---|
| [20] | 48 | { |
|---|
| [88] | 49 | switch(bo->type[i]) |
|---|
| [20] | 50 | { |
|---|
| 51 | case BONUS_GREEN: |
|---|
| [2990] | 52 | caca_set_canvas_frame(gem_sprite, (bo->n[i]/2 % 3) ? 0 : 1); |
|---|
| 53 | caca_blit(g->cv, bo->x[i], bo->y[i], gem_sprite, NULL); |
|---|
| [20] | 54 | break; |
|---|
| 55 | case BONUS_LIFE: |
|---|
| [2990] | 56 | caca_set_canvas_frame(heart_sprite, (bo->n[i] % 3) ? 0 : 1); |
|---|
| 57 | caca_blit(g->cv, bo->x[i], bo->y[i], heart_sprite, NULL); |
|---|
| [20] | 58 | break; |
|---|
| 59 | case BONUS_NONE: |
|---|
| 60 | break; |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| [88] | 65 | void update_bonus(game *g, bonus *bo) |
|---|
| [20] | 66 | { |
|---|
| 67 | int i; |
|---|
| 68 | |
|---|
| [88] | 69 | for(i = 0; i < BONUS; i++) |
|---|
| [20] | 70 | { |
|---|
| [88] | 71 | switch(bo->type[i]) |
|---|
| [20] | 72 | { |
|---|
| 73 | case BONUS_GREEN: |
|---|
| 74 | bo->n[i]++; |
|---|
| 75 | bo->y[i]++; |
|---|
| [88] | 76 | if(bo->y[i] > g->h) |
|---|
| [20] | 77 | { |
|---|
| 78 | bo->type[i] = BONUS_NONE; |
|---|
| 79 | } |
|---|
| 80 | break; |
|---|
| 81 | case BONUS_LIFE: |
|---|
| 82 | bo->n[i]++; |
|---|
| 83 | bo->y[i]++; |
|---|
| [88] | 84 | if(bo->y[i] > g->h) |
|---|
| [20] | 85 | { |
|---|
| 86 | bo->type[i] = BONUS_NONE; |
|---|
| 87 | } |
|---|
| 88 | break; |
|---|
| 89 | case BONUS_NONE: |
|---|
| 90 | break; |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| [88] | 95 | void add_bonus(game *g, bonus *bo, int x, int y, int type) |
|---|
| [20] | 96 | { |
|---|
| 97 | int i; |
|---|
| 98 | |
|---|
| [88] | 99 | for(i = 0; i < BONUS; i++) |
|---|
| [20] | 100 | { |
|---|
| [88] | 101 | if(bo->type[i] == BONUS_NONE) |
|---|
| [20] | 102 | { |
|---|
| 103 | bo->type[i] = type; |
|---|
| 104 | bo->x[i] = x; |
|---|
| 105 | bo->y[i] = y; |
|---|
| 106 | bo->n[i] = 0; |
|---|
| 107 | break; |
|---|
| 108 | } |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | |
|---|