/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:
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);
 
86
    sprite->Add("move", 1, 2, 4.0f);
79
87
    sprite->Play("idle");
80
88
    SetGraphic(sprite);
81
89
 
82
90
    AddTag("creature");
83
91
    SetCollider(new RectangleCollider(32, 32));
84
92
 
 
93
    skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
 
94
    skitter1->SetLoops(0); //loop indefinitely
 
95
 
85
96
    velocity = Vector2::Random() * ACCELERATION;
86
97
 
87
98
    //set aiTime to random so creatures tick at different times
88
 
    aiTime= (float(rand()) / float(RAND_MAX)) * 2.0f;
 
99
    aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
89
100
  }
90
101
 
91
102
  void Creature::Update()
93
104
    Entity::Update();
94
105
 
95
106
    aiTime += Monocle::deltaTime;
96
 
    if (aiTime > 2.0f)
 
107
    if (aiTime > 1.0f)
97
108
      {
98
 
        switch (rand() % 3)
 
109
        switch (rand() % 2)
99
110
          {
100
 
          case 1: // idle
 
111
          case 0: // idle
 
112
            //printf("idle\n");
101
113
            direction = Vector2::zero;
102
114
            state = "idle";
103
115
            break;
104
 
          case 2: // move
105
 
            direction = Vector2::Random();
106
 
            state = "wander";
107
 
            break;
 
116
          case 1: // move
 
117
            if (state != "wander") {
 
118
              //printf("wander\n");
 
119
              direction = Vector2::Random();
 
120
              state = "wander";
 
121
              break;
 
122
            }
108
123
          }
109
124
        
110
125
        aiTime = 0.0f;
115
130
    velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
116
131
    velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
117
132
 
118
 
        bool xcol = false;
 
133
    bool xcol = false;
119
134
    bool ycol = false;
120
135
 
121
136
    position.x += velocity.x * Monocle::deltaTime;
137
152
        position.y -= SIGN(velocity.y, 0.1);
138
153
      }
139
154
    if (ycol) {velocity.y = 0;}
 
155
 
 
156
    if (velocity.GetSquaredMagnitude() > 20)
 
157
      {
 
158
        skitter1->Play();
 
159
        sprite->Play("move");
 
160
      }
 
161
    else
 
162
      {
 
163
        skitter1->Pause(); //Stop()?
 
164
        sprite->Play("idle");
 
165
      }
140
166
  }
141
167
 
142
168
  // Scene
189
215
    creature->position = Graphics::GetScreenCenter();
190
216
    Add(creature);
191
217
 
192
 
    Graphics::SetBackgroundColor(Color::green * 0.2f);
 
218
    Creature *creature2 = new Creature;
 
219
    creature2->position = Graphics::GetScreenCenter();
 
220
    Add(creature2);
 
221
 
 
222
    Graphics::SetBackgroundColor(Color::black * 0.2f);
193
223
 
194
224
  }
195
225