6
5
Player::Player() : Entity(),
11
8
sprite = new SpriteAnimation("player.png", FILTER_NONE, 64, 64);
12
9
sprite->Add("idle", 0, 0, 0.35f);
13
10
sprite->Play("idle");
14
11
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?
15
SetCollider(new RectangleCollider(32, 32));
30
18
void Player::Update()
34
if (Input::IsKeyMaskHeld("left"))
36
velocity.x -= ACCELERATION * Monocle::deltaTime;
38
if (Input::IsKeyMaskHeld("right"))
40
velocity.x += ACCELERATION * Monocle::deltaTime;
42
if (Input::IsKeyMaskHeld("up"))
44
velocity.y -= ACCELERATION * Monocle::deltaTime;
46
if (Input::IsKeyMaskHeld("down"))
48
velocity.y += ACCELERATION * Monocle::deltaTime;
51
// velocity will approach 0 in steps of FRICTION * dt
52
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
53
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
55
if (velocity.GetSquaredMagnitude() > pow(MAXSPEED, 2))
56
velocity = velocity.GetNormalized() * MAXSPEED;
61
position.x += velocity.x * Monocle::deltaTime;
62
while (Collide("Solid"))
65
if (velocity.x == 0) { break; }
66
//printf("collision1\n");
67
position.x -= SIGN(velocity.x, 0.1);
69
if (xcol) {velocity.x = 0;}
71
position.y += velocity.y * Monocle::deltaTime;
72
while (Collide("Solid"))
75
if (velocity.y == 0) { break; }
76
//printf("collision2\n");
77
position.y -= SIGN(velocity.y, 0.1);
79
if (ycol) {velocity.y = 0;}
81
float vol = velocity.GetMagnitude() / MAXSPEED;
82
footsteps->SetVolume(vol);
84
dark->position = position;
86
22
//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");