/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
      }