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 4 main menu #114

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
60 changes: 60 additions & 0 deletions Space-Invaders/Headers/EVENT/EventService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#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


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;

//....some other code
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();
bool pressedRightKey();
bool leftmousebutton();
bool rightmousebutton();

bool pressedLeftMouseButton();
bool pressedRightMouseButton();

bool pressedAKey();
bool pressedDKey();

};
}
47 changes: 47 additions & 0 deletions Space-Invaders/Headers/Global/ServiceLocator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include"../Graphic/GraphicService.h"
#include"../EVENT/EventService.h"
#include"../player/PlayerService.h"
#include"../TIME/TimeService .h"
#include"../../UI/UISERVICE.h"
namespace Global {
using namespace player;
using namespace Graphic;
using namespace event;
using namespace UI;

class ServiceLocator
{
private:
// Private Attributes:
GraphicService* graphic_service;
EventService* event_service;
PlayerService* player_service;
TimeService* time_Service;
UiService* ui_service;

// Private Constructor and Destructor:
ServiceLocator();
// Constructor for initializing the ServiceLocator.
~ServiceLocator(); // Destructor for cleaning up resources upon object deletion.

// Private Methods:
void createServices(); // Creates instances of all services.
void clearAllServices(); // Deletes and deallocates memory for all services.

public:
// Public Methods:
static ServiceLocator* getInstance(); // Provides a method to access the unique ServiceLocator instance (object).
void initialize(); // Initializes the ServiceLocator.
void update(); // Updates all services.
void render(); // Renders using the services.

// Methods to Get Specific Services:
GraphicService* getGraphicService();
EventService* getEventService();
PlayerService* getplayerservice();
TimeService* gettimeservice();
UiService* getUiservice();
};
}
44 changes: 44 additions & 0 deletions Space-Invaders/Headers/Graphic/GraphicService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

#pragma once

#include <SFML/Graphics.hpp>
namespace Graphic {

class GraphicService
{
private:


const std::string game_window_title = "Outscal Presents - Alien Invader";

const int game_window_width = 1920;
const int game_window_height = 1080;

const sf::Color window_color = sf::Color::Blue;

const int framerate = 60;

sf::VideoMode* video_mode; // ptr to video mode
sf::RenderWindow* game_window; // ptr to a RenderWindow

void setVideoMode(); // Method for setting our video mode
void onDestroy(); // method to run when window is deleted

public:
GraphicService();
~GraphicService(); //cleanup

//method to create the game window. returns a pointer to an instance of the game window
sf::RenderWindow* createGameWindow();


void initialize(); //lifecycle functions
void update(); //..
void render(); //..
bool isGameWindowOpen(); //check if the window is open

sf::RenderWindow* getGameWindow(); //getter for the game window instance
sf::Color getWindowColor();//get the color
};

}
23 changes: 23 additions & 0 deletions Space-Invaders/Headers/TIME/TimeService .h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
//Capture the current time at the beginning of a frame
//Capture the current time again at the beginning of the next frame
//Calculate the delta time by subtracting the previous frame's start time from the current frame's start time.
//Update the current frame's start time to become the previous frame's start time so as to prepare for the next frame.
#include<chrono>

class TimeService {
private:
std::chrono::time_point<std::chrono::steady_clock> previous_time;

float delta_time;//to store the value of delta time
float calculate_delta_time();//calculate time by subtracting the previous time from the current time
void updatePreviousTime(); // finally update the current time to be previous time
void updateDeltaTime();
public:
void update();
void intialize();
float getdeltatime();



};
49 changes: 49 additions & 0 deletions Space-Invaders/Headers/main/GameService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

#include <SFML/Graphics.hpp>
#include"../Global/ServiceLocator.h"
enum class GameState //create the enum
{
BOOT,
MAIN_MENU,
GAMEPLAY,
};




namespace Main {

using namespace Global;

class GameService
{
private:


static GameState current_state;

ServiceLocator* service_locator;
sf::RenderWindow* game_window;

void initialize();
void initializeVariables();// Handles game initialization.
void destroy(); // Handles cleanup tasks.

public:

GameService(); // Constructor for initializing the GameService object.
~GameService(); // Destructor for cleaning up resources upon object deletion.

void ignite(); // Initiates the game.
void update(); // Updates the game logic and game state.
void render(); // Renders each frame of the game.
bool isRunning();// Checks if the game is currently running.
static void setGameState(GameState new_state);
static GameState getGameState();

void showmainmenu();


};
}
35 changes: 35 additions & 0 deletions Space-Invaders/Headers/player/PlayerController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once
#include<SFML/Graphics.hpp>
namespace player {

enum class PlayerState;
class PlayerView;
class PlayerModel;

class PlayerController {

private:



void processinput();
void processmoveleft();
void processmoveright();
public:

PlayerModel* model;
PlayerView* view;
PlayerController();
~PlayerController();
void intialize();
void update();
void render();




sf::Vector2f getPlayerPosition();

};

}
58 changes: 58 additions & 0 deletions Space-Invaders/Headers/player/PlayerModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#pragma once
#include <SFML/Graphics.hpp>
class PlayerView;
class PlayerModel;

namespace player {

enum class PlayerState //Our Enum
{
ALIVE,
DEAD,
// we will add more states later
};



class PlayerModel

{
private:

const sf::Vector2f initial_player_position = sf::Vector2f(950.f, 950.f); //new var
sf::Vector2f player_position; //new var
PlayerState player_state;
PlayerModel* model;
PlayerView* view;
int player_score = 0;


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

const float player_movement_speed = 350.0f;

PlayerModel();
~PlayerModel();

void initialize();

void reset(); //new method




//getters and setters
sf::Vector2f getPlayerPosition();
void setPlayerPosition(sf::Vector2f position);

PlayerState getplayerstate();


void setplayerstate(PlayerState state);



};
}
58 changes: 58 additions & 0 deletions Space-Invaders/Headers/player/PlayerService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#pragma once
#include<SFML/Graphics.hpp>"
#include"../TIME/TimeService .h"
#include"../player/PlayerController.h"


namespace player {
class PlayerService
{



private:



int health = 3;
sf::Vector2f position = sf::Vector2f(200.0f, 100.0f);
float movement_speed = 5.0f;
int player_score = 0;
const sf::Vector2f initial_player_position = sf::Vector2f(950.f, 950.f);

const sf::String player_texture_path = "assets/textures/player_ship.png";

sf::Texture player_texture;
sf::Sprite player_sprite;

sf::RenderWindow* game_window; //as always

void initializePlayerSprite();
void processPlayerInput();

PlayerController* player_controller;


public:


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

const float player_movement_speed = 350.0f;


PlayerService();
~PlayerService();

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

void moveLef();
void moveRight();
int getMoveSpeed();
sf::Vector2f getPlayerPosition();

};
}
Loading