6
5
Player::Player() : Entity(),
11
10
sprite = new SpriteAnimation("player.png", FILTER_NONE, 64, 64);
12
11
sprite->Add("idle", 0, 0, 0.35f);
13
12
sprite->Play("idle");
14
13
SetGraphic(sprite);
15
scale = Vector2(0.25, 0.25);
19
footsteps = Audio::NewDeck(Assets::RequestAudio("footsteps.ogg"));
20
footsteps->SetLoops(0); //loop indefinitely
21
footsteps->SetVolume(0);
24
SetCollider(new RectangleCollider(16, 16));
27
dark->SetGraphic(new Sprite("dark.png", FILTER_NONE, 2048, 1536)); //alpha?
17
SetCollider(new RectangleCollider(32, 32));
30
20
void Player::Update()
79
66
if (ycol) {velocity.y = 0;}
81
float vol = velocity.GetMagnitude() / MAXSPEED;
82
footsteps->SetVolume(vol);
84
dark->position = position;
86
69
//Scene::GetCamera()->position = position;
89
Creature::Creature() : Entity(),
94
sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
95
sprite->Add("idle", 0, 0, 0.35f);
96
sprite->Add("move", 1, 2, 4.0f);
99
scale = Vector2(0.25, 0.25);
102
SetCollider(new RectangleCollider(16, 16));
104
skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
105
skitter1->SetLoops(0); //loop indefinitely
107
velocity = Vector2::Random() * MAXSPEED;
109
//set aiTime to random so creatures tick at different times
110
aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
113
void Creature::Update()
117
aiTime += Monocle::deltaTime;
124
direction = Vector2::zero;
128
if (state != "wander") {
129
//printf("wander\n");
130
direction = Vector2::Random();
139
velocity += direction * ACCELERATION * Monocle::deltaTime;
141
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
142
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
144
if (velocity.GetSquaredMagnitude() > pow(MAXSPEED, 2))
145
velocity = velocity.GetNormalized() * MAXSPEED;
150
position.x += velocity.x * Monocle::deltaTime;
151
while (Collide("Solid"))
154
if (velocity.x == 0) { break; }
155
//printf("collision1\n");
156
position.x -= SIGN(velocity.x, 0.1);
158
if (xcol) {velocity.x = 0;}
160
position.y += velocity.y * Monocle::deltaTime;
161
while (Collide("Solid"))
164
if (velocity.y == 0) { break; }
165
//printf("collision2\n");
166
position.y -= SIGN(velocity.y, 0.1);
168
if (ycol) {velocity.y = 0;}
170
if (velocity.GetSquaredMagnitude() > 20)
172
Vector2 distance = ((DarkScene *)scene)->player->position - position;
173
// at distance 0, vol should be 1.0. at 800, it should be 0.
174
float vol = (distance.GetMagnitude() / -800.0f) + 1.0f;
175
skitter1->SetVolume(vol);
177
sprite->Play("move");
181
skitter1->Pause(); //Stop()?
182
sprite->Play("idle");
188
74
DarkScene::DarkScene() : Scene()
217
103
Level::LoadProject("project.xml");
218
104
Level::Load("level.xml", this);
220
std::list<Entity*> *walls = GetAllTag("wall");
221
for (std::list<Entity*>::iterator i = walls->begin(); i != walls->end(); ++i)
106
std::list<Entity*> *inv = GetAllTag("invisible");
107
for (std::list<Entity*>::iterator i = inv->begin(); i != inv->end(); ++i)
223
109
Entity *e = (*i);
224
110
Vector2 s = e->scale;
225
111
e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
228
player = new Player();
114
Player *player = new Player;
229
115
player->position = Graphics::GetScreenCenter();
233
Creature *creature = new Creature;
234
creature->position = Graphics::GetScreenCenter();
237
Creature *creature2 = new Creature;
238
creature2->position = Graphics::GetScreenCenter();
241
118
Graphics::SetBackgroundColor(Color::green * 0.2f);