/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-17 19:21:01 UTC
  • Revision ID: josh@9ix.org-20110917192101-8i3cly7ecyt9o46s
"light" in the dark

Show diffs side-by-side

added added

removed removed

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