/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 20:35:53 UTC
  • Revision ID: josh@9ix.org-20110917203553-ix6ixzngvsybetll
visible walls

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
      }