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 88 2003-11-09 13:16:19Z 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 <stdlib.h> |
---|
24 | |
---|
25 | #include "common.h" |
---|
26 | |
---|
27 | /* Init tunnel */ |
---|
28 | player * 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->special = MAX_SPECIAL; |
---|
38 | p->life = MAX_LIFE; |
---|
39 | p->dead = 0; |
---|
40 | |
---|
41 | return p; |
---|
42 | } |
---|
43 | |
---|
44 | void free_player(player *p) |
---|
45 | { |
---|
46 | free(p); |
---|
47 | } |
---|
48 | |
---|
49 | void draw_player(game *g, player *p) |
---|
50 | { |
---|
51 | if(p->dead) |
---|
52 | { |
---|
53 | return; |
---|
54 | } |
---|
55 | |
---|
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"); |
---|
68 | } |
---|
69 | |
---|
70 | void update_player(game *g, player *p) |
---|
71 | { |
---|
72 | if(p->dead) |
---|
73 | { |
---|
74 | return; |
---|
75 | } |
---|
76 | |
---|
77 | if(p->life <= 0) |
---|
78 | { |
---|
79 | add_explosion(g, g->ex, p->x, p->y, 0, 0, EXPLOSION_SMALL); |
---|
80 | p->dead = 1; |
---|
81 | return; |
---|
82 | } |
---|
83 | |
---|
84 | /* Update weapon stats */ |
---|
85 | if(p->weapon) |
---|
86 | { |
---|
87 | p->weapon--; |
---|
88 | } |
---|
89 | |
---|
90 | if(p->special < MAX_SPECIAL) |
---|
91 | { |
---|
92 | p->special++; |
---|
93 | } |
---|
94 | |
---|
95 | /* Update life */ |
---|
96 | if(p->life < MAX_LIFE) |
---|
97 | { |
---|
98 | p->life++; |
---|
99 | } |
---|
100 | |
---|
101 | /* Update coords */ |
---|
102 | p->x += p->vx; |
---|
103 | |
---|
104 | if(p->vx < 0) |
---|
105 | { |
---|
106 | p->vx++; |
---|
107 | } |
---|
108 | else if(p->vx > 0) |
---|
109 | { |
---|
110 | p->vx--; |
---|
111 | } |
---|
112 | |
---|
113 | if(p->x < 1) |
---|
114 | { |
---|
115 | p->x = 1; |
---|
116 | } |
---|
117 | else if(p->x > g->w - 7) |
---|
118 | { |
---|
119 | p->x = g->w - 7; |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|