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

Last change on this file since 88 was 88, checked in by Sam Hocevar, 17 years ago
  • Coding style everywhere.
  • Property svn:keywords set to Id
File size: 2.3 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 88 2003-11-09 13:16:19Z 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
23#include <stdlib.h>
24
25#include "common.h"
26
27/* Init tunnel */
[88]28player * create_player(game *g)
[18]29{
30    player *p = malloc(sizeof(player));
31
32    p->x = g->w / 2;
[20]33    p->y = g->h - 2;
[58]34    p->vx = 0;
35    p->vy = 0;
[18]36    p->weapon = 0;
[62]37    p->special = MAX_SPECIAL;
[60]38    p->life = MAX_LIFE;
[64]39    p->dead = 0;
[18]40
41    return p;
42}
43
[88]44void free_player(player *p)
[18]45{
[88]46    free(p);
[18]47}
48
[88]49void draw_player(game *g, player *p)
[18]50{
[88]51    if(p->dead)
[60]52    {
53        return;
54    }
55
[88]56    ee_goto(p->x + 2, p->y - 2);
57    ee_color(EE_GREEN);
58    ee_putstr("/\\");
59    ee_goto(p->x + 1, p->y - 1);
60    ee_putchar('(');
61    ee_color(EE_YELLOW);
62    ee_putstr("()");
63    ee_color(EE_GREEN);
64    ee_putchar(')');
65    ee_goto(p->x, p->y);
66    ee_color(EE_GREEN);
67    ee_putstr("I<__>I");
[18]68}
69
[88]70void update_player(game *g, player *p)
[18]71{
[88]72    if(p->dead)
[60]73    {
74        return;
75    }
76
[88]77    if(p->life <= 0)
[60]78    {
[88]79        add_explosion(g, g->ex, p->x, p->y, 0, 0, EXPLOSION_SMALL);
[60]80        p->dead = 1;
81        return;
82    }
83
84    /* Update weapon stats */
[88]85    if(p->weapon)
[18]86    {
87        p->weapon--;
88    }
89
[88]90    if(p->special < MAX_SPECIAL)
[18]91    {
[62]92        p->special++;
[18]93    }
94
[60]95    /* Update life */
[88]96    if(p->life < MAX_LIFE)
[60]97    {
98        p->life++;
99    }
100
101    /* Update coords */
[58]102    p->x += p->vx;
103
[88]104    if(p->vx < 0)
[18]105    {
[58]106        p->vx++;
107    }
[88]108    else if(p->vx > 0)
[58]109    {
110        p->vx--;
111    }
[18]112
[88]113    if(p->x < 1)
[58]114    {
115        p->x = 1;
[18]116    }
[88]117    else if(p->x > g->w - 7)
[18]118    {
[58]119        p->x = g->w - 7;
[18]120    }
121}
122
Note: See TracBrowser for help on using the repository browser.