You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.0 KiB
C++
90 lines
2.0 KiB
C++
6 years ago
|
#include "line.h"
|
||
|
|
||
|
using std::map;
|
||
|
using std::string;
|
||
|
|
||
|
Line::Line(int _start_x, int _start_y, map<string, ALLEGRO_BITMAP*> _sprites) {
|
||
|
start_x = _start_x;
|
||
|
start_y = _start_y;
|
||
|
|
||
|
sprites = _sprites;
|
||
|
|
||
|
queued = false;
|
||
|
fall = false;
|
||
|
|
||
|
for (int i = 0; i < 3; i++) {
|
||
|
catchers[i] = 0;
|
||
|
}
|
||
|
for (int i = 0; i < 5; i++) {
|
||
|
employees[i] = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
//Move the line forward
|
||
6 years ago
|
void Line::move() {
|
||
6 years ago
|
//If a catch was previously made, move catchers forward and reset catch state
|
||
6 years ago
|
if (caught) {
|
||
|
caught = false;
|
||
|
catchers[0] = catchers[1];
|
||
|
catchers[1] = catchers[2];
|
||
|
catchers[2] = 0;
|
||
|
}
|
||
|
|
||
6 years ago
|
//move employees forward
|
||
6 years ago
|
for (int i = 0; i < 5; i++) {
|
||
|
employees[i] = employees[i + 1];
|
||
|
}
|
||
6 years ago
|
//check if an employee is set to be added to this line
|
||
6 years ago
|
employees[5] = (queued) ? 1 : 0;
|
||
|
queued = false;
|
||
|
|
||
6 years ago
|
//check if a catch was made
|
||
6 years ago
|
if (employees[0]) {
|
||
|
if (catchers[0]) {
|
||
|
caught = true;
|
||
|
}
|
||
|
else {
|
||
|
fall = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
//Add employee to this line
|
||
6 years ago
|
void Line::add_employee() {
|
||
|
queued = true;
|
||
|
}
|
||
|
|
||
6 years ago
|
//Add a catched to this line
|
||
6 years ago
|
void Line::add_catcher() {
|
||
6 years ago
|
for (int i = 0; i < 3; i++) {
|
||
6 years ago
|
if (!catchers[i]) {
|
||
|
catchers[i] = 1;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
//Draw this line
|
||
6 years ago
|
void Line::draw() {
|
||
6 years ago
|
al_draw_bitmap(sprites["Conveyor"], start_x, start_y, NULL); //Sprite
|
||
6 years ago
|
|
||
6 years ago
|
for (int i = 1; i < 6; i++) {
|
||
6 years ago
|
if (employees[i]) { //If the array says there is a catcher at the current position
|
||
6 years ago
|
al_draw_bitmap(sprites["Employee"], start_x + (40 * (i-1)), start_y, NULL);
|
||
6 years ago
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
for (int i = 2; i > -1; i--) {
|
||
6 years ago
|
if (i == 0) { //If this is the position closes to the line
|
||
|
if (caught) { //If there was a catch
|
||
6 years ago
|
al_draw_bitmap(sprites["EmployeeHappy"], start_x - 40, start_y, NULL);
|
||
|
}
|
||
6 years ago
|
else if (fall) { //If there was not a catch
|
||
6 years ago
|
al_draw_bitmap(sprites["EmployeeSad"], start_x - 40, start_y + 55, ALLEGRO_FLIP_VERTICAL);
|
||
6 years ago
|
}
|
||
|
}
|
||
6 years ago
|
if (catchers[i]) { //If there is a catcher at this position
|
||
6 years ago
|
al_draw_bitmap(sprites["Mr. Man"], start_x - 40 - (50*(i)), start_y + 40, NULL);
|
||
6 years ago
|
}
|
||
|
}
|
||
|
}
|