Skip to content

Commit

Permalink
Merge pull request #23 from slo248/hotfix/feat/CCR-20
Browse files Browse the repository at this point in the history
hotfix/feat/CCR-20
  • Loading branch information
roni2406 committed Jan 4, 2024
2 parents c07f4e0 + 796716f commit b3ec8c9
Show file tree
Hide file tree
Showing 141 changed files with 2,236 additions and 1,031 deletions.
3 changes: 3 additions & 0 deletions Class-Diagrams/Lane.drawio
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
<mxCell id="279" value="- &amp;lt;&amp;lt;virtual&amp;gt;&amp;gt; updateCurrent(sf::Time): void" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;whiteSpace=wrap;html=1;" parent="261" vertex="1">
<mxGeometry y="506" width="361.94" height="26" as="geometry"/>
</mxCell>
<mxCell id="279" value="- &amp;lt;&amp;lt;virtual&amp;gt;&amp;gt; updateCurrent(sf::Time): void" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;whiteSpace=wrap;html=1;" parent="261" vertex="1">
<mxGeometry y="476" width="361.94" height="26" as="geometry"/>
</mxCell>
<mxCell id="280" value="- &amp;lt;&amp;lt;virtual, const&amp;gt;&amp;gt; drawCurrent(sf::RenderTarget&amp;amp;, &lt;br&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&#9;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&#9;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&#9;&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&#9;&lt;span style=&quot;white-space: pre;&quot;&gt;&#9;&lt;span style=&quot;white-space: pre;&quot;&gt;&#9;&lt;/span&gt; &lt;/span&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp;sf::RenderStates): void" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;whiteSpace=wrap;html=1;" parent="261" vertex="1">
<mxGeometry y="532" width="361.94" height="38" as="geometry"/>
</mxCell>
Expand Down
Binary file added asset/music/HighScore.mp3
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added asset/music/intro.ogg
Binary file not shown.
File renamed without changes.
Binary file added asset/music/music2.mp3
Binary file not shown.
Binary file added asset/music/music3.mp3
Binary file not shown.
Binary file removed asset/s_button/btn_pressed.png
Binary file not shown.
Binary file removed asset/s_button/btn_selected.png
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file added asset/sound_effect/ClickButton.mp3
Binary file not shown.
Binary file added asset/sound_effect/Death.mp3
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file modified asset/textures/BackgroundSetting.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 modified asset/textures/BarLevel.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 modified asset/textures/BarSaved.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 asset/textures/ButtonConfirm.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 modified asset/textures/ButtonGeneral.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 asset/textures/ButtonHome2.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 modified asset/textures/ButtonMusic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file modified asset/textures/ButtonSkin.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 modified asset/textures/ButtonSound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added asset/textures/ChosenMusic.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 asset/textures/CountDown.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 asset/textures/DeadArcher.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 asset/textures/DeadEnchantress.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 asset/textures/DeadKnight.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 asset/textures/DeadMusketeer.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 asset/textures/DeadSwordsman.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 asset/textures/DeadWizard.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 asset/textures/DialogCommon.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 modified asset/textures/DialogDefeat.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 removed asset/textures/DialogGeneral.png
Binary file not shown.
Binary file removed asset/textures/Group 2.png
Binary file not shown.
Binary file added asset/textures/OptionMusic.png
Binary file added asset/textures/SkinArcher.png
Binary file added asset/textures/SkinEnchantress.png
Binary file added asset/textures/SkinKnight.png
Binary file added asset/textures/SkinMusketeer.png
Binary file added asset/textures/SkinSwordsman.png
Binary file added asset/textures/SkinWizard.png
Binary file added asset/textures/daucong.png
Binary file added asset/textures/dautru.png
Binary file added asset/textures/mOpMain.png
Binary file added asset/textures/mOpSub.png
Binary file added asset/weather/rain_heavy.png
Binary file added asset/weather/rain_light.png
Binary file added asset/weather/rain_medium.png
Binary file added asset/weather/rain_noblur.png
Binary file added asset/weather/snow_heavy.png
Binary file added asset/weather/snow_light.png
Binary file added asset/weather/snow_medium.png
Empty file removed data/endless_ranking.txt
Empty file.
1 change: 1 addition & 0 deletions data/ranking.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

4 changes: 4 additions & 0 deletions data/setting.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
22
18
0
3
6 changes: 5 additions & 1 deletion include/Animation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ class Animation : public sf::Transformable, public sf::Drawable {
typedef std::unique_ptr<Animation> Ptr;

public:
Animation(const sf::Texture& texture, sf::Vector2i frameSize, int numFrame);
Animation(
const sf::Texture& texture, sf::Vector2i frameSize,
bool isTransparent = false
);

void setRepeat(bool flag);
void setDuration(sf::Time t);
Expand All @@ -33,6 +36,7 @@ class Animation : public sf::Transformable, public sf::Drawable {
private:
sf::Sprite mSprite;
sf::IntRect mStartRect;
sf::IntRect mDefaultRect;
sf::Time mElapsedTime;
sf::Time mTotalElapsedTime;
sf::Time mDuration;
Expand Down
3 changes: 1 addition & 2 deletions include/AnimationList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ class AnimationList : public sf::Transformable, public sf::Drawable {
void draw(sf::RenderTarget& target, sf::RenderStates states) const;

private:
bool mRepeat;
int mCurAnimation;
std::vector<Animation::Ptr> mAnimations;

bool mRepeat;
};

#endif // ANIMATION_LIST_HPP
41 changes: 41 additions & 0 deletions include/Application.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef APPLICATION_HPP
#define APPLICATION_HPP

#include "MusicPlayer.hpp"
#include "Player.hpp"
#include "ResourceHolder.hpp"
#include "ResourceIdentifiers.hpp"
#include "SoundEffectPlayer.hpp"
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Time.hpp>

#include "StateStack.hpp"

class Application {
public:
Application();
~Application();
void run();

private:
void processInput();
void update(sf::Time dt);
void render();

void registerStates();
State::Context initContext();

private:
const sf::Time TimePerFrame = DEFAULT_TIME_PER_FRAME;

sf::RenderWindow mWindow;
TextureHolder mTextures;
FontHolder mFonts;
MusicPlayer mMusics;
SoundEffectPlayer mSoundEffects;
Player mPlayer;
std::vector<int> mHighScores;
StateStack mStateStack;
};

#endif
23 changes: 15 additions & 8 deletions include/Button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,38 @@ class Button : public Component {

public:
Button(
State::Context context, Textures::ID button,
State::Context& context, Textures::ID button,
sf::Vector2f position = sf::Vector2f(0.f, 0.f), bool is2Mode = false
);
void setCallback(Callback callback);
void setToggle(bool flag);
void setText(
const std::string& text, const std::string& hexCode, int characterSize,
sf::Vector2f position, Fonts::ID font = Fonts::Main
);

virtual bool isMouseOver(const sf::RenderWindow& window) const;
virtual void select();
virtual void deselect();
virtual void select() override;
virtual void deselect() override;

virtual void handleEvent(const sf::Event& event);
virtual void handleEvent(const sf::Event& event) override;

private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
void callBack();
void changeSize(Size buttonSize);
void changeTexture(Mode buttonMode);
bool isMouseOver(const sf::RenderWindow& window) const;

private:
Callback mCallback;
sf::Sprite mSprite;
sf::Text mText;
sf::Vector2f originalPosition;
sf::Vector2f textOriginalPosition;
sf::FloatRect originalSize;
State::Context* mContext;
bool mIsToggle;
bool mIsOn;
bool mIs2Mode;
State::Context mContext;
sf::Vector2f originalPosition;
};

#endif
8 changes: 4 additions & 4 deletions include/ChooseModeState.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#ifndef CHOOSE_MODE_STATE_HPP
#define CHOOSE_MODE_STATE_HPP


#include "Button.hpp"
#include "State.hpp"

class ChooseModeState : public State {
public:
ChooseModeState(StateStack& stack, Context context, int mode = 0);
ChooseModeState(StateStack& stack, Context& context);

virtual void draw();
virtual bool update(sf::Time dt);
virtual void draw() override;
virtual bool update(sf::Time dt) override;
virtual bool handleEvent(const sf::Event& event);

private:
sf::Sprite mBackgroundSprite;
Config::ChooseModeState::Mode mMode;
};

#endif
1 change: 0 additions & 1 deletion include/Component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Component : public sf::Drawable,
virtual void deselect();

virtual bool isActive() const;
virtual bool isMouseOver(const sf::RenderWindow& window) const;
virtual void handleEvent(const sf::Event& event) = 0;

protected:
Expand Down
50 changes: 43 additions & 7 deletions include/Config.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
#ifndef CONFIG_HPP
#define CONFIG_HPP

#define SAVED_GAME_SURVIVAL_PATH "data/survival.txt"
#define SAVED_GAME_L1_PATH "data/level1.txt"
#define SAVED_GAME_L2_PATH "data/level2.txt"
#define SAVED_GAME_L3_PATH "data/level3.txt"
#define SAVED_GAME_L4_PATH "data/level4.txt"
#define SAVED_GAME_L5_PATH "data/level5.txt"

#define RANKING_PATH "data/ranking.txt"
#define SETTING_PATH "data/setting.txt"

#define DEFAULT_PLAYER_SLOT 6
#define DEFAULT_RANKING_SLOTS 5
#define NUMBER_OF_SKINS 6

#define DEFAULT_CELLS_PER_LANE 14
#define DEFAULT_CELL_LENGTH 64.f
#define DEFAULT_HALF_CELL_LENGTH 32.f
#define DEFAULT_SCREEN_WIDTH 896.f
#define DEFAULT_SCREEN_HEIGHT 640.f
#define DEFAULT_CELL_RECT \
sf::IntRect(0, 0, DEFAULT_CELL_LENGTH, DEFAULT_CELL_LENGTH)
#define DEFAULT_LANE_RECT \
sf::IntRect( \
0, 0, DEFAULT_CELL_LENGTH* DEFAULT_CELLS_PER_LANE, DEFAULT_CELL_LENGTH \
)

#define DEFAULT_SPAWN_INTERVAL sf::seconds(3.5)
#define DEFAULT_PLAYER_SLOT 6
#define DEFAULT_AIR_ENEMY_SPEED 450.f
#define DEFAULT_GROUND_ENEMY_SPEED 150.f
#define DEFAULT_PLAYER_SPEED 500.f
#define DEFAULT_LOG_SPEED 100.f

#define DEFAULT_TIME_PER_FRAME sf::seconds(1.f / 60.f)
#define DEFAULT_ANIMATION_DURATION sf::seconds(1.5)
#define DEFAULT_COUNTDOWN_DURATION sf::seconds(3)
#define DEFAULT_SPAWN_INTERVAL sf::seconds(3.5)
#define GREEN_LIGHT_INTERVAL sf::seconds(3.0)
#define YELLOW_LIGHT_INTERVAL sf::seconds(1.0)
#define RED_LIGHT_INTERVAL sf::seconds(2.0)
Expand All @@ -27,13 +45,31 @@
#define LEVEL_THREE_COEFFICIENT 1.2
#define LEVEL_FOUR_COEFFICIENT 1.3
#define LEVEL_FIVE_COEFFICIENT 1.4
#define SURVIVAL_COEFFICIENT 1.15

#define NUMBER_OF_BUFFER_LANE 5
#define WEATHER_NORMAL_FACTOR 1.f
#define WEATHER_RAIN_FACTOR 0.6
#define WEATHER_SNOW_FACTOR 0.4

namespace Config {
namespace GameLevel {
enum Type { L1, L2, L3, L4, L5, Endless, Count };
} // namespace GameLevel
namespace Game {
enum Level { L1, L2, L3, L4, L5, Survival, Count };
enum Weather { Rain, Snow, Normal };
} // namespace Game
namespace WinState {
enum Mode { Win, HighScore };
}
namespace LoseState {
enum Mode { Lose, Survival };
}
namespace ChooseModeState {
enum Mode { NewGame, Continue };
}
namespace LevelState {
enum Mode { NewGame, Continue };
}
namespace SettingState {
enum Mode { NonSkin, Skin };
}
} // namespace Config

#endif // CONFIG_HPP
3 changes: 0 additions & 3 deletions include/Container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class Container : public Component {
private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;

// bool hasSelection() const;
// void select(std::size_t index);

private:
std::vector<Component::Ptr> mChildren;
};
Expand Down
7 changes: 3 additions & 4 deletions include/CreditState.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#ifndef CREDIT_STATE_HPP
#define CREDIT_STATE_HPP


#include "Button.hpp"
#include "State.hpp"

class CreditState : public State {
public:
CreditState(StateStack& stack, Context context, int mode = 0);
CreditState(StateStack& stack, Context& context);

virtual void draw();
virtual bool update(sf::Time dt);
virtual void draw() override;
virtual bool update(sf::Time dt) override;
virtual bool handleEvent(const sf::Event& event);

private:
Expand Down
1 change: 0 additions & 1 deletion include/DataTables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ struct CharacterData {
float normalSpeed;
std::vector<Textures::ID> textures;
sf::Vector2i frameSize;
size_t numFrames;
};

struct ObstacleData {
Expand Down
6 changes: 4 additions & 2 deletions include/Dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@
#include "Container.hpp"
#include "State.hpp"

// potentially problematic?
using namespace GUI;

class Dialog : public Component {
public:
typedef std::shared_ptr<Dialog> Ptr;

public:
Dialog(const sf::Texture& texture, State::Context context);
Dialog(const sf::Texture& texture, State::Context& context);
virtual void update(sf::Time dt){};
virtual void handleEvent(const sf::Event& event){};

protected:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;

protected:
State::Context* mContext;
Container mGUIContainer;
State::Context mContext;
const sf::Texture& mTexture;
sf::Sprite mSprite;
};
Expand Down
19 changes: 13 additions & 6 deletions include/DialogGeneral.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,30 @@
#include "Label.hpp"
#include "Player.hpp"
#include "State.hpp"
#include "VolumeBar.hpp"

class DialogGeneral : public Dialog {
public:
DialogGeneral(const sf::Texture& texture, State::Context context);
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
DialogGeneral(const sf::Texture& texture, State::Context& context);
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
virtual void handleEvent(const sf::Event& event);

private:
void updateLabels();
void addButtonLabel(
Player::Action action, float y, Textures::ID Button,
State::Context context
);
void addButtonLabel(Player::Action action, float y, Textures::ID Button);
void addListMusic();

private:
sf::Sprite mLabelTextKeys;
sf::Sprite mLabelTextSounds;
VolumeBar mVolumeBar;
std::array<Button::Ptr, Player::Count> mBindingButtons;
std::array<Label::Ptr, Player::Count> mBindingLabels;
std::array<Button::Ptr, Musics::MusicCount - 1> mListMusics;
Button::Ptr mChosenMusic;

int volume = 50;
bool isChoosingMusic = false;
};

#endif
36 changes: 35 additions & 1 deletion include/DialogSkin.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
#ifndef DIALOG_SKIN_HPP
#define DIALOG_SKIN_HPP

class DialogSkin {};
#include <array>

#include "Animation.hpp"
#include "Button.hpp"
#include "Dialog.hpp"
#include "Label.hpp"
#include "State.hpp"

class DialogSkin : public Dialog {
public:
DialogSkin(const sf::Texture& texture, State::Context& context);
virtual void draw(sf::RenderTarget& target, sf::RenderStates states)
const override;
virtual void handleEvent(const sf::Event& event);
virtual void update(sf::Time dt) override;

private:
void addSkins(
int skinNumber, sf::Vector2f position, sf::Vector2i frameSize,
Textures::ID skin
);
void addChosenSkins(
int skinNumber, sf::Vector2f position, sf::Vector2i frameSize,
Textures::ID skin
);
void changeSkin(int skinNumber);

private:
const int mNumSkins = NUMBER_OF_SKINS;
int mCurrentSkin;
Button::Ptr mButtonLeft;
Button::Ptr mButtonRight;
std::array<Animation::Ptr, NUMBER_OF_SKINS> mSkins;
std::array<Animation::Ptr, NUMBER_OF_SKINS> mChosenSkins;
};

#endif
Loading

0 comments on commit b3ec8c9

Please sign in to comment.