Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9dd0ffb
Added LevelView
parthvaidya Dec 2, 2024
60c313c
Level Model and Controller added
parthvaidya Dec 2, 2024
6a42deb
Created LEVEL SELECTION UI
parthvaidya Dec 2, 2024
8687659
Updated service locator
parthvaidya Dec 2, 2024
57e823c
PlayerService and snakecontroller
parthvaidya Dec 2, 2024
5d11852
Snake controller updated
parthvaidya Dec 2, 2024
0f58c67
Position and Direction given
parthvaidya Dec 2, 2024
8f6243b
BodyPart added
parthvaidya Dec 2, 2024
9a1114f
BodyPart Draw
parthvaidya Dec 3, 2024
395fff5
CALCULATING SCREEN POSITION
parthvaidya Dec 3, 2024
a085f91
CALCULATING BODYPART'S NEXT POSITION
parthvaidya Dec 3, 2024
c5f8853
LinkedList created
parthvaidya Dec 3, 2024
626bbf7
Spawn Head
parthvaidya Dec 3, 2024
a848606
SPAWN SNAKE body
parthvaidya Dec 3, 2024
1b415ef
Implement Snake Movement
parthvaidya Dec 3, 2024
b079301
Screen wrapping is added
parthvaidya Dec 3, 2024
c62b359
Node collision processed
parthvaidya Dec 4, 2024
d02a0c9
Remove node at head
parthvaidya Dec 4, 2024
62dc531
Reset respawn and restart
parthvaidya Dec 4, 2024
6f84ca1
Added Input state
parthvaidya Dec 4, 2024
eb6c882
Obstacle added
parthvaidya Dec 4, 2024
a924a8c
Element Service added
parthvaidya Dec 4, 2024
64be30e
Food Item Added
parthvaidya Dec 5, 2024
f0b4161
Fodd Service Added
parthvaidya Dec 5, 2024
0483e3e
Random food spawning
parthvaidya Dec 5, 2024
9673cfb
Food Spawning In Intervals
parthvaidya Dec 5, 2024
ab36bdf
Refactor Snake Collision
parthvaidya Dec 5, 2024
0ece750
Revert "Refactor Snake Collision"
parthvaidya Dec 5, 2024
7b48873
Updated Snakecontroller
parthvaidya Dec 5, 2024
1e7cc3e
COLLISION DETECTION WITH ELEMENTS
parthvaidya Dec 5, 2024
082e1cd
Initialize Node
parthvaidya Dec 6, 2024
91f6a3e
Node at tail and head
parthvaidya Dec 6, 2024
113f071
Insert at index
parthvaidya Dec 6, 2024
555e82c
Inserting in middle
parthvaidya Dec 6, 2024
0ad5dff
Remove node
parthvaidya Dec 6, 2024
644217b
Deleted at the end
parthvaidya Dec 6, 2024
bc88c51
Split in the half
parthvaidya Dec 6, 2024
daaa523
Reversing the directtion
parthvaidya Dec 6, 2024
285798d
Food Collision
parthvaidya Dec 6, 2024
3327010
Gameplay UI Controller added
parthvaidya Dec 7, 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
31 changes: 31 additions & 0 deletions Linked-List-Snake/Linked-List-Snake.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,21 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="source\Element\ElementService.cpp" />
<ClCompile Include="source\Element\Obstacle.cpp" />
<ClCompile Include="source\Food\FoodItem.cpp" />
<ClCompile Include="source\Food\FoodService.cpp" />
<ClCompile Include="source\Level\LevelController.cpp" />
<ClCompile Include="source\Level\LevelModel.cpp" />
<ClCompile Include="source\Level\LevelView.cpp" />
<ClCompile Include="source\LinkedList\SingleLinkedList.cpp" />
<ClCompile Include="source\Player\BodyPart.cpp" />
<ClCompile Include="source\Player\PlayerService.cpp" />
<ClCompile Include="source\Player\SnakeController.cpp" />
<ClCompile Include="source\Time\TimeService.cpp" />
<ClCompile Include="source\UI\Credits\CreditsScreenUIController.cpp" />
<ClCompile Include="source\UI\Instructions\InstructionsScreenUIController.cpp" />
<ClCompile Include="source\UI\LevelSelection\LevelSelectionUIController.cpp" />
<ClCompile Include="source\UI\UIElement\AnimatedImageView.cpp" />
<ClCompile Include="source\UI\UIElement\ButtonView.cpp" />
<ClCompile Include="source\Global\Config.cpp" />
Expand All @@ -148,14 +160,32 @@
<ClCompile Include="source\Global\ServiceLocator.cpp" />
<ClCompile Include="source\Sound\SoundService.cpp" />
<ClCompile Include="source\UI\SplashScreen\SplashScreenUIController.cpp" />
<ClCompile Include="source\UI\UIElement\RectangleShapeView.cpp" />
<ClCompile Include="source\UI\UIElement\TextView.cpp" />
<ClCompile Include="source\UI\UIService.cpp" />
<ClCompile Include="source\UI\UIElement\UIView.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\Element\ElementData.h" />
<ClInclude Include="include\Element\ElementService.h" />
<ClInclude Include="include\Element\Obstacle.h" />
<ClInclude Include="include\Food\FoodItem.h" />
<ClInclude Include="include\Food\FoodService.h" />
<ClInclude Include="include\Food\FoodType.h" />
<ClInclude Include="include\Level\LevelController.h" />
<ClInclude Include="include\Level\LevelData.h" />
<ClInclude Include="include\Level\LevelModel.h" />
<ClInclude Include="include\Level\LevelView.h" />
<ClInclude Include="include\LinkedList\SingleLinkedList.h" />
<ClInclude Include="include\Player\BodyPart.h" />
<ClInclude Include="include\Player\Direction.h" />
<ClInclude Include="include\Player\Node.h" />
<ClInclude Include="include\Player\PlayerService.h" />
<ClInclude Include="include\Player\SnakeController.h" />
<ClInclude Include="include\Time\TimeService.h" />
<ClInclude Include="include\UI\Credits\CreditsScreenUIController.h" />
<ClInclude Include="include\UI\Instructions\InstructionsScreenUIController.h" />
<ClInclude Include="include\UI\LevelSelection\LevelSelectionUIController.h" />
<ClInclude Include="include\UI\UIElement\AnimatedImageView.h" />
<ClInclude Include="include\UI\UIElement\ButtonView.h" />
<ClInclude Include="include\Global\Config.h" />
Expand All @@ -168,6 +198,7 @@
<ClInclude Include="include\Global\ServiceLocator.h" />
<ClInclude Include="include\Sound\SoundService.h" />
<ClInclude Include="include\UI\SplashScreen\SplashScreenUIController.h" />
<ClInclude Include="include\UI\UIElement\RectangleShapeView.h" />
<ClInclude Include="include\UI\UIElement\TextView.h" />
<ClInclude Include="include\UI\UIService.h" />
<ClInclude Include="include\UI\UIElement\UIView.h" />
Expand Down
99 changes: 99 additions & 0 deletions Linked-List-Snake/Linked-List-Snake.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,48 @@
<ClCompile Include="source\UI\Instructions\InstructionsScreenUIController.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\Time\TimeService.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\Level\LevelView.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\UI\UIElement\RectangleShapeView.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\Level\LevelModel.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\Level\LevelController.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\UI\LevelSelection\LevelSelectionUIController.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\Player\SnakeController.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\Player\PlayerService.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\Player\BodyPart.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\LinkedList\SingleLinkedList.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\Element\Obstacle.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\Element\ElementService.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\Food\FoodItem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\Food\FoodService.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\Main\GameService.h">
Expand Down Expand Up @@ -119,5 +161,62 @@
<ClInclude Include="include\UI\Instructions\InstructionsScreenUIController.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Time\TimeService.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Level\LevelView.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\UI\UIElement\RectangleShapeView.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Level\LevelModel.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Level\LevelController.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Level\LevelData.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\UI\LevelSelection\LevelSelectionUIController.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Player\SnakeController.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Player\PlayerService.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Player\Direction.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Player\BodyPart.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Player\Node.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\LinkedList\SingleLinkedList.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Element\ElementData.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Element\Obstacle.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Element\ElementService.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Food\FoodType.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Food\FoodItem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Food\FoodService.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
22 changes: 22 additions & 0 deletions Linked-List-Snake/include/Element/ElementData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#include <SFML/System/Vector2.hpp>

namespace Element
{
enum class ElementType
{
OBSTACLE,
};

struct ElementData
{
ElementData(ElementType type, sf::Vector2i pos)
{
element_type = type;
position = pos;
}

ElementType element_type;
sf::Vector2i position;
};
}
27 changes: 27 additions & 0 deletions Linked-List-Snake/include/Element/ElementService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include <vector>
#include <SFML/System/Vector2.hpp>

namespace Element
{
class Obstacle;
struct ElementData;

class ElementService
{
private:
std::vector<Obstacle*> obstacle_list;

void spawnObstacle(sf::Vector2i position, float cell_width, float cell_height);

public:
ElementService();
~ElementService();

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

const void spawnElements(std::vector<ElementData>& element_data_list, float cell_width, float cell_height);
};
}
29 changes: 29 additions & 0 deletions Linked-List-Snake/include/Element/Obstacle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#pragma once
#include <SFML/Graphics.hpp>
#include "UI/UIElement/ImageView.h"

namespace Element
{
class Obstacle
{
private:
UI::UIElement::ImageView* obstacle_image;

sf::Vector2i grid_position;

float cell_width;
float cell_height;

void initializeObstacleImage();
sf::Vector2f getObstacleImagePosition();

public:
Obstacle();
~Obstacle();

void initialize(sf::Vector2i grid_pos, float width, float height);
void update();
void render();
};
}
37 changes: 37 additions & 0 deletions Linked-List-Snake/include/Food/FoodItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once
#include <SFML/Graphics.hpp>
#include "UI/UIElement/ImageView.h"

namespace Food
{
enum class FoodType;

class FoodItem
{
private:
UI::UIElement::ImageView* food_image;

sf::Vector2i grid_position;

float cell_width;
float cell_height;

FoodType food_type;

void initializeFoodImage();
sf::String getFoodTexturePath();
sf::Vector2f getFoodImagePosition();

public:
static const int number_of_foods = 8;

FoodItem();
~FoodItem();

void initialize(sf::Vector2i grid_pos, float width, float height, FoodType type);
void update();
void render();

FoodType getFoodType();
};
}
61 changes: 61 additions & 0 deletions Linked-List-Snake/include/Food/FoodService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once
#include <SFML/System/Vector2.hpp>
#include <random>
#include <vector>

namespace Food
{
enum class FoodType;
class FoodItem;

enum FoodSpawningStatus
{
ACTIVE,
IN_ACTIVE,
};

class FoodService
{
private:
const float spawn_duration = 4.f;

float elapsed_duration;

FoodSpawningStatus current_spawning_status;
FoodItem* current_food_item;

float cell_width;
float cell_height;

// To generate random values.
std::default_random_engine random_engine;

// To give random seed to generator.
std::random_device random_device;

FoodItem* createFood(sf::Vector2i position, FoodType type);
void spawnFood();

sf::Vector2i getValidSpawnPosition();
sf::Vector2i getRandomPosition();
FoodType getRandomFoodType();

bool isValidPosition(std::vector<sf::Vector2i> position_data, sf::Vector2i food_position);

void destroyFood();
void updateElapsedDuration();
void handleFoodSpawning();
void reset();

public:
FoodService();
~FoodService();

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

void startFoodSpawning();
void stopFoodSpawning();
};
}
15 changes: 15 additions & 0 deletions Linked-List-Snake/include/Food/FoodType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
namespace Food
{
enum class FoodType
{
APPLE,
MANGO,
ORANGE,
PIZZA,
BURGER,
CHEESE,
POISION,
ALCOHOL,
};
}
1 change: 1 addition & 0 deletions Linked-List-Snake/include/Global/ServiceLocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Global
private:
Event::EventService* event_service;
Graphics::GraphicService* graphic_service;
//Level::LevelService* level_service;
Sound::SoundService* sound_service;
UI::UIService* ui_service;
Time::TimeService* time_service;
Expand Down
Loading