source: ttyvaders/trunk/src/player.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: 2.1 KB
Line 
1/*
2 *   ttyvaders     Textmode shoot'em up
3 *   Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
4 *                 All Rights Reserved
5 *
6 *   $Id: player.c 544 2006-03-07 14:25:20Z sam $
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 */
22
23#include "config.h"
24
25#include <stdlib.h>
26
27#include "common.h"
28
29struct cucul_sprite *ship_sprite;
30
31/* Init tunnel */
32player * create_player(game *g)
33{
34    player *p = malloc(sizeof(player));
35    if(p == NULL)
36        exit(1);
37
38    p->x = g->w / 2;
39    p->y = g->h - 3;
40    p->vx = 0;
41    p->vy = 0;
42    p->weapon = 0;
43    p->special = MAX_SPECIAL;
44    p->life = MAX_LIFE;
45    p->dead = 0;
46
47    ship_sprite = cucul_load_sprite(g->qq, "data/ship.txt");
48
49    return p;
50}
51
52void free_player(player *p)
53{
54    free(p);
55}
56
57void draw_player(game *g, player *p)
58{
59    if(p->dead)
60        return;
61
62    cucul_draw_sprite(g->qq, p->x, p->y, ship_sprite, 0);
63}
64
65void update_player(game *g, player *p)
66{
67    if(p->dead)
68        return;
69
70    if(p->life <= 0)
71    {
72        add_explosion(g, g->ex, p->x, p->y, 0, 0, EXPLOSION_SMALL);
73        p->dead = 1;
74        return;
75    }
76
77    /* Update weapon stats */
78    if(p->weapon)
79        p->weapon--;
80
81    if(p->special < MAX_SPECIAL)
82        p->special++;
83
84    /* Update life */
85    if(p->life < MAX_LIFE)
86        p->life++;
87
88    /* Update coords */
89    p->x += p->vx;
90
91    if(p->vx < 0)
92        p->vx++;
93    else if(p->vx > 0)
94        p->vx--;
95
96    if(p->x < 1)
97        p->x = 1;
98    else if(p->x > g->w - 7)
99        p->x = g->w - 7;
100}
101
Note: See TracBrowser for help on using the repository browser.