aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Artist.cpp12
-rw-r--r--Museum.cpp17
2 files changed, 14 insertions, 15 deletions
diff --git a/Artist.cpp b/Artist.cpp
index 7bcd04b..9a9ac8e 100644
--- a/Artist.cpp
+++ b/Artist.cpp
@@ -5,10 +5,10 @@
using namespace std;
+static constexpr const float velocity_scale = 0.2;
+
Artist::Artist(Museum & museum, ArtistData data) : museum(museum) {
this->data = data;
- this->data.vx /= 5;
- this->data.vy /= 5;
}
void Artist::update(bool tick) {
@@ -22,8 +22,8 @@ void Artist::update(bool tick) {
}
void Artist::update_edge_collision() {
- float next_x = this->data.x + this->data.vx;
- float next_y = this->data.y + this->data.vy;
+ float next_x = this->data.x + this->data.vx * velocity_scale;
+ float next_y = this->data.y + this->data.vy * velocity_scale;
// +0.5 is for own size (the assignment explicitly defines the x,y position
// of artists as the top-left corner)
@@ -37,8 +37,8 @@ void Artist::update_movement() {
float last_x = this->data.x;
float last_y = this->data.y;
- this->data.x += this->data.vx;
- this->data.y += this->data.vy;
+ this->data.x += this->data.vx * velocity_scale;
+ this->data.y += this->data.vy * velocity_scale;
if (abs(int(last_x) - int(this->data.x)) > 0) this->step = true;
if (abs(int(last_y) - int(this->data.y)) > 0) this->step = true;
diff --git a/Museum.cpp b/Museum.cpp
index d389602..bf000e2 100644
--- a/Museum.cpp
+++ b/Museum.cpp
@@ -16,22 +16,23 @@ Museum::~Museum() {
}
void Museum::update() {
+ unsigned long long next_snapshot = this->snapshot_ticks;
+ if (!this->history.empty()) next_snapshot += this->history.top().tick;
+ if (this->tick >= next_snapshot || this->history.empty()) {
+ this->history.push(this->save_snapshot());
+ }
+
this->people.update();
this->canvas.update();
this->collision.update();
this->tick++;
-
- unsigned long long next_snapshot = this->snapshot_ticks;
- if (!this->history.empty()) next_snapshot += this->history.top().tick;
- if (next_snapshot > this->tick) return;
- this->history.push(this->save_snapshot());
- printf("saved snapshot at tick %llu\n", this->tick);
}
void Museum::skip_forward() {
this->jump++;
}
void Museum::skip_backward() {
+ this->paused = true;
this->jump--;
}
@@ -41,7 +42,6 @@ void Museum::work() {
if (this->jump > 0) {
// forward jump
for (; this->jump != 0; this->jump--) {
- printf("jumping forward %u ticks\n", this->snapshot_ticks);
for (size_t i = 0; i < this->snapshot_ticks; i++)
this->update();
}
@@ -49,9 +49,8 @@ void Museum::work() {
// backward jump
for (; this->jump != 0; this->jump++) {
if (this->history.empty()) continue;
- printf("restoring snapshot from tick %llu\n", this->history.top().tick);
this->restore_snapshot(this->history.top());
- this->history.pop();
+ if (this->tick > 0) this->history.pop();
}
}