/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 17:12:23 UTC
  • Revision ID: josh@9ix.org-20110917171223-hsvrl6q7mxxbc1sv
creatures move less, make everything smaller

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
{
5
5
  Player::Player() : Entity(),
6
6
                     FRICTION(400),
7
 
                     MAXSPEED(60.0f),
 
7
                     MAXSPEED(20.0f),
8
8
                     ACCELERATION(800)
9
9
  {
10
10
    sprite = new SpriteAnimation("player.png", FILTER_NONE, 64, 64);
11
11
    sprite->Add("idle", 0, 0, 0.35f);
12
12
    sprite->Play("idle");
13
13
    SetGraphic(sprite);
 
14
    scale = Vector2(0.25, 0.25);
14
15
 
15
16
    AddTag("player");
 
17
 
 
18
    footsteps = Audio::NewDeck(Assets::RequestAudio("footsteps.ogg"));
 
19
    footsteps->SetLoops(0); //loop indefinitely
16
20
    
17
 
    SetCollider(new RectangleCollider(32, 32));
 
21
    SetCollider(new RectangleCollider(16, 16));
18
22
  }
19
23
 
20
24
  void Player::Update()
65
69
      }
66
70
    if (ycol) {velocity.y = 0;}
67
71
 
 
72
    if (velocity.GetSquaredMagnitude() > 20)
 
73
      footsteps->Play();
 
74
    else
 
75
      footsteps->Pause(); //Stop()?
68
76
 
69
77
    //Scene::GetCamera()->position = position;
70
78
  }
71
79
 
72
80
  Creature::Creature() : Entity(),
73
 
                         FRICTION(400),
74
 
                         MAXSPEED(60.0f),
75
 
                         ACCELERATION(800)                       
 
81
                         FRICTION(800),
 
82
                         MAXSPEED(15.0f),
 
83
                         ACCELERATION(1200)                      
76
84
  {
77
85
    sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
78
86
    sprite->Add("idle", 0, 0, 0.35f);
 
87
    sprite->Add("move", 1, 2, 4.0f);
79
88
    sprite->Play("idle");
80
89
    SetGraphic(sprite);
 
90
    scale = Vector2(0.25, 0.25);
81
91
 
82
92
    AddTag("creature");
83
 
    SetCollider(new RectangleCollider(32, 32));
84
 
 
85
 
    velocity = Vector2::Random() * ACCELERATION;
 
93
    SetCollider(new RectangleCollider(16, 16));
 
94
 
 
95
    skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
 
96
    skitter1->SetLoops(0); //loop indefinitely
 
97
 
 
98
    velocity = Vector2::Random() * MAXSPEED;
86
99
 
87
100
    //set aiTime to random so creatures tick at different times
88
 
    aiTime= (float(rand()) / float(RAND_MAX)) * 2.0f;
 
101
    aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
89
102
  }
90
103
 
91
104
  void Creature::Update()
93
106
    Entity::Update();
94
107
 
95
108
    aiTime += Monocle::deltaTime;
96
 
    if (aiTime > 2.0f)
 
109
    if (aiTime > 1.0f)
97
110
      {
98
111
        switch (rand() % 3)
99
112
          {
100
 
          case 1: // idle
 
113
          case 0: // idle
 
114
            //printf("idle\n");
101
115
            direction = Vector2::zero;
102
116
            state = "idle";
103
117
            break;
104
 
          case 2: // move
105
 
            direction = Vector2::Random();
106
 
            state = "wander";
107
 
            break;
 
118
          case 1: // move
 
119
            if (state != "wander") {
 
120
              //printf("wander\n");
 
121
              direction = Vector2::Random();
 
122
              state = "wander";
 
123
              break;
 
124
            }
108
125
          }
109
126
        
110
127
        aiTime = 0.0f;
115
132
    velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
116
133
    velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
117
134
 
118
 
        bool xcol = false;
 
135
    bool xcol = false;
119
136
    bool ycol = false;
120
137
 
121
138
    position.x += velocity.x * Monocle::deltaTime;
137
154
        position.y -= SIGN(velocity.y, 0.1);
138
155
      }
139
156
    if (ycol) {velocity.y = 0;}
 
157
 
 
158
    if (velocity.GetSquaredMagnitude() > 20)
 
159
      {
 
160
        skitter1->Play();
 
161
        sprite->Play("move");
 
162
      }
 
163
    else
 
164
      {
 
165
        skitter1->Pause(); //Stop()?
 
166
        sprite->Play("idle");
 
167
      }
140
168
  }
141
169
 
142
170
  // Scene
189
217
    creature->position = Graphics::GetScreenCenter();
190
218
    Add(creature);
191
219
 
192
 
    Graphics::SetBackgroundColor(Color::green * 0.2f);
 
220
    Creature *creature2 = new Creature;
 
221
    creature2->position = Graphics::GetScreenCenter();
 
222
    Add(creature2);
 
223
 
 
224
    Graphics::SetBackgroundColor(Color::black * 0.2f);
193
225
 
194
226
  }
195
227