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