From 5763171424137e4ff1b410b73c95522ff3d3a5d0 Mon Sep 17 00:00:00 2001 From: matangeorgi <87900560+matangeorgi@users.noreply.github.com> Date: Sun, 25 Jul 2021 14:50:25 +0300 Subject: [PATCH] Add files via upload --- include/CMakeLists.txt | 1 + include/Enemys/BadMushroom.h | 13 ++ include/Enemys/Enemy.h | 12 ++ include/Enemys/FlyingTortoise.h | 14 ++ include/Enemys/PiranaPlants.h | 13 ++ include/Enemys/Tortoise.h | 21 +++ include/GameHandlers/Board.h | 48 +++++ include/GameHandlers/Collision.h | 78 ++++++++ include/GameHandlers/Controller.h | 30 +++ include/GameHandlers/GameObject.h | 24 +++ include/GameHandlers/GameWindow.h | 45 +++++ include/Macros.h | 258 ++++++++++++++++++++++++++ include/MovingObjects/Animation.h | 35 ++++ include/MovingObjects/Fireworks.h | 13 ++ include/MovingObjects/MovingObject.h | 59 ++++++ include/MovingObjects/Pickable.h | 12 ++ include/MovingObjects/Platforms.h | 12 ++ include/MovingObjects/Player.h | 73 ++++++++ include/MovingObjects/SuperMushroom.h | 19 ++ include/Obstacles/FireBall.h | 14 ++ include/Obstacles/FirePole.h | 14 ++ include/Obstacles/Obstacle.h | 13 ++ include/Singleton/AudioHolder.h | 25 +++ include/Singleton/TextureHolder.h | 41 ++++ include/StaticObjects/Block.h | 13 ++ include/StaticObjects/Brick.h | 13 ++ include/StaticObjects/Coin.h | 18 ++ include/StaticObjects/Floor.h | 11 ++ include/StaticObjects/GoalFlag.h | 16 ++ include/StaticObjects/GoalPole.h | 16 ++ include/StaticObjects/Pipe.h | 12 ++ include/StaticObjects/QuestionBlock.h | 21 +++ include/StaticObjects/StaticObject.h | 13 ++ include/StaticObjects/UnPickable.h | 12 ++ 34 files changed, 1032 insertions(+) create mode 100644 include/CMakeLists.txt create mode 100644 include/Enemys/BadMushroom.h create mode 100644 include/Enemys/Enemy.h create mode 100644 include/Enemys/FlyingTortoise.h create mode 100644 include/Enemys/PiranaPlants.h create mode 100644 include/Enemys/Tortoise.h create mode 100644 include/GameHandlers/Board.h create mode 100644 include/GameHandlers/Collision.h create mode 100644 include/GameHandlers/Controller.h create mode 100644 include/GameHandlers/GameObject.h create mode 100644 include/GameHandlers/GameWindow.h create mode 100644 include/Macros.h create mode 100644 include/MovingObjects/Animation.h create mode 100644 include/MovingObjects/Fireworks.h create mode 100644 include/MovingObjects/MovingObject.h create mode 100644 include/MovingObjects/Pickable.h create mode 100644 include/MovingObjects/Platforms.h create mode 100644 include/MovingObjects/Player.h create mode 100644 include/MovingObjects/SuperMushroom.h create mode 100644 include/Obstacles/FireBall.h create mode 100644 include/Obstacles/FirePole.h create mode 100644 include/Obstacles/Obstacle.h create mode 100644 include/Singleton/AudioHolder.h create mode 100644 include/Singleton/TextureHolder.h create mode 100644 include/StaticObjects/Block.h create mode 100644 include/StaticObjects/Brick.h create mode 100644 include/StaticObjects/Coin.h create mode 100644 include/StaticObjects/Floor.h create mode 100644 include/StaticObjects/GoalFlag.h create mode 100644 include/StaticObjects/GoalPole.h create mode 100644 include/StaticObjects/Pipe.h create mode 100644 include/StaticObjects/QuestionBlock.h create mode 100644 include/StaticObjects/StaticObject.h create mode 100644 include/StaticObjects/UnPickable.h diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 0000000..c21d270 --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1 @@ +target_include_directories (SuperMario PRIVATE ${CMAKE_CURRENT_LIST_DIR}) diff --git a/include/Enemys/BadMushroom.h b/include/Enemys/BadMushroom.h new file mode 100644 index 0000000..4a5d800 --- /dev/null +++ b/include/Enemys/BadMushroom.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Enemy.h" + +class BadMushroom : public Enemy +{ +public: + BadMushroom(int row, int col); + + void move(sf::Time deltaTime) override; + ~BadMushroom(); +private: +}; \ No newline at end of file diff --git a/include/Enemys/Enemy.h b/include/Enemys/Enemy.h new file mode 100644 index 0000000..478d6ec --- /dev/null +++ b/include/Enemys/Enemy.h @@ -0,0 +1,12 @@ +#pragma once + +#include "MovingObject.h" + +class Enemy : public MovingObject +{ +public: + Enemy(const sf::Texture& data, bool dir, int size, int row, int col); + ~Enemy(); +private: + +}; \ No newline at end of file diff --git a/include/Enemys/FlyingTortoise.h b/include/Enemys/FlyingTortoise.h new file mode 100644 index 0000000..ada49c4 --- /dev/null +++ b/include/Enemys/FlyingTortoise.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Enemy.h" + +class FlyingTortoise : public Enemy +{ +public: + FlyingTortoise(int row, int col); + + void move(sf::Time deltaTime) override; + virtual void handleDeath(sf::Time deltaTime) override; + ~FlyingTortoise(); +private: +}; \ No newline at end of file diff --git a/include/Enemys/PiranaPlants.h b/include/Enemys/PiranaPlants.h new file mode 100644 index 0000000..e585855 --- /dev/null +++ b/include/Enemys/PiranaPlants.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Enemy.h" + +class PiranaPlants : public Enemy +{ +public: + PiranaPlants(int row, int col); + + virtual void move(sf::Time deltaTime) override; + ~PiranaPlants(); +private: +}; \ No newline at end of file diff --git a/include/Enemys/Tortoise.h b/include/Enemys/Tortoise.h new file mode 100644 index 0000000..6f733db --- /dev/null +++ b/include/Enemys/Tortoise.h @@ -0,0 +1,21 @@ +#pragma once + +#include "Enemy.h" + +class Tortoise : public Enemy +{ +public: + Tortoise(int row, int col); + + void setShell(); + bool getShell() const; + bool getJumped() const; + void setJumped(bool condition); + void setDirection(float playerPosX); + virtual void move(sf::Time deltaTime) override; + ~Tortoise(); + +private: + bool m_shell, + m_jumped; +}; \ No newline at end of file diff --git a/include/GameHandlers/Board.h b/include/GameHandlers/Board.h new file mode 100644 index 0000000..ff619a3 --- /dev/null +++ b/include/GameHandlers/Board.h @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include + +#include "MovingObject.h" +#include "StaticObject.h" +#include "Collision.h" + +class Board +{ +public: + Board(); + + int restartStage(); + void createObjects(); + bool isPlayerDead() const; + bool readMap(bool restart); + bool isStageCleared() const; + float WindowLeftBorder() const; + void moveObject(sf::Time deltaTime); + void createPlayer(int life, int coins, int score,int condition); + void getGameData(int& score, int& coins, int& life); + const sf::Sprite& drawToWindow(int& index_moving, int& index_static, + bool& moving, bool& statics, bool& firePoles) const; + + ~Board(); +private: + + void shootFireWorks(); + int marioState() const; + void tryMove(int index, sf::Time deltaTime); + void checkCollision(std::unique_ptr &object); + void buildObject(int row, int col, char element); + bool tryToDelete(GameObject* Obj); + + bool m_releasedShift; + Collision m_collision; + Player* m_player; + std::ifstream m_inputFile; + std::array m_map; + std::vector> m_static; + std::vector> m_moving; +}; + +static std::unique_ptr createMovingObj(int row, int col, char element); +static std::unique_ptr createStaticObj(int row, int col, char element); \ No newline at end of file diff --git a/include/GameHandlers/Collision.h b/include/GameHandlers/Collision.h new file mode 100644 index 0000000..eaf6634 --- /dev/null +++ b/include/GameHandlers/Collision.h @@ -0,0 +1,78 @@ +#pragma once + +#include +#include +#include + +#include "AudioHolder.h" +#include "BadMushroom.h" +#include "Block.h" +#include "Brick.h" +#include "Coin.h" +#include "FireBall.h" +#include "FirePole.h" +#include "Floor.h" +#include "FlyingTortoise.h" +#include "GoalFlag.h" +#include "Pipe.h" +#include "PiranaPlants.h" +#include "Platforms.h" +#include "QuestionBlock.h" +#include "SuperMushroom.h" +#include "GoalPole.h" +#include "Tortoise.h" +#include "Player.h" +#include "Fireworks.h" + +using HitFunctionPtrMove = void (*)(MovingObject&, MovingObject&); +using HitFunctionPtrStatic = void (*)(MovingObject&, StaticObject&); +using Key = std::pair; +using HitMapStatic = std::map; +using HitMapMove = std::map; + +class Collision +{ +public: + Collision(); + void processMovCollision(MovingObject& object1, + MovingObject& object2); + void processStaticCollision(MovingObject& object1, + StaticObject& object2); + + ~Collision(); + +private: + HitFunctionPtrMove lookupMove(const std::type_index& class1, const std::type_index& class2); + HitFunctionPtrStatic lookupStatic(const std::type_index& class1, const std::type_index& class2); + HitMapMove initializeMovingCollision(); + HitMapStatic initializeStaticCollision(); +}; +void playerTortoise(MovingObject& player, MovingObject& tortoise); +void playerPlatforms(MovingObject& player, MovingObject& platforms); +void badMushroomTortoise(MovingObject& badMushroom, MovingObject& tortoise); +void playerSupermushroom(MovingObject& player, MovingObject& superMushroom); +void playerBadMushroomOrFly(MovingObject& player, MovingObject& badMushroom); +void playerPiranaPlants(MovingObject& player, MovingObject& piranaPlants); +void playerFireBallPole(MovingObject& player, MovingObject& fireBall); +void EnemyStatic(MovingObject& enemy, StaticObject& staticObj); +void PlayerQuestionBlock(MovingObject& player, MovingObject& questionBlock); +void PlayerCoin(MovingObject& player, MovingObject& coin); +void PlayerFloor(MovingObject& player, StaticObject& floor); +void PlayerStaticCollision(MovingObject& player, StaticObject& staticObj); +int getHeightStatic(MovingObject& player, StaticObject& staticObj); +int getHeightMoving(MovingObject& player, MovingObject& Obj); +bool checkAbove(MovingObject& player, int neededHeight); +bool checkBeneath(MovingObject& player, MovingObject& staticObj); +void checkSides(MovingObject& player, bool condition); +void InitializePoints(sf::Sprite rect, sf::Vector2f& bottomLeft,sf::Vector2f& bottomRight, sf::Vector2f& middlePoint); +void PlayerPipeBlock(MovingObject& player, StaticObject& obj); +void MovingBrick(MovingObject& movable, MovingObject& brick); +void badMushroomBadMushroom(MovingObject& badMushroom1, MovingObject& badMushroom2); +void tortoiseTortoise(MovingObject& tortoise1, MovingObject& tortoise2); +void questionBlockSupMush(MovingObject& questionBlock, MovingObject& superMushroom); +void questionBlockCoin(MovingObject& coin, MovingObject& questionBlock); +void FlagPole(MovingObject& flag, StaticObject& pole); +void PlayerPole(MovingObject& player, StaticObject& pole); +void fireworksEnemy(MovingObject& fireworks, MovingObject& enemy); +void fireworksObj(MovingObject& fireworks, MovingObject& Obj); +void fireworksStaticObj(MovingObject& fireworks, StaticObject& staticObj); diff --git a/include/GameHandlers/Controller.h b/include/GameHandlers/Controller.h new file mode 100644 index 0000000..a02f98a --- /dev/null +++ b/include/GameHandlers/Controller.h @@ -0,0 +1,30 @@ +#pragma once + +#include "Board.h" +#include "GameWindow.h" + +class Controller +{ +public: + Controller(); + + void startMenu(); + ~Controller(); + +private: + + void exitGame(); + void startGame(); + void openLeaderBoard(); + void handleLeaderBoard(int score); + bool gameConditions(bool& playerDied) const; + void handleEndGame(int score, bool finishedGame); + void handleObjectCreation(int& condition, int world, + bool& finishedGame, bool playerDied); + void pause(bool& spacePressed, bool& paused, sf::Clock& clock); + bool outOfTime(float timeRemained, bool& playerDied, int& life); + + bool m_startOver; + Board m_board; + GameWindow m_window; +}; \ No newline at end of file diff --git a/include/GameHandlers/GameObject.h b/include/GameHandlers/GameObject.h new file mode 100644 index 0000000..332e1bf --- /dev/null +++ b/include/GameHandlers/GameObject.h @@ -0,0 +1,24 @@ +#pragma once + +#include "TextureHolder.h" +#include "AudioHolder.h" + +class GameObject +{ +public: + GameObject(int row, int col); + + sf::Vector2f getPos() const; + bool isFirePole() const; + const sf::Sprite& draw() const; + bool isDelete() const; + void setDelete(); + virtual ~GameObject() = default; + +protected: + sf::Sprite m_sprite; + bool m_delete, + m_firePole; + +private: +}; \ No newline at end of file diff --git a/include/GameHandlers/GameWindow.h b/include/GameHandlers/GameWindow.h new file mode 100644 index 0000000..f3be583 --- /dev/null +++ b/include/GameHandlers/GameWindow.h @@ -0,0 +1,45 @@ +#pragma once + +#include +#include +#include + +#include "TextureHolder.h" +#include "AudioHolder.h" +#include "Board.h" + +class GameWindow +{ +public: + GameWindow(); + + void closeWindow(); + int openMenu(); + void leaderBoard(); + void finishScreen(); + bool isExitPressed(); + bool isWindowOpen() const; + void setBGStage(const int stage); + void messageScreen(std::string message, int sleep); + void buildMap(const Board& board, int timeRemained, float leftBorder); + void printText(float leftBorder, int score, int coins, int world, int time, int life); + ~GameWindow(); + +private: + + int runMenu(); + void readFromFile(); + void initializeText(); + void initializeScore(); + void initializeMenuText(); + int buttonPressed(sf::Event event)const; + + sf::Font m_font; + sf::Text m_finishText; + sf::Sprite m_background; + sf::RenderWindow m_window; + std::vector m_leaderVec; + std::array m_message; + std::array m_menuText; + std::array m_leaderText; +}; \ No newline at end of file diff --git a/include/Macros.h b/include/Macros.h new file mode 100644 index 0000000..94400f6 --- /dev/null +++ b/include/Macros.h @@ -0,0 +1,258 @@ +#pragma once + +// ------------------- Texture Holder Consts ---------------- +const int I_PLAYER = 0; +const int I_ENEMY = 1; +const int I_WALL = 2; +const int I_COIN = 3; +const int I_GOAL_FLAG = 4; +const int I_MENU = 5; +const int I_LEVELS = 6; +const int I_OBSTACLES = 7; +const int I_STATIC = 8; +const int I_GOOD_OBJ = 9; +const int I_FIREWORKS = 10; + +const int I_FLOOR = 0; +const int I_BRICK = 1; +const int I_BLOCK = 2; +const int I_QUESTION = 3; + +const int I_POLE = 0; +const int I_FLAG = 1; + +const int LEVEL_ONE = 0; +const int LEVEL_TWO = 1; + +const int I_FIREBALL = 0; +const int I_FIREPOLE = 1; + +const int I_PIPE = 0; +const int I_PLATFORM = 1; + +const int I_SUPER_MUSH = 0; +const int I_FIRE_FLOWER = 1; + +const int I_MENU_SCREEN = 0; +const int I_QUIT_SCREEN = 1; +const int I_LEADERBOARD_SCREEN = 2; + +const int I_MARIO = 0; +const int I_S_MARIO = 1; +const int I_F_MARIO = 2; +const int I_BADMUSHROOM = 0; +const int I_TORTOISE = 1; +const int I_F_TORTOISE = 2; +const int I_PIRANA = 3; + +const int PIRANA_SIZE = 3; +const int BAD_MUSH_SIZE = 3; +const int F_TORTOISE_SIZE = 3; +const int TORTOISE_SIZE = 3; +const int MARIO_SIZE = 9; +const int S_MARIO_SIZE = 9; +const int F_MARIO_SIZE = 10; +const int QUESTION_SIZE = 4; +const int COIN_SIZE = 5; +const int FIRE_SIZE = 2; + +const int PLAYER_STAND = 0; +const int PLAYER_WALK_FIRST = 1; +const int PLAYER_WALK_END = 3; +const int PLAYER_JUMP = 4; +const int PLAYER_SLIP = 5; +const int PULLING_PIC = 6; +const int PLAYER_D = 8; +const int PLAYER_FIRE = 9; + +//---------------- Player Consts -------------------- +const int START_LIFE = 3; +const int ERROR_SPACE = 1; +const int MARIO_END_POS = 130; +const int SUP_MARIO_END_POS = 120; + +const int KILL_POINTS = 100; +const int COIN_POINTS = 50; +const int SUPER_POINTS = 500; + +//---------------- SuperMushroom Consts -------------------- +const bool FIREFLOWER = true; +const bool SUPERMUSH = false; + +//------------------- Animation Consts ----------------- +const float SWITCH = 0.2; +const float SWITCH_PIRANA = 0.4; +const float FIRE_POLE_SWITCH = 0.05; +const float COIN_SWITCH = 0.15; +const int PULING_TIME = 5; +const int FIREPOLE_SPEED = 120; +const float FIRE_DEATH_TIME = 0.5; + +const int DEATH_TIME = 1; +const int PLAYER_DEATH_TIME = 5; +const int INVINCIBLE_TIME = 3; + +const int MARIO_LOCATION = 5; + +//------------------- Movements Consts ----------------- +const bool RIGHT = true; +const bool LEFT = false; +const bool UP = true; +const bool DOWN = false; + +const int PIRANA_SPEED = 10; +const float ENEMY_SPEED = 20; +const int FIREWORKS_SPEED = 100; +const float SHELL_SPEED = 120; +const int MIN_HEIGHT = 135; +const int MAX_HEIGHT = 50; +const int FIRE_BALL_HEIGHT = 100; +const int TORTOISE_GAP = 4; +const int MUSHROOM_GAP = 2; + +const float MIN_VELOCITY_X = 0.01; +const float MIN_DEC = 0.0001; +const float CHANGE_DIR_TIME = 0.8; +const int STOP_POINT = 5; + +const float START_VEL = 0.05; +const float BRICK_MOVE = 0.18; +const int FALLING_VEL = 2; +const float TOP_FALL_SPEED = 200; +const float BUMP = -0.4; +const float SQUARE_BUMP = -0.1; +const float PIRANA_MOV = 2.5; +const float ACCELERATION = 0.12; +const float JUMP_START = -0.55f; +const float JUMP_DEC = 0.5f; +const float DRAG = 0.25f; +const float VEL_MAX = 230.f; +const float VEL_MIN = 20.f; +const float HEIGHT_MAX = 56.f; +const int BRICK_BUMP = 25; +const int STATIC_GAP = 3; +const int GAP_BENEATH = 2; +const int FLIP = 180; + +// ------------ Board Consts -------------- +const int ROWS = 13; +const int ICON_SIZE = 14; + +// ------------ Scale Consts -------------- +const float POLE_SCALE = 0.25; +const float PIRANA_SCALE = 0.25; +const float BLOCK_SCALE = 0.4375; +const float BRICK_SCALE = 0.4375; +const float PIPE_SCALE = 0.4375; +const float FLOOR_SCALE = 0.875; +const float QUESTION_SCALE = 0.875; +const float PLAT_X_SCALE = 0.3; +const float PLAT_Y_SCALE = 0.4; +const float SCALE = 0.15; + +// ------------ Position Consts -------------- +const int COIN_X_POS = 3; +const int COIN_Y_POS = 2; +const int FLAG_X_POS = 8; +const int FLAG_Y_POS = -6; +const int PIPE_X_POS = 5; +const int PIPE_Y_POS = -7.5; +const float POLE_Y_POS = -7.5; +const float TORTOISE_Y_POS = -10; +const int FIREWORK_Y_POS = 5; + +const int FLAG_DISTANCE = 5; + +const float BRICK_GAP = 0.09; + +// ------------ Window options Consts -------------- +const int WIDTH = 1800; +const int HEIGHT = 700; +const int WINDOW_GAP = 50; +const int VIEW_HEIGHT = 182; +const int VIEW_WIDTH = 468; +const int THICKNESS = 5; +const int FONT_SIZE = 60; +const int START_X = 590; +const int START_Y = 50; +const int SCORE_X = 670; +const int SCORE_Y = 150; +const int EXIT_X = 680; +const int EXIT_Y = 250; +const int SLEEP = 4; +const int EXIT_SLEEP = 2; +const int LEADERS = 6; +const int LEADER_X = 700; +const int LEADER_Y = 150; +const int LEADER_GAP = 50; + + +const int SCORE = 0; +const int COINS = 1; +const int WORLD = 2; +const int TIME = 3; +const int LIFE = 4; + +const int STAGE_X = 134; +const int STAGE_Y = 70; +const int SCORES_X = 15; +const int COINS_X = 115; +const int WORLD_X = 210; +const int TIME_X = 310; +const int LIFE_X = 395; +const int GAME_Y = 2; +const int GAME_FONT_SIZE = 15; + +const int MESSAGES = 5; + +// ------------ Menu options Consts -------------- +const int QUIT = 0; +const int START = 1; +const int LEADER_BOARD = 2; +const int MENU_MESSAGES = 3; + +const int BACK = 3; + +// ------------ Reading map Consts -------------- +const char PLAYER = 'X'; +const char TORTOISE = 'T'; +const char PIRANA_PLANT = 'Y'; +const char FLYING_TORTOISE = 'A'; +const char BAD_MUSHROOM = 'M'; +const char FLOOR = '#'; +const char BLOCK = 'B'; +const char QUESTION = '?'; +const char BRICK = '&'; +const char COIN = '$'; +const char GOAL_FLAG = 'F'; +const char GOAL_POLE = 'J'; +const char SUPER_MUSH = 'S'; +const char PLATFORM = 'L'; +const char FIRE_BALL = 'O'; +const char FIRE_POLE = 'I'; +const char FIRE_FLOWER = 'K'; +const char PIPE = 'P'; +const char MENU = 'U'; +const char AIR = ' '; +const char FIREWORKS = '*'; + +// ------------ Controller Consts -------------- +const int STAGE_TIME = 200; + +// ------------ Audio Holder Consts -------------- +const int AUDIOS = 12; +const int AUDIO_KILL = 0; +const int AUDIO_JUMP = 1; +const int AUDIO_FIRE = 2; +const int AUDIO_COIN = 3; +const int AUDIO_FINISH_STAGE = 4; +const int AUDIO_LOST = 5; +const int AUDIO_BUMP = 6; +const int AUDIO_PAUSE = 7; +const int AUDIO_DEATH = 8; +const int AUDIO_BACKGROUND = 9; +const int AUDIO_SUPER =10; +const int AUDIO_WON = 11; + +// ------------ General Consts -------------- +const int NONE = -1; diff --git a/include/MovingObjects/Animation.h b/include/MovingObjects/Animation.h new file mode 100644 index 0000000..02cc7d4 --- /dev/null +++ b/include/MovingObjects/Animation.h @@ -0,0 +1,35 @@ +#pragma once + +#include "Macros.h" +#include + +class Animation +{ +public: + Animation(const sf::Texture& data, bool dir, sf::Sprite& sprite, int size); + + void setDeadSprite(); + void setDirection(bool Direction); + void initializeTexture(int size); + void pullingFlag(sf::Time deltaTime); + void changeMarioTexture(const sf::Texture& data, int size); + void staticShift(sf::Time deltaTime, float switchTime); + void updatePlayer(bool direction, bool standing, bool fire, + bool inAir, bool duck, float velocity, sf::Time deltaTime); + + ~Animation(); + +private: + void duckFunc(); + void fireFunc(); + void standFunc(); + + bool m_dir; + sf::Sprite& m_sprite; + sf::IntRect m_uvRect; + sf::Texture m_data; + + int m_size, + m_current; + float m_totalTime; +}; diff --git a/include/MovingObjects/Fireworks.h b/include/MovingObjects/Fireworks.h new file mode 100644 index 0000000..e951c8f --- /dev/null +++ b/include/MovingObjects/Fireworks.h @@ -0,0 +1,13 @@ +#pragma once + +#include "MovingObject.h" + +class Fireworks : public MovingObject +{ +public: + Fireworks(sf::Vector2f playerPos, bool direction); + + virtual void move(sf::Time deltaTime) override; + ~Fireworks(); +private: +}; \ No newline at end of file diff --git a/include/MovingObjects/MovingObject.h b/include/MovingObjects/MovingObject.h new file mode 100644 index 0000000..fa30380 --- /dev/null +++ b/include/MovingObjects/MovingObject.h @@ -0,0 +1,59 @@ +#pragma once + +#include "GameObject.h" +#include "Animation.h" + +class MovingObject : public GameObject +{ +public: + MovingObject(const sf::Texture& data, bool dir, int size,int row, int col); + + void bump(); + void kill(); + void setToAir(); + void squareBump(); + void setGrounded(); + bool isDead() const; + void setUniqueKill(); + void setPreviousPos(); + void decideDirection(); + void fall(sf::Time deltaTime); + int getGatheredPoints() const; + virtual bool isShouldMove() const; + void setDirection(bool direction); + void addGatheredPoints(int points); + sf::Vector2f getDirectionVec() const; + virtual void move(sf::Time deltaTime); + void elevate(const MovingObject& platform); + virtual void squareMove(sf::Time deltaTime); + void handleDeathTortoise(sf::Time deltaTime); + ~MovingObject(); + +protected: + void goDown(); + void goUp(); + void goRight(); + void goLeft(); + + virtual void handleDeath(sf::Time deltaTime); + void sideMove(sf::Time deltaTime, float speed); + void upDownMove(sf::Time deltaTime, float speed, int top, int bottom, float switchTime); + + Animation m_animation; + sf::Vector2f m_lastPos, + m_velocity; + + bool m_dir, + m_dead, + m_air, + m_shouldMove, + m_tortoiseKill; + + float m_deathTimePassed; + int m_gatheredPoints; + +private: + + float m_directionChange; + +}; \ No newline at end of file diff --git a/include/MovingObjects/Pickable.h b/include/MovingObjects/Pickable.h new file mode 100644 index 0000000..2af5e5c --- /dev/null +++ b/include/MovingObjects/Pickable.h @@ -0,0 +1,12 @@ +#pragma once + +#include "MovingObject.h" + +class Pickable : public MovingObject +{ +public: + Pickable(const sf::Texture& data, bool dir, int size, int row, int col); + ~Pickable(); +private: + +}; \ No newline at end of file diff --git a/include/MovingObjects/Platforms.h b/include/MovingObjects/Platforms.h new file mode 100644 index 0000000..4229ea3 --- /dev/null +++ b/include/MovingObjects/Platforms.h @@ -0,0 +1,12 @@ +#pragma once + +#include "MovingObject.h" + +class Platforms : public MovingObject +{ +public: + Platforms(int row, int col); + void move(sf::Time deltaTime) override; + ~Platforms(); +private: +}; \ No newline at end of file diff --git a/include/MovingObjects/Player.h b/include/MovingObjects/Player.h new file mode 100644 index 0000000..3d6dd13 --- /dev/null +++ b/include/MovingObjects/Player.h @@ -0,0 +1,73 @@ +#pragma once + +#include "MovingObject.h" + +class Player : public MovingObject +{ +public: + Player(int life,int score, int coins, int condition); + + void addCoin(); + void decLife(); + void setPoleDown(); + int getLife() const; + int getCoins() const; + bool isFiery() const; + int getPoints() const; + void transformMario(); + bool getDirection() const; + bool isInvincible() const; + void addPoints(int points); + void transformSuperMario(); + void transformFieryMario(); + bool isStageCleared() const; + float getLeftBorder() const; + bool isFieryOrSuper() const; + void setBrickCond(bool condition); + void resetVelocity(bool condition); + virtual void move(sf::Time deltaTime); + void reachedFlagActions(sf::Time deltaTime); + ~Player(); + +private: + void checkGoLeft(); + void varInitialize(); + void handleMovement(); + void updateLeftBorder(); + void checkStatusJump(); + void jump(sf::Time deltaTime); + void goLeft(sf::Time deltaTime); + void goRight(sf::Time deltaTime); + void moveUpDown(sf::Time deltaTime); + void moveToSides(sf::Time deltaTime); + void decVelocityX(sf::Time deltaTime); + void directionChanged(sf::Time deltaTime); + void handleInvincible(sf::Time deltaTime); + virtual void handleDeath(sf::Time deltaTime) override; + void makeAMove(const float dir_x, sf::Time deltaTime); + void playerCheckFalling(bool falling, sf::Time deltaTime); + + bool m_changedDirection, + m_reachedTop, + m_startedJump, + m_jumpPressed, + m_hitBrick, + m_hitSideObj, + m_upKeyReleased, + m_duck, + m_keepDucking, + m_superMario, + m_fieryMario, + m_invincible, + m_poleDown, + m_stageFinished, + m_jumped; + + float m_startHeight, + m_leftBorder, + m_invincibleTime; + + int m_life, + m_points, + m_coins; +}; \ No newline at end of file diff --git a/include/MovingObjects/SuperMushroom.h b/include/MovingObjects/SuperMushroom.h new file mode 100644 index 0000000..45ba40b --- /dev/null +++ b/include/MovingObjects/SuperMushroom.h @@ -0,0 +1,19 @@ +#pragma once + +#include "Pickable.h" + +class SuperMushroom : public Pickable +{ +public: + SuperMushroom(int row, int col); + + void setShouldMove(); + bool getKind() const; + void setKind(bool kind); + virtual void move(sf::Time deltaTime); + ~SuperMushroom(); + +private: + bool m_kind, + m_rising; +}; \ No newline at end of file diff --git a/include/Obstacles/FireBall.h b/include/Obstacles/FireBall.h new file mode 100644 index 0000000..d99fc69 --- /dev/null +++ b/include/Obstacles/FireBall.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Obstacle.h" + +class FireBall : public Obstacle +{ +public: + FireBall(int row, int col); + + void move(sf::Time deltaTime) override; + ~FireBall(); +private: + void changeSpriteDirection(); +}; \ No newline at end of file diff --git a/include/Obstacles/FirePole.h b/include/Obstacles/FirePole.h new file mode 100644 index 0000000..9ee45ea --- /dev/null +++ b/include/Obstacles/FirePole.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Obstacle.h" + +class FirePole : public Obstacle +{ +public: + FirePole(int row, int col); + + virtual void move(sf::Time deltaTime) override; +private: + float m_timePassed, + m_angle; +}; \ No newline at end of file diff --git a/include/Obstacles/Obstacle.h b/include/Obstacles/Obstacle.h new file mode 100644 index 0000000..82e15dd --- /dev/null +++ b/include/Obstacles/Obstacle.h @@ -0,0 +1,13 @@ +#pragma once + +#include "MovingObject.h" + +class Obstacle : public MovingObject +{ +public: + Obstacle(const sf::Texture& data, bool dir, int size, int row, int col); + ~Obstacle(); + +private: + +}; \ No newline at end of file diff --git a/include/Singleton/AudioHolder.h b/include/Singleton/AudioHolder.h new file mode 100644 index 0000000..38aabac --- /dev/null +++ b/include/Singleton/AudioHolder.h @@ -0,0 +1,25 @@ +#pragma once +#include +#include "Macros.h" + +// Singleton Class for audio. +class AudioHolder +{ +public: + + static AudioHolder& instance(); + + void playSound(int element); + void stopBGSound(); + ~AudioHolder(); + +private: + + AudioHolder(); + AudioHolder(const AudioHolder&) = default; + AudioHolder& operator=(const AudioHolder&) = default; + + sf::SoundBuffer m_tracks[AUDIOS]; + sf::Sound m_sound[AUDIOS]; + sf::Music m_background; +}; \ No newline at end of file diff --git a/include/Singleton/TextureHolder.h b/include/Singleton/TextureHolder.h new file mode 100644 index 0000000..438b164 --- /dev/null +++ b/include/Singleton/TextureHolder.h @@ -0,0 +1,41 @@ +#pragma once + +#include +#include +#include "Macros.h" + +// This is a singleton class. +class TextureHolder +{ +public: + static TextureHolder& instance(); + const sf::Texture& getTextures(char element) const; + const sf::Texture& getLevel(int level) const; + const sf::Texture& getPlayer(int mode) const; + const sf::Texture& getEnemy(int kind) const; + const sf::Texture& getScreen(int screen) const; + const sf::Texture& getFlag(int kind) const; + ~TextureHolder(); + +private: + TextureHolder(); + TextureHolder(const TextureHolder&) = default; + TextureHolder& operator=(const TextureHolder&) = default; + + void uploadFiles(); + + void uploadPlayer(sf::Texture temp); + void uploadEnemy(sf::Texture temp); + void uploadGoalFlag(sf::Texture temp); + void uploadCoin(sf::Texture temp); + void uploadWall(sf::Texture temp); + void uploadObstacles(sf::Texture temp); + void uploadLevels(sf::Texture temp); + void uploadMenu(sf::Texture temp); + void uploadStatic(sf::Texture temp); + void uploadGoodObj(sf::Texture temp); + void uploadFireworks(sf::Texture temp); + + std::vector> m_texture; + +}; \ No newline at end of file diff --git a/include/StaticObjects/Block.h b/include/StaticObjects/Block.h new file mode 100644 index 0000000..1f9d14e --- /dev/null +++ b/include/StaticObjects/Block.h @@ -0,0 +1,13 @@ +#pragma once + +#include "UnPickable.h" + +class Block : public UnPickable +{ +public: + Block(int row, int col); + + ~Block(); +private: + +}; \ No newline at end of file diff --git a/include/StaticObjects/Brick.h b/include/StaticObjects/Brick.h new file mode 100644 index 0000000..5ee8ff8 --- /dev/null +++ b/include/StaticObjects/Brick.h @@ -0,0 +1,13 @@ +#pragma once + +#include "MovingObject.h" + +class Brick : public MovingObject +{ +public: + Brick(int row, int col); + + virtual void move(sf::Time deltaTime) override; + ~Brick(); +private: +}; \ No newline at end of file diff --git a/include/StaticObjects/Coin.h b/include/StaticObjects/Coin.h new file mode 100644 index 0000000..0d8a4b2 --- /dev/null +++ b/include/StaticObjects/Coin.h @@ -0,0 +1,18 @@ +#pragma once + +#include "Pickable.h" +#include "Animation.h" + +class Coin : public Pickable +{ +public: + Coin(int row, int col); + + void setTaken(); + bool getTaken() const; + virtual void move(sf::Time deltaTime); + + ~Coin(); +private: + bool m_taken; +}; \ No newline at end of file diff --git a/include/StaticObjects/Floor.h b/include/StaticObjects/Floor.h new file mode 100644 index 0000000..679226f --- /dev/null +++ b/include/StaticObjects/Floor.h @@ -0,0 +1,11 @@ +#pragma once + +#include "UnPickable.h" + +class Floor : public UnPickable +{ +public: + Floor(int row, int col); + ~Floor(); +private: +}; \ No newline at end of file diff --git a/include/StaticObjects/GoalFlag.h b/include/StaticObjects/GoalFlag.h new file mode 100644 index 0000000..7898439 --- /dev/null +++ b/include/StaticObjects/GoalFlag.h @@ -0,0 +1,16 @@ +#pragma once + +#include "MovingObject.h" + +class GoalFlag : public MovingObject +{ +public: + GoalFlag(int row, int col); + + void setShouldMove(); + virtual bool isShouldMove() const override; + virtual void move(sf::Time deltaTime) override; + ~GoalFlag(); + +private: +}; \ No newline at end of file diff --git a/include/StaticObjects/GoalPole.h b/include/StaticObjects/GoalPole.h new file mode 100644 index 0000000..59a04aa --- /dev/null +++ b/include/StaticObjects/GoalPole.h @@ -0,0 +1,16 @@ +#pragma once + +#include "UnPickable.h" + +class GoalPole : public UnPickable +{ +public: + GoalPole(int row, int col); + + void setPlayerReached(); + bool isPlayerReached() const; + ~GoalPole(); + +private: + bool m_playerReached; +}; \ No newline at end of file diff --git a/include/StaticObjects/Pipe.h b/include/StaticObjects/Pipe.h new file mode 100644 index 0000000..5c7cfdf --- /dev/null +++ b/include/StaticObjects/Pipe.h @@ -0,0 +1,12 @@ +#pragma once + +#include "UnPickable.h" + +class Pipe : public UnPickable +{ +public: + Pipe(int row, int col); + ~Pipe(); +private: + +}; \ No newline at end of file diff --git a/include/StaticObjects/QuestionBlock.h b/include/StaticObjects/QuestionBlock.h new file mode 100644 index 0000000..c06bfd9 --- /dev/null +++ b/include/StaticObjects/QuestionBlock.h @@ -0,0 +1,21 @@ +#pragma once + +#include "MovingObject.h" + +class QuestionBlock : public MovingObject +{ +public: + QuestionBlock(int row, int col); + + bool isOpen() const; + bool getKind() const; + void setOpen(bool kind); + virtual void move(sf::Time deltaTime) override; + virtual bool isShouldMove() const override; + ~QuestionBlock(); + +private: + bool m_open, + m_finished, + m_kind; // This var stores the player state in order to choose what to pull out +}; \ No newline at end of file diff --git a/include/StaticObjects/StaticObject.h b/include/StaticObjects/StaticObject.h new file mode 100644 index 0000000..94a4bf8 --- /dev/null +++ b/include/StaticObjects/StaticObject.h @@ -0,0 +1,13 @@ +#pragma once + +#include "GameObject.h" + +class StaticObject : public GameObject +{ +public: + StaticObject(int row, int col); + virtual void shift(sf::Time deltaTime); + ~StaticObject(); +private: + +}; \ No newline at end of file diff --git a/include/StaticObjects/UnPickable.h b/include/StaticObjects/UnPickable.h new file mode 100644 index 0000000..e405ee1 --- /dev/null +++ b/include/StaticObjects/UnPickable.h @@ -0,0 +1,12 @@ +#pragma once + +#include "StaticObject.h" + +class UnPickable : public StaticObject +{ +public: + UnPickable(int row, int col); + ~UnPickable(); +private: + +}; \ No newline at end of file