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 10 collisions #109

Open
wants to merge 64 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
9756614
Window
GR-tejas Jun 20, 2024
738edd7
Merge pull request #1 from GR-tejas/Feature-1-SFML
GR-tejas Jun 20, 2024
ae9627a
Update main.cpp
GR-tejas Jun 20, 2024
7492978
Merge pull request #2 from GR-tejas/Feature-1-SFML
GR-tejas Jun 20, 2024
5abb636
Update main.cpp
GR-tejas Jun 25, 2024
92f4fbe
Merge pull request #3 from GR-tejas/Feature-1-SFML
GR-tejas Jun 25, 2024
66e9bd2
Player Class
GR-tejas Jul 4, 2024
0633651
Update main.cpp
GR-tejas Jul 5, 2024
540dcca
Player Movement
GR-tejas Jul 5, 2024
0d45c91
Added header and source file
GR-tejas Jul 6, 2024
4918d6f
Added gameService in the main file
GR-tejas Jul 6, 2024
4ce1d67
Added service locator files
GR-tejas Jul 9, 2024
021e498
Organizing code
GR-tejas Jul 11, 2024
c0ab1c9
Added event service
GR-tejas Jul 11, 2024
436b2a5
Added player service
GR-tejas Jul 12, 2024
84c77d0
Temp
GR-tejas Jul 12, 2024
acb1182
Added TimeService
GR-tejas Jul 12, 2024
76d4f58
Added Player Model Class
GR-tejas Jul 13, 2024
98e9d89
Added Player controller and player view
GR-tejas Jul 14, 2024
94561ba
Forward Declaration
GR-tejas Jul 14, 2024
f71a244
Implemented namespace
GR-tejas Jul 14, 2024
f256d32
Added game state enum
GR-tejas Jul 14, 2024
33ea4c6
Implimented main menu controller
GR-tejas Jul 15, 2024
489a3b6
Implemented Main Menu Sprites
GR-tejas Jul 15, 2024
7f72037
Added buttons and other menu elements
GR-tejas Jul 15, 2024
833be80
Manage Button State
GR-tejas Jul 15, 2024
e118c62
temp
GR-tejas Jul 16, 2024
efca13f
Temp 2
GR-tejas Jul 22, 2024
b4f9742
Enemy Service
GR-tejas Jul 22, 2024
de1469c
Implement Enemy Movement
GR-tejas Jul 23, 2024
ad152df
Spawn Multiple Enemies
GR-tejas Jul 23, 2024
5af7057
Create Gameplay Service
GR-tejas Jul 23, 2024
857cc9a
Common Enemy Properties
GR-tejas Jul 24, 2024
7c5aac1
Unique Enemy Functionality
GR-tejas Jul 24, 2024
469c761
Movement Functionality
GR-tejas Jul 25, 2024
0340efc
Spawn Enemies
GR-tejas Jul 26, 2024
0c817e6
Create Barriers
GR-tejas Jul 26, 2024
6dec415
data for barriers
GR-tejas Jul 26, 2024
fecfead
Spawn Multiple Barriers
GR-tejas Jul 26, 2024
771f2ac
Config File Added
GR-tejas Jul 26, 2024
229ae00
Sound Service
GR-tejas Jul 26, 2024
cf94f83
Added Sounds and Music
GR-tejas Jul 26, 2024
e6e3f37
Create Projectile Interface
GR-tejas Jul 27, 2024
67f9fab
Bullet MVC
GR-tejas Jul 27, 2024
0f37aec
The Model And View
GR-tejas Jul 27, 2024
165af8e
Bullets Created
GR-tejas Jul 27, 2024
e41a287
Spawn Bullets
GR-tejas Jul 27, 2024
3d9b89b
Move The Bullets
GR-tejas Jul 27, 2024
62f71c3
Fire The Bullets
GR-tejas Jul 29, 2024
221ce22
Collectible Interface
GR-tejas Jul 29, 2024
a263aa7
Powerup Controllers
GR-tejas Jul 29, 2024
6eab029
Spawning Powerups
GR-tejas Jul 29, 2024
0fd6323
UI Interface
GR-tejas Jul 29, 2024
84b74da
Changed UI Service
GR-tejas Jul 30, 2024
2077669
Implemented Image View
GR-tejas Jul 30, 2024
14815c7
Text View
GR-tejas Jul 30, 2024
dba7736
Button View usage
GR-tejas Jul 30, 2024
4b8c1ea
Multiple Entities
GR-tejas Jul 31, 2024
fe2f6ba
Collision Interface And Service
GR-tejas Jul 31, 2024
4ac1b5e
Player Collision
GR-tejas Jul 31, 2024
0911906
Player Collision
GR-tejas Jul 31, 2024
41de6a2
Bullet Collision
GR-tejas Aug 1, 2024
b3c3dd9
Enemy And Powerup Collisions
GR-tejas Aug 1, 2024
1b57c9d
Screen UI Elements
GR-tejas Aug 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
28 changes: 28 additions & 0 deletions Space-Invaders/Header/Bullet/BulletConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
#include <SFML/Graphics.hpp>

namespace Bullet
{
enum class BulletType
{
LASER_BULLET,
TORPEDO,
FROST_BULLET,
};

enum class MovementDirection
{
UP,
DOWN,
};

class BulletConfig
{
public:
static const sf::String laser_bullet_texture_path;
static const sf::String torpedoe_texture_path;
static const sf::String frost_beam_texture_path;

static sf::String getBulletTexturePath(BulletType bullet_type);
};
}
44 changes: 44 additions & 0 deletions Space-Invaders/Header/Bullet/BulletController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once
#include "../../Header/Projectile/IProjectile.h"
#include "../../Header/Bullet/BulletConfig.h"
#include "../../Header/Entity/EntityConfig.h"

namespace Bullet
{
class BulletView;
class BulletModel;
enum class BulletType;

class BulletController : public Projectile::IProjectile, public Collision::ICollider
{
protected:
BulletView* bullet_view;
BulletModel* bullet_model;

void updateProjectilePosition() override;

void processBulletCollision(ICollider* other_collider);
void processEnemyCollision(ICollider* other_collider);
void processPlayerCollision(ICollider* other_collider);
void processBunkerCollision(ICollider* other_collider);

void moveUp();
void moveDown();
void handleOutOfBounds();

public:
BulletController(BulletType type, Entity::EntityType owner_type);
virtual ~BulletController() override;

void initialize(sf::Vector2f position, Bullet::MovementDirection direction) override;
void update() override;
void render() override;

sf::Vector2f getProjectilePosition() override;
BulletType getBulletType();
Entity::EntityType getOwnerEntityType();

const sf::Sprite& getColliderSprite() override;
void onCollision(ICollider* other_collider) override;
};
}
41 changes: 41 additions & 0 deletions Space-Invaders/Header/Bullet/BulletModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once
#include <SFML/Graphics.hpp>
#include "../../Header/Entity/EntityConfig.h"

namespace Bullet
{
enum class BulletType;
enum class MovementDirection;

class BulletModel
{
private:
float movement_speed = 300.f;
sf::Vector2f bullet_position;

BulletType bullet_type;
MovementDirection movement_direction;
Entity::EntityType owner_type;

public:

BulletModel(BulletType type, Entity::EntityType e_type);
~BulletModel();

void initialize(sf::Vector2f position, MovementDirection direction);

sf::Vector2f getBulletPosition();
void setBulletPosition(sf::Vector2f position);

BulletType getBulletType();
void setBulletType(BulletType type);

MovementDirection getMovementDirection();
void setMovementDirection(MovementDirection direction);

float getMovementSpeed();
void setMovementSpeed(float speed);

Entity::EntityType getEntityType();
};
}
39 changes: 39 additions & 0 deletions Space-Invaders/Header/Bullet/BulletService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once
#include <vector>
#include "SFML/System/Vector2.hpp"
#include "../../Header/Projectile/IProjectile.h"
#include "../../Header/Entity/EntityConfig.h"

namespace Bullet
{
class BulletController;
enum class BulletType;
enum class MovementDirection;

class BulletService
{
private:
std::vector<Projectile::IProjectile*> flagged_bullet_list;
std::vector<Projectile::IProjectile*> bullet_list;

BulletController* createBullet(BulletType bullet_type, Entity::EntityType owner_type);

bool isValidBullet(int index_i, std::vector<Projectile::IProjectile*>& bullet_list);
void destroyFlaggedBullets();

void destroy();

public:
BulletService();
virtual ~BulletService();

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

void reset();

BulletController* spawnBullet(BulletType bullet_type, sf::Vector2f position, MovementDirection direction, Entity::EntityType owner_type);
void destroyBullet(BulletController* bullet_controller);
};
}
32 changes: 32 additions & 0 deletions Space-Invaders/Header/Bullet/BulletView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once
#include <SFML/Graphics.hpp>

namespace Bullet
{
class BulletController;
enum class BulletType;

class BulletView
{
private:
const float bullet_sprite_width = 18.f;
const float bullet_sprite_height = 18.f;

sf::RenderWindow* game_window;
sf::Texture bullet_texture;
sf::Sprite bullet_sprite;

BulletController* bullet_controller;

void initializeImage(BulletType type);
void scaleImage();

public:
BulletView();
~BulletView();

void initialize(BulletController* controller);
void update();
void render();
};
}
20 changes: 20 additions & 0 deletions Space-Invaders/Header/Bullet/Controllers/FrostBulletController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "../../Header/Bullet/BulletController.h"

namespace Bullet
{
namespace Controller
{
class FrostBulletController : public BulletController
{
private:
const float torpedo_movement_speed = 200.f;

public:
FrostBulletController(BulletType type);
~FrostBulletController();

void initialize(sf::Vector2f position, MovementDirection direction) override;
};
}
}
17 changes: 17 additions & 0 deletions Space-Invaders/Header/Bullet/Controllers/LaserBulletController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include "../../Header/Bullet/BulletController.h"

namespace Bullet
{
namespace Controller
{
class LaserBulletController : public BulletController
{
public:
LaserBulletController(BulletType type);
~LaserBulletController();

void initialize(sf::Vector2f position, MovementDirection direction) override;
};
}
}
20 changes: 20 additions & 0 deletions Space-Invaders/Header/Bullet/Controllers/TorpedoController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "../../Header/Bullet/BulletController.h"

namespace Bullet
{
namespace Controller
{
class TorpedoController : public BulletController
{
private:
const float torpedo_movement_speed = 200.f;

public:
TorpedoController(BulletType type);
~TorpedoController();

void initialize(sf::Vector2f position, MovementDirection direction) override;
};
}
}
17 changes: 17 additions & 0 deletions Space-Invaders/Header/Collectible/ICollectible.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include <SFML/System/Vector2.hpp>

namespace Collectible
{
class ICollectible
{
public:
virtual void onCollected() = 0;
virtual void initialize(sf::Vector2f position) = 0;
virtual void update() = 0;
virtual void render() = 0;
virtual sf::Vector2f getCollectiblePosition() = 0;

virtual ~ICollectible() {};
};
}
28 changes: 28 additions & 0 deletions Space-Invaders/Header/Collision/CollisionService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
#include <vector>

namespace Collision
{
class ICollider;

class CollisionService
{
private:
std::vector<ICollider*> collider_list;

void processCollision();
void doCollision(int index_i, int index_j);
bool hasCollisionOccurred(int index_i, int index_j);
bool areActiveColliders(int index_i, int index_j);

public:
CollisionService();
~CollisionService();

void initialize();
void update();

void addCollider(ICollider* collider);
void removeCollider(ICollider* collider);
};
}
28 changes: 28 additions & 0 deletions Space-Invaders/Header/Collision/ICollider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
#include <SFML/Graphics.hpp>

namespace Collision
{
enum class CollisionState
{
ENABLED,
DISABLED,
};

class ICollider
{
private:
CollisionState collision_state;

public:
ICollider();
virtual ~ICollider();

virtual const sf::Sprite& getColliderSprite() = 0;
virtual void onCollision(ICollider* other_collider) = 0;

void enableCollision();
void disableCollision();
CollisionState getCollisionState();
};
}
28 changes: 28 additions & 0 deletions Space-Invaders/Header/Element/Bunker/BunkerController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
#include <SFML/Graphics.hpp>
#include "../../Header/Element/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();
};
}
}
15 changes: 15 additions & 0 deletions Space-Invaders/Header/Element/Bunker/BunkerModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include <SFML/System/Vector2.hpp>

namespace Element
{
namespace Bunker
{
struct BunkerData
{
sf::Vector2f position;
BunkerData();
BunkerData(sf::Vector2f position);
};
}
}
Loading