Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 6 barriers and sounds #116

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
29 changes: 29 additions & 0 deletions Space-Invaders/Header/Elements/Bunker/BunkerController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#include<SFML/Graphics.hpp>
#include"../../Header/Elements/Bunker/BunkerModel.h"

namespace Element
{
namespace Bunker
{
class BunkerView;

class BunkerController
{
private:
BunkerView* bunker_view;
BunkerData bunker_data;

public:
BunkerController();
~BunkerController();

void initialize(BunkerData data);
void update();
void render();

sf::Vector2f getBunkerPosition();
};
}

}
14 changes: 14 additions & 0 deletions Space-Invaders/Header/Elements/Bunker/BunkerModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include <SFML/System/Vector2.hpp>

namespace Element
{
namespace Bunker
{
struct BunkerData
{
sf::Vector2f position;BunkerData();
BunkerData(sf::Vector2f position);
};
}
}
36 changes: 36 additions & 0 deletions Space-Invaders/Header/Elements/Bunker/BunkerView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once
#include<SFML/Graphics.hpp>

namespace Element
{
namespace Bunker
{
class BunkerController;

class BunkerView
{
private:
const float bunker_sprite_width = 80.f;
const float bunker_sprite_height = 80.f;

BunkerController* bunker_controller;
sf::RenderWindow* game_window;

sf::Texture bunker_texture;
sf::Sprite bunker_sprite;



void scaleSprite();
void initializeImage();

public:
BunkerView();
~BunkerView();

void initialize(BunkerController* controller);
void update();
void render();
};
}
}
36 changes: 36 additions & 0 deletions Space-Invaders/Header/Elements/ElementService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once
#include<vector>
#include<SFML/System/Vector2.hpp>
#include"../../Header/Elements/Bunker/BunkerController.h"
#include"../../Header/Elements/Bunker/BunkerModel.h"

namespace Element
{
class BunkerController;


class ElementService
{
private:
const std::vector<Bunker::BunkerData>bunker_data_list = {
Bunker::BunkerData(sf::Vector2f(130.f,800.f)),
Bunker::BunkerData(sf::Vector2f(430.0f,800.f)),
Bunker::BunkerData(sf::Vector2f(730.0f,800.f)),
Bunker::BunkerData(sf::Vector2f(1130.0f,800.f)),
Bunker::BunkerData(sf::Vector2f(1430.f,800.f)),
Bunker::BunkerData(sf::Vector2f(1730.0f,800.f))
};

std::vector<Bunker::BunkerController*> bunker_list;

void destroy();

public:
ElementService();
virtual ~ElementService();

void initialize();
void update();
void render();
};
}
23 changes: 23 additions & 0 deletions Space-Invaders/Header/Enemy/Controllers/SubZeroController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include "../../header/Enemy/EnemyController.h"

namespace Enemy
{
namespace Controller
{
class SubzeroController : public EnemyController
{
private:
float vertical_movement_speed = 100.f;

void move() override;
void moveDown();

public:
SubzeroController(EnemyType type);
~SubzeroController();

void initialize() override;
};
}
}
25 changes: 25 additions & 0 deletions Space-Invaders/Header/Enemy/Controllers/ZapperController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
#include "../../header/Enemy/EnemyController.h"

namespace Enemy
{
namespace Controller
{
class ZapperController : public EnemyController
{
private:
float vertical_travel_distance = 100.f;

void move() override;
void moveLeft();
void moveRight();
void moveDown();

public:
ZapperController(EnemyType type);
~ZapperController();

void initialize() override;
};
}
}
26 changes: 26 additions & 0 deletions Space-Invaders/Header/Enemy/EnemyConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

namespace Enemy
{
enum class EnemyType
{
ZAPPER,
SUBZERO,
//UFO,
//THUNDER_SNAKE,
};

enum class EnemyState
{
PATROLLING,
ATTACK,
DEAD,
};

enum class MovementDirection
{
LEFT,
RIGHT,
DOWN,
};
}
39 changes: 39 additions & 0 deletions Space-Invaders/Header/Enemy/EnemyController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once
#include <SFML/Graphics.hpp>

namespace Enemy
{
class EnemyView;
class EnemyModel;

enum class EnemyType;
enum class EnemyState;

class EnemyController
{
protected:

EnemyView* enemy_view;
EnemyModel* enemy_model;

virtual void move() = 0;
//void moveLeft();
//void moveRight();
//void moveDown();

sf::Vector2f getRandomInitialPosition();
void handleOutOfBounds();

public:
EnemyController(EnemyType type);
virtual ~EnemyController();

virtual void initialize();
void update();
void render();

sf::Vector2f getEnemyPosition();
EnemyState getEnemyState();
EnemyType getEnemyType();
};
}
48 changes: 48 additions & 0 deletions Space-Invaders/Header/Enemy/EnemyModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once
#include <SFML/Graphics.hpp>

namespace Enemy
{
enum class EnemyType;
enum class MovementDirection;
enum class EnemyState;

class EnemyModel
{
private:
sf::Vector2f reference_position = sf::Vector2f(50.f, 50.f);
sf::Vector2f enemy_position;

MovementDirection movement_direction;
EnemyType enemy_type;
EnemyState enemy_state;

public:

const sf::Vector2f left_most_position = sf::Vector2f(50.f, 50.f);
const sf::Vector2f right_most_position = sf::Vector2f(1800.f, 50.f);

const float vertical_travel_distance = 100.f;
const float enemy_movement_speed = 250.0f;

EnemyModel(EnemyType type);
~EnemyModel();

void initialize();

sf::Vector2f getEnemyPosition();
void setEnemyPosition(sf::Vector2f position);

sf::Vector2f getReferencePosition();
void setReferencePosition(sf::Vector2f position);

EnemyState getEnemyState();
void setEnemyState(EnemyState state);

EnemyType getEnemyType();
void setEnemyType(EnemyType type);

MovementDirection getMovementDirection();
void setMovementDirection(MovementDirection direction);
};
}
36 changes: 36 additions & 0 deletions Space-Invaders/Header/Enemy/EnemyService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once
#include <vector>

namespace Enemy
{
class EnemyController;
enum class EnemyType;

class EnemyService
{
private:

const float spawn_interval = 3.f;

std::vector<EnemyController*> enemy_list;
float spawn_timer;

EnemyController* createEnemy(EnemyType enemy_type);
EnemyType getRandomEnemyType();

void updateSpawnTimer();
void processEnemySpawn();

public:
EnemyService();
virtual ~EnemyService();

void initialize();
void update();
void render();


EnemyController* spawnEnemy();
void destroyEnemy(EnemyController* enemy_controller);
};
}
33 changes: 33 additions & 0 deletions Space-Invaders/Header/Enemy/EnemyView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once
#include <SFML/Graphics.hpp>

namespace Enemy
{
class EnemyController;
enum class EnemyType;

class EnemyView
{
private:

const float enemy_sprite_width = 60.f;
const float enemy_sprite_height = 60.f;

EnemyController* enemy_controller;

sf::RenderWindow* game_window;
sf::Texture enemy_texture;
sf::Sprite enemy_sprite;

void initializeEnemySprite(EnemyType type);
void scaleEnemySprite();

public:
EnemyView();
~EnemyView();

void initialize(EnemyController* controller);
void update();
void render();
};
}
Loading