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

Last change on this file since 38 was 38, checked in by Sam Hocevar, 18 years ago
  • I think I fucked up the $Id tags on my previous commit.
File size: 2.0 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.4 2002/12/22 18:44:12 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->dir = 0;
35    p->weapon = 0;
36    p->nuke = 0;
37
38    return p;
39}
40
41void free_player( player *p )
42{
43    free( p );
44}
45
46void draw_player( game *g, player *p )
47{
48    gfx_goto( p->x + 2, p->y - 2 );
49    gfx_color( GREEN );
50    gfx_putstr( "/\\" );
51    gfx_goto( p->x + 1, p->y - 1 );
52    gfx_putchar( '(' );
53    gfx_color( YELLOW );
54    gfx_putstr( "()" );
55    gfx_color( GREEN );
56    gfx_putchar( ')' );
57    gfx_goto( p->x, p->y );
58    gfx_color( GREEN );
59    gfx_putstr( "I<__>I" );
60}
61
62void update_player( game *g, player *p )
63{
64    if( p->weapon )
65    {
66        p->weapon--;
67    }
68
69    if( p->nuke )
70    {
71        p->nuke--;
72    }
73
74    if( p->dir < 0 )
75    {
76        if( p->dir == -3 && p->x > -2 ) p->x -= 1;
77        else if( p->x > -1 ) p->x -= 1;
78
79        p->dir++;
80    }
81    else if( p->dir > 0 )
82    {
83        if( p->dir == 3 && p->x < g->w - 8 ) p->x += 1;
84        else if( p->x < g->w - 7 ) p->x += 1;
85        p->dir--;
86    }
87}
88
Note: See TracBrowser for help on using the repository browser.