/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 17:12:23 UTC
  • Revision ID: josh@9ix.org-20110917171223-hsvrl6q7mxxbc1sv
creatures move less, make everything smaller

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