/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:
4
4
{
5
5
  Player::Player() : Entity(),
6
6
                     FRICTION(400),
7
 
                     MAXSPEED(20.0f),
 
7
                     MAXSPEED(60.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);
15
14
 
16
15
    AddTag("player");
17
 
 
18
 
    footsteps = Audio::NewDeck(Assets::RequestAudio("footsteps.ogg"));
19
 
    footsteps->SetLoops(0); //loop indefinitely
20
16
    
21
 
    SetCollider(new RectangleCollider(16, 16));
22
 
 
23
 
    dark = new Entity();
24
 
    dark->SetGraphic(new Sprite("dark.png", FILTER_NONE, 2048, 1536)); //alpha?
 
17
    SetCollider(new RectangleCollider(32, 32));
25
18
  }
26
19
 
27
20
  void Player::Update()
72
65
      }
73
66
    if (ycol) {velocity.y = 0;}
74
67
 
75
 
    if (velocity.GetSquaredMagnitude() > 20)
76
 
      footsteps->Play();
77
 
    else
78
 
      footsteps->Pause(); //Stop()?
79
 
 
80
 
    dark->position = position;
81
68
 
82
69
    //Scene::GetCamera()->position = position;
83
70
  }
84
71
 
85
72
  Creature::Creature() : Entity(),
86
73
                         FRICTION(800),
87
 
                         MAXSPEED(15.0f),
 
74
                         MAXSPEED(30.0f),
88
75
                         ACCELERATION(1200)                      
89
76
  {
90
77
    sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
91
78
    sprite->Add("idle", 0, 0, 0.35f);
92
 
    sprite->Add("move", 1, 2, 4.0f);
93
79
    sprite->Play("idle");
94
80
    SetGraphic(sprite);
95
 
    scale = Vector2(0.25, 0.25);
96
81
 
97
82
    AddTag("creature");
98
 
    SetCollider(new RectangleCollider(16, 16));
 
83
    SetCollider(new RectangleCollider(32, 32));
99
84
 
100
85
    skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
101
86
    skitter1->SetLoops(0); //loop indefinitely
102
87
 
103
 
    velocity = Vector2::Random() * MAXSPEED;
 
88
    velocity = Vector2::Random() * ACCELERATION;
104
89
 
105
90
    //set aiTime to random so creatures tick at different times
106
91
    aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
113
98
    aiTime += Monocle::deltaTime;
114
99
    if (aiTime > 1.0f)
115
100
      {
116
 
        switch (rand() % 3)
 
101
        switch (rand() % 2)
117
102
          {
118
103
          case 0: // idle
119
104
            //printf("idle\n");
160
145
      }
161
146
    if (ycol) {velocity.y = 0;}
162
147
 
163
 
    if (velocity.GetSquaredMagnitude() > 20)
164
 
      {
165
 
        skitter1->Play();
166
 
        sprite->Play("move");
167
 
      }
 
148
    if (velocity.GetSquaredMagnitude() > 0)
 
149
      skitter1->Play();
168
150
    else
169
 
      {
170
 
        skitter1->Pause(); //Stop()?
171
 
        sprite->Play("idle");
172
 
      }
 
151
      skitter1->Pause(); //Stop()?
173
152
  }
174
153
 
175
154
  // Scene
217
196
    Player *player = new Player;
218
197
    player->position = Graphics::GetScreenCenter();
219
198
    Add(player);
220
 
    Add(player->dark);
221
199
 
222
200
    Creature *creature = new Creature;
223
201
    creature->position = Graphics::GetScreenCenter();
224
202
    Add(creature);
225
203
 
226
 
    Creature *creature2 = new Creature;
227
 
    creature2->position = Graphics::GetScreenCenter();
228
 
    Add(creature2);
229
 
 
230
204
    Graphics::SetBackgroundColor(Color::green * 0.2f);
231
205
 
232
206
  }