/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 16:54:23 UTC
  • Revision ID: josh@9ix.org-20110917165423-wflahgpej1hbjowe
harder to see creatures

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(60.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);
13
12
    sprite->Play("idle");
14
13
    SetGraphic(sprite);
15
 
    scale = Vector2(0.25, 0.25);
16
14
 
17
15
    AddTag("player");
18
16
 
19
17
    footsteps = Audio::NewDeck(Assets::RequestAudio("footsteps.ogg"));
20
18
    footsteps->SetLoops(0); //loop indefinitely
21
 
    footsteps->SetVolume(0);
22
 
    footsteps->Play();
23
19
    
24
 
    SetCollider(new RectangleCollider(16, 16));
25
 
 
26
 
    dark = new Entity();
27
 
    dark->SetGraphic(new Sprite("dark.png", FILTER_NONE, 2048, 1536)); //alpha?
 
20
    SetCollider(new RectangleCollider(32, 32));
28
21
  }
29
22
 
30
23
  void Player::Update()
52
45
    velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
53
46
    velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
54
47
 
55
 
    if (velocity.GetSquaredMagnitude() > pow(MAXSPEED, 2))
56
 
      velocity = velocity.GetNormalized() * MAXSPEED;
57
 
 
58
48
    bool xcol = false;
59
49
    bool ycol = false;
60
50
 
78
68
      }
79
69
    if (ycol) {velocity.y = 0;}
80
70
 
81
 
    float vol = velocity.GetMagnitude() / MAXSPEED;
82
 
    footsteps->SetVolume(vol);
83
 
 
84
 
    dark->position = position;
 
71
    if (velocity.GetSquaredMagnitude() > 20)
 
72
      footsteps->Play();
 
73
    else
 
74
      footsteps->Pause(); //Stop()?
85
75
 
86
76
    //Scene::GetCamera()->position = position;
87
77
  }
88
78
 
89
79
  Creature::Creature() : Entity(),
90
80
                         FRICTION(800),
91
 
                         MAXSPEED(80.0f),
 
81
                         MAXSPEED(30.0f),
92
82
                         ACCELERATION(1200)                      
93
83
  {
94
84
    sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
96
86
    sprite->Add("move", 1, 2, 4.0f);
97
87
    sprite->Play("idle");
98
88
    SetGraphic(sprite);
99
 
    scale = Vector2(0.25, 0.25);
100
89
 
101
90
    AddTag("creature");
102
 
    SetCollider(new RectangleCollider(16, 16));
 
91
    SetCollider(new RectangleCollider(32, 32));
103
92
 
104
93
    skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
105
94
    skitter1->SetLoops(0); //loop indefinitely
106
95
 
107
 
    velocity = Vector2::Random() * MAXSPEED;
 
96
    velocity = Vector2::Random() * ACCELERATION;
108
97
 
109
98
    //set aiTime to random so creatures tick at different times
110
99
    aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
117
106
    aiTime += Monocle::deltaTime;
118
107
    if (aiTime > 1.0f)
119
108
      {
120
 
        switch (rand() % 3)
 
109
        switch (rand() % 2)
121
110
          {
122
111
          case 0: // idle
123
112
            //printf("idle\n");
141
130
    velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
142
131
    velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
143
132
 
144
 
    if (velocity.GetSquaredMagnitude() > pow(MAXSPEED, 2))
145
 
      velocity = velocity.GetNormalized() * MAXSPEED;
146
 
 
147
133
    bool xcol = false;
148
134
    bool ycol = false;
149
135
 
169
155
 
170
156
    if (velocity.GetSquaredMagnitude() > 20)
171
157
      {
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
158
        skitter1->Play();
177
159
        sprite->Play("move");
178
160
      }
217
199
    Level::LoadProject("project.xml");
218
200
    Level::Load("level.xml", this);
219
201
 
220
 
    std::list<Entity*> *walls = GetAllTag("wall");
221
 
    for (std::list<Entity*>::iterator i = walls->begin(); i != walls->end(); ++i)
 
202
    std::list<Entity*> *inv = GetAllTag("invisible");
 
203
    for (std::list<Entity*>::iterator i = inv->begin(); i != inv->end(); ++i)
222
204
      {
223
205
        Entity *e = (*i);
224
206
        Vector2 s = e->scale;
225
207
        e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
226
208
      }
227
209
   
228
 
    player = new Player();
 
210
    Player *player = new Player;
229
211
    player->position = Graphics::GetScreenCenter();
230
212
    Add(player);
231
 
    Add(player->dark);
232
213
 
233
214
    Creature *creature = new Creature;
234
215
    creature->position = Graphics::GetScreenCenter();
238
219
    creature2->position = Graphics::GetScreenCenter();
239
220
    Add(creature2);
240
221
 
241
 
    Graphics::SetBackgroundColor(Color::green * 0.2f);
 
222
    Graphics::SetBackgroundColor(Color::black * 0.2f);
242
223
 
243
224
  }
244
225
 
268
249
          {
269
250
            isPaused = !isPaused;
270
251
            
271
 
            if (isPaused) {
272
 
              player->dark->isVisible = false;
 
252
            if (isPaused)
273
253
              levelEditor->Enable();
274
 
            } else {
 
254
            else
275
255
              levelEditor->Disable();
276
 
              player->dark->isVisible = true;
277
 
            }
278
256
          }
279
257
      }
280
258
 
287
265
      this->font = Assets::RequestFont("LiberationSans-Regular.ttf", 18.0f);
288
266
    else
289
267
      this->font = font;
290
 
 
291
 
    SetLayer(-2);
292
268
  }
293
269
 
294
270
  void Text::Render()