]> Dogcows Code - chaz/yoink/blob - src/Heroine.cc
sockets documentation and cleanup
[chaz/yoink] / src / Heroine.cc
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #include <Moof/Sound.hh>
13
14 #include "Heroine.hh"
15 #include "Log.hh"
16
17
18 Heroine::Heroine() :
19 Character("Heroine") {}
20
21
22 void Heroine::update(Mf::Scalar t, Mf::Scalar dt)
23 {
24 Character::update(t, dt);
25
26 Mf::Vector3 at(0.0, 0.0, 0.0);
27 const Mf::Vector3 up(0.0, 1.0, 0.0);
28
29 if (mState.velocity[0] < 0.0) at[0] = -1.0;
30 else at[0] = 1.0;
31
32 Mf::Sound::setListenerPosition(Mf::promote(mState.position));
33 Mf::Sound::setListenerVelocity(Mf::promote(mState.velocity));
34 Mf::Sound::setListenerOrientation(at, up);
35 }
36
37
38 bool Heroine::handleEvent(const Mf::Event& event)
39 {
40 Mf::Scalar force = 40.0;
41
42 switch (event.type)
43 {
44 case SDL_KEYDOWN:
45 if (event.key.keysym.sym == SDLK_a)
46 {
47 mState.force += Mf::Vector2(-force, 0.0);
48 return true;
49 }
50 else if (event.key.keysym.sym == SDLK_d)
51 {
52 mState.force += Mf::Vector2(force, 0.0);
53 return true;
54 }
55 else if (event.key.keysym.sym == SDLK_s)
56 {
57 mState.force += Mf::Vector2(0.0, -force);
58 return true;
59 }
60 else if (event.key.keysym.sym == SDLK_w)
61 {
62 mState.force += Mf::Vector2(0.0, force);
63 return true;
64 }
65
66 case SDL_KEYUP:
67 if (event.key.keysym.sym == SDLK_a)
68 {
69 mState.force += Mf::Vector2(force, 0.0);
70 return true;
71 }
72 else if (event.key.keysym.sym == SDLK_d)
73 {
74 mState.force += Mf::Vector2(-force, 0.0);
75 return true;
76 }
77 else if (event.key.keysym.sym == SDLK_s)
78 {
79 mState.force += Mf::Vector2(0.0, force);
80 return true;
81 }
82 else if (event.key.keysym.sym == SDLK_w)
83 {
84 mState.force += Mf::Vector2(0.0, -force);
85 return true;
86 }
87 }
88 return false;
89 }
90
This page took 0.033358 seconds and 4 git commands to generate.