forked from wrazik/TankBotFight
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
231 additions
and
577 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
Top-down Tanks Redux | ||
by Kenney Vleugels (Kenney.nl) | ||
------------------------------ | ||
License (Creative Commons Zero, CC0) | ||
http://creativecommons.org/publicdomain/zero/1.0/ | ||
You may use these assets in personal and commercial projects. | ||
Credit (Kenney or www.kenney.nl) would be nice but is not mandatory. | ||
------------------------------ | ||
Donate: http://support.kenney.nl | ||
Request: http://request.kenney.nl | ||
Follow on Twitter for updates: | ||
|
||
|
||
Top-down Tanks Redux | ||
|
||
by Kenney Vleugels (Kenney.nl) | ||
|
||
------------------------------ | ||
|
||
License (Creative Commons Zero, CC0) | ||
http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
You may use these assets in personal and commercial projects. | ||
Credit (Kenney or www.kenney.nl) would be nice but is not mandatory. | ||
|
||
------------------------------ | ||
|
||
Donate: http://support.kenney.nl | ||
Request: http://request.kenney.nl | ||
|
||
Follow on Twitter for updates: | ||
@KenneyNL |
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "Animation.hpp" | ||
|
||
#include <SFML/Graphics/Sprite.hpp> | ||
|
||
Animation::Animation(const std::string& file_name, int frame_count, double animation_time, | ||
sf::Vector2f position, TextureStore& store) | ||
: mPosition(position), mStore(store) { | ||
for (int i = 1; i <= frame_count; ++i) { | ||
mAnimationFiles.push_back(file_name + std::to_string(i) + ".png"); | ||
} | ||
mDeltaTime = animation_time / frame_count; | ||
} | ||
void Animation::draw(sf::RenderWindow& render_window) { | ||
auto elapsed_time = mClock.getElapsedTime(); | ||
|
||
if (elapsed_time.asMilliseconds() > mDeltaTime) { | ||
mClock.restart(); | ||
mCurrentFrame++; | ||
if (mCurrentFrame >= mAnimationFiles.size()) { | ||
mIsDrawingFinished = true; | ||
return; | ||
} | ||
} | ||
sf::Sprite sprite; | ||
sprite.setTexture(mStore.get().get_texture(mAnimationFiles[mCurrentFrame])); | ||
sprite.setPosition(mPosition - sf::Vector2f{sprite.getGlobalBounds().width / 2, | ||
sprite.getGlobalBounds().height / 2}); | ||
render_window.draw(sprite); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
#include <SFML/Graphics/RenderWindow.hpp> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "TextureStore.hpp" | ||
|
||
class Animation { | ||
public: | ||
Animation(const std::string& file_name, int frame_count, double animation_time, | ||
sf::Vector2f position, TextureStore& store); | ||
void draw(sf::RenderWindow& render_window); | ||
bool is_finished() const { return mIsDrawingFinished; } | ||
|
||
Animation(const Animation&) = delete; | ||
Animation& operator=(const Animation&) = delete; | ||
Animation(Animation&&) = default; | ||
Animation& operator=(Animation&&) = default; | ||
|
||
private: | ||
std::vector<std::string> mAnimationFiles; | ||
int mCurrentFrame = 0; | ||
bool mIsDrawingFinished = false; | ||
double mDeltaTime = 0; | ||
sf::Clock mClock; | ||
sf::Vector2f mPosition; | ||
std::reference_wrapper<TextureStore> mStore; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
#include "Sound.hpp" | ||
|
||
Sound::Sound(const Sound& sound) { | ||
mBuffer = sound.mBuffer; | ||
mSound = sound.mSound; | ||
mSound.setBuffer(mBuffer); | ||
} | ||
#include <iostream> | ||
|
||
Sound::Sound(const std::string& file_name) { | ||
if (load_from_file(file_name)) { | ||
mSound.setBuffer(mBuffer); | ||
} else { | ||
std::string path_to_file = files::asset_path() + "Sounds/" + file_name; | ||
if (!mBuffer.loadFromFile(path_to_file)) { | ||
throw std::runtime_error("couldn't load sound"); | ||
} | ||
} | ||
|
||
void Sound::play() { mSound.play(); } | ||
|
||
bool Sound::load_from_file(std::string file_name) { | ||
std::string path_to_file = files::asset_path() + "Sounds/" + file_name; | ||
|
||
return mBuffer.loadFromFile(path_to_file); | ||
} | ||
void Sound::play() { | ||
mSound.setBuffer(mBuffer); | ||
mSound.play(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.