42
42
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
43
43
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
45
position += velocity * Monocle::deltaTime;
48
position.x += velocity.x * Monocle::deltaTime;
49
while (Collide("Solid"))
52
if (velocity.x == 0) { break; }
53
//printf("collision1\n");
54
position.x -= SIGN(velocity.x, 0.1);
56
if (xcol) {velocity.x = 0;}
58
position.y += velocity.y * Monocle::deltaTime;
59
while (Collide("Solid"))
62
if (velocity.y == 0) { break; }
63
//printf("collision2\n");
64
position.y -= SIGN(velocity.y, 0.1);
66
if (ycol) {velocity.y = 0;}
47
69
//Scene::GetCamera()->position = position;
72
Creature::Creature() : Entity(),
77
sprite = new SpriteAnimation("creature.png", FILTER_NONE, 64, 64);
78
sprite->Add("idle", 0, 0, 0.35f);
83
SetCollider(new RectangleCollider(32, 32));
85
skitter1 = Audio::NewDeck(Assets::RequestAudio("skitter1.ogg"));
86
skitter1->SetLoops(0); //loop indefinitely
88
velocity = Vector2::Random() * ACCELERATION;
90
//set aiTime to random so creatures tick at different times
91
aiTime= (float(rand()) / float(RAND_MAX)) * 1.0f;
94
void Creature::Update()
98
aiTime += Monocle::deltaTime;
105
direction = Vector2::zero;
109
if (state != "wander") {
110
//printf("wander\n");
111
direction = Vector2::Random();
120
velocity += direction * ACCELERATION * Monocle::deltaTime;
122
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
123
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
128
position.x += velocity.x * Monocle::deltaTime;
129
while (Collide("Solid"))
132
if (velocity.x == 0) { break; }
133
//printf("collision1\n");
134
position.x -= SIGN(velocity.x, 0.1);
136
if (xcol) {velocity.x = 0;}
138
position.y += velocity.y * Monocle::deltaTime;
139
while (Collide("Solid"))
142
if (velocity.y == 0) { break; }
143
//printf("collision2\n");
144
position.y -= SIGN(velocity.y, 0.1);
146
if (ycol) {velocity.y = 0;}
148
if (velocity.GetSquaredMagnitude() > 0)
151
skitter1->Pause(); //Stop()?
82
184
// load level from files
83
185
Level::LoadProject("project.xml");
84
186
Level::Load("level.xml", this);
188
std::list<Entity*> *inv = GetAllTag("invisible");
189
for (std::list<Entity*>::iterator i = inv->begin(); i != inv->end(); ++i)
192
Vector2 s = e->scale;
193
e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
86
196
Player *player = new Player;
87
197
player->position = Graphics::GetScreenCenter();
200
Creature *creature = new Creature;
201
creature->position = Graphics::GetScreenCenter();
90
204
Graphics::SetBackgroundColor(Color::green * 0.2f);