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