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
velocity = Vector2::Random() * ACCELERATION;
87
//set aiTime to random so creatures tick at different times
88
aiTime= (float(rand()) / float(RAND_MAX)) * 2.0f;
91
void Creature::Update()
95
aiTime += Monocle::deltaTime;
101
direction = Vector2::zero;
105
direction = Vector2::Random();
113
velocity += direction * ACCELERATION * Monocle::deltaTime;
115
velocity.x = APPROACH(velocity.x, 0, FRICTION * Monocle::deltaTime);
116
velocity.y = APPROACH(velocity.y, 0, FRICTION * Monocle::deltaTime);
121
position.x += velocity.x * Monocle::deltaTime;
122
while (Collide("Solid"))
125
if (velocity.x == 0) { break; }
126
//printf("collision1\n");
127
position.x -= SIGN(velocity.x, 0.1);
129
if (xcol) {velocity.x = 0;}
131
position.y += velocity.y * Monocle::deltaTime;
132
while (Collide("Solid"))
135
if (velocity.y == 0) { break; }
136
//printf("collision2\n");
137
position.y -= SIGN(velocity.y, 0.1);
139
if (ycol) {velocity.y = 0;}
82
172
// load level from files
83
173
Level::LoadProject("project.xml");
84
174
Level::Load("level.xml", this);
176
std::list<Entity*> *inv = GetAllTag("invisible");
177
for (std::list<Entity*>::iterator i = inv->begin(); i != inv->end(); ++i)
180
Vector2 s = e->scale;
181
e->SetCollider(new RectangleCollider(s.x * 64, s.y * 64));
86
184
Player *player = new Player;
87
185
player->position = Graphics::GetScreenCenter();
188
Creature *creature = new Creature;
189
creature->position = Graphics::GetScreenCenter();
90
192
Graphics::SetBackgroundColor(Color::green * 0.2f);