diff --git a/Assignment3Project/Assignment3Project/behavior_manager.h b/Assignment3Project/Assignment3Project/behavior_manager.h new file mode 100644 index 0000000..7102054 --- /dev/null +++ b/Assignment3Project/Assignment3Project/behavior_manager.h @@ -0,0 +1,3 @@ +#pragma once + +#include "enums.h" \ No newline at end of file diff --git a/Assignment3Project/Assignment3Project/enemies.txt b/Assignment3Project/Assignment3Project/enemies.txt new file mode 100644 index 0000000..565a32c --- /dev/null +++ b/Assignment3Project/Assignment3Project/enemies.txt @@ -0,0 +1 @@ +n,10,240 \ No newline at end of file diff --git a/Assignment3Project/Assignment3Project/enemy.cpp b/Assignment3Project/Assignment3Project/enemy.cpp deleted file mode 100644 index f832355..0000000 --- a/Assignment3Project/Assignment3Project/enemy.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "enemy.h" - -Enemy::Enemy() -{ -} - -void Enemy::reset_pos(float x, float y) -{ -} - -void Enemy::draw() -{ -} - -void Enemy::move(Direction dir) -{ -} diff --git a/Assignment3Project/Assignment3Project/enemy.h b/Assignment3Project/Assignment3Project/enemy.h deleted file mode 100644 index e1b39f1..0000000 --- a/Assignment3Project/Assignment3Project/enemy.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "game_element.h" - -class Enemy : public GameElement { -public: - ALLEGRO_BITMAP* sprite; - - Enemy(); - - void reset_pos(float x, float y); - void draw(); - void move(Direction dir); -}; \ No newline at end of file diff --git a/Assignment3Project/Assignment3Project/game_screen.cpp b/Assignment3Project/Assignment3Project/game_screen.cpp index ff5f64a..31c649a 100644 --- a/Assignment3Project/Assignment3Project/game_screen.cpp +++ b/Assignment3Project/Assignment3Project/game_screen.cpp @@ -31,8 +31,9 @@ GameScreen::GameScreen(std::map _sprites, std::map //Resets game to default values, and uses new given values void GameScreen::reset() { - ship.set_sprite(sprites["Ship"]); - ship.reset_pos(SCREEN_W / 2, SCREEN_H / 8); + objects.player = new Ship(); + objects.player->set_sprite(sprites["Ship"]); + objects.player->reset_pos(SCREEN_W / 2, SCREEN_H / 8); max_bullets = 3; } @@ -72,45 +73,45 @@ void GameScreen::run(ALLEGRO_FONT* font) { //Ship Movement if (keys[KEYUP]) { if (keys[KEYRIGHT]) { - ship.move(UR); + objects.player->move(UR); } else if (keys[KEYLEFT]) { - ship.move(UL); + objects.player->move(UL); } else { - ship.move(U); + objects.player->move(U); } } else if (keys[KEYDOWN]) { if (keys[KEYRIGHT]) { - ship.move(DR); + objects.player->move(DR); } else if (keys[KEYLEFT]) { - ship.move(DL); + objects.player->move(DL); } else { - ship.move(D); + objects.player->move(D); } } else if (keys[KEYLEFT]) { - ship.move(L); + objects.player->move(L); } else if (keys[KEYRIGHT]) { - ship.move(R); + objects.player->move(R); } //Firing if (keys[KEYSPACE]) { - if (bullets.size() < max_bullets) { - if (!ship.fired) { - bullets.push_back(ship.fire()); + if (objects.player_bullets.size() < max_bullets) { + if (!objects.player->fired) { + objects.player_bullets.push_back(&objects.player->fire()); } - ship.fired = true; + objects.player->fired = true; } } - if (ship.fired) { + if (objects.player->fired) { if (fired_counter >= 20) { - ship.fired = false; + objects.player->fired = false; fired_counter = 0; } else { @@ -207,21 +208,21 @@ void GameScreen::run(ALLEGRO_FONT* font) { //Redraw all elements of the screen void GameScreen::redraw(ALLEGRO_FONT* font) { - ship.draw(); + objects.player->draw(); vector unload; - for (unsigned int i = 0; i < bullets.size(); i++) { - if (bullets.at(i).oob) { + for (unsigned int i = 0; i < objects.player_bullets.size(); i++) { + if (objects.player_bullets.at(i)->oob) { unload.push_back(i); } else { - bullets.at(i).move(U); - bullets.at(i).draw(); + objects.player_bullets.at(i)->move(U); + objects.player_bullets.at(i)->draw(); } } for (unsigned int i = 0; i < unload.size(); i++) { int x = unload.at(i); - bullets.erase(bullets.begin() + x); + objects.player_bullets.erase(objects.player_bullets.begin() + x); } } diff --git a/Assignment3Project/Assignment3Project/game_screen.h b/Assignment3Project/Assignment3Project/game_screen.h index 4410c76..4598866 100644 --- a/Assignment3Project/Assignment3Project/game_screen.h +++ b/Assignment3Project/Assignment3Project/game_screen.h @@ -5,6 +5,7 @@ #include "screen.h" #include "ship.h" #include "bullet.h" +#include "object_manager.h" //Main screen for gameplay class GameScreen : public Screen { @@ -15,9 +16,8 @@ public: int score; int level; bool music; - Ship ship; + ObjectManager objects; unsigned int max_bullets; - std::vector bullets; GameScreen(std::map _sprites, std::map _samples); diff --git a/Assignment3Project/Assignment3Project/object_manager.cpp b/Assignment3Project/Assignment3Project/object_manager.cpp new file mode 100644 index 0000000..7404ad7 --- /dev/null +++ b/Assignment3Project/Assignment3Project/object_manager.cpp @@ -0,0 +1,17 @@ +#include "object_manager.h" + +ObjectManager::ObjectManager() { + +} + +void ObjectManager::initiate(Ship * _player) { + player = _player; +} + +bool ObjectManager::chk_player_col() { + return false; +} + +int ObjectManager::chk_bullet_col() { + return 0; +} diff --git a/Assignment3Project/Assignment3Project/object_manager.h b/Assignment3Project/Assignment3Project/object_manager.h new file mode 100644 index 0000000..88fe0fb --- /dev/null +++ b/Assignment3Project/Assignment3Project/object_manager.h @@ -0,0 +1,20 @@ +#pragma once +#include + +#include "enums.h" +#include "bullet.h" +#include "ship.h" + +class ObjectManager { +public: + Ship* player; + std::vector enemies; + std::vector player_bullets; + std::vector enemy_bullets; + + ObjectManager(); + + void initiate(Ship* _player); + bool chk_player_col(); + int chk_bullet_col(); +}; \ No newline at end of file