final commenting

main
Braydon Kains 6 years ago
parent 30254bb816
commit 45872673f0

@ -91,6 +91,19 @@
<Allegro_AddonMemfile>true</Allegro_AddonMemfile> <Allegro_AddonMemfile>true</Allegro_AddonMemfile>
<Allegro_AddonVideo>true</Allegro_AddonVideo> <Allegro_AddonVideo>true</Allegro_AddonVideo>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Allegro_AddonImage>true</Allegro_AddonImage>
<Allegro_AddonTTF>true</Allegro_AddonTTF>
<Allegro_AddonPrimitives>true</Allegro_AddonPrimitives>
<Allegro_AddonAudio>true</Allegro_AddonAudio>
<Allegro_AddonAcodec>true</Allegro_AddonAcodec>
<Allegro_AddonPhysfs>true</Allegro_AddonPhysfs>
<Allegro_AddonDialog>true</Allegro_AddonDialog>
<Allegro_AddonMemfile>true</Allegro_AddonMemfile>
<Allegro_AddonFont>true</Allegro_AddonFont>
<Allegro_AddonColor>true</Allegro_AddonColor>
<Allegro_AddonVideo>true</Allegro_AddonVideo>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>

@ -101,12 +101,12 @@
<ClCompile Include="result_screen.cpp"> <ClCompile Include="result_screen.cpp">
<Filter>Source Files\ScreensImplement</Filter> <Filter>Source Files\ScreensImplement</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="star.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="help_screen.cpp"> <ClCompile Include="help_screen.cpp">
<Filter>Source Files\ScreensImplement</Filter> <Filter>Source Files\ScreensImplement</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="star.cpp">
<Filter>Source Files\Assignment3Implement</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Text Include="enemies.txt"> <Text Include="enemies.txt">

@ -2,6 +2,7 @@
Bullet::Bullet(Behavior _behavior) { Bullet::Bullet(Behavior _behavior) {
behavior = _behavior; behavior = _behavior;
//Build properties based on behavior
switch (behavior) { switch (behavior) {
case Enemy: case Enemy:
speed = 1.0; speed = 1.0;
@ -38,6 +39,7 @@ void Bullet::move(Direction dir) {
y_pos += 6; y_pos += 6;
break; break;
} }
//Only player bullets are used currently so only player bullet bound is checked
if (y_pos < 0 - height) { if (y_pos < 0 - height) {
oob = true; oob = true;
} }

@ -3,6 +3,7 @@
#include "game_element.h" #include "game_element.h"
//Bullet fired by ships
class Bullet : public GameElement { class Bullet : public GameElement {
public: public:
Bullet(Behavior _behavior); Bullet(Behavior _behavior);

@ -7,6 +7,7 @@
#define TILE_SIZE 40 #define TILE_SIZE 40
#define LEVEL_LEN 120 #define LEVEL_LEN 120
//State machine states
enum State { enum State {
Start, Start,
Gameplay, Gameplay,
@ -15,6 +16,7 @@ enum State {
Exit Exit
}; };
//Movement directions
enum Direction { enum Direction {
U, U,
D, D,
@ -26,17 +28,20 @@ enum Direction {
DL DL
}; };
//Game object behaviors
enum Behavior { enum Behavior {
Player, Player,
Enemy Enemy
}; };
//Define current background layer for scrolling
enum BgLayer { enum BgLayer {
Front, Front,
Middle, Middle,
Back Back
}; };
//Game object hitbox for collision detection
struct Hitbox { struct Hitbox {
int x; int x;
int y; int y;
@ -44,12 +49,14 @@ struct Hitbox {
int width; int width;
}; };
//Struct for enemy queue
struct NewEnemy { struct NewEnemy {
int x; int x;
Behavior e_type; Behavior e_type;
int when; int when;
}; };
//When inputs must be delayed by a number of frames (no longer used, kept for possible future use
struct InputDelay { struct InputDelay {
bool input_hit; bool input_hit;
int delay_sec; int delay_sec;

@ -3,6 +3,7 @@
#include "enums.h" #include "enums.h"
//Game Element base class, with position, height, and screen bounding properties along with its behavior
class GameElement { class GameElement {
public: public:
float x_pos; float x_pos;
@ -16,9 +17,13 @@ public:
float width; float width;
bool oob; bool oob;
Behavior behavior; Behavior behavior;
//Set position of object
virtual void reset_pos(float x, float y) = 0; virtual void reset_pos(float x, float y) = 0;
//Move object
virtual void move(Direction dir) = 0; virtual void move(Direction dir) = 0;
//Draw object to screen
virtual void draw() = 0; virtual void draw() = 0;
//Build hitbox struct for the object at position in current frame
virtual Hitbox get_hitbox() = 0; virtual Hitbox get_hitbox() = 0;
}; };

@ -10,7 +10,7 @@
#include <map> #include <map>
#include <ctime> #include <ctime>
//#include "mappy_A5.h" //#include "mappy_A5.h" I couldn't get this to work
#include "game_screen.h" #include "game_screen.h"
#include "help_screen.h" #include "help_screen.h"
@ -26,10 +26,12 @@ using std::map;
using std::pair; using std::pair;
using std::rand; using std::rand;
//Keys that will be listener for in events
enum KEYS { enum KEYS {
KEYUP, KEYDOWN, KEYLEFT, KEYRIGHT, KEYSPACE, KEYCTRL, KEYH, KEYM, KEYESC KEYUP, KEYDOWN, KEYLEFT, KEYRIGHT, KEYSPACE, KEYCTRL, KEYH, KEYM, KEYESC
}; };
//Actions to manage
enum ACTIONS { enum ACTIONS {
FIRE, MUSIC, HELP FIRE, MUSIC, HELP
}; };
@ -63,6 +65,7 @@ void GameScreen::play(ALLEGRO_SAMPLE_INSTANCE* x) {
al_play_sample_instance(x); al_play_sample_instance(x);
} }
//Builds enemy queue out of enemies txt file, possibly used later
void GameScreen::build_enemy_queue() { void GameScreen::build_enemy_queue() {
string line; string line;
ifstream enemies_file("enemies.txt"); ifstream enemies_file("enemies.txt");
@ -102,6 +105,7 @@ void GameScreen::run(ALLEGRO_FONT* font) {
NewEnemy next_enemy = enemy_q.back(); NewEnemy next_enemy = enemy_q.back();
enemy_q.pop_back(); enemy_q.pop_back();
//Sets input delay structs
InputDelay inputs[3]; InputDelay inputs[3];
inputs[FIRE].input_hit = false; inputs[FIRE].input_hit = false;
inputs[FIRE].delay_sec = 0; inputs[FIRE].delay_sec = 0;
@ -115,6 +119,7 @@ void GameScreen::run(ALLEGRO_FONT* font) {
inputs[HELP].delay_sec = 0; inputs[HELP].delay_sec = 0;
inputs[HELP].max_delay = 80; inputs[HELP].max_delay = 80;
//Sets tilemap size and background data
int max_map = TILE_SIZE * LEVEL_LEN; int max_map = TILE_SIZE * LEVEL_LEN;
map_y = max_map; map_y = max_map;
objects.set_background(); objects.set_background();
@ -122,6 +127,7 @@ void GameScreen::run(ALLEGRO_FONT* font) {
redraw(font); redraw(font);
al_flip_display(); al_flip_display();
//key tracking array
bool keys[ALLEGRO_KEY_MAX]; bool keys[ALLEGRO_KEY_MAX];
for (int i = 0; i < ALLEGRO_KEY_MAX; i++) keys[i] = false; for (int i = 0; i < ALLEGRO_KEY_MAX; i++) keys[i] = false;

@ -3,10 +3,9 @@
#include "cursor.h" #include "cursor.h"
#include <string> #include <string>
//Screen to display results upon losing //Screen to display help menu
class HelpScreen : public Screen { class HelpScreen : public Screen {
public: public:
std::map<std::string, ALLEGRO_BITMAP*> sprites;
Cursor<std::string> menu; Cursor<std::string> menu;
HelpScreen(); HelpScreen();

@ -9,6 +9,7 @@
#include "game.h" #include "game.h"
int main() { int main() {
//Initialize components and addons
if (!al_init()) { if (!al_init()) {
fprintf(stderr, "Could not initialize Allegro!"); fprintf(stderr, "Could not initialize Allegro!");
} }
@ -31,13 +32,16 @@ int main() {
fprintf(stderr, "Could not initialize primitives addon!"); fprintf(stderr, "Could not initialize primitives addon!");
} }
//Create display
ALLEGRO_DISPLAY* display = NULL; ALLEGRO_DISPLAY* display = NULL;
display = al_create_display(SCREEN_W, SCREEN_H); display = al_create_display(SCREEN_W, SCREEN_H);
//Run game
Game main_game; Game main_game;
main_game.init(); main_game.init();
main_game.run(); main_game.run();
//Garbage collection
al_uninstall_keyboard(); al_uninstall_keyboard();
al_uninstall_audio(); al_uninstall_audio();

@ -120,9 +120,11 @@ void ObjectManager::move_enemies() {
} }
} }
//Initialize background stars
void ObjectManager::set_background() { void ObjectManager::set_background() {
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
Star new_star; //Pick random layer and position
Star new_star;
int l = rand() % 2; int l = rand() % 2;
BgLayer layer; BgLayer layer;
switch (l) { switch (l) {
@ -171,10 +173,13 @@ void ObjectManager::move_background() {
} }
} }
//Check if the hitboxes are overlapping
bool ObjectManager::col_eval(Hitbox h1, Hitbox h2) { bool ObjectManager::col_eval(Hitbox h1, Hitbox h2) {
//Check if one hitbox is within the other's width
if (h1.x > (h2.x + h2.width) || h2.x > (h1.x + h1.width)) if (h1.x > (h2.x + h2.width) || h2.x > (h1.x + h1.width))
return false; return false;
//Check if one hitbox is within the other's height
if (h1.y > (h2.y + h2.height) || h2.y > (h1.y + h1.height)) if (h1.y > (h2.y + h2.height) || h2.y > (h1.y + h1.height))
return false; return false;

@ -6,25 +6,32 @@
#include "ship.h" #include "ship.h"
#include "star.h" #include "star.h"
//Manages all onscreen object movements, drawing, and hitbox detection
class ObjectManager { class ObjectManager {
public: public:
Ship player; Ship player;
std::vector<Ship> enemies; std::vector<Ship> enemies;
std::vector<Bullet> player_bullets; std::vector<Bullet> player_bullets;
std::vector<Bullet> enemy_bullets; std::vector<Bullet> enemy_bullets; //saved for future use
std::vector<Star> background; std::vector<Star> background;
ObjectManager(); ObjectManager();
void init_player(Ship _player); void init_player(Ship _player);
//Collision detection methods
bool chk_player_col(); bool chk_player_col();
int chk_bullet_col(); int chk_bullet_col();
//Draw objects to screen
void draw_objects(); void draw_objects();
//Originally for garbage collection, once moved away fromp pointers it became kind of useless
void destroy_objects(); void destroy_objects();
//Moves all enemies on screen and checks bounds
void move_enemies(); void move_enemies();
//Set and move the background, originally supposed to be tilemaps now Star objects
void set_background(); void set_background();
void move_background(); void move_background();
private: private:
//Check if two hitboxes are colliding
bool col_eval(Hitbox h1, Hitbox h2); bool col_eval(Hitbox h1, Hitbox h2);
}; };

@ -12,6 +12,7 @@ void Ship::set_props(ALLEGRO_BITMAP* _sprite, Behavior _behavior) {
sprite = _sprite; sprite = _sprite;
behavior = _behavior; behavior = _behavior;
oob = false; oob = false;
//Build properties based on behavior
switch (behavior) { switch (behavior) {
case Enemy: case Enemy:
speed = 1.1; speed = 1.1;
@ -74,6 +75,8 @@ void Ship::move(Direction dir) {
break; break;
} }
//Check screen boundaries
//The player must be kept within the boundaries, but other objects must be set as oob so they can be unloaded
if (x_pos <= l_bound) { if (x_pos <= l_bound) {
if (behavior == Player) { if (behavior == Player) {
x_pos = l_bound; x_pos = l_bound;

@ -4,11 +4,12 @@
#include "game_element.h" #include "game_element.h"
#include "bullet.h" #include "bullet.h"
//Ship sprite displayed over background
class Ship : public GameElement { class Ship : public GameElement {
public: public:
ALLEGRO_BITMAP* sprite; ALLEGRO_BITMAP* sprite; //loads a sprite rather than a primitive
bool fired; bool fired; //no longer used
Ship(); Ship();
@ -18,7 +19,6 @@ public:
void move(Direction dir); void move(Direction dir);
Hitbox get_hitbox(); Hitbox get_hitbox();
//unique to object void set_props(ALLEGRO_BITMAP* _sprite, Behavior _behavior); //Sets ship properties
void set_props(ALLEGRO_BITMAP* _sprite, Behavior _behavior); Bullet fire(); //Creates a new bullet
Bullet fire();
}; };

@ -11,7 +11,8 @@ void Star::reset_pos(float x, float y) {
void Star::set_layer(BgLayer _layer) { void Star::set_layer(BgLayer _layer) {
layer = _layer; layer = _layer;
//Set properties based on layer
//Scrolls at a different speed based on layer
switch (layer) { switch (layer) {
case Front: case Front:
speed = 1.2; speed = 1.2;

Loading…
Cancel
Save