diff options
Diffstat (limited to 'Artist.cpp')
-rw-r--r-- | Artist.cpp | 28 |
1 files changed, 21 insertions, 7 deletions
@@ -1,25 +1,39 @@ +#include <cstdlib> + #include "Artist.h" #include "Museum.h" -void Artist::update(Museum & m) { - this->update_edge_collision(m); - this->update_movement(m); +Artist::Artist(Museum & museum, ArtistData data) : museum(museum) { + this->data = data; + this->data.vx /= 50; + this->data.vy /= 50; +} + +void Artist::update() { + this->update_edge_collision(); + this->update_movement(); } -void Artist::update_edge_collision(Museum & museum) { +void Artist::update_edge_collision() { float next_x = this->data.x + this->data.vx; float next_y = this->data.y + this->data.vy; // +0.5 is for own size (the assignment explicitly defines the x,y position // of artists as the top-left corner) - if ((next_x + 0.5) > museum.canvas.data.columns || next_x < 0) + if ((next_x + 0.5) > this->museum.canvas.data.columns || next_x < 0) this->data.vx *= -1; - if ((next_y + 0.5) > museum.canvas.data.rows || next_y < 0) + if ((next_y + 0.5) > this->museum.canvas.data.rows || next_y < 0) this->data.vy *= -1; } -void Artist::update_movement(Museum & museum) { +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; + + 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; } |