1 /*
2 * Kuklomenos
3 * Copyright (C) 2008-2009 Martin Bays <mbays@sdf.lonestar.org>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see http://www.gnu.org/licenses/.
17 */
18
19 #include <algorithm>
20
21 #include "gfx.h"
22 #include "shot.h"
23
update(int time)24 void Shot::update(int time)
25 {
26 pos += vel*time;
27 timeLived += time;
28 }
29
draw(SDL_Surface * surface,const View & view,View * boundView,bool noAA)30 void Shot::draw(SDL_Surface* surface, const View& view, View* boundView,
31 bool noAA)
32 {
33 Uint32 basecolour;
34
35 switch (weight)
36 {
37 case 3: basecolour = 0xff000000;
38 break;
39 case 2: basecolour = 0xffff0000;
40 break;
41 default: basecolour = 0x00ff0000;
42 }
43
44 Line(pos, pos + vel * -std::min(timeLived, 50),
45 basecolour + (super ? 0xb0 : 0x70)
46 ).draw(surface, view, boundView, noAA);
47
48 Pixel(pos, basecolour + (super ? 0xff : 0xe0)
49 ).draw(surface, view, boundView, noAA);
50 }
51
hit(int damage)52 int Shot::hit(int damage)
53 {
54 int lost = std::min(weight, damage);
55 weight -= lost;
56 if (weight == 0)
57 dead = 1;
58 return lost;
59 }
60
die()61 int Shot::die()
62 {
63 return hit(weight);
64 }
65