5
5
Player::Player() : Entity(),
8
10
sprite = new SpriteAnimation("player.png", FILTER_NONE, 64, 64);
9
11
sprite->Add("idle", 0, 0, 0.35f);
10
12
sprite->Play("idle");
11
13
SetGraphic(sprite);
14
scale = Vector2(0.25, 0.25);
18
footsteps = Audio::NewDeck(Assets::RequestAudio("footsteps.ogg"));
19
footsteps->SetLoops(0); //loop indefinitely
15
SetCollider(new RectangleCollider(32, 32));
21
SetCollider(new RectangleCollider(16, 16));
18
24
void Player::Update()
28
if (Input::IsKeyMaskHeld("left"))
30
velocity.x -= ACCELERATION * Monocle::deltaTime;
32
if (Input::IsKeyMaskHeld("right"))
34
velocity.x += ACCELERATION * Monocle::deltaTime;
36
if (Input::IsKeyMaskHeld("up"))
38
velocity.y -= ACCELERATION * Monocle::deltaTime;
40
if (Input::IsKeyMaskHeld("down"))
42
velocity.y += ACCELERATION * Monocle::deltaTime;
45
// velocity will approach 0 in steps of FRICTION * dt
46
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
47
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
52
position.x += velocity.x * Monocle::deltaTime;
53
while (Collide("Solid"))
56
if (velocity.x == 0) { break; }
57
//printf("collision1\n");
58
position.x -= SIGN(velocity.x, 0.1);
60
if (xcol) {velocity.x = 0;}
62
position.y += velocity.y * Monocle::deltaTime;
63
while (Collide("Solid"))
66
if (velocity.y == 0) { break; }
67
//printf("collision2\n");
68
position.y -= SIGN(velocity.y, 0.1);
70
if (ycol) {velocity.y = 0;}
72
if (velocity.GetSquaredMagnitude() > 20)
75
footsteps->Pause(); //Stop()?
22
77
//Scene::GetCamera()->position = position;
80
Creature::Creature() : Entity(),
85
sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
86
sprite->Add("idle", 0, 0, 0.35f);
87
sprite->Add("move", 1, 2, 4.0f);
90
scale = Vector2(0.25, 0.25);
93
SetCollider(new RectangleCollider(16, 16));
95
skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
96
skitter1->SetLoops(0); //loop indefinitely
98
velocity = Vector2::Random() * MAXSPEED;
100
//set aiTime to random so creatures tick at different times
101
aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
104
void Creature::Update()
108
aiTime += Monocle::deltaTime;
115
direction = Vector2::zero;
119
if (state != "wander") {
120
//printf("wander\n");
121
direction = Vector2::Random();
130
velocity += direction * ACCELERATION * Monocle::deltaTime;
132
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
133
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
138
position.x += velocity.x * Monocle::deltaTime;
139
while (Collide("Solid"))
142
if (velocity.x == 0) { break; }
143
//printf("collision1\n");
144
position.x -= SIGN(velocity.x, 0.1);
146
if (xcol) {velocity.x = 0;}
148
position.y += velocity.y * Monocle::deltaTime;
149
while (Collide("Solid"))
152
if (velocity.y == 0) { break; }
153
//printf("collision2\n");
154
position.y -= SIGN(velocity.y, 0.1);
156
if (ycol) {velocity.y = 0;}
158
if (velocity.GetSquaredMagnitude() > 20)
161
sprite->Play("move");
165
skitter1->Pause(); //Stop()?
166
sprite->Play("idle");
57
200
// load level from files
58
201
Level::LoadProject("project.xml");
59
202
Level::Load("level.xml", this);
204
std::list<Entity*> *inv = GetAllTag("invisible");
205
for (std::list<Entity*>::iterator i = inv->begin(); i != inv->end(); ++i)
208
Vector2 s = e->scale;
209
e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
61
212
Player *player = new Player;
62
213
player->position = Graphics::GetScreenCenter();
65
Graphics::SetBackgroundColor(Color::green * 0.2f);
216
Creature *creature = new Creature;
217
creature->position = Graphics::GetScreenCenter();
220
Creature *creature2 = new Creature;
221
creature2->position = Graphics::GetScreenCenter();
224
Graphics::SetBackgroundColor(Color::black * 0.2f);