Finished Line object and all drawing mechanics for it
							parent
							
								
									2a355a51ba
								
							
						
					
					
						commit
						4ae3a615c2
					
				
											
												Binary file not shown.
											
										
									
								| 
		 After Width: | Height: | Size: 19 KiB  | 
@ -0,0 +1,9 @@
 | 
			
		||||
#include "catcher.h"
 | 
			
		||||
 | 
			
		||||
Catcher::Catcher(int _position) {
 | 
			
		||||
	position = _position;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Catcher::move_up()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,9 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
class Catcher {
 | 
			
		||||
public:
 | 
			
		||||
	int position;
 | 
			
		||||
 | 
			
		||||
	Catcher(int _position);
 | 
			
		||||
 | 
			
		||||
	void move_up();
 | 
			
		||||
};
 | 
			
		||||
											
												Binary file not shown.
											
										
									
								| 
		 After Width: | Height: | Size: 52 KiB  | 
											
												Binary file not shown.
											
										
									
								| 
		 After Width: | Height: | Size: 4.8 KiB  | 
@ -0,0 +1,11 @@
 | 
			
		||||
#include "employee.h"
 | 
			
		||||
 | 
			
		||||
Employee::Employee(int _line) {
 | 
			
		||||
	position = 6;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Employee::move() {
 | 
			
		||||
	position -= 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,9 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
class Employee {
 | 
			
		||||
public:
 | 
			
		||||
	int position;
 | 
			
		||||
	
 | 
			
		||||
	Employee(int _line);
 | 
			
		||||
 | 
			
		||||
	void move();
 | 
			
		||||
};
 | 
			
		||||
											
												Binary file not shown.
											
										
									
								| 
		 After Width: | Height: | Size: 4.8 KiB  | 
											
												Binary file not shown.
											
										
									
								| 
		 After Width: | Height: | Size: 4.8 KiB  | 
@ -0,0 +1,89 @@
 | 
			
		||||
#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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Line::move() {
 | 
			
		||||
	if (caught) {
 | 
			
		||||
		caught = false;
 | 
			
		||||
		catchers[0] = catchers[1];
 | 
			
		||||
		catchers[1] = catchers[0];
 | 
			
		||||
		catchers[2] = 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (employees[0]) {
 | 
			
		||||
		if (catchers[0]) {
 | 
			
		||||
			caught = true;
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			fall = true;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	for (int i = 0; i < 4; i++) {
 | 
			
		||||
		employees[i] = employees[i + 1];
 | 
			
		||||
	}
 | 
			
		||||
	employees[4] = (queued) ? 1 : 0;
 | 
			
		||||
	queued = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Line::add_employee() {
 | 
			
		||||
	queued = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Line::add_catcher() {
 | 
			
		||||
	for (int i = 2; i > -1; i--) {
 | 
			
		||||
		if (!catchers[i]) {
 | 
			
		||||
			catchers[i] = 1;
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Line::draw() {
 | 
			
		||||
	al_draw_bitmap(sprites["Conveyor"], start_x, start_y, NULL);
 | 
			
		||||
	
 | 
			
		||||
	for (int i = 0; i < 5; i++) {
 | 
			
		||||
		if (employees[i]) {
 | 
			
		||||
			al_draw_bitmap(sprites["Employee"], start_x + (40 * i), start_y, NULL);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for (int i = 2; i > -1; i++) {
 | 
			
		||||
		if (i = 0) {
 | 
			
		||||
			if (caught) {
 | 
			
		||||
				al_draw_bitmap(sprites["EmployeeHappy"], start_x - 40, start_y, NULL);
 | 
			
		||||
				al_draw_bitmap(sprites["MrMan"], start_x - 40, start_y - 40, NULL);
 | 
			
		||||
			}
 | 
			
		||||
			else if (fall) {
 | 
			
		||||
					al_draw_bitmap(sprites["EmployeeSad"], start_x - 40, start_y - 55, ALLEGRO_FLIP_VERTICAL);
 | 
			
		||||
			}
 | 
			
		||||
			else {
 | 
			
		||||
				if (catchers[i]) {
 | 
			
		||||
					al_draw_bitmap(sprites["MrMan"], start_x - 40, start_y - 40, NULL);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			if (catchers[i]) {
 | 
			
		||||
				al_draw_bitmap(sprites["MrMan"], start_x - 40 - (50*(i+1)), start_y - 40, NULL);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,30 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <allegro5/allegro.h>
 | 
			
		||||
#include <allegro5/allegro_image.h>
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
#include "catcher.h"
 | 
			
		||||
#include "employee.h"
 | 
			
		||||
 | 
			
		||||
class Line {
 | 
			
		||||
public:
 | 
			
		||||
	float start_x;
 | 
			
		||||
	float start_y;
 | 
			
		||||
 | 
			
		||||
	std::map<std::string, ALLEGRO_BITMAP*> sprites;
 | 
			
		||||
 | 
			
		||||
	int catchers[3];
 | 
			
		||||
	int employees[5];
 | 
			
		||||
 | 
			
		||||
	bool queued;
 | 
			
		||||
	bool fall;
 | 
			
		||||
	bool caught;
 | 
			
		||||
 | 
			
		||||
	Line(int _start_x, int _start_y, std::map<std::string, ALLEGRO_BITMAP*> _sprites);
 | 
			
		||||
 | 
			
		||||
	void move();
 | 
			
		||||
	void draw();
 | 
			
		||||
	void add_employee();
 | 
			
		||||
	void add_catcher();
 | 
			
		||||
};
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue