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

Last change on this file since 58 was 58, checked in by Sam Hocevar, 17 years ago
  • ship has vx and vy.
File size: 1.9 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.5 2002/12/23 13:13:04 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->nuke = 0;
38
39    return p;
40}
41
42void free_player( player *p )
43{
44    free( p );
45}
46
47void draw_player( game *g, player *p )
48{
49    gfx_goto( p->x + 2, p->y - 2 );
50    gfx_color( GREEN );
51    gfx_putstr( "/\\" );
52    gfx_goto( p->x + 1, p->y - 1 );
53    gfx_putchar( '(' );
54    gfx_color( YELLOW );
55    gfx_putstr( "()" );
56    gfx_color( GREEN );
57    gfx_putchar( ')' );
58    gfx_goto( p->x, p->y );
59    gfx_color( GREEN );
60    gfx_putstr( "I<__>I" );
61}
62
63void update_player( game *g, player *p )
64{
65    if( p->weapon )
66    {
67        p->weapon--;
68    }
69
70    if( p->nuke )
71    {
72        p->nuke--;
73    }
74
75    p->x += p->vx;
76
77    if( p->vx < 0 )
78    {
79        p->vx++;
80    }
81    else if( p->vx > 0 )
82    {
83        p->vx--;
84    }
85
86    if( p->x < 1 )
87    {
88        p->x = 1;
89    }
90    else if( p->x > g->w - 7 )
91    {
92        p->x = g->w - 7;
93    }
94}
95
Note: See TracBrowser for help on using the repository browser.