diff --git a/Flappy.sln b/Flappy.sln new file mode 100644 index 0000000..8c10d58 --- /dev/null +++ b/Flappy.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Flappy", "Flappy\Flappy.vcxproj", "{9035B83C-F117-480E-9DEB-435AA0EBEA3F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9035B83C-F117-480E-9DEB-435AA0EBEA3F}.Debug|x64.ActiveCfg = Debug|x64 + {9035B83C-F117-480E-9DEB-435AA0EBEA3F}.Debug|x64.Build.0 = Debug|x64 + {9035B83C-F117-480E-9DEB-435AA0EBEA3F}.Debug|x86.ActiveCfg = Debug|Win32 + {9035B83C-F117-480E-9DEB-435AA0EBEA3F}.Debug|x86.Build.0 = Debug|Win32 + {9035B83C-F117-480E-9DEB-435AA0EBEA3F}.Release|x64.ActiveCfg = Release|x64 + {9035B83C-F117-480E-9DEB-435AA0EBEA3F}.Release|x64.Build.0 = Release|x64 + {9035B83C-F117-480E-9DEB-435AA0EBEA3F}.Release|x86.ActiveCfg = Release|Win32 + {9035B83C-F117-480E-9DEB-435AA0EBEA3F}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Flappy/Assets/bird.png b/Flappy/Assets/bird.png new file mode 100644 index 0000000..213c738 Binary files /dev/null and b/Flappy/Assets/bird.png differ diff --git a/Flappy/Assets/ceiling.png b/Flappy/Assets/ceiling.png new file mode 100644 index 0000000..ca0d665 Binary files /dev/null and b/Flappy/Assets/ceiling.png differ diff --git a/Flappy/Assets/font_big.psd b/Flappy/Assets/font_big.psd new file mode 100644 index 0000000..1fb7ddf Binary files /dev/null and b/Flappy/Assets/font_big.psd differ diff --git a/Flappy/Assets/font_big_0.png b/Flappy/Assets/font_big_0.png new file mode 100644 index 0000000..894e22d Binary files /dev/null and b/Flappy/Assets/font_big_0.png differ diff --git a/Flappy/Assets/font_big_1.png b/Flappy/Assets/font_big_1.png new file mode 100644 index 0000000..d05a684 Binary files /dev/null and b/Flappy/Assets/font_big_1.png differ diff --git a/Flappy/Assets/font_big_2.png b/Flappy/Assets/font_big_2.png new file mode 100644 index 0000000..4c541ee Binary files /dev/null and b/Flappy/Assets/font_big_2.png differ diff --git a/Flappy/Assets/font_big_3.png b/Flappy/Assets/font_big_3.png new file mode 100644 index 0000000..634fd5f Binary files /dev/null and b/Flappy/Assets/font_big_3.png differ diff --git a/Flappy/Assets/font_big_4.png b/Flappy/Assets/font_big_4.png new file mode 100644 index 0000000..ddaeef6 Binary files /dev/null and b/Flappy/Assets/font_big_4.png differ diff --git a/Flappy/Assets/font_big_5.png b/Flappy/Assets/font_big_5.png new file mode 100644 index 0000000..8ac9c8a Binary files /dev/null and b/Flappy/Assets/font_big_5.png differ diff --git a/Flappy/Assets/font_big_6.png b/Flappy/Assets/font_big_6.png new file mode 100644 index 0000000..4b18cf1 Binary files /dev/null and b/Flappy/Assets/font_big_6.png differ diff --git a/Flappy/Assets/font_big_7.png b/Flappy/Assets/font_big_7.png new file mode 100644 index 0000000..de96aa3 Binary files /dev/null and b/Flappy/Assets/font_big_7.png differ diff --git a/Flappy/Assets/font_big_8.png b/Flappy/Assets/font_big_8.png new file mode 100644 index 0000000..cb78094 Binary files /dev/null and b/Flappy/Assets/font_big_8.png differ diff --git a/Flappy/Assets/font_big_9.png b/Flappy/Assets/font_big_9.png new file mode 100644 index 0000000..4723fe5 Binary files /dev/null and b/Flappy/Assets/font_big_9.png differ diff --git a/Flappy/Assets/font_small.psd b/Flappy/Assets/font_small.psd new file mode 100644 index 0000000..772c2e3 Binary files /dev/null and b/Flappy/Assets/font_small.psd differ diff --git a/Flappy/Assets/font_small_0.png b/Flappy/Assets/font_small_0.png new file mode 100644 index 0000000..a148e6c Binary files /dev/null and b/Flappy/Assets/font_small_0.png differ diff --git a/Flappy/Assets/font_small_1.png b/Flappy/Assets/font_small_1.png new file mode 100644 index 0000000..14e23d8 Binary files /dev/null and b/Flappy/Assets/font_small_1.png differ diff --git a/Flappy/Assets/font_small_2.png b/Flappy/Assets/font_small_2.png new file mode 100644 index 0000000..d742784 Binary files /dev/null and b/Flappy/Assets/font_small_2.png differ diff --git a/Flappy/Assets/font_small_3.png b/Flappy/Assets/font_small_3.png new file mode 100644 index 0000000..da7ec28 Binary files /dev/null and b/Flappy/Assets/font_small_3.png differ diff --git a/Flappy/Assets/font_small_4.png b/Flappy/Assets/font_small_4.png new file mode 100644 index 0000000..2ebd7d2 Binary files /dev/null and b/Flappy/Assets/font_small_4.png differ diff --git a/Flappy/Assets/font_small_5.png b/Flappy/Assets/font_small_5.png new file mode 100644 index 0000000..237639c Binary files /dev/null and b/Flappy/Assets/font_small_5.png differ diff --git a/Flappy/Assets/font_small_6.png b/Flappy/Assets/font_small_6.png new file mode 100644 index 0000000..33db0ef Binary files /dev/null and b/Flappy/Assets/font_small_6.png differ diff --git a/Flappy/Assets/font_small_7.png b/Flappy/Assets/font_small_7.png new file mode 100644 index 0000000..808fad9 Binary files /dev/null and b/Flappy/Assets/font_small_7.png differ diff --git a/Flappy/Assets/font_small_8.png b/Flappy/Assets/font_small_8.png new file mode 100644 index 0000000..9bb457f Binary files /dev/null and b/Flappy/Assets/font_small_8.png differ diff --git a/Flappy/Assets/font_small_9.png b/Flappy/Assets/font_small_9.png new file mode 100644 index 0000000..bb62d0d Binary files /dev/null and b/Flappy/Assets/font_small_9.png differ diff --git a/Flappy/Assets/land.png b/Flappy/Assets/land.png new file mode 100644 index 0000000..6f34834 Binary files /dev/null and b/Flappy/Assets/land.png differ diff --git a/Flappy/Assets/medal_bronze.png b/Flappy/Assets/medal_bronze.png new file mode 100644 index 0000000..1be1ff1 Binary files /dev/null and b/Flappy/Assets/medal_bronze.png differ diff --git a/Flappy/Assets/medal_gold.png b/Flappy/Assets/medal_gold.png new file mode 100644 index 0000000..b7fd250 Binary files /dev/null and b/Flappy/Assets/medal_gold.png differ diff --git a/Flappy/Assets/medal_platinum.png b/Flappy/Assets/medal_platinum.png new file mode 100644 index 0000000..39c57d9 Binary files /dev/null and b/Flappy/Assets/medal_platinum.png differ diff --git a/Flappy/Assets/medal_silver.png b/Flappy/Assets/medal_silver.png new file mode 100644 index 0000000..f3630de Binary files /dev/null and b/Flappy/Assets/medal_silver.png differ diff --git a/Flappy/Assets/pipe-down.png b/Flappy/Assets/pipe-down.png new file mode 100644 index 0000000..5b60698 Binary files /dev/null and b/Flappy/Assets/pipe-down.png differ diff --git a/Flappy/Assets/pipe-up.png b/Flappy/Assets/pipe-up.png new file mode 100644 index 0000000..e4661cd Binary files /dev/null and b/Flappy/Assets/pipe-up.png differ diff --git a/Flappy/Assets/pipe.png b/Flappy/Assets/pipe.png new file mode 100644 index 0000000..f541b15 Binary files /dev/null and b/Flappy/Assets/pipe.png differ diff --git a/Flappy/Assets/replay.png b/Flappy/Assets/replay.png new file mode 100644 index 0000000..3773e23 Binary files /dev/null and b/Flappy/Assets/replay.png differ diff --git a/Flappy/Assets/scoreboard.png b/Flappy/Assets/scoreboard.png new file mode 100644 index 0000000..71064f0 Binary files /dev/null and b/Flappy/Assets/scoreboard.png differ diff --git a/Flappy/Assets/sky.png b/Flappy/Assets/sky.png new file mode 100644 index 0000000..bd1ba9e Binary files /dev/null and b/Flappy/Assets/sky.png differ diff --git a/Flappy/Assets/sounds/sfx_die.ogg b/Flappy/Assets/sounds/sfx_die.ogg new file mode 100644 index 0000000..a980e92 Binary files /dev/null and b/Flappy/Assets/sounds/sfx_die.ogg differ diff --git a/Flappy/Assets/sounds/sfx_hit.ogg b/Flappy/Assets/sounds/sfx_hit.ogg new file mode 100644 index 0000000..72d821a Binary files /dev/null and b/Flappy/Assets/sounds/sfx_hit.ogg differ diff --git a/Flappy/Assets/sounds/sfx_point.ogg b/Flappy/Assets/sounds/sfx_point.ogg new file mode 100644 index 0000000..efb2d99 Binary files /dev/null and b/Flappy/Assets/sounds/sfx_point.ogg differ diff --git a/Flappy/Assets/sounds/sfx_swooshing.ogg b/Flappy/Assets/sounds/sfx_swooshing.ogg new file mode 100644 index 0000000..f483cd6 Binary files /dev/null and b/Flappy/Assets/sounds/sfx_swooshing.ogg differ diff --git a/Flappy/Assets/sounds/sfx_wing.ogg b/Flappy/Assets/sounds/sfx_wing.ogg new file mode 100644 index 0000000..76e3a2a Binary files /dev/null and b/Flappy/Assets/sounds/sfx_wing.ogg differ diff --git a/Flappy/Assets/splash.png b/Flappy/Assets/splash.png new file mode 100644 index 0000000..5107974 Binary files /dev/null and b/Flappy/Assets/splash.png differ diff --git a/Flappy/Assets/thumb.png b/Flappy/Assets/thumb.png new file mode 100644 index 0000000..f2dcc24 Binary files /dev/null and b/Flappy/Assets/thumb.png differ diff --git a/Flappy/Flappy.vcxproj b/Flappy/Flappy.vcxproj new file mode 100644 index 0000000..e95a82e --- /dev/null +++ b/Flappy/Flappy.vcxproj @@ -0,0 +1,162 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {9035B83C-F117-480E-9DEB-435AA0EBEA3F} + Win32Proj + Flappy + 8.1 + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + Z:\Cpp_Libs\SFML-Visual_Studio2015RCx64\include;$(IncludePath) + Z:\Cpp_Libs\SFML-Visual_Studio2015RCx64\lib;$(LibraryPath) + + + false + + + false + Z:\Cpp_Libs\SFML-Visual_Studio2015RCx64\include;$(IncludePath) + Z:\Cpp_Libs\SFML-Visual_Studio2015RCx64\lib;$(LibraryPath) + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + Z:\Cpp_Libs\SFML-Visual_Studio2015RCx64\include;%(AdditionalIncludeDirectories) + + + Console + true + sfml-graphics-d.lib;sfml-audio-d.lib;sfml-network-d.lib;sfml-system-d.lib;sfml-window-d.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + Z:\Cpp_Libs\SFML-Visual_Studio2015RCx64\include;%(AdditionalIncludeDirectories) + + + Console + true + true + true + sfml-graphics.lib;sfml-audio.lib;sfml-network.lib;sfml-system.lib;sfml-window.lib;%(AdditionalDependencies) + + + + + + + + + \ No newline at end of file diff --git a/Flappy/Flappy.vcxproj.filters b/Flappy/Flappy.vcxproj.filters new file mode 100644 index 0000000..0d8d9e4 --- /dev/null +++ b/Flappy/Flappy.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/Flappy/main.cpp b/Flappy/main.cpp new file mode 100644 index 0000000..83ad0e1 --- /dev/null +++ b/Flappy/main.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +#include + +const float g = 7.8; +const int WINDOW_X = 600; +const int WINDOW_Y = 800; +const int pipe_dist = 300; + +int main() +{ + std::mt19937 rng(time(NULL)); + std::uniform_int_distribution rgen(100, 200); + + sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "flappy"); + + // Init flappy + sf::Texture flappy_texture[4] = { sf::Texture(), sf::Texture(), sf::Texture(), sf::Texture() }; + for (int i = 0; i < 4; i++) { + flappy_texture[i].loadFromFile("Assets\\bird.png", sf::IntRect(0, i*12, 34, 24)); + } + + sf::RectangleShape flappy(sf::Vector2f(34, 24)); + flappy.setTexture(&flappy_texture[0],false); + flappy.setPosition(WINDOW_X / 2, WINDOW_Y / 2); + + // Init world + sf::Texture background = sf::Texture(); background.loadFromFile("Assets\\sky.png"); + sf::Sprite background_sprite = sf::Sprite(background); background_sprite.setPosition(0, 0); background_sprite.setScale(8, 8); + sf::Texture land = sf::Texture(); land.loadFromFile("Assets\\land.png"); + sf::Sprite land_sprite = sf::Sprite(land); land_sprite.setPosition(0, WINDOW_Y - WINDOW_Y / 10); land_sprite.setScale(2, 2); + sf::Texture pipe_up, pipe_down = sf::Texture(); pipe_down.loadFromFile("Assets\\pipe-down.png"); pipe_up.loadFromFile("Assets\\pipe-up.png"); + sf::Sprite pipe_up_sprite = sf::Sprite(pipe_up); sf::Sprite pipe_down_sprite = sf::Sprite(pipe_down); + sf::Texture pipe_shaft = sf::Texture(); pipe_shaft.loadFromFile("Assets\\pipe.png"); + sf::Sprite pipe_shaft_sprite = sf::Sprite(pipe_shaft); + + double momentum = 0; + int r = 0; + + while (window.isOpen()) + { + std::cout << r++ << std::endl; + + sf::Event event; + while (window.pollEvent(event)) { + if (event.type == sf::Event::Closed) { + window.close(); + } + } + + // Move pipes, background + + if (pipe_down_sprite.getPosition().x < -pipe_down_sprite.getGlobalBounds().width) { + pipe_down_sprite.setPosition(WINDOW_X, rgen(rng)); + pipe_up_sprite.setPosition(WINDOW_X, pipe_down_sprite.getPosition().y + pipe_dist); + } + else { + pipe_up_sprite.setPosition(pipe_up_sprite.getPosition().x - 0.2, pipe_up_sprite.getPosition().y); + pipe_down_sprite.setPosition(pipe_down_sprite.getPosition().x - 0.2, pipe_down_sprite.getPosition().y); + } + + if (background_sprite.getPosition().x + background_sprite.getGlobalBounds().width < WINDOW_X) { + background_sprite.setPosition(0, 0); + } + else { + background_sprite.setPosition(background_sprite.getPosition().x - 0.1, background_sprite.getPosition().y); + } + + if (land_sprite.getPosition().x + 10 + land_sprite.getGlobalBounds().width < WINDOW_X) { + land_sprite.setPosition(14, land_sprite.getPosition().y); + } + else { + land_sprite.setPosition(land_sprite.getPosition().x - 0.2, land_sprite.getPosition().y); + } + + if (flappy.getPosition().y > land_sprite.getPosition().y) { + flappy.setPosition(WINDOW_X / 2, WINDOW_Y / 2); + momentum = 0; + std::cout << "dead"; + } + + sf::Vector2f f_pos = flappy.getPosition(); + sf::Vector2f p_pos = pipe_up_sprite.getPosition(); + + if (((f_pos.x < p_pos.x + 26) && (f_pos.x > p_pos.x)) && ((f_pos.y > p_pos.y) || (f_pos.y < p_pos.y - pipe_dist))) { + f_pos = sf::Vector2f(WINDOW_X / 2, WINDOW_Y / 2); + momentum = 0; + std::cout << "dead"; + } + + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { + momentum = -.4; + } + + momentum += g / 10000; + f_pos.y += momentum; + flappy.setPosition(f_pos); + + window.clear(sf::Color::Black); + window.draw(background_sprite); + window.draw(land_sprite); + window.draw(flappy); + window.draw(pipe_up_sprite); + window.draw(pipe_down_sprite); + + pipe_shaft_sprite.setPosition(pipe_up_sprite.getPosition()); + int y_pos = pipe_up_sprite.getPosition().y + pipe_up_sprite.getGlobalBounds().height; + while (y_pos < WINDOW_Y) { + pipe_shaft_sprite.setPosition(pipe_shaft_sprite.getPosition().x, y_pos); + y_pos++; + window.draw(pipe_shaft_sprite); + } + + y_pos = pipe_down_sprite.getPosition().y; + while (y_pos > 0) { + pipe_shaft_sprite.setPosition(pipe_shaft_sprite.getPosition().x, y_pos); + y_pos--; + window.draw(pipe_shaft_sprite); + } + + window.display(); + + + + } + return 0; + +} \ No newline at end of file