source: ttyvaders/trunk/src/aliens.c @ 3423

Last change on this file since 3423 was 3423, checked in by Sam Hocevar, 11 years ago
  • Toying around with the old ttyvaders version.
  • Property svn:keywords set to Id
File size: 3.5 KB
RevLine 
[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: aliens.c 3423 2009-04-28 16:55:01Z sam $
[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 */
[18]14
[110]15#include "config.h"
16
[18]17#include <stdlib.h>
18
19#include "common.h"
20
[2990]21caca_canvas_t *foo_sprite;
22caca_canvas_t *bar_sprite;
23caca_canvas_t *baz_sprite;
[122]24
[88]25void init_aliens(game *g, aliens *al)
[18]26{
27    int i;
28
[88]29    for(i = 0; i < ALIENS; i++)
[18]30    {
[20]31        al->type[i] = ALIEN_NONE;
[18]32    }
[122]33
[3423]34    foo_sprite = caca_create_canvas(0, 0);
35    caca_import_file(foo_sprite, "data/foofight.txt", "utf8");
[1057]36
[3423]37    bar_sprite = caca_create_canvas(0, 0);
38    caca_import_file(bar_sprite, "data/barfight.txt", "utf8");
[1057]39
[3423]40    baz_sprite = caca_create_canvas(0, 0);
41    caca_import_file(baz_sprite, "data/bazfight.txt", "utf8");
[18]42}
43
[88]44void draw_aliens(game *g, aliens *al)
[18]45{
46    int i;
47
[88]48    for(i = 0; i < ALIENS; i++)
[18]49    {
[88]50        switch(al->type[i])
[18]51        {
[60]52            case ALIEN_FOO:
[3423]53                caca_set_frame(foo_sprite, al->img[i] % 5);
[2990]54                caca_blit(g->cv, al->x[i], al->y[i], foo_sprite, NULL);
[20]55                break;
[60]56            case ALIEN_BAR:
[3423]57                caca_set_frame(bar_sprite, al->img[i] % 2);
[2990]58                caca_blit(g->cv, al->x[i], al->y[i], bar_sprite, NULL);
[20]59                break;
[60]60            case ALIEN_BAZ:
[3423]61                caca_set_frame(baz_sprite, al->img[i] % 4);
[2990]62                caca_blit(g->cv, al->x[i], al->y[i], baz_sprite, NULL);
[20]63                break;
64            case ALIEN_NONE:
65                break;
[18]66        }
67    }
68}
69
[88]70void update_aliens(game *g, aliens *al)
[18]71{
72    int i;
73
[88]74    for(i = 0; i < ALIENS; i++)
[18]75    {
[42]76        /* If alien died, make it explode */
[88]77        if(al->type[i] != ALIEN_NONE && al->life[i] < 0)
[42]78        {
[88]79            add_explosion(g, g->ex, al->x[i], al->y[i], 0, 0, EXPLOSION_MEDIUM);
[42]80            al->type[i] = ALIEN_NONE;
[2990]81            add_bonus(g, g->bo, al->x[i], al->y[i], caca_rand(0,4) ? BONUS_GREEN : BONUS_LIFE);
[42]82        }
83
84        /* Update coordinates */
[88]85        switch(al->type[i])
[18]86        {
[60]87            case ALIEN_FOO:
88            case ALIEN_BAR:
89            case ALIEN_BAZ:
[20]90                al->x[i] = ((al->x[i] + 5) % (g->w + 3)) - 3;
91                al->y[i] = al->y[i] + (rand() % 8) / 7 - (rand() % 8) / 7;
92                al->img[i] = al->img[i] + 1;
[18]93
[20]94                /* Check bounds */
[88]95                if(al->y[i] < 0 ) al->y[i] = 0;
96                if(al->y[i] > g->w - 1 ) al->y[i] = g->w - 1;
[20]97                break;
98            case ALIEN_NONE:
99                break;
[18]100        }
101    }
102}
103
[88]104void add_alien(game *g, aliens *al, int x, int y, int type)
[18]105{
106    int i;
107
[88]108    for(i = 0; i < ALIENS; i++)
[18]109    {
[88]110        if(al->type[i] == ALIEN_NONE)
[18]111        {
[20]112            al->type[i] = type;
[18]113            al->x[i] = x;
114            al->y[i] = y;
115            al->img[i] = 0;
[20]116
[88]117            switch(al->type[i])
[20]118            {
[60]119                case ALIEN_FOO:
[24]120                    al->life[i] = 3;
[20]121                    break;
[60]122                case ALIEN_BAR:
[24]123                    al->life[i] = 3;
[20]124                    break;
[60]125                case ALIEN_BAZ:
[24]126                    al->life[i] = 3;
[20]127                    break;
128                case ALIEN_NONE:
129                    break;
130            }
131
[18]132            break;
133        }
134    }
135}
136
Note: See TracBrowser for help on using the repository browser.