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

Create code to render Player #4

Open
wants to merge 8 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
20 changes: 19 additions & 1 deletion Array-Jumper/Array-Jumper.vcxproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
Expand Down Expand Up @@ -137,6 +137,14 @@
<ClCompile Include="source\Event\EventService.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="source\Global\ServiceLocator.cpp" />
<ClCompile Include="source\Level\LevelController.cpp" />
<ClCompile Include="source\Level\LevelModel.cpp" />
<ClCompile Include="source\Level\LevelService.cpp" />
<ClCompile Include="source\Level\LevelView.cpp" />
<ClCompile Include="source\Player\PlayerController.cpp" />
<ClCompile Include="source\Player\PlayerModel.cpp" />
<ClCompile Include="source\Player\PlayerService.cpp" />
<ClCompile Include="source\Player\PlayerView.cpp" />
<ClCompile Include="source\Sound\SoundService.cpp" />
<ClCompile Include="source\Main\GameService.cpp" />
<ClCompile Include="source\Graphics\GraphicService.cpp" />
Expand All @@ -154,6 +162,16 @@
<ItemGroup>
<ClInclude Include="header\Global\Config.h" />
<ClInclude Include="header\Event\EventService.h" />
<ClInclude Include="header\Level\BlockType.h" />
<ClInclude Include="header\Level\LevelController.h" />
<ClInclude Include="header\Level\LevelData.h" />
<ClInclude Include="header\Level\LevelModel.h" />
<ClInclude Include="header\Level\LevelService.h" />
<ClInclude Include="header\Level\LevelView.h" />
<ClInclude Include="header\Player\PlayerController.h" />
<ClInclude Include="header\Player\PlayerModel.h" />
<ClInclude Include="header\Player\PlayerService.h" />
<ClInclude Include="header\Player\PlayerView.h" />
<ClInclude Include="header\Sound\SoundService.h" />
<ClInclude Include="header\Main\GameService.h" />
<ClInclude Include="header\Graphics\GraphicService.h" />
Expand Down
17 changes: 17 additions & 0 deletions Array-Jumper/Array-Jumper.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
<ClCompile Include="source\UI\UIElement\ImageView.cpp" />
<ClCompile Include="source\UI\UIElement\TextView.cpp" />
<ClCompile Include="source\UI\UIElement\UIView.cpp" />
<ClCompile Include="source\Player\PlayerModel.cpp" />
<ClCompile Include="source\Player\PlayerView.cpp" />
<ClCompile Include="source\Player\PlayerController.cpp" />
<ClCompile Include="source\Player\PlayerService.cpp" />
<ClCompile Include="source\Level\LevelModel.cpp" />
<ClCompile Include="source\Level\LevelView.cpp" />
<ClCompile Include="source\Level\LevelController.cpp" />
<ClCompile Include="source\Level\LevelService.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="header\Main\GameService.h">
Expand Down Expand Up @@ -74,6 +82,15 @@
<ClInclude Include="header\UI\UIElement\ImageView.h" />
<ClInclude Include="header\UI\UIElement\TextView.h" />
<ClInclude Include="header\UI\UIElement\UIView.h" />
<ClInclude Include="header\Player\PlayerModel.h" />
<ClInclude Include="header\Player\PlayerView.h" />
<ClInclude Include="header\Player\PlayerController.h" />
<ClInclude Include="header\Player\PlayerService.h" />
<ClInclude Include="header\Level\LevelModel.h" />
<ClInclude Include="header\Level\LevelController.h" />
<ClInclude Include="header\Level\LevelView.h" />
<ClInclude Include="header\Level\LevelService.h" />
<ClInclude Include="header\Level\BlockType.h" />
</ItemGroup>
<ItemGroup>
<Media Include="assets\sounds\background_music.mp3" />
Expand Down
6 changes: 6 additions & 0 deletions Array-Jumper/header/Global/ServiceLocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "../../header/Event/EventService.h"
#include "../../header/UI/UIService.h"
#include "../../header/Sound/SoundService.h"
#include "../../header/Player/PlayerService.h"
#include "../../header/Level/LevelService.h"

namespace Global
{
Expand All @@ -13,6 +15,8 @@ namespace Global
Event::EventService* event_service;
Sound::SoundService* sound_service;
UI::UIService* ui_service;
Player::PlayerService* player_service;
Level::LevelService* level_service;

~ServiceLocator();

Expand All @@ -31,5 +35,7 @@ namespace Global
Event::EventService* getEventService();
Sound::SoundService* getSoundService();
UI::UIService* getUIService();
Player::PlayerService* getPlayerService();
Level::LevelService* getLevelService();
};
}
11 changes: 11 additions & 0 deletions Array-Jumper/header/Level/BlockType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

enum class BlockType
{
OBSTACLE_ONE = -1,
OBSTACLE_TWO = -2,
TARGET = 0,
ONE = 1,
TWO = 2,
THREE = 3,
};
25 changes: 25 additions & 0 deletions Array-Jumper/header/Level/LevelController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
#include "BlockType.h"
#include "../../header/Level/LevelModel.h"
namespace Level
{
class LevelModel;
class LevelView;
class LevelController
{
public:
LevelController();
~LevelController();

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

BlockType getCurrentBoxValue(int currentPosion);
BoxDimension getBoxDimension();

private:
LevelModel* level_model;
LevelView* level_view;
};
}
26 changes: 26 additions & 0 deletions Array-Jumper/header/Level/LevelData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include "../../header/Level/BlockType.h"

namespace Level
{
struct LevelData
{
static const int number_of_box = 10;
BlockType level_boxes[number_of_box] = {
BlockType::ONE,
BlockType::TWO,
BlockType::OBSTACLE_ONE,
BlockType::TWO,
BlockType::THREE,
BlockType::ONE,
BlockType::OBSTACLE_TWO,
BlockType::TWO,
BlockType::ONE,
BlockType::TARGET
};



};
}

29 changes: 29 additions & 0 deletions Array-Jumper/header/Level/LevelModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#include "../../header/Level/LevelData.h"
namespace Level
{
struct BoxDimension
{
float box_width;
float box_height;

float box_spacing;

float box_spacing_percentage = 0.3f;
float bottom_offset = 200.f;

};
class LevelModel
{
public:
LevelModel();
~LevelModel();

BlockType getCurrentBoxValue(int currentPosion);

private:
LevelData current_level_data;
};


}
22 changes: 22 additions & 0 deletions Array-Jumper/header/Level/LevelService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
namespace Level
{
struct BoxDimension;
class LevelController;
class LevelService
{
public:
LevelService();
~LevelService();

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

BoxDimension getBoxDimension();

private:
LevelController* level_controller;
};

}
54 changes: 54 additions & 0 deletions Array-Jumper/header/Level/LevelView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma once
#include "../../header/UI/UIElement/ImageView.h"
#include "LevelModel.h"
namespace Level
{
class LevelController;
class LevelView
{
public:
LevelView(LevelController* controller);
~LevelView();

void initilaize();
void update();
void render();

void calculateBoxWidthHeightDimension();
void calculateBoxSpacing();
void calcuateBoxDimension();
sf::Vector2f calculateBoxPosition(int index);
UI::UIElement::ImageView* getBoxImage(BlockType type);

void drawBox(sf::Vector2f position);
void drawBoxValue(sf::Vector2f position, BlockType type);

BoxDimension getBoxDimension();



private:
LevelController* level_controller;
UI::UIElement::ImageView* background_image;
UI::UIElement::ImageView* box_image;
sf::RenderWindow* game_window;

const float background_alpha = 110.f;

BoxDimension box_dimension;

UI::UIElement::ImageView* target_overlay_image;
UI::UIElement::ImageView* letter_one_overlay_image;
UI::UIElement::ImageView* letter_two_overlay_image;
UI::UIElement::ImageView* letter_three_overlay_image;
UI::UIElement::ImageView* obstacle_one_overlay_image;
UI::UIElement::ImageView* obstacle_two_overlay_image;

void createImage();
void initilizeImage();
void updateImage();
void drawImage();
void deleteImage();
};

}
28 changes: 28 additions & 0 deletions Array-Jumper/header/Player/PlayerController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
namespace Player
{
class PlayerModel;
class PlayerView;
enum class PlayerState;

class PlayerController
{
public:
PlayerController();
~ PlayerController();

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

PlayerState getPlayerState();
void setPlayerState(PlayerState state);
int getCurrentPosition();

private:
PlayerModel* player_model;
PlayerView* player_view;


};
}
26 changes: 26 additions & 0 deletions Array-Jumper/header/Player/PlayerModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
namespace Player
{
enum class PlayerState
{
ALIVE,
DEAD
};

class PlayerModel
{
public:

int getPosition();
void setPosition(int player_position);

PlayerState getPlayerState();
void setPlayerState(PlayerState state);
private:
int current_position;
PlayerState player_state;

};


}
20 changes: 20 additions & 0 deletions Array-Jumper/header/Player/PlayerService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
namespace Player
{
class PlayerController;
class PlayerService
{
public:
PlayerService();
~PlayerService();

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

private:
PlayerController* player_conroller;
};


}
40 changes: 40 additions & 0 deletions Array-Jumper/header/Player/PlayerView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once
#include "../../header/UI/UIElement/ImageView.h"
#include "../../header/Level/LevelModel.h"

namespace Player
{
using namespace Level;
class PlayerController;
class PlayerView
{
public:
PlayerView(PlayerController* controller);
~PlayerView();

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

BoxDimension current_box_dimensions;


private:
UI::UIElement::ImageView* player_image;
sf::RenderWindow* game_window;

PlayerController* player_controller;

float player_height;
float player_width;

void initializePlayerImage();
void drawPlayer();
void loadImage();
void calculatePlayerDimension();
void updatePlayerPosition();

sf::Vector2f calculatePlayerPosition();

};
}
Loading