5
5
Player::Player() : Entity(),
10
8
sprite = new SpriteAnimation("player.png", FILTER_NONE, 64, 64);
11
9
sprite->Add("idle", 0, 0, 0.35f);
12
10
sprite->Play("idle");
13
11
SetGraphic(sprite);
14
scale = Vector2(0.25, 0.25);
18
footsteps = Audio::NewDeck(Assets::RequestAudio("footsteps.ogg"));
19
footsteps->SetLoops(0); //loop indefinitely
21
SetCollider(new RectangleCollider(16, 16));
24
dark->SetGraphic(new Sprite("dark.png", FILTER_NONE, 2048, 1536)); //alpha?
15
SetCollider(new RectangleCollider(32, 32));
27
18
void Player::Update()
31
if (Input::IsKeyMaskHeld("left"))
33
velocity.x -= ACCELERATION * Monocle::deltaTime;
35
if (Input::IsKeyMaskHeld("right"))
37
velocity.x += ACCELERATION * Monocle::deltaTime;
39
if (Input::IsKeyMaskHeld("up"))
41
velocity.y -= ACCELERATION * Monocle::deltaTime;
43
if (Input::IsKeyMaskHeld("down"))
45
velocity.y += ACCELERATION * Monocle::deltaTime;
48
// velocity will approach 0 in steps of FRICTION * dt
49
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
50
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
55
position.x += velocity.x * Monocle::deltaTime;
56
while (Collide("Solid"))
59
if (velocity.x == 0) { break; }
60
//printf("collision1\n");
61
position.x -= SIGN(velocity.x, 0.1);
63
if (xcol) {velocity.x = 0;}
65
position.y += velocity.y * Monocle::deltaTime;
66
while (Collide("Solid"))
69
if (velocity.y == 0) { break; }
70
//printf("collision2\n");
71
position.y -= SIGN(velocity.y, 0.1);
73
if (ycol) {velocity.y = 0;}
75
if (velocity.GetSquaredMagnitude() > 20)
78
footsteps->Pause(); //Stop()?
80
dark->position = position;
82
22
//Scene::GetCamera()->position = position;
85
Creature::Creature() : Entity(),
90
sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
91
sprite->Add("idle", 0, 0, 0.35f);
92
sprite->Add("move", 1, 2, 4.0f);
95
scale = Vector2(0.25, 0.25);
98
SetCollider(new RectangleCollider(16, 16));
100
skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
101
skitter1->SetLoops(0); //loop indefinitely
103
velocity = Vector2::Random() * MAXSPEED;
105
//set aiTime to random so creatures tick at different times
106
aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
109
void Creature::Update()
113
aiTime += Monocle::deltaTime;
120
direction = Vector2::zero;
124
if (state != "wander") {
125
//printf("wander\n");
126
direction = Vector2::Random();
135
velocity += direction * ACCELERATION * Monocle::deltaTime;
137
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
138
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
143
position.x += velocity.x * Monocle::deltaTime;
144
while (Collide("Solid"))
147
if (velocity.x == 0) { break; }
148
//printf("collision1\n");
149
position.x -= SIGN(velocity.x, 0.1);
151
if (xcol) {velocity.x = 0;}
153
position.y += velocity.y * Monocle::deltaTime;
154
while (Collide("Solid"))
157
if (velocity.y == 0) { break; }
158
//printf("collision2\n");
159
position.y -= SIGN(velocity.y, 0.1);
161
if (ycol) {velocity.y = 0;}
163
if (velocity.GetSquaredMagnitude() > 20)
166
sprite->Play("move");
170
skitter1->Pause(); //Stop()?
171
sprite->Play("idle");
205
57
// load level from files
206
58
Level::LoadProject("project.xml");
207
59
Level::Load("level.xml", this);
209
std::list<Entity*> *inv = GetAllTag("invisible");
210
for (std::list<Entity*>::iterator i = inv->begin(); i != inv->end(); ++i)
213
Vector2 s = e->scale;
214
e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
217
61
Player *player = new Player;
218
62
player->position = Graphics::GetScreenCenter();
222
Creature *creature = new Creature;
223
creature->position = Graphics::GetScreenCenter();
226
Creature *creature2 = new Creature;
227
creature2->position = Graphics::GetScreenCenter();
230
65
Graphics::SetBackgroundColor(Color::green * 0.2f);