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 "player.h"
22 #include "gfx.h"
23 #include "geom.h"
24
Player()25 Player::Player() :
26 shootCoolrate(10), shootHeat(0), shootMaxHeat(32000), shield(0),
27 aim(0,50), shootTimer(0), podTimer(0),
28 score(0), doneLaunchedPod(false), dead(false)
29 {}
30
31 /* returns angle used for the standard deviation of the gaussian noise applied
32 * to shots:
33 */
aimAccuracy()34 float Player::aimAccuracy()
35 {
36 return 0.2*(AIM_MIN*AIM_MIN)/(aim.dist * aim.dist);
37 }
38
draw(SDL_Surface * surface,const View & view,View * boundView,bool noAA)39 void Player::draw(SDL_Surface* surface, const View& view, View* boundView,
40 bool noAA)
41 {
42 for (int i = 0; i < 4; i++)
43 if (shield > i)
44 {
45 const float r = 4+3*i;
46 const Uint32 baseColour =
47 (i == 0) ? 0x01000000 :
48 (i == 1) ? 0x01010000 :
49 (i == 2) ? 0x00010000 :
50 0x00010100;
51 const Uint32 colour =
52 baseColour*(55 + std::min(200, (int)(200*shield)-200*i))
53 + 0x000000ff;
54 Circle(ARENA_CENTRE, r, colour).draw(surface, view, boundView,
55 noAA);
56 }
57 }
58
update(int time,bool superShield)59 void Player::update(int time, bool superShield)
60 {
61 if (!dead && shootHeat == 0)
62 {
63 const double shieldRateMult = superShield ? 2.5 : 1.0;
64 if (shield < 1)
65 shield += time*0.0001*shieldRateMult;
66 else if (shield < 2)
67 shield += time*0.00005*shieldRateMult;
68 else if (shield < 3)
69 shield += time*0.000025*shieldRateMult;
70 else if (shield < 4)
71 shield = std::min(4.0, shield + time*0.0000125*shieldRateMult);
72 }
73
74 shootHeat = std::max(0, shootHeat - shootCoolrate*time);
75 }
76
radius()77 float Player::radius()
78 {
79 return 4 + 3*((int)floor(shield)+1);
80 }
81