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 153 2003-11-12 01:48:58Z 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 | struct ee_sprite *ship_sprite; |
---|
30 | |
---|
31 | /* Init tunnel */ |
---|
32 | player * create_player(game *g) |
---|
33 | { |
---|
34 | player *p = malloc(sizeof(player)); |
---|
35 | |
---|
36 | p->x = g->w / 2; |
---|
37 | p->y = g->h - 3; |
---|
38 | p->vx = 0; |
---|
39 | p->vy = 0; |
---|
40 | p->weapon = 0; |
---|
41 | p->special = MAX_SPECIAL; |
---|
42 | p->life = MAX_LIFE; |
---|
43 | p->dead = 0; |
---|
44 | |
---|
45 | ship_sprite = ee_load_sprite("data/ship_green"); |
---|
46 | |
---|
47 | return p; |
---|
48 | } |
---|
49 | |
---|
50 | void free_player(player *p) |
---|
51 | { |
---|
52 | free(p); |
---|
53 | } |
---|
54 | |
---|
55 | void draw_player(game *g, player *p) |
---|
56 | { |
---|
57 | if(p->dead) |
---|
58 | return; |
---|
59 | |
---|
60 | ee_draw_sprite(p->x, p->y, ship_sprite, 0); |
---|
61 | } |
---|
62 | |
---|
63 | void update_player(game *g, player *p) |
---|
64 | { |
---|
65 | if(p->dead) |
---|
66 | return; |
---|
67 | |
---|
68 | if(p->life <= 0) |
---|
69 | { |
---|
70 | add_explosion(g, g->ex, p->x, p->y, 0, 0, EXPLOSION_SMALL); |
---|
71 | p->dead = 1; |
---|
72 | return; |
---|
73 | } |
---|
74 | |
---|
75 | /* Update weapon stats */ |
---|
76 | if(p->weapon) |
---|
77 | p->weapon--; |
---|
78 | |
---|
79 | if(p->special < MAX_SPECIAL) |
---|
80 | p->special++; |
---|
81 | |
---|
82 | /* Update life */ |
---|
83 | if(p->life < MAX_LIFE) |
---|
84 | p->life++; |
---|
85 | |
---|
86 | /* Update coords */ |
---|
87 | p->x += p->vx; |
---|
88 | |
---|
89 | if(p->vx < 0) |
---|
90 | p->vx++; |
---|
91 | else if(p->vx > 0) |
---|
92 | p->vx--; |
---|
93 | |
---|
94 | if(p->x < 1) |
---|
95 | p->x = 1; |
---|
96 | else if(p->x > g->w - 7) |
---|
97 | p->x = g->w - 7; |
---|
98 | } |
---|
99 | |
---|