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 110 2003-11-09 23:34:24Z 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 */ |
---|
30 | player * 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 | |
---|
46 | void free_player(player *p) |
---|
47 | { |
---|
48 | free(p); |
---|
49 | } |
---|
50 | |
---|
51 | void draw_player(game *g, player *p) |
---|
52 | { |
---|
53 | if(p->dead) |
---|
54 | { |
---|
55 | return; |
---|
56 | } |
---|
57 | |
---|
58 | ee_goto(p->x + 2, p->y - 2); |
---|
59 | ee_color(EE_GREEN); |
---|
60 | ee_putstr("/\\"); |
---|
61 | ee_goto(p->x + 1, p->y - 1); |
---|
62 | ee_putchar('('); |
---|
63 | ee_color(EE_YELLOW); |
---|
64 | ee_putstr("()"); |
---|
65 | ee_color(EE_GREEN); |
---|
66 | ee_putchar(')'); |
---|
67 | ee_goto(p->x, p->y); |
---|
68 | ee_color(EE_GREEN); |
---|
69 | ee_putstr("I<__>I"); |
---|
70 | } |
---|
71 | |
---|
72 | void update_player(game *g, player *p) |
---|
73 | { |
---|
74 | if(p->dead) |
---|
75 | { |
---|
76 | return; |
---|
77 | } |
---|
78 | |
---|
79 | if(p->life <= 0) |
---|
80 | { |
---|
81 | add_explosion(g, g->ex, p->x, p->y, 0, 0, EXPLOSION_SMALL); |
---|
82 | p->dead = 1; |
---|
83 | return; |
---|
84 | } |
---|
85 | |
---|
86 | /* Update weapon stats */ |
---|
87 | if(p->weapon) |
---|
88 | { |
---|
89 | p->weapon--; |
---|
90 | } |
---|
91 | |
---|
92 | if(p->special < MAX_SPECIAL) |
---|
93 | { |
---|
94 | p->special++; |
---|
95 | } |
---|
96 | |
---|
97 | /* Update life */ |
---|
98 | if(p->life < MAX_LIFE) |
---|
99 | { |
---|
100 | p->life++; |
---|
101 | } |
---|
102 | |
---|
103 | /* Update coords */ |
---|
104 | p->x += p->vx; |
---|
105 | |
---|
106 | if(p->vx < 0) |
---|
107 | { |
---|
108 | p->vx++; |
---|
109 | } |
---|
110 | else if(p->vx > 0) |
---|
111 | { |
---|
112 | p->vx--; |
---|
113 | } |
---|
114 | |
---|
115 | if(p->x < 1) |
---|
116 | { |
---|
117 | p->x = 1; |
---|
118 | } |
---|
119 | else if(p->x > g->w - 7) |
---|
120 | { |
---|
121 | p->x = g->w - 7; |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|