/minild29

To get this branch, use:
bzr branch http://9ix.org/bzr/minild29

« back to all changes in this revision

Viewing changes to Dark.cpp

  • Committer: Josh C
  • Date: 2011-09-18 02:03:11 UTC
  • Revision ID: josh@9ix.org-20110918020311-pfahqi05rhcnhz20
make maxspeed work.  footstep volume has to do with speed.  skitter 
volume has to do with distance from you.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "Dark.h"
 
2
#include <cmath>
2
3
 
3
4
namespace Dark
4
5
{
5
6
  Player::Player() : Entity(),
6
 
                     FRICTION(400),
7
 
                     MAXSPEED(20.0f),
8
 
                     ACCELERATION(800)
 
7
                     FRICTION(150),
 
8
                     MAXSPEED(150.0f),
 
9
                     ACCELERATION(300)
9
10
  {
10
11
    sprite = new SpriteAnimation("player.png", FILTER_NONE, 64, 64);
11
12
    sprite->Add("idle", 0, 0, 0.35f);
17
18
 
18
19
    footsteps = Audio::NewDeck(Assets::RequestAudio("footsteps.ogg"));
19
20
    footsteps->SetLoops(0); //loop indefinitely
 
21
    footsteps->SetVolume(0);
 
22
    footsteps->Play();
20
23
    
21
24
    SetCollider(new RectangleCollider(16, 16));
22
25
 
49
52
    velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
50
53
    velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
51
54
 
 
55
    if (velocity.GetSquaredMagnitude() > pow(MAXSPEED, 2))
 
56
      velocity = velocity.GetNormalized() * MAXSPEED;
 
57
 
52
58
    bool xcol = false;
53
59
    bool ycol = false;
54
60
 
72
78
      }
73
79
    if (ycol) {velocity.y = 0;}
74
80
 
75
 
    if (velocity.GetSquaredMagnitude() > 20)
76
 
      footsteps->Play();
77
 
    else
78
 
      footsteps->Pause(); //Stop()?
 
81
    float vol = velocity.GetMagnitude() / MAXSPEED;
 
82
    footsteps->SetVolume(vol);
79
83
 
80
84
    dark->position = position;
81
85
 
84
88
 
85
89
  Creature::Creature() : Entity(),
86
90
                         FRICTION(800),
87
 
                         MAXSPEED(15.0f),
 
91
                         MAXSPEED(80.0f),
88
92
                         ACCELERATION(1200)                      
89
93
  {
90
94
    sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
137
141
    velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
138
142
    velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
139
143
 
 
144
    if (velocity.GetSquaredMagnitude() > pow(MAXSPEED, 2))
 
145
      velocity = velocity.GetNormalized() * MAXSPEED;
 
146
 
140
147
    bool xcol = false;
141
148
    bool ycol = false;
142
149
 
162
169
 
163
170
    if (velocity.GetSquaredMagnitude() > 20)
164
171
      {
 
172
        Vector2 distance = ((DarkScene *)scene)->player->position - position;
 
173
        // at distance 0, vol should be 1.0.  at 800, it should be 0.
 
174
        float vol = (distance.GetMagnitude() / -800.0f) + 1.0f;
 
175
        skitter1->SetVolume(vol);
165
176
        skitter1->Play();
166
177
        sprite->Play("move");
167
178
      }
206
217
    Level::LoadProject("project.xml");
207
218
    Level::Load("level.xml", this);
208
219
 
209
 
    std::list<Entity*> *inv = GetAllTag("invisible");
210
 
    for (std::list<Entity*>::iterator i = inv->begin(); i != inv->end(); ++i)
 
220
    std::list<Entity*> *walls = GetAllTag("wall");
 
221
    for (std::list<Entity*>::iterator i = walls->begin(); i != walls->end(); ++i)
211
222
      {
212
223
        Entity *e = (*i);
213
224
        Vector2 s = e->scale;
214
225
        e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
215
226
      }
216
227
   
217
 
    Player *player = new Player;
 
228
    player = new Player();
218
229
    player->position = Graphics::GetScreenCenter();
219
230
    Add(player);
220
231
    Add(player->dark);
257
268
          {
258
269
            isPaused = !isPaused;
259
270
            
260
 
            if (isPaused)
 
271
            if (isPaused) {
 
272
              player->dark->isVisible = false;
261
273
              levelEditor->Enable();
262
 
            else
 
274
            } else {
263
275
              levelEditor->Disable();
 
276
              player->dark->isVisible = true;
 
277
            }
264
278
          }
265
279
      }
266
280
 
273
287
      this->font = Assets::RequestFont("LiberationSans-Regular.ttf", 18.0f);
274
288
    else
275
289
      this->font = font;
 
290
 
 
291
    SetLayer(-2);
276
292
  }
277
293
 
278
294
  void Text::Render()