/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 04:24:47 UTC
  • Revision ID: josh@9ix.org-20110917042447-pht93k6g9j22wtar
added a "creature" moving around w/ the same dynamics as you do 
(acceleration, collision)

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