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

Last change on this file since 544 was 544, checked in by Sam Hocevar, 15 years ago
  • Ported to new libcaca/libcucul API.
  • Property svn:keywords set to Id
File size: 3.6 KB
RevLine 
[36]1/*
2 *   ttyvaders     Textmode shoot'em up
3 *   Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
4 *                 All Rights Reserved
5 *
[80]6 *   $Id: aliens.c 544 2006-03-07 14:25:20Z sam $
[36]7 *
8 *   This program is free software; you can redistribute it and/or modify
9 *   it under the terms of the GNU General Public License as published by
10 *   the Free Software Foundation; either version 2 of the License, or
11 *   (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
[18]22
[110]23#include "config.h"
24
[18]25#include <stdlib.h>
26
27#include "common.h"
28
[544]29struct cucul_sprite *foo_sprite;
30struct cucul_sprite *bar_sprite;
31struct cucul_sprite *baz_sprite;
[122]32
[88]33void init_aliens(game *g, aliens *al)
[18]34{
35    int i;
36
[88]37    for(i = 0; i < ALIENS; i++)
[18]38    {
[20]39        al->type[i] = ALIEN_NONE;
[18]40    }
[122]41
[544]42    foo_sprite = cucul_load_sprite(g->qq, "data/foofight.txt");
43    bar_sprite = cucul_load_sprite(g->qq, "data/barfight.txt");
44    baz_sprite = cucul_load_sprite(g->qq, "data/bazfight.txt");
[18]45}
46
[88]47void draw_aliens(game *g, aliens *al)
[18]48{
49    int i;
50
[88]51    for(i = 0; i < ALIENS; i++)
[18]52    {
[88]53        switch(al->type[i])
[18]54        {
[60]55            case ALIEN_FOO:
[544]56                cucul_draw_sprite(g->qq, al->x[i], al->y[i], foo_sprite, al->img[i] % 5);
[20]57                break;
[60]58            case ALIEN_BAR:
[544]59                cucul_draw_sprite(g->qq, al->x[i], al->y[i], bar_sprite, al->img[i] % 2);
[20]60                break;
[60]61            case ALIEN_BAZ:
[544]62                cucul_draw_sprite(g->qq, al->x[i], al->y[i], baz_sprite, al->img[i] % 4);
[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;
[544]81            add_bonus(g, g->bo, al->x[i], al->y[i], cucul_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.