/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 20:10:52 UTC
  • Revision ID: josh@9ix.org-20110917201052-ehpgcrfxfey2q81y
drastically less hacky way to hide the darkness

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
 
                         FRICTION(400),
74
 
                         MAXSPEED(60.0f),
75
 
                         ACCELERATION(800)                       
 
86
                         FRICTION(800),
 
87
                         MAXSPEED(15.0f),
 
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));
84
 
 
85
 
    velocity = Vector2::Random() * ACCELERATION;
 
98
    SetCollider(new RectangleCollider(16, 16));
 
99
 
 
100
    skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
 
101
    skitter1->SetLoops(0); //loop indefinitely
 
102
 
 
103
    velocity = Vector2::Random() * MAXSPEED;
86
104
 
87
105
    //set aiTime to random so creatures tick at different times
88
 
    aiTime= (float(rand()) / float(RAND_MAX)) * 2.0f;
 
106
    aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
89
107
  }
90
108
 
91
109
  void Creature::Update()
93
111
    Entity::Update();
94
112
 
95
113
    aiTime += Monocle::deltaTime;
96
 
    if (aiTime > 2.0f)
 
114
    if (aiTime > 1.0f)
97
115
      {
98
116
        switch (rand() % 3)
99
117
          {
100
 
          case 1: // idle
 
118
          case 0: // idle
 
119
            //printf("idle\n");
101
120
            direction = Vector2::zero;
102
121
            state = "idle";
103
122
            break;
104
 
          case 2: // move
105
 
            direction = Vector2::Random();
106
 
            state = "wander";
107
 
            break;
 
123
          case 1: // move
 
124
            if (state != "wander") {
 
125
              //printf("wander\n");
 
126
              direction = Vector2::Random();
 
127
              state = "wander";
 
128
              break;
 
129
            }
108
130
          }
109
131
        
110
132
        aiTime = 0.0f;
115
137
    velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
116
138
    velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
117
139
 
118
 
        bool xcol = false;
 
140
    bool xcol = false;
119
141
    bool ycol = false;
120
142
 
121
143
    position.x += velocity.x * Monocle::deltaTime;
137
159
        position.y -= SIGN(velocity.y, 0.1);
138
160
      }
139
161
    if (ycol) {velocity.y = 0;}
 
162
 
 
163
    if (velocity.GetSquaredMagnitude() > 20)
 
164
      {
 
165
        skitter1->Play();
 
166
        sprite->Play("move");
 
167
      }
 
168
    else
 
169
      {
 
170
        skitter1->Pause(); //Stop()?
 
171
        sprite->Play("idle");
 
172
      }
140
173
  }
141
174
 
142
175
  // Scene
181
214
        e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
182
215
      }
183
216
   
184
 
    Player *player = new Player;
 
217
    player = new Player();
185
218
    player->position = Graphics::GetScreenCenter();
186
219
    Add(player);
 
220
    Add(player->dark);
187
221
 
188
222
    Creature *creature = new Creature;
189
223
    creature->position = Graphics::GetScreenCenter();
190
224
    Add(creature);
191
225
 
 
226
    Creature *creature2 = new Creature;
 
227
    creature2->position = Graphics::GetScreenCenter();
 
228
    Add(creature2);
 
229
 
192
230
    Graphics::SetBackgroundColor(Color::green * 0.2f);
193
231
 
194
232
  }
219
257
          {
220
258
            isPaused = !isPaused;
221
259
            
222
 
            if (isPaused)
 
260
            if (isPaused) {
 
261
              player->dark->isVisible = false;
223
262
              levelEditor->Enable();
224
 
            else
 
263
            } else {
225
264
              levelEditor->Disable();
 
265
              player->dark->isVisible = true;
 
266
            }
226
267
          }
227
268
      }
228
269
 
235
276
      this->font = Assets::RequestFont("LiberationSans-Regular.ttf", 18.0f);
236
277
    else
237
278
      this->font = font;
 
279
 
 
280
    SetLayer(-2);
238
281
  }
239
282
 
240
283
  void Text::Render()