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

Last change on this file since 62 was 62, checked in by Sam Hocevar, 18 years ago
  • better handling of special weapon timeout.
  • the bomb is now part of the standard fire button effect.
  • overlay for life and special weapon jauges.
File size: 2.4 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,v 1.7 2002/12/23 15:06:13 sam Exp $
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 <stdlib.h>
24
25#include "common.h"
26
27/* Init tunnel */
28player * create_player( game *g )
29{
30    player *p = malloc(sizeof(player));
31
32    p->x = g->w / 2;
33    p->y = g->h - 2;
34    p->vx = 0;
35    p->vy = 0;
36    p->weapon = 0;
37    p->special = MAX_SPECIAL;
38    p->life = MAX_LIFE;
39
40    return p;
41}
42
43void free_player( player *p )
44{
45    free( p );
46}
47
48void draw_player( game *g, player *p )
49{
50    if( p->dead )
51    {
52        return;
53    }
54
55    gfx_goto( p->x + 2, p->y - 2 );
56    gfx_color( GREEN );
57    gfx_putstr( "/\\" );
58    gfx_goto( p->x + 1, p->y - 1 );
59    gfx_putchar( '(' );
60    gfx_color( YELLOW );
61    gfx_putstr( "()" );
62    gfx_color( GREEN );
63    gfx_putchar( ')' );
64    gfx_goto( p->x, p->y );
65    gfx_color( GREEN );
66    gfx_putstr( "I<__>I" );
67}
68
69void update_player( game *g, player *p )
70{
71    if( p->dead )
72    {
73        return;
74    }
75
76    if( p->life <= 0 )
77    {
78        add_explosion( g, g->ex, p->x, p->y, 0, 0, EXPLOSION_SMALL );
79        p->dead = 1;
80        return;
81    }
82
83    /* Update weapon stats */
84    if( p->weapon )
85    {
86        p->weapon--;
87    }
88
89    if( p->special < MAX_SPECIAL )
90    {
91        p->special++;
92    }
93
94    /* Update life */
95    if( p->life < MAX_LIFE )
96    {
97        p->life++;
98    }
99
100    /* Update coords */
101    p->x += p->vx;
102
103    if( p->vx < 0 )
104    {
105        p->vx++;
106    }
107    else if( p->vx > 0 )
108    {
109        p->vx--;
110    }
111
112    if( p->x < 1 )
113    {
114        p->x = 1;
115    }
116    else if( p->x > g->w - 7 )
117    {
118        p->x = g->w - 7;
119    }
120}
121
Note: See TracBrowser for help on using the repository browser.