/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));
 
25
 
 
26
    dark = new Entity();
 
27
    dark->SetGraphic(new Sprite("dark.png", FILTER_NONE, 2048, 1536)); //alpha?
22
28
  }
23
29
 
24
30
  void Player::Update()
46
52
    velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
47
53
    velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
48
54
 
 
55
    if (velocity.GetSquaredMagnitude() > pow(MAXSPEED, 2))
 
56
      velocity = velocity.GetNormalized() * MAXSPEED;
 
57
 
49
58
    bool xcol = false;
50
59
    bool ycol = false;
51
60
 
69
78
      }
70
79
    if (ycol) {velocity.y = 0;}
71
80
 
72
 
    if (velocity.GetSquaredMagnitude() > 20)
73
 
      footsteps->Play();
74
 
    else
75
 
      footsteps->Pause(); //Stop()?
 
81
    float vol = velocity.GetMagnitude() / MAXSPEED;
 
82
    footsteps->SetVolume(vol);
 
83
 
 
84
    dark->position = position;
76
85
 
77
86
    //Scene::GetCamera()->position = position;
78
87
  }
79
88
 
80
89
  Creature::Creature() : Entity(),
81
90
                         FRICTION(800),
82
 
                         MAXSPEED(15.0f),
 
91
                         MAXSPEED(80.0f),
83
92
                         ACCELERATION(1200)                      
84
93
  {
85
94
    sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
132
141
    velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
133
142
    velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
134
143
 
 
144
    if (velocity.GetSquaredMagnitude() > pow(MAXSPEED, 2))
 
145
      velocity = velocity.GetNormalized() * MAXSPEED;
 
146
 
135
147
    bool xcol = false;
136
148
    bool ycol = false;
137
149
 
157
169
 
158
170
    if (velocity.GetSquaredMagnitude() > 20)
159
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);
160
176
        skitter1->Play();
161
177
        sprite->Play("move");
162
178
      }
201
217
    Level::LoadProject("project.xml");
202
218
    Level::Load("level.xml", this);
203
219
 
204
 
    std::list<Entity*> *inv = GetAllTag("invisible");
205
 
    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)
206
222
      {
207
223
        Entity *e = (*i);
208
224
        Vector2 s = e->scale;
209
225
        e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
210
226
      }
211
227
   
212
 
    Player *player = new Player;
 
228
    player = new Player();
213
229
    player->position = Graphics::GetScreenCenter();
214
230
    Add(player);
 
231
    Add(player->dark);
215
232
 
216
233
    Creature *creature = new Creature;
217
234
    creature->position = Graphics::GetScreenCenter();
221
238
    creature2->position = Graphics::GetScreenCenter();
222
239
    Add(creature2);
223
240
 
224
 
    Graphics::SetBackgroundColor(Color::black * 0.2f);
 
241
    Graphics::SetBackgroundColor(Color::green * 0.2f);
225
242
 
226
243
  }
227
244
 
251
268
          {
252
269
            isPaused = !isPaused;
253
270
            
254
 
            if (isPaused)
 
271
            if (isPaused) {
 
272
              player->dark->isVisible = false;
255
273
              levelEditor->Enable();
256
 
            else
 
274
            } else {
257
275
              levelEditor->Disable();
 
276
              player->dark->isVisible = true;
 
277
            }
258
278
          }
259
279
      }
260
280
 
267
287
      this->font = Assets::RequestFont("LiberationSans-Regular.ttf", 18.0f);
268
288
    else
269
289
      this->font = font;
 
290
 
 
291
    SetLayer(-2);
270
292
  }
271
293
 
272
294
  void Text::Render()