Ignore:
Timestamp:
Sep 18, 2006, 6:54:08 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Bring the tree back in sync with the new libcaca API.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ttyvaders/trunk/src/weapons.c

    r544 r1057  
    2424
    2525#include <stdlib.h>
     26#include <math.h>
    2627
    2728#include "common.h"
     
    3233static void draw_fragbomb(game *g, int x, int y, int frame);
    3334
    34 struct cucul_sprite *bomb_sprite;
    35 struct cucul_sprite *fragbomb_sprite;
     35cucul_canvas_t *bomb_sprite;
     36cucul_canvas_t *fragbomb_sprite;
    3637
    3738void init_weapons(game *g, weapons *wp)
    3839{
     40    cucul_buffer_t *b;
    3941    int i;
    4042
     
    4446    }
    4547
    46     bomb_sprite = cucul_load_sprite(g->qq, "data/wpnbomb.txt");
    47     fragbomb_sprite = cucul_load_sprite(g->qq, "data/wpnfrag.txt");
     48    b = cucul_load_file("data/wpnbomb.caca");
     49    bomb_sprite = cucul_import_canvas(b, "");
     50    cucul_free_buffer(b);
     51
     52    b = cucul_load_file("data/wpnfrag.caca");
     53    bomb_sprite = cucul_import_canvas(b, "");
     54    cucul_free_buffer(b);
    4855}
    4956
     
    5764        {
    5865            case WEAPON_LASER:
    59                 cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
    60                 cucul_putchar(g->qq, wp->x[i] >> 4, wp->y[i] >> 4, '|');
    61                 cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
    62                 cucul_putchar(g->qq, wp->x[i] >> 4, (wp->y[i] >> 4) + 1, '|');
     66                cucul_set_color(g->cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
     67                cucul_putchar(g->cv, wp->x[i] >> 4, wp->y[i] >> 4, '|');
     68                cucul_set_color(g->cv, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
     69                cucul_putchar(g->cv, wp->x[i] >> 4, (wp->y[i] >> 4) + 1, '|');
    6370                break;
    6471            case WEAPON_SEEKER:
    65                 cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
    66                 cucul_putchar(g->qq, wp->x3[i] >> 4, wp->y3[i] >> 4, '.');
    67                 cucul_putchar(g->qq, wp->x2[i] >> 4, wp->y2[i] >> 4, 'o');
    68                 cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
    69                 cucul_putchar(g->qq, wp->x[i] >> 4, wp->y[i] >> 4, '@');
     72                cucul_set_color(g->cv, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
     73                cucul_putchar(g->cv, wp->x3[i] >> 4, wp->y3[i] >> 4, '.');
     74                cucul_putchar(g->cv, wp->x2[i] >> 4, wp->y2[i] >> 4, 'o');
     75                cucul_set_color(g->cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
     76                cucul_putchar(g->cv, wp->x[i] >> 4, wp->y[i] >> 4, '@');
    7077                break;
    7178            case WEAPON_BOMB:
    72                 cucul_set_color(g->qq, CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_BLACK);
    73                 cucul_putchar(g->qq, (wp->x[i] - wp->vx[i]) >> 4, (wp->y[i] - wp->vy[i]) >> 4, '.');
    74                 cucul_putchar(g->qq, (wp->x3[i] - wp->vx[i]) >> 4, (wp->y3[i] - wp->vy[i]) >> 4, '.');
    75                 cucul_putchar(g->qq, (wp->x2[i] - wp->vx[i]) >> 4, (wp->y2[i] - wp->vy[i]) >> 4, '.');
    76                 cucul_putchar(g->qq, wp->x3[i] >> 4, wp->y3[i] >> 4, '.');
    77                 cucul_putchar(g->qq, wp->x2[i] >> 4, wp->y2[i] >> 4, '.');
     79                cucul_set_color(g->cv, CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_BLACK);
     80                cucul_putchar(g->cv, (wp->x[i] - wp->vx[i]) >> 4, (wp->y[i] - wp->vy[i]) >> 4, '.');
     81                cucul_putchar(g->cv, (wp->x3[i] - wp->vx[i]) >> 4, (wp->y3[i] - wp->vy[i]) >> 4, '.');
     82                cucul_putchar(g->cv, (wp->x2[i] - wp->vx[i]) >> 4, (wp->y2[i] - wp->vy[i]) >> 4, '.');
     83                cucul_putchar(g->cv, wp->x3[i] >> 4, wp->y3[i] >> 4, '.');
     84                cucul_putchar(g->cv, wp->x2[i] >> 4, wp->y2[i] >> 4, '.');
    7885                draw_bomb(g, wp->x[i] >> 4, wp->y[i] >> 4, wp->vx[i], wp->vy[i]);
    7986                break;
     
    171178                if(dx | dy)
    172179                {
    173                     unsigned int norm = cucul_sqrt(dx * dx + 4 * dy * dy);
     180                    unsigned int norm = (int)sqrt((double)(dx * dx + 4 * dy * dy));
    174181                    dx = dx * 32 / norm;
    175182                    dy = dy * 32 / norm;
     
    183190                if(dx | dy)
    184191                {
    185                     unsigned int norm = cucul_sqrt(dx * dx + 4 * dy * dy);
     192                    unsigned int norm = (int)sqrt((double)(dx * dx + 4 * dy * dy));
    186193                    wp->vx[i] = dx * 32 / norm;
    187194                    wp->vy[i] = dy * 32 / norm;
     
    335342    }
    336343
    337     cucul_draw_sprite(g->qq, x, y, bomb_sprite, frame);
     344    cucul_set_canvas_frame(bomb_sprite, frame);
     345    cucul_blit(g->cv, x, y, bomb_sprite, NULL);
    338346}
    339347
     
    341349{
    342350    /* Draw the head */
    343     cucul_draw_sprite(g->qq, x, y, fragbomb_sprite, frame & 1);
     351    cucul_set_canvas_frame(fragbomb_sprite, frame & 1);
     352    cucul_blit(g->cv, x, y, fragbomb_sprite, NULL);
    344353
    345354    /* Draw the tail */
    346     cucul_draw_sprite(g->qq, x, y, fragbomb_sprite, 2 + (frame % 4));
     355    cucul_set_canvas_frame(fragbomb_sprite, 2 + (frame % 4));
     356    cucul_blit(g->cv, x, y, fragbomb_sprite, NULL);
    347357}
    348358
     
    355365    {
    356366        case 24:
    357             cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
    358             cucul_putstr(g->qq, x, y-3, "__");
    359             cucul_putchar(g->qq, x-1, y-2, '\'');
    360             cucul_putchar(g->qq, x+2, y-2, '`');
     367            cucul_set_color(g->cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
     368            cucul_putstr(g->cv, x, y-3, "__");
     369            cucul_putchar(g->cv, x-1, y-2, '\'');
     370            cucul_putchar(g->cv, x+2, y-2, '`');
    361371            break;
    362372        case 23:
    363             cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
    364             cucul_putstr(g->qq, x, y-3, "__");
    365             cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
    366             cucul_putstr(g->qq, x-2, y-2, "-'");
    367             cucul_putstr(g->qq, x+2, y-2, "`-");
     373            cucul_set_color(g->cv, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
     374            cucul_putstr(g->cv, x, y-3, "__");
     375            cucul_set_color(g->cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
     376            cucul_putstr(g->cv, x-2, y-2, "-'");
     377            cucul_putstr(g->cv, x+2, y-2, "`-");
    368378            break;
    369379        case 22:
    370             cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
    371             cucul_putstr(g->qq, x, y-3, "__");
    372             cucul_putchar(g->qq, x-1, y-2, '\'');
    373             cucul_putchar(g->qq, x+2, y-2, '`');
    374             cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
    375             cucul_putstr(g->qq, x-3, y-2, ",-");
    376             cucul_putstr(g->qq, x+3, y-2, "-.");
     380            cucul_set_color(g->cv, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
     381            cucul_putstr(g->cv, x, y-3, "__");
     382            cucul_putchar(g->cv, x-1, y-2, '\'');
     383            cucul_putchar(g->cv, x+2, y-2, '`');
     384            cucul_set_color(g->cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
     385            cucul_putstr(g->cv, x-3, y-2, ",-");
     386            cucul_putstr(g->cv, x+3, y-2, "-.");
    377387            break;
    378388        case 21:
    379             cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
    380             cucul_putstr(g->qq, x-1, y-3, "____");
    381             cucul_putchar(g->qq, x-2, y-2, '\'');
    382             cucul_putchar(g->qq, x+3, y-2, '`');
    383             cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
    384             cucul_putstr(g->qq, x-4, y-2, ",-");
    385             cucul_putstr(g->qq, x+4, y-2, "-.");
     389            cucul_set_color(g->cv, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
     390            cucul_putstr(g->cv, x-1, y-3, "____");
     391            cucul_putchar(g->cv, x-2, y-2, '\'');
     392            cucul_putchar(g->cv, x+3, y-2, '`');
     393            cucul_set_color(g->cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
     394            cucul_putstr(g->cv, x-4, y-2, ",-");
     395            cucul_putstr(g->cv, x+4, y-2, "-.");
    386396            break;
    387397        case 20:
    388             cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
    389             cucul_putstr(g->qq, x, y-3, "%%");
    390             cucul_putchar(g->qq, x-4, y-2, ',');
    391             cucul_putchar(g->qq, x+5, y-2, '.');
    392             cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
    393             cucul_putchar(g->qq, x-1, y-3, ':');
    394             cucul_putchar(g->qq, x+2, y-3, ':');
    395             cucul_putstr(g->qq, x-3, y-2, "-'");
    396             cucul_putstr(g->qq, x+3, y-2, "`-");
     398            cucul_set_color(g->cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
     399            cucul_putstr(g->cv, x, y-3, "%%");
     400            cucul_putchar(g->cv, x-4, y-2, ',');
     401            cucul_putchar(g->cv, x+5, y-2, '.');
     402            cucul_set_color(g->cv, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
     403            cucul_putchar(g->cv, x-1, y-3, ':');
     404            cucul_putchar(g->cv, x+2, y-3, ':');
     405            cucul_putstr(g->cv, x-3, y-2, "-'");
     406            cucul_putstr(g->cv, x+3, y-2, "`-");
    397407            break;
    398408        case 19:
    399             cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
    400             cucul_putstr(g->qq, x, y-4, "%%");
    401             cucul_putstr(g->qq, x, y-3, "##");
    402             cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
    403             cucul_putchar(g->qq, x-1, y-4, ':');
    404             cucul_putchar(g->qq, x+2, y-4, ':');
    405             cucul_putchar(g->qq, x-1, y-3, '%');
    406             cucul_putchar(g->qq, x+2, y-3, '%');
    407             cucul_putstr(g->qq, x-4, y-2, ",-'");
    408             cucul_putstr(g->qq, x+3, y-2, "`-.");
    409             cucul_set_color(g->qq, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK);
    410             cucul_putchar(g->qq, x-2, y-3, ':');
    411             cucul_putchar(g->qq, x+3, y-3, ':');
     409            cucul_set_color(g->cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
     410            cucul_putstr(g->cv, x, y-4, "%%");
     411            cucul_putstr(g->cv, x, y-3, "##");
     412            cucul_set_color(g->cv, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
     413            cucul_putchar(g->cv, x-1, y-4, ':');
     414            cucul_putchar(g->cv, x+2, y-4, ':');
     415            cucul_putchar(g->cv, x-1, y-3, '%');
     416            cucul_putchar(g->cv, x+2, y-3, '%');
     417            cucul_putstr(g->cv, x-4, y-2, ",-'");
     418            cucul_putstr(g->cv, x+3, y-2, "`-.");
     419            cucul_set_color(g->cv, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK);
     420            cucul_putchar(g->cv, x-2, y-3, ':');
     421            cucul_putchar(g->cv, x+3, y-3, ':');
    412422            break;
    413423        case 18:
    414424        default:
    415425            r = (18 - frame) * (18 - frame);
    416             cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
    417             cucul_putstr(g->qq, x-1, y-5-r, ":%%:");
    418             cucul_putstr(g->qq, x-1, y-4-r, "%##%");
    419             cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
    420             cucul_putchar(g->qq, x-2, y-4-r, ':');
    421             cucul_putchar(g->qq, x+3, y-4-r, ':');
    422             cucul_putchar(g->qq, x-2, y-2, '\'');
    423             cucul_putchar(g->qq, x+3, y-2, '`');
    424             cucul_set_color(g->qq, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK);
    425             cucul_putchar(g->qq, x-3, y-2, ':');
    426             cucul_putchar(g->qq, x+4, y-2, ':');
     426            cucul_set_color(g->cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
     427            cucul_putstr(g->cv, x-1, y-5-r, ":%%:");
     428            cucul_putstr(g->cv, x-1, y-4-r, "%##%");
     429            cucul_set_color(g->cv, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
     430            cucul_putchar(g->cv, x-2, y-4-r, ':');
     431            cucul_putchar(g->cv, x+3, y-4-r, ':');
     432            cucul_putchar(g->cv, x-2, y-2, '\'');
     433            cucul_putchar(g->cv, x+3, y-2, '`');
     434            cucul_set_color(g->cv, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK);
     435            cucul_putchar(g->cv, x-3, y-2, ':');
     436            cucul_putchar(g->cv, x+4, y-2, ':');
    427437            for(i = 0; i <= r; i++)
    428438            {
    429                 cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
    430                 cucul_putstr(g->qq, x-1, y-3-i, ((i+frame) % 5) ? "####" : "%%%%");
    431                 cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
    432                 cucul_putchar(g->qq, x-2, y-3-i, '%');
    433                 cucul_putchar(g->qq, x+3, y-3-i, '%');
    434                 cucul_set_color(g->qq, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK);
    435                 cucul_putchar(g->qq, x-3, y-3-i, ':');
    436                 cucul_putchar(g->qq, x+4, y-3-i, ':');
     439                cucul_set_color(g->cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
     440                cucul_putstr(g->cv, x-1, y-3-i, ((i+frame) % 5) ? "####" : "%%%%");
     441                cucul_set_color(g->cv, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
     442                cucul_putchar(g->cv, x-2, y-3-i, '%');
     443                cucul_putchar(g->cv, x+3, y-3-i, '%');
     444                cucul_set_color(g->cv, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK);
     445                cucul_putchar(g->cv, x-3, y-3-i, ':');
     446                cucul_putchar(g->cv, x+4, y-3-i, ':');
    437447            }
    438448            break;
     
    445455
    446456    /* Lots of duplicate pixels, but we don't care */
    447     cucul_set_color(g->qq, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK);
    448     cucul_draw_ellipse(g->qq, x, y, r, r / 2, ':');
    449     cucul_set_color(g->qq, CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_BLUE);
    450     cucul_draw_ellipse(g->qq, x, y, r + 1, r / 2, '#');
    451     cucul_set_color(g->qq, CUCUL_COLOR_BLUE, CUCUL_COLOR_LIGHTBLUE);
    452     cucul_draw_ellipse(g->qq, x, y, r + 2, r / 2, '#');
    453     cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_LIGHTBLUE);
    454     cucul_draw_ellipse(g->qq, x, y, r + 2, r / 2 + 1, '#');
    455     cucul_set_color(g->qq, CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_CYAN);
    456     cucul_draw_ellipse(g->qq, x, y, r + 3, r / 2 + 1, '#');
    457     cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_CYAN);
    458     cucul_draw_ellipse(g->qq, x, y, r + 3, r / 2 + 2, '#');
    459     cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_WHITE);
    460     cucul_draw_ellipse(g->qq, x, y, r + 4, r / 2 + 2, '#');
    461     cucul_draw_ellipse(g->qq, x, y, r + 4, r / 2 + 3, ' ');
    462 }
    463 
     457    cucul_set_color(g->cv, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK);
     458    cucul_draw_ellipse(g->cv, x, y, r, r / 2, ":");
     459    cucul_set_color(g->cv, CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_BLUE);
     460    cucul_draw_ellipse(g->cv, x, y, r + 1, r / 2, "#");
     461    cucul_set_color(g->cv, CUCUL_COLOR_BLUE, CUCUL_COLOR_LIGHTBLUE);
     462    cucul_draw_ellipse(g->cv, x, y, r + 2, r / 2, "#");
     463    cucul_set_color(g->cv, CUCUL_COLOR_CYAN, CUCUL_COLOR_LIGHTBLUE);
     464    cucul_draw_ellipse(g->cv, x, y, r + 2, r / 2 + 1, "#");
     465    cucul_set_color(g->cv, CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_CYAN);
     466    cucul_draw_ellipse(g->cv, x, y, r + 3, r / 2 + 1, "#");
     467    cucul_set_color(g->cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_CYAN);
     468    cucul_draw_ellipse(g->cv, x, y, r + 3, r / 2 + 2, "#");
     469    cucul_set_color(g->cv, CUCUL_COLOR_CYAN, CUCUL_COLOR_WHITE);
     470    cucul_draw_ellipse(g->cv, x, y, r + 4, r / 2 + 2, "#");
     471    cucul_draw_ellipse(g->cv, x, y, r + 4, r / 2 + 3, " ");
     472}
     473
Note: See TracChangeset for help on using the changeset viewer.