diff --git a/TrustFall/TrustFall/TrustFall.vcxproj b/TrustFall/TrustFall/TrustFall.vcxproj
index ff05b35..86edf0c 100644
--- a/TrustFall/TrustFall/TrustFall.vcxproj
+++ b/TrustFall/TrustFall/TrustFall.vcxproj
@@ -148,9 +148,7 @@
-
-
@@ -159,9 +157,7 @@
-
-
diff --git a/TrustFall/TrustFall/TrustFall.vcxproj.filters b/TrustFall/TrustFall/TrustFall.vcxproj.filters
index 4c20cbd..0f73592 100644
--- a/TrustFall/TrustFall/TrustFall.vcxproj.filters
+++ b/TrustFall/TrustFall/TrustFall.vcxproj.filters
@@ -54,12 +54,6 @@
Source Files\TrustFallImplement
-
- Source Files
-
-
- Source Files
-
Source Files\ScreensImplement
@@ -86,12 +80,6 @@
Header Files\TrustFall
-
- Header Files
-
-
- Header Files
-
Header Files\Screens
diff --git a/TrustFall/TrustFall/catch.wav b/TrustFall/TrustFall/catch.wav
new file mode 100644
index 0000000..c5e0a57
Binary files /dev/null and b/TrustFall/TrustFall/catch.wav differ
diff --git a/TrustFall/TrustFall/catcher.cpp b/TrustFall/TrustFall/catcher.cpp
deleted file mode 100644
index 3831755..0000000
--- a/TrustFall/TrustFall/catcher.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "catcher.h"
-
-Catcher::Catcher(int _position) {
- position = _position;
-}
-
-void Catcher::move_up()
-{
-}
diff --git a/TrustFall/TrustFall/catcher.h b/TrustFall/TrustFall/catcher.h
deleted file mode 100644
index 0ad20af..0000000
--- a/TrustFall/TrustFall/catcher.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#pragma once
-class Catcher {
-public:
- int position;
-
- Catcher(int _position);
-
- void move_up();
-};
\ No newline at end of file
diff --git a/TrustFall/TrustFall/cursor.cpp b/TrustFall/TrustFall/cursor.cpp
index e591e93..b43c230 100644
--- a/TrustFall/TrustFall/cursor.cpp
+++ b/TrustFall/TrustFall/cursor.cpp
@@ -15,6 +15,7 @@ Cursor::Cursor()
active = false;
}
+//Give items to the cursor, and set the selected item to be the first
template
void Cursor::activate(std::vector _items)
{
@@ -23,12 +24,14 @@ void Cursor::activate(std::vector _items)
active = true;
}
+//Functionality that was not used for this game, may be used in future projects.
template
void Cursor::deactivate()
{
active = false;
}
+//Draw the menu options on the screen based on the x and y coordinates for the menu to start at
template
void Cursor::draw(float _x_start, float _y_start, float _y_offset, ALLEGRO_FONT* _font) {
vector items_text = get_item_strings();
@@ -38,13 +41,14 @@ void Cursor::draw(float _x_start, float _y_start, float _y_offset, ALLEGRO_FO
y_offset = _y_offset;
font = _font;
- for (int i = 0; i < items_text.size(); i++) {
+ for (unsigned int i = 0; i < items_text.size(); i++) {
al_draw_text(font, al_map_rgb(255, 255, 255), x_start, y_start + (y_offset*i), ALLEGRO_ALIGN_LEFT, items_text.at(i).c_str());
}
update_selector();
}
+//Change the selection of the cursor
template
void Cursor::down()
{
@@ -68,6 +72,7 @@ T Cursor::get_selected() {
return items.at(selected);
}
+//Clear screen before drawing menu
template
void Cursor::redraw()
{
@@ -75,6 +80,7 @@ void Cursor::redraw()
draw(x_start, y_start, y_offset, font);
}
+//Draw selector to highlight proper selected item
template
void Cursor::update_selector() {
ALLEGRO_COLOR white = al_map_rgb(255, 255, 255);
@@ -89,6 +95,7 @@ void Cursor::update_selector() {
al_draw_filled_triangle(x1, y1, x2, y2, x3, y3, white);
}
+//Define how the template will function when given various types. Only string was needed for this project.
template Cursor::Cursor();
template void Cursor::activate(std::vector _options);
template void Cursor::deactivate();
diff --git a/TrustFall/TrustFall/cursor.h b/TrustFall/TrustFall/cursor.h
index a668e6d..98df0d7 100644
--- a/TrustFall/TrustFall/cursor.h
+++ b/TrustFall/TrustFall/cursor.h
@@ -3,11 +3,12 @@
#include
#include
+//Default object used for menues
template
class Cursor {
public:
std::vector items;
- int selected;
+ unsigned int selected;
bool active;
Cursor();
diff --git a/TrustFall/TrustFall/employee.cpp b/TrustFall/TrustFall/employee.cpp
deleted file mode 100644
index 69382ae..0000000
--- a/TrustFall/TrustFall/employee.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "employee.h"
-
-Employee::Employee(int _line) {
- position = 6;
-}
-
-void Employee::move() {
- position -= 1;
-}
-
-
diff --git a/TrustFall/TrustFall/employee.h b/TrustFall/TrustFall/employee.h
deleted file mode 100644
index 90337cc..0000000
--- a/TrustFall/TrustFall/employee.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#pragma once
-class Employee {
-public:
- int position;
-
- Employee(int _line);
-
- void move();
-};
\ No newline at end of file
diff --git a/TrustFall/TrustFall/enums.h b/TrustFall/TrustFall/enums.h
index bccad62..9e06aa3 100644
--- a/TrustFall/TrustFall/enums.h
+++ b/TrustFall/TrustFall/enums.h
@@ -3,9 +3,13 @@
#define SCREEN_W 640
#define SCREEN_H 480
+//Collection of states run by state machine
enum State {
Start,
- Gameplay,
+ Easy,
+ Medium,
+ Hard,
+ EXTREME,
Help,
End,
Exit
diff --git a/TrustFall/TrustFall/fall.wav b/TrustFall/TrustFall/fall.wav
new file mode 100644
index 0000000..fb27628
Binary files /dev/null and b/TrustFall/TrustFall/fall.wav differ
diff --git a/TrustFall/TrustFall/game.cpp b/TrustFall/TrustFall/game.cpp
index 91b68d7..743e5cc 100644
--- a/TrustFall/TrustFall/game.cpp
+++ b/TrustFall/TrustFall/game.cpp
@@ -10,6 +10,7 @@ using std::pair;
Game::Game() {
}
+//Load all global data for the game: sprites, audio, and font.
void Game::init() {
score = 0;
state = Start;
@@ -28,32 +29,72 @@ void Game::init() {
sprites.insert(pair("KeyH", al_load_bitmap("small_key_h.bmp")));
sprites.insert(pair("KeyM", al_load_bitmap("small_key_m.bmp")));
sprites.insert(pair("KeyEsc", al_load_bitmap("small_key_esc.bmp")));
+ sprites.insert(pair("MusicOn", al_load_bitmap("music_on.bmp")));
+ sprites.insert(pair("MusicOff", al_load_bitmap("music_off.bmp")));
+ al_reserve_samples(4);
+ samples.insert(pair("Theme", al_load_sample("rasputin.wav")));
+ samples.insert(pair("Move", al_load_sample("move.wav")));
+ samples.insert(pair("Catch", al_load_sample("catch.wav")));
+ samples.insert(pair("Fall", al_load_sample("fall.wav")));
+ samples.insert(pair("Place", al_load_sample("place.wav")));
+ samples.insert(pair("LevelUp", al_load_sample("level.wav")));
+
font = al_create_builtin_font();
}
+//Was not used in this project
void Game::reset() {
- score = 0;
- state = Start;
}
+//Run the game state machine
void Game::run() {
- GameScreen game_screen(sprites);
+ //Load screens
+ GameScreen game_screen(sprites, samples);
StartScreen start_screen(sprites);
- ResultScreen result_screen(sprites, 0, 0);
+ ResultScreen result_screen(sprites, 0, 0, Easy);
+ int difficulty = 1; //Difficulty to run
+ bool EXTREME_ON = false; //Flag for EXTREME easter egg
while (state != Exit) {
al_clear_to_color(al_map_rgb(0, 0, 0));
switch (state) {
case Start:
start_screen.run(font);
- state = start_screen.next_state;
+ if (start_screen.next_state == EXTREME) {
+ EXTREME_ON = true;
+ state = Hard;
+ }
+ else {
+ state = start_screen.next_state;
+ }
break;
- case Gameplay:
- game_screen.reset(3, 5, 3);
+ //The same set of code will be run for any difficulty state
+ case Easy:
+ case Medium:
+ case Hard:
+ //But we need to check once here whether the difficulty value needs to be adjusted
+ switch (state) {
+ case Medium:
+ difficulty = 3;
+ result_screen.prev_state = Medium;
+ break;
+ case Hard:
+ difficulty = 5;
+ result_screen.prev_state = Hard;
+ break;
+ }
+ if (EXTREME_ON) {
+ game_screen.reset(5, 5, difficulty); //If the EXTREME easter egg is enabled, the game will be run with 5 lines on hard mode
+ }
+ else {
+ game_screen.reset(3, 5, difficulty);
+ }
+ EXTREME_ON = false;
game_screen.run(font);
state = game_screen.next_state;
break;
case End:
+ //Send proper finishing values for this game to the result screen
result_screen.score = game_screen.score;
result_screen.difficulty = game_screen.difficulty;
result_screen.run(font);
@@ -61,4 +102,14 @@ void Game::run() {
break;
}
}
+
+ //Garbage collection
+ map::iterator it;
+ for (it = sprites.begin(); it != sprites.end(); it++) {
+ al_destroy_bitmap(it->second);
+ }
+ map::iterator it2;
+ for (it2 = samples.begin(); it2 != samples.end(); it2++) {
+ al_destroy_sample(it2->second);
+ }
}
\ No newline at end of file
diff --git a/TrustFall/TrustFall/game.h b/TrustFall/TrustFall/game.h
index 5b15833..1354ce1 100644
--- a/TrustFall/TrustFall/game.h
+++ b/TrustFall/TrustFall/game.h
@@ -12,6 +12,7 @@
#include "enums.h"
+//Game state machine, contains data global to game
class Game {
public:
//Allegro elements
@@ -23,6 +24,7 @@ public:
int score;
std::map sprites;
+ std::map samples;
Game();
diff --git a/TrustFall/TrustFall/game_screen.cpp b/TrustFall/TrustFall/game_screen.cpp
index c4d2fcc..3e39b6e 100644
--- a/TrustFall/TrustFall/game_screen.cpp
+++ b/TrustFall/TrustFall/game_screen.cpp
@@ -1,9 +1,12 @@
#include
#include
+#include
+#include
#include
#include
#include
#include