Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
matangeorgi authored Jul 25, 2021
1 parent 96f6b53 commit 5763171
Show file tree
Hide file tree
Showing 34 changed files with 1,032 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target_include_directories (SuperMario PRIVATE ${CMAKE_CURRENT_LIST_DIR})
13 changes: 13 additions & 0 deletions include/Enemys/BadMushroom.h
Original file line number Diff line number Diff line change
@@ -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:
};
12 changes: 12 additions & 0 deletions include/Enemys/Enemy.h
Original file line number Diff line number Diff line change
@@ -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:

};
14 changes: 14 additions & 0 deletions include/Enemys/FlyingTortoise.h
Original file line number Diff line number Diff line change
@@ -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:
};
13 changes: 13 additions & 0 deletions include/Enemys/PiranaPlants.h
Original file line number Diff line number Diff line change
@@ -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:
};
21 changes: 21 additions & 0 deletions include/Enemys/Tortoise.h
Original file line number Diff line number Diff line change
@@ -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;
};
48 changes: 48 additions & 0 deletions include/GameHandlers/Board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include <fstream>
#include <string>
#include <array>

#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<MovingObject> &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 <std::string, ROWS> m_map;
std::vector<std::unique_ptr<StaticObject>> m_static;
std::vector<std::unique_ptr<MovingObject>> m_moving;
};

static std::unique_ptr<MovingObject> createMovingObj(int row, int col, char element);
static std::unique_ptr<StaticObject> createStaticObj(int row, int col, char element);
78 changes: 78 additions & 0 deletions include/GameHandlers/Collision.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#pragma once

#include <map>
#include <typeinfo>
#include <typeindex>

#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<std::type_index, std::type_index>;
using HitMapStatic = std::map<Key, HitFunctionPtrStatic>;
using HitMapMove = std::map<Key, HitFunctionPtrMove>;

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);
30 changes: 30 additions & 0 deletions include/GameHandlers/Controller.h
Original file line number Diff line number Diff line change
@@ -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;
};
24 changes: 24 additions & 0 deletions include/GameHandlers/GameObject.h
Original file line number Diff line number Diff line change
@@ -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:
};
45 changes: 45 additions & 0 deletions include/GameHandlers/GameWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <thread>
#include <chrono>
#include <array>

#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<int> m_leaderVec;
std::array<sf::Text, MESSAGES> m_message;
std::array<sf::Text, MENU_MESSAGES> m_menuText;
std::array<sf::Text, LEADERS> m_leaderText;
};
Loading

0 comments on commit 5763171

Please sign in to comment.