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

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