final commenting

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

@ -91,6 +91,19 @@
<Allegro_AddonMemfile>true</Allegro_AddonMemfile>
<Allegro_AddonVideo>true</Allegro_AddonVideo>
</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'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>

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

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

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

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

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

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

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

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

@ -120,8 +120,10 @@ void ObjectManager::move_enemies() {
}
}
//Initialize background stars
void ObjectManager::set_background() {
for (int i = 0; i < 20; i++) {
//Pick random layer and position
Star new_star;
int l = rand() % 2;
BgLayer layer;
@ -171,10 +173,13 @@ void ObjectManager::move_background() {
}
}
//Check if the hitboxes are overlapping
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))
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))
return false;

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

@ -12,6 +12,7 @@ void Ship::set_props(ALLEGRO_BITMAP* _sprite, Behavior _behavior) {
sprite = _sprite;
behavior = _behavior;
oob = false;
//Build properties based on behavior
switch (behavior) {
case Enemy:
speed = 1.1;
@ -74,6 +75,8 @@ void Ship::move(Direction dir) {
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 (behavior == Player) {
x_pos = l_bound;

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

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

Loading…
Cancel
Save