/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:03:52 UTC
  • Revision ID: josh@9ix.org-20110917150352-j6nh9t61px2eitdu
skittering blue square

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
  }
71
71
 
72
72
  Creature::Creature() : Entity(),
73
 
                         FRICTION(400),
74
 
                         MAXSPEED(60.0f),
75
 
                         ACCELERATION(800)                       
 
73
                         FRICTION(800),
 
74
                         MAXSPEED(30.0f),
 
75
                         ACCELERATION(1200)                      
76
76
  {
77
77
    sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
78
78
    sprite->Add("idle", 0, 0, 0.35f);
82
82
    AddTag("creature");
83
83
    SetCollider(new RectangleCollider(32, 32));
84
84
 
 
85
    skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
 
86
    skitter1->SetLoops(0); //loop indefinitely
 
87
 
85
88
    velocity = Vector2::Random() * ACCELERATION;
86
89
 
87
90
    //set aiTime to random so creatures tick at different times
88
 
    aiTime= (float(rand()) / float(RAND_MAX)) * 2.0f;
 
91
    aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
89
92
  }
90
93
 
91
94
  void Creature::Update()
93
96
    Entity::Update();
94
97
 
95
98
    aiTime += Monocle::deltaTime;
96
 
    if (aiTime > 2.0f)
 
99
    if (aiTime > 1.0f)
97
100
      {
98
 
        switch (rand() % 3)
 
101
        switch (rand() % 2)
99
102
          {
100
 
          case 1: // idle
 
103
          case 0: // idle
 
104
            //printf("idle\n");
101
105
            direction = Vector2::zero;
102
106
            state = "idle";
103
107
            break;
104
 
          case 2: // move
105
 
            direction = Vector2::Random();
106
 
            state = "wander";
107
 
            break;
 
108
          case 1: // move
 
109
            if (state != "wander") {
 
110
              //printf("wander\n");
 
111
              direction = Vector2::Random();
 
112
              state = "wander";
 
113
              break;
 
114
            }
108
115
          }
109
116
        
110
117
        aiTime = 0.0f;
115
122
    velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
116
123
    velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
117
124
 
118
 
        bool xcol = false;
 
125
    bool xcol = false;
119
126
    bool ycol = false;
120
127
 
121
128
    position.x += velocity.x * Monocle::deltaTime;
137
144
        position.y -= SIGN(velocity.y, 0.1);
138
145
      }
139
146
    if (ycol) {velocity.y = 0;}
 
147
 
 
148
    if (velocity.GetSquaredMagnitude() > 0)
 
149
      skitter1->Play();
 
150
    else
 
151
      skitter1->Pause(); //Stop()?
140
152
  }
141
153
 
142
154
  // Scene