/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 15:42:47 UTC
  • Revision ID: josh@9ix.org-20110917154247-vdk48n09rbnrmzgg
footsteps

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
    SetGraphic(sprite);
14
14
 
15
15
    AddTag("player");
 
16
 
 
17
    footsteps = Audio::NewDeck(Assets::RequestAudio("footsteps.ogg"));
 
18
    footsteps->SetLoops(0); //loop indefinitely
16
19
    
17
20
    SetCollider(new RectangleCollider(32, 32));
18
21
  }
65
68
      }
66
69
    if (ycol) {velocity.y = 0;}
67
70
 
 
71
    if (velocity.GetSquaredMagnitude() > 20)
 
72
      footsteps->Play();
 
73
    else
 
74
      footsteps->Pause(); //Stop()?
68
75
 
69
76
    //Scene::GetCamera()->position = position;
70
77
  }
71
78
 
72
79
  Creature::Creature() : Entity(),
73
 
                         FRICTION(400),
74
 
                         MAXSPEED(60.0f),
75
 
                         ACCELERATION(800)                       
 
80
                         FRICTION(800),
 
81
                         MAXSPEED(30.0f),
 
82
                         ACCELERATION(1200)                      
76
83
  {
77
84
    sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
78
85
    sprite->Add("idle", 0, 0, 0.35f);
82
89
    AddTag("creature");
83
90
    SetCollider(new RectangleCollider(32, 32));
84
91
 
 
92
    skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
 
93
    skitter1->SetLoops(0); //loop indefinitely
 
94
 
85
95
    velocity = Vector2::Random() * ACCELERATION;
86
96
 
87
97
    //set aiTime to random so creatures tick at different times
88
 
    aiTime= (float(rand()) / float(RAND_MAX)) * 2.0f;
 
98
    aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
89
99
  }
90
100
 
91
101
  void Creature::Update()
93
103
    Entity::Update();
94
104
 
95
105
    aiTime += Monocle::deltaTime;
96
 
    if (aiTime > 2.0f)
 
106
    if (aiTime > 1.0f)
97
107
      {
98
 
        switch (rand() % 3)
 
108
        switch (rand() % 2)
99
109
          {
100
 
          case 1: // idle
 
110
          case 0: // idle
 
111
            //printf("idle\n");
101
112
            direction = Vector2::zero;
102
113
            state = "idle";
103
114
            break;
104
 
          case 2: // move
105
 
            direction = Vector2::Random();
106
 
            state = "wander";
107
 
            break;
 
115
          case 1: // move
 
116
            if (state != "wander") {
 
117
              //printf("wander\n");
 
118
              direction = Vector2::Random();
 
119
              state = "wander";
 
120
              break;
 
121
            }
108
122
          }
109
123
        
110
124
        aiTime = 0.0f;
115
129
    velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
116
130
    velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
117
131
 
118
 
        bool xcol = false;
 
132
    bool xcol = false;
119
133
    bool ycol = false;
120
134
 
121
135
    position.x += velocity.x * Monocle::deltaTime;
137
151
        position.y -= SIGN(velocity.y, 0.1);
138
152
      }
139
153
    if (ycol) {velocity.y = 0;}
 
154
 
 
155
    if (velocity.GetSquaredMagnitude() > 20)
 
156
      skitter1->Play();
 
157
    else
 
158
      skitter1->Pause(); //Stop()?
140
159
  }
141
160
 
142
161
  // Scene
189
208
    creature->position = Graphics::GetScreenCenter();
190
209
    Add(creature);
191
210
 
 
211
    Creature *creature2 = new Creature;
 
212
    creature2->position = Graphics::GetScreenCenter();
 
213
    Add(creature2);
 
214
 
192
215
    Graphics::SetBackgroundColor(Color::green * 0.2f);
193
216
 
194
217
  }