Finished Line object and all drawing mechanics for it

windows
Braydon Kains 6 years ago
parent 2a355a51ba
commit 4ae3a615c2

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

@ -131,6 +131,7 @@
<ItemGroup>
<ClCompile Include="cursor.cpp" />
<ClCompile Include="game.cpp" />
<ClCompile Include="game_screen.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="start_screen.cpp" />
</ItemGroup>
@ -138,6 +139,7 @@
<ClInclude Include="cursor.h" />
<ClInclude Include="enums.h" />
<ClInclude Include="game.h" />
<ClInclude Include="game_screen.h" />
<ClInclude Include="screen.h" />
<ClInclude Include="start_screen.h" />
</ItemGroup>

@ -45,6 +45,9 @@
<ClCompile Include="start_screen.cpp">
<Filter>Source Files\ScreensImplement</Filter>
</ClCompile>
<ClCompile Include="game_screen.cpp">
<Filter>Source Files\ScreensImplement</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="cursor.h">
@ -62,5 +65,8 @@
<ClInclude Include="start_screen.h">
<Filter>Header Files\Screens</Filter>
</ClInclude>
<ClInclude Include="game_screen.h">
<Filter>Header Files\Screens</Filter>
</ClInclude>
</ItemGroup>
</Project>

@ -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

@ -4,6 +4,7 @@
#include <string>
#include "cursor.h"
#include "line.h"
using std::string;
using std::vector;
@ -99,4 +100,4 @@ template string Cursor<string>::get_selected();
template void Cursor<string>::update_selector();
vector<string> Cursor<string>::get_item_strings() {
return items;
}
}

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

@ -1,5 +1,6 @@
#include "game.h"
#include "start_screen.h"
#include "game_screen.h"
using std::string;
using std::map;
@ -13,10 +14,14 @@ void Game::init() {
state = Start;
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Title", al_load_bitmap("logo.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Mr. Man", al_load_bitmap("MrMan.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Mr. Manager", al_load_bitmap("MrManager.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Mr. Manager", al_load_bitmap("BigMrManager.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("KeyUp", al_load_bitmap("small_key_up.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Spacebar", al_load_bitmap("spacebar.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Employee", al_load_bitmap("employee.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("EmployeeHappy", al_load_bitmap("employee_happy.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("EmployeeSad", al_load_bitmap("employee_sad.bmp")));
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Conveyor", al_load_bitmap("conveyor.bmp")));
font = al_create_builtin_font();
}
@ -26,13 +31,18 @@ void Game::reset() {
}
void Game::run() {
StartScreen start_screen(sprites);
GameScreen game_screen(sprites);
while (state != Exit) {
switch (state) {
case Start:
StartScreen start_screen(sprites);
start_screen.run(font);
state = start_screen.next_state;
break;
case Gameplay:
game_screen.run(font);
state = game_screen.next_state;
break;
}
}
}

@ -6,8 +6,14 @@
using std::vector;
using std::string;
GameScreen::GameScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites) {
GameScreen::GameScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites, int _lines) {
sprites = _sprites;
for (int i = 0; i < _lines; i++) {
Line new_line(SCREEN_W-220, SCREEN_H/_lines * i, sprites);
}
selected = 0;
}
void GameScreen::run(ALLEGRO_FONT * font) {

@ -1,12 +1,15 @@
#pragma once
#include "line.h"
#include "screen.h"
#include "cursor.h"
class GameScreen : public Screen {
public:
std::map<std::string, ALLEGRO_BITMAP*> sprites;
std::vector<Line> lines;
int selected;
GameScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites);
GameScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites, int _lines);
void run(ALLEGRO_FONT* font);
void redraw(ALLEGRO_FONT* font);

@ -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();
};

@ -54,9 +54,9 @@ void StartScreen::run(ALLEGRO_FONT * font) {
void StartScreen::redraw(ALLEGRO_FONT* font) {
al_draw_bitmap(sprites["Title"], 0, 20, NULL);
al_draw_bitmap(sprites["Mr. Manager"], SCREEN_W / 2 - 24, 150, NULL);
al_draw_bitmap(sprites["Mr. Manager"], SCREEN_W / 2 - 40, 120, NULL);
for (int i = 1; i < 7; i++) {
al_draw_bitmap(sprites["Mr. Man"], SCREEN_W / 8 * i + 14, SCREEN_H / 2 - 40, NULL);
al_draw_bitmap(sprites["Mr. Man"], SCREEN_W / 8 * i + 14, SCREEN_H / 2 - 30, NULL);
}
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 + 20, ALLEGRO_ALIGN_CENTER, "Mr. Manager wants to run a teambuilding exercise for his employees.");

Loading…
Cancel
Save