/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 19:21:01 UTC
  • Revision ID: josh@9ix.org-20110917192101-8i3cly7ecyt9o46s
"light" in the dark

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