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 5 enemies #115

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
93f3e44
Added my own window file
Alcatraz714 Jul 28, 2024
676acb2
Added new Main.cpp
Alcatraz714 Jul 29, 2024
fe06d7c
Shapes added
Alcatraz714 Jul 29, 2024
a096bda
Logo and Sprites
Alcatraz714 Jul 29, 2024
fcc675e
added text and sprites
Alcatraz714 Jul 29, 2024
f3f7ec0
Merge pull request #1 from Alcatraz714/Feature-1-SFML
Alcatraz714 Jul 29, 2024
9b096bb
OOP
Alcatraz714 Jul 29, 2024
1116b79
Added keyboard inputs and getters and setters
Alcatraz714 Jul 29, 2024
f7c02e3
Added move functions
Alcatraz714 Jul 29, 2024
45ea812
Added Header and Source folders with GameService
Alcatraz714 Jul 30, 2024
e527f50
comments and gameloop code shift
Alcatraz714 Jul 30, 2024
5fe3d91
Merge pull request #2 from Alcatraz714/Feature-2-OOP
Alcatraz714 Jul 30, 2024
a5529a7
Added Service Locator header and cpp
Alcatraz714 Jul 30, 2024
067493a
Merge pull request #3 from Alcatraz714/Feature-2-OOP
Alcatraz714 Jul 30, 2024
9c1cd5a
Changed Architecture and added links between units
Alcatraz714 Jul 30, 2024
88e545b
Merge pull request #4 from Alcatraz714/Feature-2-OOP
Alcatraz714 Jul 30, 2024
452befa
added event service header and cpp
Alcatraz714 Jul 30, 2024
c2b5ccf
Merge pull request #5 from Alcatraz714/Feature-2-OOP
Alcatraz714 Jul 30, 2024
abdf09b
Added Player Service Header and cpp
Alcatraz714 Jul 31, 2024
e759f6e
Added time Service
Alcatraz714 Jul 31, 2024
974eae8
Merge pull request #6 from Alcatraz714/Feature-3-Player-Ship
Alcatraz714 Jul 31, 2024
943dfd9
Split the player into 3 different units
Alcatraz714 Jul 31, 2024
63c6c72
Merge pull request #7 from Alcatraz714/Feature-3-Player-Ship
Alcatraz714 Jul 31, 2024
e01b88b
Added code to player units
Alcatraz714 Jul 31, 2024
c642815
Merge pull request #8 from Alcatraz714/Feature-3-Player-Ship
Alcatraz714 Jul 31, 2024
621747d
Delete Space-Invaders/Header directory
Alcatraz714 Aug 1, 2024
4339484
Delete Space-Invaders/Source directory
Alcatraz714 Aug 1, 2024
8df483d
Delete Space-Invaders/main.cpp
Alcatraz714 Aug 1, 2024
f01bc02
Delete Space-Invaders/Space-Invaders.sln
Alcatraz714 Aug 1, 2024
5844287
New Feature 3 Arch branch
Alcatraz714 Aug 1, 2024
58622f5
Delete Space-Invaders/Header directory
Alcatraz714 Aug 1, 2024
4f64943
Delete Space-Invaders/Source directory
Alcatraz714 Aug 1, 2024
97ebea3
Merge pull request #10 from Alcatraz714/Feature-3-Player-Ship
Alcatraz714 Aug 1, 2024
2f3005b
Added Namespaces
Alcatraz714 Aug 1, 2024
ff152f2
Game State added
Alcatraz714 Aug 2, 2024
6601dac
Added Main Menu and lifecycle
Alcatraz714 Aug 2, 2024
50e219c
Added new control functions
Alcatraz714 Aug 2, 2024
35c51f6
Added EnemyService
Alcatraz714 Aug 4, 2024
f515f61
Added movement
Alcatraz714 Aug 4, 2024
fb6f2c4
fixed move and multiple enemies
Alcatraz714 Aug 4, 2024
c2cf915
Added Gameplay Services
Alcatraz714 Aug 4, 2024
f3b7383
Enemy Config
Alcatraz714 Aug 6, 2024
39fdfbe
Added Zapper and Sub Zero
Alcatraz714 Aug 6, 2024
e448b2c
Added Element folder MVC
Alcatraz714 Aug 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Space-Invaders/Header/Element/Bunker/BunkerController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#pragma once
1 change: 1 addition & 0 deletions Space-Invaders/Header/Element/Bunker/BunkerModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#pragma once
1 change: 1 addition & 0 deletions Space-Invaders/Header/Element/Bunker/BunkerView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#pragma once
8 changes: 8 additions & 0 deletions Space-Invaders/Header/Element/ElementService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once
namespace Element
{
class ElementService
{

};
}
27 changes: 27 additions & 0 deletions Space-Invaders/Header/Enemy/Controllers/SubZeroController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#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;

};
}
}
29 changes: 29 additions & 0 deletions Space-Invaders/Header/Enemy/Controllers/ZapperController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#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,
};
}
37 changes: 37 additions & 0 deletions Space-Invaders/Header/Enemy/EnemyController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#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;

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();
};
}
45 changes: 45 additions & 0 deletions Space-Invaders/Header/Enemy/EnemyModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#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:
EnemyModel(EnemyType type);
~EnemyModel();

//const settings for enemy
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;

void initialize();

// Getters and Setters
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);
};
}
35 changes: 35 additions & 0 deletions Space-Invaders/Header/Enemy/EnemyService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once
#include <vector>

namespace Enemy
{
class EnemyController;
enum class EnemyType;

class EnemyService
{
private:

const float spawn_interval = 2.f;

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

void updateSpawnTimer();
void processEnemySpawn();
EnemyType getRandomEnemyType();
EnemyController* createEnemy(EnemyType enemy_type);
void destroy();

public:
EnemyService();
~EnemyService();

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

EnemyController* spawnEnemy(); // Function to spawn enemy
void destroyEnemy(EnemyController* enemy_controller);
};
}
36 changes: 36 additions & 0 deletions Space-Invaders/Header/Enemy/EnemyView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <SFML/Graphics.hpp>
#include "../../Header/Enemy/EnemyConfig.h"

namespace Enemy
{
class EnemyController;

class EnemyView
{
private:
const sf::String subzero_texture_path = "assets/textures/subzero.png";
const sf::String zapper_texture_path = "assets/textures/zapper.png";

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();
};
}
56 changes: 56 additions & 0 deletions Space-Invaders/Header/Event/EventService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#pragma once

#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Event.hpp>

namespace Event
{
enum class ButtonState
{
PRESSED,
HELD,
RELEASED,
};

class EventService
{
private:
sf::Event game_event; //event var
sf::RenderWindow* game_window; //ptr to our game window

bool isGameWindowOpen();
bool gameWindowWasClosed(); //for the condition we already had - the title bar cross.
bool hasQuitGame(); //for our new 'ESC' condition

//Button States
ButtonState left_mouse_button_state;
ButtonState right_mouse_button_state;
ButtonState left_arrow_button_state;
ButtonState right_arrow_button_state;
ButtonState A_button_state;
ButtonState D_button_state;

//Button and mouse state functions
void updateMouseButtonsState(ButtonState& current_button_state, sf::Mouse::Button mouse_button);
void updateKeyboardButtonsState(ButtonState& current_button_state, sf::Keyboard::Key keyboard_button);


public:
EventService();
~EventService();

void initialize();
void update();
void processEvents(); // while window is open we will check for events
bool pressedEscapeKey();
bool isKeyboardEvent();
bool pressedLeftKey(); // getting inputs for the player
bool pressedRightKey();
bool pressedLeftMouseButton(); // Mouse inputs for the player
bool pressedRightMouseButton();
bool pressedAKey(); // AD held check
bool pressedDKey();

};
}

21 changes: 21 additions & 0 deletions Space-Invaders/Header/Gameplay/GameplayController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include <SFML/Graphics.hpp>

namespace Gameplay
{
class GameplayView;

class GameplayController
{
private:
GameplayView* gameplay_view;

public:
GameplayController();
~GameplayController();

void initialize();
void update();
void render();
};
}
19 changes: 19 additions & 0 deletions Space-Invaders/Header/Gameplay/GameplayService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
namespace Gameplay
{
class GameplayController;

class GameplayService
{
private:
GameplayController* gameplay_controller;

public:
GameplayService();
~GameplayService();

void initialize();
void update();
void render();
};
}
26 changes: 26 additions & 0 deletions Space-Invaders/Header/Gameplay/GameplayView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include <SFML/Graphics.hpp>

namespace Gameplay
{
class GameplayView
{
private:
const sf::String background_texture_path = "assets/textures/space_invaders_bg.png";

sf::RenderWindow* game_window;
sf::Texture background_texture;
sf::Sprite background_sprite;

void initializeBackgroundSprite();
void scaleBackgroundSprite();

public:
GameplayView();
~GameplayView();

void initialize();
void update();
void render();
};
}
Loading