source: ttyvaders/trunk/src/player.c @ 1057

Last change on this file since 1057 was 1057, checked in by Sam Hocevar, 14 years ago
  • Bring the tree back in sync with the new libcaca API.
  • Property svn:keywords set to Id
File size: 2.2 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: player.c 1057 2006-09-18 16:54:08Z 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
[1057]29cucul_canvas_t *ship_sprite;
[150]30
[18]31/* Init tunnel */
[88]32player * create_player(game *g)
[18]33{
[1057]34    cucul_buffer_t *b;
35
[18]36    player *p = malloc(sizeof(player));
[174]37    if(p == NULL)
38        exit(1);
[18]39
40    p->x = g->w / 2;
[150]41    p->y = g->h - 3;
[58]42    p->vx = 0;
43    p->vy = 0;
[18]44    p->weapon = 0;
[62]45    p->special = MAX_SPECIAL;
[60]46    p->life = MAX_LIFE;
[64]47    p->dead = 0;
[18]48
[1057]49    b = cucul_load_file("data/ship.caca");
50    ship_sprite = cucul_import_canvas(b, "");
51    cucul_free_buffer(b);
[150]52
[18]53    return p;
54}
55
[88]56void free_player(player *p)
[18]57{
[88]58    free(p);
[18]59}
60
[88]61void draw_player(game *g, player *p)
[18]62{
[88]63    if(p->dead)
[60]64        return;
65
[1057]66    cucul_set_canvas_frame(ship_sprite, 0);
67    cucul_blit(g->cv, p->x, p->y, ship_sprite, NULL);
[18]68}
69
[88]70void update_player(game *g, player *p)
[18]71{
[88]72    if(p->dead)
[60]73        return;
74
[88]75    if(p->life <= 0)
[60]76    {
[88]77        add_explosion(g, g->ex, p->x, p->y, 0, 0, EXPLOSION_SMALL);
[60]78        p->dead = 1;
79        return;
80    }
81
82    /* Update weapon stats */
[88]83    if(p->weapon)
[18]84        p->weapon--;
85
[88]86    if(p->special < MAX_SPECIAL)
[62]87        p->special++;
[18]88
[60]89    /* Update life */
[88]90    if(p->life < MAX_LIFE)
[60]91        p->life++;
92
93    /* Update coords */
[58]94    p->x += p->vx;
95
[88]96    if(p->vx < 0)
[58]97        p->vx++;
[88]98    else if(p->vx > 0)
[58]99        p->vx--;
[18]100
[88]101    if(p->x < 1)
[58]102        p->x = 1;
[88]103    else if(p->x > g->w - 7)
[58]104        p->x = g->w - 7;
[18]105}
106
Note: See TracBrowser for help on using the repository browser.