Skip to content

Commit

Permalink
Refactoring and small improvements done
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvikalpa7 committed Jul 4, 2022
1 parent 8563638 commit 484b34a
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@
/BinForRun/Textures/ImageTarget5.bmp
/BinForRun/Textures/ImageTarget6.bmp
/BinForRun
/GunsAndPans_BinForRun_Win64_v1.6.0.zip
File renamed without changes
File renamed without changes
Binary file added ClassDiagrams/ClassDiagram_ver1.6.0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/screen01.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Screenshots/screen01.png
Binary file not shown.
Binary file added Screenshots/screen02.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Screenshots/screen02.png
Binary file not shown.
Binary file added Screenshots/screen03.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Screenshots/screen03.png
Binary file not shown.
Binary file added Screenshots/screen04.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Screenshots/screen04.png
Binary file not shown.
Binary file added Screenshots/screen05.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Screenshots/screen05.png
Binary file not shown.
4 changes: 3 additions & 1 deletion SourceCode/GunsAndPans/Score.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Guns & Pans Game Results
=== Guns & Pans game results ===
Start scores: 50
Max possible scores: 175
Your current scores: 165
Bullet cost: 5
You did: 8 shots
8 changes: 3 additions & 5 deletions SourceCode/GunsAndPans/TGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ namespace GunsAndPuns
soundsNames.push_back(soundsDir + L"SoundFinish.wav");
}

TGame::~TGame()
{
}

std::string __fastcall TGame::wstringToString(const std::wstring& wstr) const
{
using convert_typeX = std::codecvt_utf8<wchar_t>;
Expand Down Expand Up @@ -365,10 +361,12 @@ namespace GunsAndPuns
{
const size_t maxScores = startScores + level.getAllTargetsPoints() - (bulletCost * 6);

fout << "Guns & Pans Game Results" << std::endl;
fout << "=== Guns & Pans game results === " << std::endl;
fout << "Start scores: " << startScores << std::endl;
fout << "Max possible scores: " << maxScores << std::endl;
fout << "Your current scores: " << scores << std::endl;
fout << "Bullet cost: " << bulletCost << std::endl;
fout << "You did: " << amun.getShotsNumber() << " shots" << std::endl;
}
}

Expand Down
1 change: 0 additions & 1 deletion SourceCode/GunsAndPans/TGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace GunsAndPuns
public:

TGame();
~TGame();

enum class TKeyCode : uint8_t
{
Expand Down
57 changes: 45 additions & 12 deletions SourceCode/GunsAndPans/TObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace GunsAndPuns
cz = 3.0f;
}

void TBullet::calcVector(const GLfloat xzAngleDegree, const GLfloat yzAngleDegree)
void __fastcall TBullet::calcVector(const GLfloat xzAngleDegree, const GLfloat yzAngleDegree)
{
vx = 0.0f;
vy = 0.0f;
Expand Down Expand Up @@ -181,12 +181,15 @@ namespace GunsAndPuns
//================================================================================================
// class TTarget

TTarget::TTarget()
: active{ true }, z{ -5.0f }
TTarget::TTarget(const TScene& scene)
: active{ true }, speed{ 0.001f }
, cx{ 0.0f }, cy{ 0.0f }, vx{ 0.0f }, vy{ 0.0f }, size{ 0.0f }
, points{ 0U }, horizontalTarget{ false }
, sceneWidth{ scene.getWidth() }
, yTop{ scene.getTopY() }
, yDown{ scene.getDownY() }
, z{ scene.getZ() }
{

}

void TTarget::draw() const
Expand Down Expand Up @@ -302,6 +305,13 @@ namespace GunsAndPuns
//================================================================================================
// class TScreen

TScreen::TScreen()
: z{ 0.0f }
, width{ 6.0f }
, height{ 5.0f }
{
}

void TScreen::draw() const
{
const GLfloat h2 = height * 0.5f;
Expand All @@ -322,6 +332,13 @@ namespace GunsAndPuns
//================================================================================================
// class TGunAmunitions

TGunAmunitions::TGunAmunitions()
: currentAmunitionsNumber{ 10U }, shots{ 0U }
, height{0.0f}, width{0.0f}
, cx{0.0f}, cy{0.0f}, cz{0.0f}
{
}

void __fastcall TGunAmunitions::addFileAsTexture(const std::string& fname)
{
fileNames.push_back(fname);
Expand Down Expand Up @@ -350,7 +367,18 @@ namespace GunsAndPuns
//================================================================================================
// class TLevels

void TLevels::init(const std::vector<std::string>& texturesNames)
TLevels::TLevels()
: appleTarget(scene)
, smallTarget(scene)
, bigTarget(scene)
, leftTarget(scene)
, rightTarget(scene)
, lemonTarget(scene)
, level{ TLevelNum::FIRST }
{
}

void __fastcall TLevels::init(const std::vector<std::string>& texturesNames)
{
appleTarget.loadTexture(texturesNames[TGame::TTexture::APPLE_TARGET]);
smallTarget.loadTexture(texturesNames[TGame::TTexture::SMALL_TARGET]);
Expand All @@ -374,13 +402,18 @@ namespace GunsAndPuns

void TLevels::reInit()
{
appleTarget.init(0.0f, 4.9f, 1.5f, 0.0f, 0.5f, true);
smallTarget.init(0.0f, 2.3f, -1.0f, 0.0f, 0.75f, true);
bigTarget.init(0.0f, -0.2f, 1.0f, 0.0f, 1.0f, true);
const GLfloat smallSize{ 0.5f };
const GLfloat middleSize{ 0.75f };
const GLfloat bigSize{ 1.0f };

appleTarget.init(0.0f, 4.9f, 1.5f, 0.0f, smallSize);
smallTarget.init(0.0f, 2.3f, -1.0f, 0.0f, middleSize);
bigTarget.init(0.0f, -0.2f, 1.0f, 0.0f, bigSize);

lemonTarget.init(0.0f, 4.9f, -1.6f, 0.0f, 0.5f, true);
leftTarget.init(-3.0f, 1.0f, 0.0f, 1.0f, 0.75f, false);
rightTarget.init(3.0f, 1.0f, 0.0f, -1.0f, 0.75f, false);
const GLfloat sceneCenterY = scene.getDownY() + (scene.getTopY() - scene.getDownY()) * 0.5f;
lemonTarget.init(0.0f, 4.9f, -1.7f, 0.0f, smallSize);
leftTarget.init(-3.0f, sceneCenterY, 0.0f, 1.0f, middleSize, false);
rightTarget.init(3.0f, sceneCenterY, 0.0f, -1.0f, middleSize, false);

level = TLevelNum::FIRST;
}
Expand All @@ -405,7 +438,7 @@ namespace GunsAndPuns
leftTarget.getPoints() + rightTarget.getPoints() + lemonTarget.getPoints();
}

bool TLevels::collisionCheck(const GLfloat x, const GLfloat y, size_t& scores, TBullet& bullet)
bool __fastcall TLevels::collisionCheck(const GLfloat x, const GLfloat y, size_t& scores, TBullet& bullet)
{
if (level == TLevelNum::FIRST)
{
Expand Down
44 changes: 27 additions & 17 deletions SourceCode/GunsAndPans/TObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace GunsAndPuns
GLfloat getRadius() const { return radius; }

void resetCenter();
void calcVector(const GLfloat xzAngleDegree, const GLfloat yzAngleDegree);
void __fastcall calcVector(const GLfloat xzAngleDegree, const GLfloat yzAngleDegree);

bool active;

Expand All @@ -108,6 +108,9 @@ namespace GunsAndPuns
void draw() const override;

GLfloat getZ() const { return z; }
GLfloat getWidth() const { return width; }
GLfloat getTopY() const { return topY; }
GLfloat getDownY() const { return downY; }

private:

Expand All @@ -126,7 +129,7 @@ namespace GunsAndPuns
{
public:

TTarget();
TTarget(const TScene & scene);

void draw() const override;
void __fastcall move(const size_t dtMs) override;
Expand All @@ -137,7 +140,7 @@ namespace GunsAndPuns
size_t getPoints() const { return points; }

void __fastcall init(const GLfloat _cx, const GLfloat _cy,
const GLfloat _vx, const GLfloat _vy, const GLfloat _size, const bool _horizontalTarget)
const GLfloat _vx, const GLfloat _vy, const GLfloat _size, const bool _horizontalTarget = true)
{
cx = _cx;
cy = _cy;
Expand All @@ -152,10 +155,10 @@ namespace GunsAndPuns

private:

const GLfloat speed{ 0.001f };
const GLfloat sceneWidth{ 10.0f };
const GLfloat yTop{ 4.0f };
const GLfloat yDown{ -2.0f };
const GLfloat speed;
const GLfloat sceneWidth;
const GLfloat yTop;
const GLfloat yDown;
GLfloat z, cx, cy, vx, vy, size /* half width */;
size_t points;
bool horizontalTarget;
Expand Down Expand Up @@ -196,6 +199,8 @@ namespace GunsAndPuns
{
public:

TScreen();

void draw() const override;

void __fastcall setParams(const GLfloat _z, const GLfloat _width, const GLfloat _height)
Expand All @@ -207,9 +212,9 @@ namespace GunsAndPuns

private:

GLfloat z{ 0.0f };
GLfloat width{ 6.0f };
GLfloat height{ 5.0f };
GLfloat z;
GLfloat width;
GLfloat height;
};

//================================================================================================
Expand All @@ -219,10 +224,12 @@ namespace GunsAndPuns
{
public:

TGunAmunitions();
void __fastcall addFileAsTexture(const std::string& fname);
void __fastcall setAmunNumber(const size_t num) { currentAmunitionsNumber = num; }
void __fastcall setAmunNumber(const size_t num) { currentAmunitionsNumber = num; shots = 0U; }

size_t getAmunNumber() const { return currentAmunitionsNumber; }
size_t getShotsNumber() const { return shots; }

void initCurTexture()
{
Expand All @@ -234,10 +241,11 @@ namespace GunsAndPuns
void decrementNumber()
{
currentAmunitionsNumber--;
shots++;
initCurTexture();
}

void setParams(const GLfloat _width, const GLfloat _height,
void __fastcall setParams(const GLfloat _width, const GLfloat _height,
const GLfloat _cx, const GLfloat _cy, const GLfloat _cz)
{
height = _height;
Expand All @@ -254,7 +262,7 @@ namespace GunsAndPuns
std::vector<std::string> fileNames;

TImage curImage;
size_t currentAmunitionsNumber{ 10U };
size_t currentAmunitionsNumber, shots;

GLfloat width, height, cx, cy, cz;
};
Expand All @@ -273,9 +281,11 @@ namespace GunsAndPuns
FINISH
};

void init(const std::vector<std::string> & textures);
TLevels();

void __fastcall init(const std::vector<std::string> & textures);
void reInit();
bool collisionCheck(const GLfloat x, const GLfloat y, size_t& scores, TBullet& bullet);
bool __fastcall collisionCheck(const GLfloat x, const GLfloat y, size_t& scores, TBullet& bullet);

void draw() const override;
void __fastcall move(const size_t dtMs) override;
Expand All @@ -289,8 +299,8 @@ namespace GunsAndPuns

private:

TGround ground;
TScene scene;
TGround ground;

// Level 1
TTarget appleTarget;
Expand All @@ -302,7 +312,7 @@ namespace GunsAndPuns
TTarget rightTarget;
TTarget lemonTarget;

TLevelNum level{ TLevelNum::FIRST };
TLevelNum level;
};


Expand Down
Binary file modified SourceCode/GunsAndPans/Textures/ImageStart1.bmp
Binary file not shown.
Binary file modified SourceCode/x64/Debug/GunsAndPans.exe
Binary file not shown.
Binary file modified SourceCode/x64/Release/GunsAndPans.exe
Binary file not shown.

0 comments on commit 484b34a

Please sign in to comment.