├── .gitignore ├── BallGame ├── Ball.cpp ├── Ball.h ├── BallController.cpp ├── BallController.h ├── BallGame.vcxproj ├── BallGame.vcxproj.filters ├── BallRenderer.cpp ├── BallRenderer.h ├── Fonts │ └── chintzy.ttf ├── Grid.cpp ├── Grid.h ├── Main.cpp ├── MainGame.cpp ├── MainGame.h ├── Shaders │ ├── momentumShading.frag │ ├── momentumShading.vert │ ├── textureShading.frag │ └── textureShading.vert └── Textures │ └── circle.png ├── Bengine ├── AudioEngine.cpp ├── AudioEngine.h ├── Bengine.cpp ├── Bengine.h ├── Bengine.vcxproj ├── Bengine.vcxproj.filters ├── BengineErrors.cpp ├── BengineErrors.h ├── Camera2D.cpp ├── Camera2D.h ├── DebugRenderer.cpp ├── DebugRenderer.h ├── GLSLProgram.cpp ├── GLSLProgram.h ├── GLTexture.h ├── GUI.cpp ├── GUI.h ├── IGameScreen.h ├── IMainGame.cpp ├── IMainGame.h ├── IOManager.cpp ├── IOManager.h ├── ImageLoader.cpp ├── ImageLoader.h ├── InputManager.cpp ├── InputManager.h ├── ParticleBatch2D.cpp ├── ParticleBatch2D.h ├── ParticleEngine2D.cpp ├── ParticleEngine2D.h ├── ReadMe.txt ├── ResourceManager.cpp ├── ResourceManager.h ├── ScreenList.cpp ├── ScreenList.h ├── Sprite.cpp ├── Sprite.h ├── SpriteBatch.cpp ├── SpriteBatch.h ├── SpriteFont.cpp ├── SpriteFont.h ├── TextureCache.cpp ├── TextureCache.h ├── TileSheet.h ├── Timing.cpp ├── Timing.h ├── Vertex.h ├── Window.cpp ├── Window.h ├── picoPNG.cpp └── picoPNG.h ├── LICENSE ├── NinjaPlatformer ├── App.cpp ├── App.h ├── Assets │ ├── blank.png │ ├── blue_ninja.png │ ├── bricks_light_top.png │ ├── bricks_loam_top.png │ ├── bricks_top.png │ ├── credits.txt │ └── glass_metal_frame_top.png ├── Box.cpp ├── Box.h ├── Capsule.cpp ├── Capsule.h ├── EditorScreen.cpp ├── EditorScreen.h ├── Fonts │ └── chintzy.ttf ├── GUI │ ├── animations │ │ ├── GameMenu.anims │ │ └── example.anims │ ├── fonts │ │ ├── Batang-18.font │ │ ├── DejaVuSans-10-NoScale.font │ │ ├── DejaVuSans-10.font │ │ ├── DejaVuSans-12-NoScale.font │ │ ├── DejaVuSans-12.font │ │ ├── DejaVuSans-14-NoScale.font │ │ ├── DejaVuSans-14.font │ │ ├── DejaVuSans.ttf │ │ ├── DejaVuSerif.ttf │ │ ├── FairChar-30.font │ │ ├── FetteClassicUNZFraktur.ttf │ │ ├── Futhark Adapted.ttf │ │ ├── GreatVibes-16.font │ │ ├── GreatVibes-22.font │ │ ├── GreatVibes-Regular.ttf │ │ ├── IMFePIrm29P.ttf │ │ ├── Junicode-13.font │ │ ├── Junicode.ttf │ │ ├── Jura-10.font │ │ ├── Jura-13.font │ │ ├── Jura-18.font │ │ ├── Jura-DemiBold.ttf │ │ ├── Jura-Light.ttf │ │ ├── Jura-Medium.ttf │ │ ├── Jura-Regular.ttf │ │ ├── Klingon-pIqaD-HaSta.ttf │ │ ├── Legal.txt │ │ ├── LicenseApache.txt │ │ ├── LicenseDejaVu.txt │ │ ├── LicenseGPL.txt │ │ ├── LicenseMIT.txt │ │ ├── LicenseSIL.txt │ │ ├── LicenseUbuntuFont.txt │ │ ├── RichStyle.ttf │ │ ├── Tnua-Libre.ttf │ │ ├── batang.ttf │ │ └── mizufalp.ttf │ ├── imagesets │ │ ├── AlfiskoSkin.imageset │ │ ├── AlfiskoSkin.png │ │ ├── Aliasing.jpg │ │ ├── BackgroundSampleBrowser.jpg │ │ ├── DriveIcons.imageset │ │ ├── DriveIcons.png │ │ ├── FairChar.imageset │ │ ├── FairChar.png │ │ ├── GameMenu.imageset │ │ ├── GameMenu.png │ │ ├── HUDDemo.imageset │ │ ├── HUDDemo.png │ │ ├── HUDDemoGameOver.png │ │ ├── OgreTray.imageset │ │ ├── OgreTrayImages.png │ │ ├── ReadMe.txt │ │ ├── SampleBrowser.imageset │ │ ├── SampleBrowser.png │ │ ├── SpaceBackground.jpg │ │ ├── TaharezLook.imageset │ │ ├── TaharezLook.png │ │ ├── Vanilla.imageset │ │ ├── WindowsLook.imageset │ │ ├── WindowsLook.png │ │ ├── logo.png │ │ └── vanilla.png │ ├── layouts │ │ ├── Console.wnd │ │ ├── Demo8.layout │ │ ├── DragDropDemo.layout │ │ ├── EffectsDemo.layout │ │ ├── FontDemo.layout │ │ ├── GameMenu.layout │ │ ├── HUDDemoGameOver.layout │ │ ├── HUDDemoIngame.layout │ │ ├── SampleBrowser.layout │ │ ├── SampleBrowserLoadScreen.layout │ │ ├── TabControlDemo.layout │ │ ├── TabPage.layout │ │ ├── TabPage1.layout │ │ ├── TabPage1.layout.orig │ │ ├── TabPage2.layout │ │ ├── TextDemo.layout │ │ ├── TreeDemoTaharez.layout │ │ ├── VanillaConsole.layout │ │ └── VanillaWindows.layout │ ├── looknfeel │ │ ├── AlfiskoSkin.looknfeel │ │ ├── GameMenu.looknfeel │ │ ├── Generic.looknfeel │ │ ├── HUDDemo.looknfeel │ │ ├── Inherited.looknfeel │ │ ├── InventoryComponents.looknfeel │ │ ├── OgreTray.looknfeel │ │ ├── SampleBrowser.looknfeel │ │ ├── TaharezLook.looknfeel │ │ ├── Vanilla.looknfeel │ │ ├── VanillaCommonDialogs.looknfeel │ │ └── WindowsLook.looknfeel │ ├── lua_scripts │ │ └── demo8.lua │ ├── schemes │ │ ├── AlfiskoSkin.scheme │ │ ├── GameMenu.scheme │ │ ├── Generic.scheme │ │ ├── HUDDemo.scheme │ │ ├── OgreTray.scheme │ │ ├── SampleBrowser.scheme │ │ ├── TaharezLook.scheme │ │ ├── TaharezLook.scheme.orig │ │ ├── VanillaCommonDialogs.scheme │ │ ├── VanillaCommonDialogs.scheme.orig │ │ ├── VanillaSkin.scheme │ │ └── WindowsLook.scheme │ └── xml_schemas │ │ ├── Animation.xsd │ │ ├── CEGUIConfig.xsd │ │ ├── Falagard.xsd │ │ ├── Font.xsd │ │ ├── GUILayout.xsd │ │ ├── GUIScheme.xsd │ │ ├── Imageset.xsd │ │ └── Samples.xsd ├── GameplayScreen.cpp ├── GameplayScreen.h ├── LevelReaderWriter.cpp ├── LevelReaderWriter.h ├── Levels │ └── DumbLevel.txt ├── Light.h ├── MainMenuScreen.cpp ├── MainMenuScreen.h ├── NinjaPlatformer.vcxproj ├── NinjaPlatformer.vcxproj.filters ├── Player.cpp ├── Player.h ├── ScreenIndices.h ├── Shaders │ ├── color.frag │ ├── color.vert │ ├── lightShading.frag │ ├── lightShading.vert │ ├── textureShading.frag │ └── textureShading.vert └── main.cpp ├── README.md ├── ZombieGame ├── Agent.cpp ├── Agent.h ├── Bullet.cpp ├── Bullet.h ├── Fonts │ └── chintzy.ttf ├── Gun.cpp ├── Gun.h ├── Human.cpp ├── Human.h ├── Level.cpp ├── Level.h ├── Levels │ └── level1.txt ├── MainGame.cpp ├── MainGame.h ├── Player.cpp ├── Player.h ├── Shaders │ ├── textureShading.frag │ └── textureShading.vert ├── Sound │ ├── XYZ.ogg │ ├── credits.txt │ └── shots │ │ ├── cg1.wav │ │ ├── info.txt │ │ ├── pistol.wav │ │ ├── rifle.wav │ │ └── shotgun.wav ├── Textures │ ├── circle.png │ ├── credits.txt │ ├── glass.png │ ├── human.png │ ├── light_bricks.png │ ├── particle.png │ ├── player.png │ ├── red_bricks.png │ └── zombie.png ├── Zombie.cpp ├── Zombie.h ├── ZombieGame.vcxproj ├── ZombieGame.vcxproj.filters └── main.cpp ├── graphicsTutorials.sln └── graphicsTutorials ├── Bullet.cpp ├── Bullet.h ├── MainGame.cpp ├── MainGame.h ├── Shaders ├── colorShading.frag └── colorShading.vert ├── Textures └── jimmyJump_pack │ ├── PNG │ ├── AngryCloud.png │ ├── Background.png │ ├── BrokenLandPiece_Beige.png │ ├── BrokenLandPiece_Blue.png │ ├── BrokenLandPiece_Gray.png │ ├── BrokenLandPiece_Green.png │ ├── BrokenLandPiece_Multicolored.png │ ├── BrokenLandPiece_Pink.png │ ├── Bubble_Big.png │ ├── Bubble_Small.png │ ├── Bullet.png │ ├── CharacterLeft_Jump.png │ ├── CharacterLeft_Standing.png │ ├── CharacterLeft_Walk1.png │ ├── CharacterLeft_Walk2.png │ ├── CharacterRight_Jump.png │ ├── CharacterRight_Standing.png │ ├── CharacterRight_Walk1.png │ ├── CharacterRight_Walk2.png │ ├── CloudWind.png │ ├── Coin.png │ ├── HalfLandPiece_Left_Beige.png │ ├── HalfLandPiece_Left_Blue.png │ ├── HalfLandPiece_Left_Gray.png │ ├── HalfLandPiece_Left_Green.png │ ├── HalfLandPiece_Left_Multicolored.png │ ├── HalfLandPiece_Left_Pink.png │ ├── HalfLandPiece_Right_Beige.png │ ├── HalfLandPiece_Right_Blue.png │ ├── HalfLandPiece_Right_Gray.png │ ├── HalfLandPiece_Right_Green.png │ ├── HalfLandPiece_Right_Multicolored.png │ ├── HalfLandPiece_Right_Pink.png │ ├── HappyCloud.png │ ├── HearthEnemy1.png │ ├── HearthEnemy2.png │ ├── JetFire1.png │ ├── JetFire2.png │ ├── Jetpack_Big.png │ ├── Jetpack_Small.png │ ├── LandPiece_DarkBeige.png │ ├── LandPiece_DarkBlue.png │ ├── LandPiece_DarkGray.png │ ├── LandPiece_DarkGreen.png │ ├── LandPiece_DarkMulticolored.png │ ├── LandPiece_DarkPing.png │ ├── LandPiece_LightBeige.png │ ├── LandPiece_LightBlue.png │ ├── LandPiece_LightGray.png │ ├── LandPiece_LightGreen.png │ ├── LandPiece_LightMulticolored.png │ ├── LandPiece_LightPing.png │ ├── Lightning1.png │ ├── Lightning2.png │ ├── Mushroom.png │ ├── Number_0.png │ ├── Number_1.png │ ├── Number_2.png │ ├── Number_3.png │ ├── Number_4.png │ ├── Number_5.png │ ├── Number_6.png │ ├── Number_7.png │ ├── Number_8.png │ ├── Number_9.png │ ├── Number_Point.png │ ├── Pistol.png │ └── Spring.png │ └── license.txt ├── graphicsTutorials.vcxproj ├── graphicsTutorials.vcxproj.filters └── main.cpp /BallGame/Ball.cpp: -------------------------------------------------------------------------------- 1 | #include "Ball.h" 2 | 3 | Ball::Ball(float radius, float mass, const glm::vec2& pos, 4 | const glm::vec2& vel, unsigned int textureId, 5 | const Bengine::ColorRGBA8& color) { 6 | this->radius = radius; 7 | this->mass = mass; 8 | this->position = pos; 9 | this->velocity = vel; 10 | this->textureId = textureId; 11 | this->color = color; 12 | } 13 | -------------------------------------------------------------------------------- /BallGame/Ball.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | struct Cell; 7 | 8 | // POD 9 | struct Ball { 10 | Ball(float radius, float mass, const glm::vec2& pos, 11 | const glm::vec2& vel, unsigned int textureId, 12 | const Bengine::ColorRGBA8& color); 13 | 14 | float radius; 15 | float mass; 16 | glm::vec2 velocity; 17 | glm::vec2 position; 18 | unsigned int textureId = 0; 19 | Bengine::ColorRGBA8 color; 20 | Cell* ownerCell = nullptr; 21 | int cellVectorIndex = -1; 22 | }; 23 | -------------------------------------------------------------------------------- /BallGame/BallController.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Ball.h" 6 | 7 | enum class GravityDirection {NONE, LEFT, UP, RIGHT, DOWN}; 8 | 9 | class Grid; 10 | 11 | class BallController { 12 | public: 13 | /// Updates the balls 14 | void updateBalls(std::vector & balls, Grid* grid, float deltaTime, int maxX, int maxY); 15 | /// Some simple event functions 16 | void onMouseDown(std::vector & balls, float mouseX, float mouseY); 17 | void onMouseUp(std::vector & balls); 18 | void onMouseMove(std::vector & balls, float mouseX, float mouseY); 19 | void setGravityDirection(GravityDirection dir) { m_gravityDirection = dir; } 20 | private: 21 | // Updates collision 22 | void updateCollision(Grid* grid); 23 | /// Checks collision between a ball and a vector of balls, starting at a specific index 24 | void checkCollision(Ball* ball, std::vector& ballsToCheck, int startingIndex); 25 | /// Checks collision between two balls 26 | void checkCollision(Ball& b1, Ball& b2); 27 | /// Returns true if the mouse is hovering over a ball 28 | bool isMouseOnBall(Ball&b, float mouseX, float mouseY); 29 | glm::vec2 getGravityAccel(); 30 | 31 | int m_grabbedBall = -1; ///< The ball we are currently grabbing on to 32 | glm::vec2 m_prevPos = glm::vec2(0.0f); ///< Previous position of the grabbed ball 33 | glm::vec2 m_grabOffset = glm::vec2(0.0f); ///< Offset of the cursor on the selected ball 34 | 35 | GravityDirection m_gravityDirection = GravityDirection::NONE; 36 | }; 37 | 38 | -------------------------------------------------------------------------------- /BallGame/BallGame.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | -------------------------------------------------------------------------------- /BallGame/BallRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "Ball.h" 8 | 9 | // Ball renderer interface 10 | class BallRenderer { 11 | public: 12 | virtual void renderBalls(Bengine::SpriteBatch& spriteBatch, const std::vector& balls, 13 | const glm::mat4& projectionMatrix); 14 | protected: 15 | std::unique_ptr m_program = nullptr; 16 | }; 17 | 18 | // Visualizes kinetic energy 19 | class MomentumBallRenderer : public BallRenderer { 20 | public: 21 | virtual void renderBalls(Bengine::SpriteBatch& spriteBatch, const std::vector& balls, 22 | const glm::mat4& projectionMatrix) override; 23 | }; 24 | 25 | // Visualizes positive X component of velocity, as well as position 26 | class VelocityBallRenderer : public BallRenderer { 27 | public: 28 | VelocityBallRenderer(int screenWidth, int screenHeight); 29 | 30 | virtual void renderBalls(Bengine::SpriteBatch& spriteBatch, const std::vector& balls, 31 | const glm::mat4& projectionMatrix) override; 32 | private: 33 | int m_screenWidth; 34 | int m_screenHeight; 35 | }; 36 | 37 | // Trippy renderer! 38 | class TrippyBallRenderer : public BallRenderer { 39 | public: 40 | TrippyBallRenderer(int screenWidth, int screenHeight); 41 | 42 | virtual void renderBalls(Bengine::SpriteBatch& spriteBatch, const std::vector& balls, 43 | const glm::mat4& projectionMatrix) override; 44 | private: 45 | int m_screenWidth; 46 | int m_screenHeight; 47 | float m_time = 0.0f; 48 | }; -------------------------------------------------------------------------------- /BallGame/Fonts/chintzy.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/BallGame/Fonts/chintzy.ttf -------------------------------------------------------------------------------- /BallGame/Grid.cpp: -------------------------------------------------------------------------------- 1 | #include "Grid.h" 2 | 3 | #include 4 | #include 5 | 6 | Grid::Grid(int width, int height, int cellSize) : 7 | m_width(width), 8 | m_height(height), 9 | m_cellSize(cellSize) { 10 | m_numXCells = (int)ceil((float)m_width / m_cellSize); 11 | m_numYCells = (int)ceil((float)m_height / m_cellSize); 12 | 13 | // Allocate all the cells 14 | const int BALLS_TO_RESERVE = 20; 15 | m_cells.resize(m_numYCells * m_numXCells); 16 | for (size_t i = 0; i < m_cells.size(); i++) { 17 | m_cells[i].balls.reserve(BALLS_TO_RESERVE); 18 | } 19 | } 20 | 21 | Grid::~Grid() { 22 | } 23 | 24 | void Grid::addBall(Ball* ball) { 25 | Cell* cell = getCell(ball->position); 26 | cell->balls.push_back(ball); 27 | ball->ownerCell = cell; 28 | ball->cellVectorIndex = cell->balls.size() - 1; 29 | } 30 | 31 | void Grid::addBall(Ball* ball, Cell* cell) { 32 | cell->balls.push_back(ball); 33 | ball->ownerCell = cell; 34 | ball->cellVectorIndex = cell->balls.size() - 1; 35 | } 36 | 37 | Cell* Grid::getCell(int x, int y) { 38 | if (x < 0) x = 0; 39 | if (x >= m_numXCells) x = m_numXCells - 1; 40 | if (y < 0) y = 0; 41 | if (y >= m_numYCells) y = m_numYCells - 1; 42 | 43 | return &m_cells[y * m_numXCells + x]; 44 | } 45 | 46 | Cell* Grid::getCell(const glm::vec2& pos) { 47 | int cellX = (int)(pos.x / m_cellSize); 48 | int cellY = (int)(pos.y / m_cellSize); 49 | 50 | return getCell(cellX, cellY); 51 | } 52 | 53 | void Grid::removeBallFromCell(Ball* ball) { 54 | std::vector& balls = ball->ownerCell->balls; 55 | // Normal vector swap 56 | balls[ball->cellVectorIndex] = balls.back(); 57 | balls.pop_back(); 58 | // Update vector index 59 | if ((size_t)ball->cellVectorIndex < balls.size()) { 60 | balls[ball->cellVectorIndex]->cellVectorIndex = ball->cellVectorIndex; 61 | } 62 | // Set the index of ball to -1 63 | ball->cellVectorIndex = -1; 64 | ball->ownerCell = nullptr; 65 | } 66 | -------------------------------------------------------------------------------- /BallGame/Grid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Ball.h" 4 | #include 5 | 6 | struct Cell { 7 | std::vector balls; 8 | }; 9 | 10 | class Grid { 11 | friend class BallController; 12 | public: 13 | Grid(int width, int height, int cellSize); 14 | ~Grid(); 15 | 16 | /// Adds a ball and determines which cell it belongs to 17 | void addBall(Ball* ball); 18 | /// Adds a ball to the specified cell 19 | void addBall(Ball* ball, Cell* cell); 20 | /// Gets cell based on cell coordinates 21 | Cell* getCell(int x, int y); 22 | /// Gets cell based on window coordinates 23 | Cell* getCell(const glm::vec2& pos); 24 | 25 | void removeBallFromCell(Ball* ball); 26 | 27 | private: 28 | std::vector m_cells; 29 | int m_cellSize; 30 | int m_width; 31 | int m_height; 32 | int m_numXCells; 33 | int m_numYCells; 34 | }; 35 | -------------------------------------------------------------------------------- /BallGame/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "MainGame.h" 2 | 3 | int main(int argc, char** argv) { 4 | MainGame mainGame; 5 | mainGame.run(); 6 | 7 | return 0; 8 | } -------------------------------------------------------------------------------- /BallGame/MainGame.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "BallController.h" 13 | #include "BallRenderer.h" 14 | #include "Grid.h" 15 | 16 | // TODO: 17 | // Visualize momentum with color 18 | // Visualize velocity with color 19 | // Visualize position with color 20 | 21 | enum class GameState { RUNNING, EXIT }; 22 | 23 | const int CELL_SIZE = 12; 24 | 25 | class MainGame { 26 | public: 27 | ~MainGame(); 28 | void run(); 29 | 30 | 31 | private: 32 | void init(); 33 | void initRenderers(); 34 | void initBalls(); 35 | void update(float deltaTime); 36 | void draw(); 37 | void drawHud(); 38 | void processInput(); 39 | 40 | int m_screenWidth = 0; 41 | int m_screenHeight = 0; 42 | 43 | std::vector m_balls; ///< All the balls 44 | std::unique_ptr m_grid; ///< Grid for spatial partitioning for collision 45 | 46 | int m_currentRenderer = 0; 47 | std::vector > m_ballRenderers; 48 | 49 | BallController m_ballController; ///< Controls balls 50 | 51 | Bengine::Window m_window; ///< The main window 52 | Bengine::SpriteBatch m_spriteBatch; ///< Renders all the balls 53 | std::unique_ptr m_spriteFont; ///< For font rendering 54 | Bengine::Camera2D m_camera; ///< Renders the scene 55 | Bengine::InputManager m_inputManager; ///< Handles input 56 | Bengine::GLSLProgram m_textureProgram; ///< Shader for textures] 57 | 58 | Bengine::FpsLimiter m_fpsLimiter; ///< Limits and calculates fps 59 | float m_fps = 0.0f; 60 | 61 | GameState m_gameState = GameState::RUNNING; ///< The state of the game 62 | }; 63 | 64 | -------------------------------------------------------------------------------- /BallGame/Shaders/momentumShading.frag: -------------------------------------------------------------------------------- 1 | #version 130 2 | //The fragment shader operates on each pixel in a given polygon 3 | 4 | in vec2 fragmentPosition; 5 | in vec4 fragmentColor; 6 | in vec2 fragmentUV; 7 | 8 | //This is the 3 component float vector that gets outputted to the screen 9 | //for each pixel. 10 | out vec4 color; 11 | 12 | uniform sampler2D mySampler; 13 | 14 | void main() { 15 | 16 | //cos(x) returns a number between -1 and 1. To convert it into the range 0 to 1 17 | //you simply do (cos(x) + 1.0) * 0.5 18 | 19 | vec4 textureColor = texture(mySampler, fragmentUV); 20 | 21 | //Make crazy colors using time and position! 22 | color = fragmentColor * textureColor; 23 | } -------------------------------------------------------------------------------- /BallGame/Shaders/momentumShading.vert: -------------------------------------------------------------------------------- 1 | #version 130 2 | //The vertex shader operates on each vertex 3 | 4 | //input data from the VBO. Each vertex is 2 floats 5 | in vec2 vertexPosition; 6 | in vec4 vertexColor; 7 | in vec2 vertexUV; 8 | 9 | out vec2 fragmentPosition; 10 | out vec4 fragmentColor; 11 | out vec2 fragmentUV; 12 | 13 | uniform mat4 P; 14 | 15 | void main() { 16 | //Set the x,y position on the screen 17 | gl_Position.xy = (P * vec4(vertexPosition, 0.0, 1.0)).xy; 18 | //the z position is zero since we are in 2D 19 | gl_Position.z = 0.0; 20 | 21 | //Indicate that the coordinates are normalized 22 | gl_Position.w = 1.0; 23 | 24 | fragmentPosition = vertexPosition; 25 | 26 | fragmentColor = vertexColor; 27 | 28 | fragmentUV = vec2(vertexUV.x, 1.0 - vertexUV.y); 29 | } -------------------------------------------------------------------------------- /BallGame/Shaders/textureShading.frag: -------------------------------------------------------------------------------- 1 | #version 130 2 | //The fragment shader operates on each pixel in a given polygon 3 | 4 | in vec2 fragmentPosition; 5 | in vec4 fragmentColor; 6 | in vec2 fragmentUV; 7 | 8 | //This is the 3 component float vector that gets outputted to the screen 9 | //for each pixel. 10 | out vec4 color; 11 | 12 | uniform sampler2D mySampler; 13 | 14 | void main() { 15 | 16 | //cos(x) returns a number between -1 and 1. To convert it into the range 0 to 1 17 | //you simply do (cos(x) + 1.0) * 0.5 18 | 19 | vec4 textureColor = texture(mySampler, fragmentUV); 20 | 21 | //Make crazy colors using time and position! 22 | color = fragmentColor * textureColor; 23 | } -------------------------------------------------------------------------------- /BallGame/Shaders/textureShading.vert: -------------------------------------------------------------------------------- 1 | #version 130 2 | //The vertex shader operates on each vertex 3 | 4 | //input data from the VBO. Each vertex is 2 floats 5 | in vec2 vertexPosition; 6 | in vec4 vertexColor; 7 | in vec2 vertexUV; 8 | 9 | out vec2 fragmentPosition; 10 | out vec4 fragmentColor; 11 | out vec2 fragmentUV; 12 | 13 | uniform mat4 P; 14 | 15 | void main() { 16 | //Set the x,y position on the screen 17 | gl_Position.xy = (P * vec4(vertexPosition, 0.0, 1.0)).xy; 18 | //the z position is zero since we are in 2D 19 | gl_Position.z = 0.0; 20 | 21 | //Indicate that the coordinates are normalized 22 | gl_Position.w = 1.0; 23 | 24 | fragmentPosition = vertexPosition; 25 | 26 | fragmentColor = vertexColor; 27 | 28 | fragmentUV = vec2(vertexUV.x, 1.0 - vertexUV.y); 29 | } -------------------------------------------------------------------------------- /BallGame/Textures/circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/BallGame/Textures/circle.png -------------------------------------------------------------------------------- /Bengine/AudioEngine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Bengine { 8 | 9 | class SoundEffect { 10 | public: 11 | friend class AudioEngine; 12 | 13 | /// Plays the effect file 14 | /// @param loops: If loops == -1, loop forever, 15 | /// otherwise play it loops+1 times 16 | void play(int loops = 0); 17 | private: 18 | Mix_Chunk* m_chunk = nullptr; 19 | }; 20 | 21 | class Music { 22 | public: 23 | friend class AudioEngine; 24 | 25 | /// Plays the music file 26 | /// @param loops: If loops == -1, loop forever, 27 | /// otherwise play it loops times 28 | void play(int loops = 1); 29 | 30 | /// Pauses whatever song is currently playing 31 | static void pause(); 32 | /// Stops whatever song is currently playing 33 | static void stop(); 34 | /// Resumes whatever song is currently playing 35 | static void resume(); 36 | private: 37 | Mix_Music* m_music = nullptr; 38 | }; 39 | 40 | class AudioEngine { 41 | public: 42 | AudioEngine(); 43 | ~AudioEngine(); 44 | 45 | void init(); 46 | void destroy(); 47 | 48 | SoundEffect loadSoundEffect(const std::string& filePath); 49 | Music loadMusic(const std::string& filePath); 50 | private: 51 | 52 | std::map m_effectMap; ///< Effects cache 53 | std::map m_musicMap; ///< Music cache 54 | 55 | bool m_isInitialized = false; 56 | }; 57 | 58 | } -------------------------------------------------------------------------------- /Bengine/Bengine.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Bengine.h" 5 | 6 | namespace Bengine { 7 | 8 | int init() { 9 | //Initialize SDL 10 | SDL_Init(SDL_INIT_EVERYTHING); 11 | 12 | //Tell SDL that we want a double buffered window so we dont get 13 | //any flickering 14 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 15 | 16 | return 0; 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /Bengine/Bengine.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | namespace Bengine { 4 | extern int init(); 5 | } -------------------------------------------------------------------------------- /Bengine/BengineErrors.cpp: -------------------------------------------------------------------------------- 1 | #include "BengineErrors.h" 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace Bengine { 9 | 10 | //Prints out an error message and exits the game 11 | void fatalError(std::string errorString) { 12 | std::cout << errorString << std::endl; 13 | std::cout << "Enter any key to quit..."; 14 | int tmp; 15 | std::cin >> tmp; 16 | SDL_Quit(); 17 | exit(69); 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /Bengine/BengineErrors.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | //This file holds some global error functions 3 | 4 | #include 5 | 6 | namespace Bengine { 7 | 8 | extern void fatalError(std::string errorString); 9 | 10 | } -------------------------------------------------------------------------------- /Bengine/Camera2D.cpp: -------------------------------------------------------------------------------- 1 | #include "Camera2D.h" 2 | 3 | namespace Bengine { 4 | 5 | Camera2D::Camera2D() : _position(0.0f, 0.0f), 6 | _cameraMatrix(1.0f), 7 | _orthoMatrix(1.0f), 8 | _scale(1.0f), 9 | _needsMatrixUpdate(true), 10 | _screenWidth(500), 11 | _screenHeight(500) 12 | { 13 | } 14 | 15 | Camera2D::~Camera2D() 16 | { 17 | } 18 | 19 | void Camera2D::init(int screenWidth, int screenHeight) { 20 | _screenWidth = screenWidth; 21 | _screenHeight = screenHeight; 22 | _orthoMatrix = glm::ortho(0.0f, (float)_screenWidth, 0.0f, (float)_screenHeight); 23 | } 24 | 25 | //updates the camera matrix if needed 26 | void Camera2D::update() { 27 | 28 | //Only update if our position or scale have changed 29 | if (_needsMatrixUpdate) { 30 | 31 | //Camera Translation 32 | glm::vec3 translate(-_position.x + _screenWidth / 2, -_position.y + _screenHeight / 2, 0.0f); 33 | _cameraMatrix = glm::translate(_orthoMatrix, translate); 34 | 35 | //Camera Scale 36 | glm::vec3 scale(_scale, _scale, 0.0f); 37 | _cameraMatrix = glm::scale(glm::mat4(1.0f), scale) * _cameraMatrix; 38 | 39 | _needsMatrixUpdate = false; 40 | } 41 | } 42 | 43 | glm::vec2 Camera2D::convertScreenToWorld(glm::vec2 screenCoords) { 44 | // Invert Y direction 45 | screenCoords.y = _screenHeight - screenCoords.y; 46 | // Make it so that 0 is the center 47 | screenCoords -= glm::vec2(_screenWidth / 2, _screenHeight / 2); 48 | // Scale the coordinates 49 | screenCoords /= _scale; 50 | // Translate with the camera position 51 | screenCoords += _position; 52 | return screenCoords; 53 | } 54 | 55 | // Simple AABB test to see if a box is in the camera view 56 | bool Camera2D::isBoxInView(const glm::vec2& position, const glm::vec2& dimensions) { 57 | 58 | glm::vec2 scaledScreenDimensions = glm::vec2(_screenWidth, _screenHeight) / (_scale); 59 | 60 | // The minimum distance before a collision occurs 61 | const float MIN_DISTANCE_X = dimensions.x / 2.0f + scaledScreenDimensions.x / 2.0f; 62 | const float MIN_DISTANCE_Y = dimensions.y / 2.0f + scaledScreenDimensions.y / 2.0f; 63 | 64 | // Center position of the parameters 65 | glm::vec2 centerPos = position + dimensions / 2.0f; 66 | // Center position of the camera 67 | glm::vec2 centerCameraPos = _position; 68 | // Vector from the input to the camera 69 | glm::vec2 distVec = centerPos - centerCameraPos; 70 | 71 | // Get the depth of the collision 72 | float xDepth = MIN_DISTANCE_X - abs(distVec.x); 73 | float yDepth = MIN_DISTANCE_Y - abs(distVec.y); 74 | 75 | // If both the depths are > 0, then we collided 76 | if (xDepth > 0 && yDepth > 0) { 77 | // There was a collision 78 | return true; 79 | } 80 | return false; 81 | } 82 | } -------------------------------------------------------------------------------- /Bengine/Camera2D.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Bengine { 6 | 7 | //Camera class for 2D games 8 | class Camera2D 9 | { 10 | public: 11 | Camera2D(); 12 | ~Camera2D(); 13 | 14 | //sets up the orthographic matrix and screen dimensions 15 | void init(int screenWidth, int screenHeight); 16 | 17 | //updates the camera matrix if needed 18 | void update(); 19 | 20 | glm::vec2 convertScreenToWorld(glm::vec2 screenCoords); 21 | 22 | bool isBoxInView(const glm::vec2& position, const glm::vec2& dimensions); 23 | 24 | void offsetPosition(const glm::vec2& offset) { _position += offset; _needsMatrixUpdate = true; } 25 | void offsetScale(float offset) { _scale += offset; if (_scale < 0.001f) _scale = 0.001f; _needsMatrixUpdate = true; } 26 | 27 | //setters 28 | void setPosition(const glm::vec2& newPosition) { _position = newPosition; _needsMatrixUpdate = true; } 29 | void setScale(float newScale) { _scale = newScale; _needsMatrixUpdate = true; } 30 | 31 | //getters 32 | const glm::vec2& getPosition() const { return _position; } 33 | float getScale() const { return _scale; } 34 | const glm::mat4& getCameraMatrix() const { return _cameraMatrix; } 35 | float getAspectRatio() const { return (float)_screenWidth / (float)_screenHeight; } 36 | 37 | private: 38 | int _screenWidth, _screenHeight; 39 | bool _needsMatrixUpdate; 40 | float _scale; 41 | glm::vec2 _position; 42 | glm::mat4 _cameraMatrix; 43 | glm::mat4 _orthoMatrix; 44 | }; 45 | 46 | } -------------------------------------------------------------------------------- /Bengine/DebugRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GLSLProgram.h" 4 | #include "Vertex.h" 5 | #include 6 | #include 7 | 8 | namespace Bengine { 9 | class DebugRenderer { 10 | public: 11 | DebugRenderer(); 12 | ~DebugRenderer(); 13 | 14 | void init(); 15 | void end(); 16 | void drawLine(const glm::vec2& a, const glm::vec2& b, const ColorRGBA8& color); 17 | void drawBox(const glm::vec4& destRect, const ColorRGBA8& color, float angle); 18 | void drawCircle(const glm::vec2& center, const ColorRGBA8& color, float radius); 19 | void render(const glm::mat4& projectionMatrix, float lineWidth); 20 | void dispose(); 21 | 22 | struct DebugVertex { 23 | glm::vec2 position; 24 | Bengine::ColorRGBA8 color; 25 | }; 26 | private: 27 | Bengine::GLSLProgram m_program; 28 | std::vector m_verts; 29 | std::vector m_indices; 30 | GLuint m_vbo = 0, m_vao = 0, m_ibo = 0; 31 | int m_numElements = 0; 32 | }; 33 | 34 | } -------------------------------------------------------------------------------- /Bengine/GLSLProgram.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Bengine { 7 | 8 | //This class handles the compilation, linking, and usage of a GLSL shader program. 9 | //Reference: http://www.opengl.org/wiki/Shader_Compilation 10 | class GLSLProgram 11 | { 12 | public: 13 | GLSLProgram(); 14 | ~GLSLProgram(); 15 | 16 | void compileShaders(const std::string& vertexShaderFilePath, const std::string& fragmentShaderFilePath); 17 | 18 | void compileShadersFromSource(const char* vertexSource, const char* fragmentSource); 19 | 20 | void linkShaders(); 21 | 22 | void addAttribute(const std::string& attributeName); 23 | 24 | GLint getUniformLocation(const std::string& uniformName); 25 | 26 | void use(); 27 | void unuse(); 28 | 29 | void dispose(); 30 | private: 31 | 32 | int _numAttributes; 33 | 34 | void compileShader(const char* source, const std::string& name, GLuint id); 35 | 36 | GLuint _programID; 37 | 38 | GLuint _vertexShaderID; 39 | GLuint _fragmentShaderID; 40 | }; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Bengine/GLTexture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Bengine { 6 | 7 | struct GLTexture { 8 | std::string filePath = ""; 9 | GLuint id; 10 | int width; 11 | int height; 12 | }; 13 | } -------------------------------------------------------------------------------- /Bengine/GUI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Bengine { 9 | class GUI { 10 | public: 11 | void init(const std::string& resourceDirectory); 12 | void destroy(); 13 | 14 | void draw(); 15 | void update(); 16 | 17 | void setMouseCursor(const std::string& imageFile); 18 | void showMouseCursor(); 19 | void hideMouseCursor(); 20 | 21 | void onSDLEvent(SDL_Event& evnt); 22 | 23 | void loadScheme(const std::string& schemeFile); 24 | void setFont(const std::string& fontFile); 25 | CEGUI::Window* createWidget(const std::string& type, const glm::vec4& destRectPerc, const glm::vec4& destRectPix, const std::string& name = ""); 26 | CEGUI::Window* createWidget(CEGUI::Window* parent, const std::string& type, const glm::vec4& destRectPerc, const glm::vec4& destRectPix, const std::string& name = ""); 27 | static void setWidgetDestRect(CEGUI::Window* widget, const glm::vec4& destRectPerc, const glm::vec4& destRectPix); 28 | 29 | // Getters 30 | static CEGUI::OpenGL3Renderer* getRenderer() { return m_renderer; } 31 | const CEGUI::GUIContext* getContext() { return m_context; } 32 | private: 33 | static CEGUI::OpenGL3Renderer* m_renderer; 34 | CEGUI::GUIContext* m_context = nullptr; 35 | CEGUI::Window* m_root = nullptr; 36 | unsigned int m_lastTime = 0; 37 | }; 38 | } -------------------------------------------------------------------------------- /Bengine/IGameScreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define SCREEN_INDEX_NO_SCREEN -1 4 | 5 | namespace Bengine{ 6 | 7 | class IMainGame; 8 | 9 | enum class ScreenState { 10 | NONE, 11 | RUNNING, 12 | EXIT_APPLICATION, 13 | CHANGE_NEXT, 14 | CHANGE_PREVIOUS 15 | }; 16 | 17 | class IGameScreen { 18 | public: 19 | friend class ScreenList; 20 | 21 | IGameScreen() { 22 | // Empty 23 | } 24 | virtual ~IGameScreen() { 25 | // Empty 26 | } 27 | 28 | // Return the index of the next or previous screen when changing screens 29 | virtual int getNextScreenIndex() const = 0; 30 | virtual int getPreviousScreenIndex() const = 0; 31 | 32 | // Called at beginning and end of application 33 | virtual void build() = 0; 34 | virtual void destroy() = 0; 35 | 36 | // Called when a screen enters and exits focus 37 | virtual void onEntry() = 0; 38 | virtual void onExit() = 0; 39 | 40 | // Called in the main game loop 41 | virtual void update() = 0; 42 | virtual void draw() = 0; 43 | 44 | // Gets the index of the current screen 45 | int getScreenIndex() const { 46 | return m_screenIndex; 47 | } 48 | void setRunning() { 49 | m_currentState = ScreenState::RUNNING; 50 | } 51 | 52 | ScreenState getState() const { return m_currentState; } 53 | 54 | /// Sets m_game to the parent game 55 | void setParentGame(IMainGame* game) { m_game = game; } 56 | 57 | protected: 58 | ScreenState m_currentState = ScreenState::NONE; 59 | IMainGame* m_game = nullptr; 60 | int m_screenIndex = -1; 61 | }; 62 | 63 | } -------------------------------------------------------------------------------- /Bengine/IMainGame.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Bengine.h" 4 | #include "Window.h" 5 | #include "InputManager.h" 6 | #include 7 | 8 | namespace Bengine { 9 | 10 | class ScreenList; 11 | class IGameScreen; 12 | 13 | class IMainGame { 14 | public: 15 | IMainGame(); 16 | virtual ~IMainGame(); 17 | 18 | // Runs and initializes the game 19 | void run(); 20 | // Exits the game 21 | void exitGame(); 22 | 23 | // Called on initialization 24 | virtual void onInit() = 0; 25 | // For adding all screens 26 | virtual void addScreens() = 0; 27 | // Called when exiting 28 | virtual void onExit() = 0; 29 | 30 | void onSDLEvent(SDL_Event& evnt); 31 | 32 | const float getFps() const { 33 | return m_fps; 34 | } 35 | 36 | InputManager inputManager; 37 | 38 | protected: 39 | // Custom update function 40 | virtual void update(); 41 | // Custom render function 42 | virtual void draw(); 43 | 44 | bool init(); 45 | bool initSystems(); 46 | 47 | std::unique_ptr m_screenList = nullptr; 48 | IGameScreen* m_currentScreen = nullptr; 49 | bool m_isRunning = false; 50 | float m_fps = 0.0f; 51 | Window m_window; 52 | }; 53 | } -------------------------------------------------------------------------------- /Bengine/IOManager.cpp: -------------------------------------------------------------------------------- 1 | #include "IOManager.h" 2 | 3 | #include 4 | #include 5 | 6 | // Namespace alias 7 | namespace fs = std::tr2::sys; 8 | 9 | namespace Bengine { 10 | 11 | bool IOManager::readFileToBuffer(std::string filePath, std::vector& buffer) { 12 | std::ifstream file(filePath, std::ios::binary); 13 | if (file.fail()) { 14 | perror(filePath.c_str()); 15 | return false; 16 | } 17 | 18 | //seek to the end 19 | file.seekg(0, std::ios::end); 20 | 21 | //Get the file size 22 | unsigned int fileSize = (unsigned int)file.tellg(); 23 | file.seekg(0, std::ios::beg); 24 | 25 | //Reduce the file size by any header bytes that might be present 26 | fileSize -= (unsigned int)file.tellg(); 27 | 28 | buffer.resize(fileSize); 29 | file.read((char *)&(buffer[0]), fileSize); 30 | file.close(); 31 | 32 | return true; 33 | } 34 | 35 | bool IOManager::readFileToBuffer(std::string filePath, std::string& buffer) { 36 | std::ifstream file(filePath, std::ios::binary); 37 | if (file.fail()) { 38 | perror(filePath.c_str()); 39 | return false; 40 | } 41 | 42 | //seek to the end 43 | file.seekg(0, std::ios::end); 44 | 45 | //Get the file size 46 | unsigned int fileSize = (unsigned int)file.tellg(); 47 | file.seekg(0, std::ios::beg); 48 | 49 | //Reduce the file size by any header bytes that might be present 50 | fileSize -= (unsigned int)file.tellg(); 51 | 52 | buffer.resize(fileSize); 53 | file.read((char *)&(buffer[0]), fileSize); 54 | file.close(); 55 | 56 | return true; 57 | } 58 | 59 | bool IOManager::getDirectoryEntries(const char* path, std::vector& rvEntries) { 60 | auto dpath = fs::path(path); 61 | // Must be directory 62 | if (!fs::is_directory(dpath)) return false; 63 | 64 | for (auto it = fs::directory_iterator(dpath); it != fs::directory_iterator(); ++it) { 65 | rvEntries.emplace_back(); 66 | rvEntries.back().path = it->path().string(); 67 | if (is_directory(it->path())) { 68 | rvEntries.back().isDirectory = true; 69 | } else { 70 | rvEntries.back().isDirectory = false; 71 | } 72 | } 73 | return true; 74 | } 75 | 76 | bool IOManager::makeDirectory(const char* path) { 77 | return fs::create_directory(fs::path(path)); 78 | } 79 | } -------------------------------------------------------------------------------- /Bengine/IOManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Bengine { 6 | 7 | struct DirEntry { 8 | std::string path; 9 | bool isDirectory; 10 | }; 11 | 12 | class IOManager 13 | { 14 | public: 15 | static bool readFileToBuffer(std::string filePath, std::vector& buffer); 16 | static bool readFileToBuffer(std::string filePath, std::string& buffer); 17 | // Gets all directory entries in the directory specified by path and stores in rvEntries. 18 | // Returns false if path is not a directory. 19 | static bool getDirectoryEntries(const char* path, std::vector& rvEntries); 20 | static bool makeDirectory(const char* path); 21 | }; 22 | 23 | } -------------------------------------------------------------------------------- /Bengine/ImageLoader.cpp: -------------------------------------------------------------------------------- 1 | #include "ImageLoader.h" 2 | #include "picoPNG.h" 3 | #include "IOManager.h" 4 | #include "BengineErrors.h" 5 | 6 | namespace Bengine { 7 | 8 | GLTexture ImageLoader::loadPNG(std::string filePath) { 9 | //Create a GLTexture and initialize all its fields to 0 10 | GLTexture texture = {}; 11 | 12 | //This is the input data to decodePNG, which we load from a file 13 | std::vector in; 14 | //This is the output data from decodePNG, which is the pixel data for our texture 15 | std::vector out; 16 | 17 | unsigned long width, height; 18 | 19 | //Read in the image file contents into a buffer 20 | if (IOManager::readFileToBuffer(filePath, in) == false) { 21 | fatalError("Failed to load PNG file to buffer!"); 22 | } 23 | 24 | //Decode the .png format into an array of pixels 25 | int errorCode = decodePNG(out, width, height, &(in[0]), in.size()); 26 | if (errorCode != 0) { 27 | fatalError("decodePNG failed with error: " + std::to_string(errorCode)); 28 | } 29 | 30 | //Generate the openGL texture object 31 | glGenTextures(1, &(texture.id)); 32 | 33 | //Bind the texture object 34 | glBindTexture(GL_TEXTURE_2D, texture.id); 35 | //Upload the pixels to the texture 36 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &(out[0])); 37 | 38 | //Set some texture parameters 39 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 40 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 41 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 42 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 43 | 44 | //Generate the mipmaps 45 | glGenerateMipmap(GL_TEXTURE_2D); 46 | 47 | //Unbind the texture 48 | glBindTexture(GL_TEXTURE_2D, 0); 49 | 50 | texture.width = width; 51 | texture.height = height; 52 | texture.filePath = filePath; 53 | 54 | //Return a copy of the texture data 55 | return texture; 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /Bengine/ImageLoader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GLTexture.h" 3 | 4 | #include 5 | 6 | namespace Bengine { 7 | 8 | //Loads images into GLTextures 9 | class ImageLoader 10 | { 11 | public: 12 | static GLTexture loadPNG(std::string filePath); 13 | }; 14 | 15 | } -------------------------------------------------------------------------------- /Bengine/InputManager.cpp: -------------------------------------------------------------------------------- 1 | #include "InputManager.h" 2 | 3 | namespace Bengine { 4 | 5 | InputManager::InputManager() : _mouseCoords(0.0f) 6 | { 7 | } 8 | 9 | 10 | InputManager::~InputManager() 11 | { 12 | } 13 | 14 | void InputManager::update() { 15 | // Loop through _keyMap using a for each loop, and copy it over to _previousKeyMap 16 | for (auto& it : _keyMap) { 17 | _previousKeyMap[it.first] = it.second; 18 | } 19 | } 20 | 21 | void InputManager::pressKey(unsigned int keyID) { 22 | // Here we are treating _keyMap as an associative array. 23 | // if keyID doesn't already exist in _keyMap, it will get added 24 | _keyMap[keyID] = true; 25 | } 26 | 27 | void InputManager::releaseKey(unsigned int keyID) { 28 | _keyMap[keyID] = false; 29 | } 30 | 31 | void InputManager::setMouseCoords(float x, float y) { 32 | _mouseCoords.x = x; 33 | _mouseCoords.y = y; 34 | } 35 | 36 | bool InputManager::isKeyDown(unsigned int keyID) { 37 | // We dont want to use the associative array approach here 38 | // because we don't want to create a key if it doesnt exist. 39 | // So we do it manually 40 | auto it = _keyMap.find(keyID); 41 | if (it != _keyMap.end()) { 42 | // Found the key 43 | return it->second; 44 | } else { 45 | // Didn't find the key 46 | return false; 47 | } 48 | } 49 | 50 | bool InputManager::isKeyPressed(unsigned int keyID) { 51 | // Check if it is pressed this frame, and wasn't pressed last frame 52 | if (isKeyDown(keyID) == true && wasKeyDown(keyID) == false) { 53 | return true; 54 | } 55 | return false; 56 | } 57 | 58 | bool InputManager::wasKeyDown(unsigned int keyID) { 59 | // We dont want to use the associative array approach here 60 | // because we don't want to create a key if it doesnt exist. 61 | // So we do it manually 62 | auto it = _previousKeyMap.find(keyID); 63 | if (it != _previousKeyMap.end()) { 64 | // Found the key 65 | return it->second; 66 | } else { 67 | // Didn't find the key 68 | return false; 69 | } 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /Bengine/InputManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Bengine { 7 | 8 | // Input manager stores a key map that maps SDL_Keys to booleans. 9 | // If the value in the key map is true, then the key is pressed. 10 | // Otherwise, it is released. 11 | class InputManager 12 | { 13 | public: 14 | InputManager(); 15 | ~InputManager(); 16 | 17 | void update(); 18 | 19 | void pressKey(unsigned int keyID); 20 | void releaseKey(unsigned int keyID); 21 | 22 | void setMouseCoords(float x, float y); 23 | 24 | /// Returns true if the key is held down 25 | bool isKeyDown(unsigned int keyID); 26 | 27 | /// Returns true if the key was just pressed 28 | bool isKeyPressed(unsigned int keyID); 29 | 30 | //getters 31 | glm::vec2 getMouseCoords() const { return _mouseCoords; } 32 | private: 33 | /// Returns true if the key is held down 34 | bool wasKeyDown(unsigned int keyID); 35 | 36 | std::unordered_map _keyMap; 37 | std::unordered_map _previousKeyMap; 38 | glm::vec2 _mouseCoords; 39 | }; 40 | 41 | } -------------------------------------------------------------------------------- /Bengine/ParticleBatch2D.cpp: -------------------------------------------------------------------------------- 1 | #include "ParticleBatch2D.h" 2 | 3 | namespace Bengine { 4 | 5 | ParticleBatch2D::ParticleBatch2D() { 6 | // Empty 7 | } 8 | 9 | 10 | ParticleBatch2D::~ParticleBatch2D() { 11 | delete[] m_particles; 12 | } 13 | 14 | void ParticleBatch2D::init(int maxParticles, 15 | float decayRate, 16 | GLTexture texture, 17 | std::function updateFunc /* = defaultParticleUpdate */) { 18 | m_maxParticles = maxParticles; 19 | m_particles = new Particle2D[maxParticles]; 20 | m_decayRate = decayRate; 21 | m_texture = texture; 22 | m_updateFunc = updateFunc; 23 | } 24 | 25 | void ParticleBatch2D::update(float deltaTime) { 26 | for (int i = 0; i < m_maxParticles; i++) { 27 | // Check if it is active 28 | if (m_particles[i].life > 0.0f) { 29 | // Update using function pointer 30 | m_updateFunc(m_particles[i], deltaTime); 31 | m_particles[i].life -= m_decayRate * deltaTime; 32 | } 33 | } 34 | } 35 | 36 | void ParticleBatch2D::draw(SpriteBatch* spriteBatch) { 37 | glm::vec4 uvRect(0.0f, 0.0f, 1.0f, 1.0f); 38 | for (int i = 0; i < m_maxParticles; i++) { 39 | // Check if it is active 40 | auto& p = m_particles[i]; 41 | if (p.life > 0.0f) { 42 | glm::vec4 destRect(p.position.x, p.position.y, p.width, p.width); 43 | spriteBatch->draw(destRect, uvRect, m_texture.id, 0.0f, p.color); 44 | } 45 | } 46 | } 47 | 48 | void ParticleBatch2D::addParticle(const glm::vec2& position, 49 | const glm::vec2& velocity, 50 | const ColorRGBA8& color, 51 | float width) { 52 | int particleIndex = findFreeParticle(); 53 | 54 | auto& p = m_particles[particleIndex]; 55 | 56 | p.life = 1.0f; 57 | p.position = position; 58 | p.velocity = velocity; 59 | p.color = color; 60 | p.width = width; 61 | } 62 | 63 | int ParticleBatch2D::findFreeParticle() { 64 | 65 | for (int i = m_lastFreeParticle; i < m_maxParticles; i++) { 66 | if (m_particles[i].life <= 0.0f) { 67 | m_lastFreeParticle = i; 68 | return i; 69 | } 70 | } 71 | 72 | for (int i = 0; i < m_lastFreeParticle; i++) { 73 | if (m_particles[i].life <= 0.0f) { 74 | m_lastFreeParticle = i; 75 | return i; 76 | } 77 | } 78 | 79 | // No particles are free, overwrite first particle 80 | return 0; 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /Bengine/ParticleBatch2D.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Vertex.h" 6 | #include "SpriteBatch.h" 7 | #include "GLTexture.h" 8 | 9 | namespace Bengine { 10 | 11 | class Particle2D { 12 | public: 13 | glm::vec2 position = glm::vec2(0.0f); 14 | glm::vec2 velocity = glm::vec2(0.0f); 15 | ColorRGBA8 color; 16 | float life = 0.0f; 17 | float width = 0.0f; 18 | }; 19 | 20 | // Default function pointer 21 | inline void defaultParticleUpdate(Particle2D& particle, float deltaTime) { 22 | particle.position += particle.velocity * deltaTime; 23 | } 24 | 25 | class ParticleBatch2D { 26 | public: 27 | ParticleBatch2D(); 28 | ~ParticleBatch2D(); 29 | 30 | void init(int maxParticles, 31 | float decayRate, 32 | GLTexture texture, 33 | std::function updateFunc = defaultParticleUpdate); 34 | 35 | void update(float deltaTime); 36 | 37 | void draw(SpriteBatch* spriteBatch); 38 | 39 | void addParticle(const glm::vec2& position, 40 | const glm::vec2& velocity, 41 | const ColorRGBA8& color, 42 | float width); 43 | 44 | private: 45 | int findFreeParticle(); 46 | 47 | std::function m_updateFunc; ///< Function pointer for custom updates 48 | float m_decayRate = 0.1f; 49 | Particle2D* m_particles = nullptr; 50 | int m_maxParticles = 0; 51 | int m_lastFreeParticle = 0; 52 | GLTexture m_texture; 53 | }; 54 | 55 | } -------------------------------------------------------------------------------- /Bengine/ParticleEngine2D.cpp: -------------------------------------------------------------------------------- 1 | #include "ParticleEngine2D.h" 2 | 3 | #include "ParticleBatch2D.h" 4 | #include "SpriteBatch.h" 5 | 6 | namespace Bengine { 7 | 8 | 9 | ParticleEngine2D::ParticleEngine2D() { 10 | // Empty 11 | } 12 | 13 | ParticleEngine2D::~ParticleEngine2D() { 14 | for (auto& b : m_batches) { 15 | delete b; 16 | } 17 | } 18 | 19 | void ParticleEngine2D::addParticleBatch(ParticleBatch2D* particleBatch) { 20 | m_batches.push_back(particleBatch); 21 | } 22 | 23 | void ParticleEngine2D::update(float deltaTime) { 24 | for (auto& b : m_batches) { 25 | b->update(deltaTime); 26 | } 27 | } 28 | 29 | void ParticleEngine2D::draw(SpriteBatch* spriteBatch) { 30 | for (auto& b : m_batches) { 31 | spriteBatch->begin(); 32 | b->draw(spriteBatch); 33 | spriteBatch->end(); 34 | spriteBatch->renderBatch(); 35 | } 36 | } 37 | 38 | 39 | } -------------------------------------------------------------------------------- /Bengine/ParticleEngine2D.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Bengine { 6 | 7 | class ParticleBatch2D; 8 | class SpriteBatch; 9 | 10 | class ParticleEngine2D { 11 | public: 12 | ParticleEngine2D(); 13 | ~ParticleEngine2D(); 14 | 15 | // After adding a particle batch, the ParticleEngine2D becomes 16 | // responsible for deallocation. 17 | void addParticleBatch(ParticleBatch2D* particleBatch); 18 | 19 | void update(float deltaTime); 20 | 21 | void draw(SpriteBatch* spriteBatch); 22 | 23 | private: 24 | std::vector m_batches; 25 | }; 26 | 27 | } -------------------------------------------------------------------------------- /Bengine/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | STATIC LIBRARY : Bengine Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this Bengine library project for you. 6 | 7 | No source files were created as part of your project. 8 | 9 | 10 | Bengine.vcxproj 11 | This is the main project file for VC++ projects generated using an Application Wizard. 12 | It contains information about the version of Visual C++ that generated the file, and 13 | information about the platforms, configurations, and project features selected with the 14 | Application Wizard. 15 | 16 | Bengine.vcxproj.filters 17 | This is the filters file for VC++ projects generated using an Application Wizard. 18 | It contains information about the association between the files in your project 19 | and the filters. This association is used in the IDE to show grouping of files with 20 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 21 | "Source Files" filter). 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | Other notes: 25 | 26 | AppWizard uses "TODO:" comments to indicate parts of the source code you 27 | should add to or customize. 28 | 29 | ///////////////////////////////////////////////////////////////////////////// 30 | -------------------------------------------------------------------------------- /Bengine/ResourceManager.cpp: -------------------------------------------------------------------------------- 1 | #include "ResourceManager.h" 2 | 3 | namespace Bengine { 4 | 5 | TextureCache ResourceManager::_textureCache; 6 | 7 | GLTexture ResourceManager::getTexture(std::string texturePath) { 8 | return _textureCache.getTexture(texturePath); 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /Bengine/ResourceManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "TextureCache.h" 3 | #include 4 | 5 | namespace Bengine { 6 | 7 | //This is a way for us to access all our resources, such as 8 | //Models or textures. 9 | class ResourceManager 10 | { 11 | public: 12 | static GLTexture getTexture(std::string texturePath); 13 | 14 | private: 15 | static TextureCache _textureCache; 16 | }; 17 | 18 | } -------------------------------------------------------------------------------- /Bengine/ScreenList.cpp: -------------------------------------------------------------------------------- 1 | #include "ScreenList.h" 2 | 3 | #include "IGameScreen.h" 4 | 5 | namespace Bengine { 6 | 7 | ScreenList::ScreenList(IMainGame* game) : 8 | m_game(game) { 9 | // Empty 10 | } 11 | 12 | ScreenList::~ScreenList() { 13 | destroy(); 14 | } 15 | 16 | IGameScreen* Bengine::ScreenList::moveNext() { 17 | IGameScreen* currentScreen = getCurrent(); 18 | if (currentScreen->getNextScreenIndex() != SCREEN_INDEX_NO_SCREEN) { 19 | m_currentScreenIndex = currentScreen->getNextScreenIndex(); 20 | } 21 | return getCurrent(); 22 | } 23 | 24 | IGameScreen* Bengine::ScreenList::movePrevious() { 25 | IGameScreen* currentScreen = getCurrent(); 26 | if (currentScreen->getPreviousScreenIndex() != SCREEN_INDEX_NO_SCREEN) { 27 | m_currentScreenIndex = currentScreen->getPreviousScreenIndex(); 28 | } 29 | return getCurrent(); 30 | } 31 | 32 | void Bengine::ScreenList::setScreen(int nextScreen) { 33 | m_currentScreenIndex = nextScreen; 34 | } 35 | 36 | void Bengine::ScreenList::addScreen(IGameScreen* newScreen) { 37 | newScreen->m_screenIndex = m_screens.size(); 38 | m_screens.push_back(newScreen); 39 | newScreen->build(); 40 | newScreen->setParentGame(m_game); 41 | } 42 | 43 | void Bengine::ScreenList::destroy() { 44 | for (size_t i = 0; i < m_screens.size(); i++) { 45 | m_screens[i]->destroy(); 46 | } 47 | m_screens.resize(0); 48 | m_currentScreenIndex = SCREEN_INDEX_NO_SCREEN; 49 | } 50 | 51 | IGameScreen* ScreenList::getCurrent() { 52 | if (m_currentScreenIndex == SCREEN_INDEX_NO_SCREEN) return nullptr; 53 | return m_screens[m_currentScreenIndex]; 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /Bengine/ScreenList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Bengine { 6 | 7 | class IMainGame; 8 | class IGameScreen; 9 | 10 | class ScreenList { 11 | public: 12 | ScreenList(IMainGame* game); 13 | ~ScreenList(); 14 | 15 | IGameScreen* moveNext(); 16 | IGameScreen* movePrevious(); 17 | 18 | void setScreen(int nextScreen); 19 | void addScreen(IGameScreen* newScreen); 20 | 21 | void destroy(); 22 | 23 | IGameScreen* getCurrent(); 24 | 25 | protected: 26 | IMainGame* m_game = nullptr; 27 | std::vector m_screens; 28 | int m_currentScreenIndex = -1; 29 | }; 30 | 31 | } -------------------------------------------------------------------------------- /Bengine/Sprite.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "GLTexture.h" 4 | 5 | #include 6 | 7 | namespace Bengine { 8 | 9 | //A 2D quad that can be rendered to the screen 10 | class Sprite 11 | { 12 | public: 13 | Sprite(); 14 | ~Sprite(); 15 | 16 | void init(float x, float y, float width, float height, std::string texturePath); 17 | 18 | void draw(); 19 | 20 | //private: 21 | float _x; 22 | float _y; 23 | float _width; 24 | float _height; 25 | GLuint _vboID; 26 | GLTexture _texture; 27 | 28 | }; 29 | 30 | } -------------------------------------------------------------------------------- /Bengine/SpriteBatch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Vertex.h" 8 | 9 | namespace Bengine{ 10 | 11 | // Determines how we should sort the glyphs 12 | enum class GlyphSortType { 13 | NONE, 14 | FRONT_TO_BACK, 15 | BACK_TO_FRONT, 16 | TEXTURE 17 | }; 18 | 19 | // A glyph is a single quad. These are added via SpriteBatch::draw 20 | class Glyph { 21 | public: 22 | Glyph() {}; 23 | Glyph(const glm::vec4& destRect, const glm::vec4& uvRect, GLuint Texture, float Depth, const ColorRGBA8& color); 24 | Glyph(const glm::vec4& destRect, const glm::vec4& uvRect, GLuint Texture, float Depth, const ColorRGBA8& color, float angle); 25 | 26 | GLuint texture; 27 | float depth; 28 | 29 | Vertex topLeft; 30 | Vertex bottomLeft; 31 | Vertex topRight; 32 | Vertex bottomRight; 33 | private: 34 | // Rotates a point about (0,0) by angle 35 | glm::vec2 rotatePoint(const glm::vec2& pos, float angle); 36 | }; 37 | 38 | // Each render batch is used for a single draw call 39 | class RenderBatch { 40 | public: 41 | RenderBatch(GLuint Offset, GLuint NumVertices, GLuint Texture) : offset(Offset), 42 | numVertices(NumVertices), texture(Texture) { 43 | } 44 | GLuint offset; 45 | GLuint numVertices; 46 | GLuint texture; 47 | }; 48 | 49 | // The SpriteBatch class is a more efficient way of drawing sprites 50 | class SpriteBatch 51 | { 52 | public: 53 | SpriteBatch(); 54 | ~SpriteBatch(); 55 | 56 | // Initializes the spritebatch 57 | void init(); 58 | void dispose(); 59 | 60 | // Begins the spritebatch 61 | void begin(GlyphSortType sortType = GlyphSortType::TEXTURE); 62 | 63 | // Ends the spritebatch 64 | void end(); 65 | 66 | // Adds a glyph to the spritebatch 67 | void draw(const glm::vec4& destRect, const glm::vec4& uvRect, GLuint texture, float depth, const ColorRGBA8& color); 68 | // Adds a glyph to the spritebatch with rotation 69 | void draw(const glm::vec4& destRect, const glm::vec4& uvRect, GLuint texture, float depth, const ColorRGBA8& color, float angle); 70 | // Adds a glyph to the spritebatch with rotation 71 | void draw(const glm::vec4& destRect, const glm::vec4& uvRect, GLuint texture, float depth, const ColorRGBA8& color, const glm::vec2& dir); 72 | 73 | // Renders the entire SpriteBatch to the screen 74 | void renderBatch(); 75 | 76 | private: 77 | // Creates all the needed RenderBatches 78 | void createRenderBatches(); 79 | 80 | // Generates our VAO and VBO 81 | void createVertexArray(); 82 | 83 | // Sorts glyphs according to _sortType 84 | void sortGlyphs(); 85 | 86 | // Comparators used by sortGlyphs() 87 | static bool compareFrontToBack(Glyph* a, Glyph* b); 88 | static bool compareBackToFront(Glyph* a, Glyph* b); 89 | static bool compareTexture(Glyph* a, Glyph* b); 90 | 91 | GLuint _vbo; 92 | GLuint _vao; 93 | 94 | GlyphSortType _sortType; 95 | 96 | std::vector _glyphPointers; ///< This is for sorting 97 | std::vector _glyphs; ///< These are the actual glyphs 98 | std::vector _renderBatches; 99 | }; 100 | 101 | } -------------------------------------------------------------------------------- /Bengine/SpriteFont.h: -------------------------------------------------------------------------------- 1 | /* 2 | This is a modified version of the SpriteFont class from the 3 | Seed Of Andromeda source code. 4 | Use it for any of your projects, commercial or otherwise, 5 | free of charge, but do not remove this disclaimer. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS 8 | ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL 9 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO 10 | EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 12 | RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 14 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 15 | OF THIS SOFTWARE. 16 | 17 | November 28 2014 18 | Original Author: Cristian Zaloj 19 | Modified By: Benjamin Arnold 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifndef SpriteFont_h__ 25 | #define SpriteFont_h__ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "Vertex.h" 33 | 34 | namespace Bengine { 35 | 36 | struct GLTexture; 37 | class SpriteBatch; 38 | 39 | struct CharGlyph { 40 | public: 41 | char character; 42 | glm::vec4 uvRect; 43 | glm::vec2 size; 44 | }; 45 | 46 | #define FIRST_PRINTABLE_CHAR ((char)32) 47 | #define LAST_PRINTABLE_CHAR ((char)126) 48 | 49 | /// For text justification 50 | enum class Justification { 51 | LEFT, MIDDLE, RIGHT 52 | }; 53 | 54 | class SpriteFont { 55 | public: 56 | SpriteFont() {}; 57 | SpriteFont(const char* font, int size, char cs, char ce); 58 | SpriteFont(const char* font, int size) : 59 | SpriteFont(font, size, FIRST_PRINTABLE_CHAR, LAST_PRINTABLE_CHAR) { 60 | } 61 | 62 | void init(const char* font, int size); 63 | void init(const char* font, int size, char cs, char ce); 64 | 65 | /// Destroys the font resources 66 | void dispose(); 67 | 68 | int getFontHeight() const { 69 | return _fontHeight; 70 | } 71 | 72 | /// Measures the dimensions of the text 73 | glm::vec2 measure(const char* s); 74 | 75 | /// Draws using a spritebatch 76 | void draw(SpriteBatch& batch, const char* s, glm::vec2 position, glm::vec2 scaling, 77 | float depth, ColorRGBA8 tint, Justification just = Justification::LEFT); 78 | private: 79 | static std::vector* createRows(glm::ivec4* rects, int rectsLength, int r, int padding, int& w); 80 | 81 | int _regStart, _regLength; 82 | CharGlyph* _glyphs; 83 | int _fontHeight; 84 | 85 | unsigned int _texID; 86 | }; 87 | 88 | } 89 | 90 | #endif // SpriteFont_h__ -------------------------------------------------------------------------------- /Bengine/TextureCache.cpp: -------------------------------------------------------------------------------- 1 | #include "TextureCache.h" 2 | #include "ImageLoader.h" 3 | #include 4 | 5 | namespace Bengine { 6 | 7 | TextureCache::TextureCache() 8 | { 9 | } 10 | 11 | TextureCache::~TextureCache() 12 | { 13 | } 14 | 15 | GLTexture TextureCache::getTexture(std::string texturePath) { 16 | 17 | //lookup the texture and see if its in the map 18 | auto mit = _textureMap.find(texturePath); 19 | 20 | //check if its not in the map 21 | if (mit == _textureMap.end()) { 22 | //Load the texture 23 | GLTexture newTexture = ImageLoader::loadPNG(texturePath); 24 | 25 | //Insert it into the map 26 | _textureMap.insert(make_pair(texturePath, newTexture)); 27 | 28 | return newTexture; 29 | } 30 | return mit->second; 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /Bengine/TextureCache.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "GLTexture.h" 4 | 5 | namespace Bengine { 6 | 7 | //This caches the textures so that multiple sprites can use the same textures 8 | class TextureCache 9 | { 10 | public: 11 | TextureCache(); 12 | ~TextureCache(); 13 | 14 | GLTexture getTexture(std::string texturePath); 15 | 16 | private: 17 | std::map _textureMap; 18 | }; 19 | 20 | } -------------------------------------------------------------------------------- /Bengine/TileSheet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GLTexture.h" 4 | #include 5 | 6 | namespace Bengine { 7 | class TileSheet { 8 | public: 9 | void init(const GLTexture& texture, const glm::ivec2& tileDims) { 10 | this->texture = texture; 11 | this->dims = tileDims; 12 | } 13 | 14 | glm::vec4 getUVs(int index) { 15 | int xTile = index % dims.x; 16 | int yTile = index / dims.x; 17 | 18 | glm::vec4 uvs; 19 | uvs.x = xTile / (float)dims.x; 20 | uvs.y = yTile / (float)dims.y; 21 | uvs.z = 1.0f / dims.x; 22 | uvs.w = 1.0f / dims.y; 23 | 24 | return uvs; 25 | } 26 | 27 | GLTexture texture; 28 | glm::ivec2 dims; 29 | }; 30 | } -------------------------------------------------------------------------------- /Bengine/Timing.cpp: -------------------------------------------------------------------------------- 1 | #include "Timing.h" 2 | 3 | #include 4 | 5 | namespace Bengine { 6 | 7 | FpsLimiter::FpsLimiter() { 8 | } 9 | void FpsLimiter::init(float maxFPS) { 10 | setMaxFPS(maxFPS); 11 | } 12 | 13 | void FpsLimiter::setMaxFPS(float maxFPS) { 14 | _maxFPS = maxFPS; 15 | } 16 | 17 | void FpsLimiter::begin() { 18 | _startTicks = SDL_GetTicks(); 19 | } 20 | 21 | float FpsLimiter::end() { 22 | calculateFPS(); 23 | 24 | float frameTicks = (float)(SDL_GetTicks() - _startTicks); 25 | //Limit the FPS to the max FPS 26 | if (1000.0f / _maxFPS > frameTicks) { 27 | SDL_Delay((Uint32)(1000.0f / _maxFPS - frameTicks)); 28 | } 29 | 30 | return _fps; 31 | } 32 | 33 | void FpsLimiter::calculateFPS() { 34 | //The number of frames to average 35 | static const int NUM_SAMPLES = 10; 36 | //Stores all the frametimes for each frame that we will average 37 | static float frameTimes[NUM_SAMPLES]; 38 | //The current frame we are on 39 | static int currentFrame = 0; 40 | //the ticks of the previous frame 41 | static Uint32 prevTicks = SDL_GetTicks(); 42 | 43 | //Ticks for the current frame 44 | Uint32 currentTicks = SDL_GetTicks(); 45 | 46 | //Calculate the number of ticks (ms) for this frame 47 | _frameTime = (float)(currentTicks - prevTicks); 48 | frameTimes[currentFrame % NUM_SAMPLES] = _frameTime; 49 | 50 | //current ticks is now previous ticks 51 | prevTicks = currentTicks; 52 | 53 | //The number of frames to average 54 | int count; 55 | 56 | currentFrame++; 57 | if (currentFrame < NUM_SAMPLES) { 58 | count = currentFrame; 59 | } else { 60 | count = NUM_SAMPLES; 61 | } 62 | 63 | //Average all the frame times 64 | float frameTimeAverage = 0; 65 | for (int i = 0; i < count; i++) { 66 | frameTimeAverage += frameTimes[i]; 67 | } 68 | frameTimeAverage /= count; 69 | 70 | //Calculate FPS 71 | if (frameTimeAverage > 0) { 72 | _fps = 1000.0f / frameTimeAverage; 73 | } else { 74 | _fps = 60.0f; 75 | } 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /Bengine/Timing.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Bengine { 4 | 5 | ///Calculates FPS and also limits FPS 6 | class FpsLimiter { 7 | public: 8 | FpsLimiter(); 9 | 10 | // Initializes the FPS limiter. For now, this is 11 | // analogous to setMaxFPS 12 | void init(float maxFPS); 13 | 14 | // Sets the desired max FPS 15 | void setMaxFPS(float maxFPS); 16 | 17 | void begin(); 18 | 19 | // end() will return the current FPS as a float 20 | float end(); 21 | private: 22 | // Calculates the current FPS 23 | void calculateFPS(); 24 | 25 | // Variables 26 | float _fps; 27 | float _maxFPS; 28 | float _frameTime; 29 | unsigned int _startTicks; 30 | }; 31 | 32 | } -------------------------------------------------------------------------------- /Bengine/Vertex.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Bengine { 6 | 7 | struct Position { 8 | float x; 9 | float y; 10 | }; 11 | 12 | struct ColorRGBA8 { 13 | ColorRGBA8() : r(0), g(0), b(0), a(0) { } 14 | ColorRGBA8(GLubyte R, GLubyte G, GLubyte B, GLubyte A) : 15 | r(R), g(G), b(B), a(A) { } 16 | GLubyte r; 17 | GLubyte g; 18 | GLubyte b; 19 | GLubyte a; 20 | }; 21 | 22 | struct UV { 23 | float u; 24 | float v; 25 | }; 26 | 27 | //The vertex definition 28 | struct Vertex { 29 | //This is the position struct. When you store a struct or class 30 | //inside of another struct or class, it is called composition. This is 31 | //layed out exactly the same in memory as if we had a float position[2], 32 | //but doing it this way makes more sense. 33 | Position position; 34 | 35 | //4 bytes for r g b a color. 36 | ColorRGBA8 color; 37 | 38 | //UV texture coordinates. 39 | UV uv; 40 | 41 | void setPosition(float x, float y) { 42 | position.x = x; 43 | position.y = y; 44 | } 45 | 46 | void setColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) { 47 | color.r = r; 48 | color.g = g; 49 | color.b = b; 50 | color.a = a; 51 | } 52 | 53 | void setUV(float u, float v) { 54 | uv.u = u; 55 | uv.v = v; 56 | } 57 | }; 58 | 59 | } -------------------------------------------------------------------------------- /Bengine/Window.cpp: -------------------------------------------------------------------------------- 1 | #include "Window.h" 2 | #include "BengineErrors.h" 3 | 4 | namespace Bengine { 5 | 6 | Window::Window() 7 | { 8 | } 9 | 10 | 11 | Window::~Window() 12 | { 13 | } 14 | 15 | int Window::create(std::string windowName, int screenWidth, int screenHeight, unsigned int currentFlags) { 16 | 17 | Uint32 flags = SDL_WINDOW_OPENGL; 18 | _screenWidth = screenWidth; 19 | _screenHeight = screenHeight; 20 | 21 | if (currentFlags & INVISIBLE) { 22 | flags |= SDL_WINDOW_HIDDEN; 23 | } 24 | if (currentFlags & FULLSCREEN) { 25 | flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; 26 | } 27 | if (currentFlags & BORDERLESS) { 28 | flags |= SDL_WINDOW_BORDERLESS; 29 | } 30 | 31 | //Open an SDL window 32 | _sdlWindow = SDL_CreateWindow(windowName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screenWidth, screenHeight, flags); 33 | if (_sdlWindow == nullptr) { 34 | fatalError("SDL Window could not be created!"); 35 | } 36 | 37 | //Set up our OpenGL context 38 | SDL_GLContext glContext = SDL_GL_CreateContext(_sdlWindow); 39 | if (glContext == nullptr) { 40 | fatalError("SDL_GL context could not be created!"); 41 | } 42 | 43 | //Set up glew (optional but recommended) 44 | GLenum error = glewInit(); 45 | if (error != GLEW_OK) { 46 | fatalError("Could not initialize glew!"); 47 | } 48 | 49 | //Check the OpenGL version 50 | std::printf("*** OpenGL Version: %s ***\n", glGetString(GL_VERSION)); 51 | 52 | //Set the background color to blue 53 | glClearColor(0.0f, 0.0f, 1.0f, 1.0f); 54 | 55 | //Set VSYNC 56 | SDL_GL_SetSwapInterval(0); 57 | 58 | // Enable alpha blend 59 | glEnable(GL_BLEND); 60 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 61 | 62 | return 0; 63 | } 64 | 65 | void Window::swapBuffer() { 66 | SDL_GL_SwapWindow(_sdlWindow); 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /Bengine/Window.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Bengine { 7 | 8 | enum WindowFlags { INVISIBLE = 0x1, FULLSCREEN = 0x2, BORDERLESS = 0x4 }; 9 | 10 | class Window 11 | { 12 | public: 13 | Window(); 14 | ~Window(); 15 | 16 | int create(std::string windowName, int screenWidth, int screenHeight, unsigned int currentFlags); 17 | 18 | void swapBuffer(); 19 | 20 | int getScreenWidth() { return _screenWidth; } 21 | int getScreenHeight() { return _screenHeight; } 22 | private: 23 | SDL_Window* _sdlWindow; 24 | int _screenWidth, _screenHeight; 25 | }; 26 | 27 | } -------------------------------------------------------------------------------- /Bengine/picoPNG.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace Bengine { 4 | 5 | extern int decodePNG(std::vector& out_image, unsigned long& image_width, unsigned long& image_height, const unsigned char* in_png, size_t in_size, bool convert_to_rgba32 = true); 6 | 7 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Benjamin Arnold 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /NinjaPlatformer/App.cpp: -------------------------------------------------------------------------------- 1 | #include "App.h" 2 | #include 3 | 4 | 5 | App::App() { 6 | 7 | } 8 | 9 | App::~App() { 10 | 11 | } 12 | 13 | void App::onInit() { 14 | 15 | } 16 | 17 | void App::addScreens() { 18 | m_mainMenuScreen = std::make_unique(&m_window); 19 | m_gameplayScreen = std::make_unique(&m_window); 20 | m_editorScreen = std::make_unique(&m_window); 21 | 22 | m_screenList->addScreen(m_mainMenuScreen.get()); 23 | m_screenList->addScreen(m_gameplayScreen.get()); 24 | m_screenList->addScreen(m_editorScreen.get()); 25 | 26 | m_screenList->setScreen(m_mainMenuScreen->getScreenIndex()); 27 | } 28 | 29 | void App::onExit() { 30 | 31 | } 32 | -------------------------------------------------------------------------------- /NinjaPlatformer/App.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "GameplayScreen.h" 5 | #include "MainMenuScreen.h" 6 | #include "EditorScreen.h" 7 | 8 | // Our custom app that inherits from IMainGame 9 | class App : public Bengine::IMainGame{ 10 | public: 11 | App(); 12 | ~App(); 13 | 14 | // Called on initialization 15 | virtual void onInit() override; 16 | // For adding all screens 17 | virtual void addScreens() override; 18 | // Called when exiting 19 | virtual void onExit() override; 20 | private: 21 | std::unique_ptr m_gameplayScreen = nullptr; 22 | std::unique_ptr m_mainMenuScreen = nullptr; 23 | std::unique_ptr m_editorScreen = nullptr; 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /NinjaPlatformer/Assets/blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/Assets/blank.png -------------------------------------------------------------------------------- /NinjaPlatformer/Assets/blue_ninja.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/Assets/blue_ninja.png -------------------------------------------------------------------------------- /NinjaPlatformer/Assets/bricks_light_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/Assets/bricks_light_top.png -------------------------------------------------------------------------------- /NinjaPlatformer/Assets/bricks_loam_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/Assets/bricks_loam_top.png -------------------------------------------------------------------------------- /NinjaPlatformer/Assets/bricks_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/Assets/bricks_top.png -------------------------------------------------------------------------------- /NinjaPlatformer/Assets/credits.txt: -------------------------------------------------------------------------------- 1 | Blue ninja by KZR 2 | Base by Miguel Duarte -------------------------------------------------------------------------------- /NinjaPlatformer/Assets/glass_metal_frame_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/Assets/glass_metal_frame_top.png -------------------------------------------------------------------------------- /NinjaPlatformer/Box.cpp: -------------------------------------------------------------------------------- 1 | #include "Box.h" 2 | 3 | 4 | Box::Box() { 5 | } 6 | 7 | 8 | Box::~Box() { 9 | } 10 | 11 | void Box::init(b2World* world, 12 | const glm::vec2& position, 13 | const glm::vec2& dimensions, 14 | Bengine::GLTexture texture, 15 | Bengine::ColorRGBA8 color, 16 | bool fixedRotation, 17 | bool isDynamic, 18 | float angle, /* = 0.0f */ 19 | glm::vec4 uvRect /*= glm::vec4(0.0f, 0.0f, 1.0f, 1.0f)*/) { 20 | m_dimensions = dimensions; 21 | m_color = color; 22 | m_texture = texture; 23 | m_uvRect = uvRect; 24 | m_fixedRotation = fixedRotation; 25 | m_isDynamic = isDynamic; 26 | 27 | // Make the body 28 | b2BodyDef bodyDef; 29 | if (isDynamic) { 30 | bodyDef.type = b2_dynamicBody; 31 | } else { 32 | bodyDef.type = b2_staticBody; 33 | } 34 | bodyDef.position.Set(position.x, position.y); 35 | bodyDef.fixedRotation = fixedRotation; 36 | bodyDef.angle = angle; 37 | m_body = world->CreateBody(&bodyDef); 38 | 39 | b2PolygonShape boxShape; 40 | boxShape.SetAsBox(dimensions.x / 2.0f, dimensions.y / 2.0f); 41 | 42 | b2FixtureDef fixtureDef; 43 | fixtureDef.shape = &boxShape; 44 | fixtureDef.density = 1.0f; 45 | fixtureDef.friction = 0.3f; 46 | m_fixture = m_body->CreateFixture(&fixtureDef); 47 | } 48 | 49 | void Box::destroy(b2World* world) { 50 | world->DestroyBody(m_body); 51 | } 52 | 53 | void Box::draw(Bengine::SpriteBatch& spriteBatch) { 54 | glm::vec4 destRect; 55 | destRect.x = m_body->GetPosition().x - m_dimensions.x / 2.0f; 56 | destRect.y = m_body->GetPosition().y - m_dimensions.y / 2.0f; 57 | destRect.z = m_dimensions.x; 58 | destRect.w = m_dimensions.y; 59 | spriteBatch.draw(destRect, m_uvRect, m_texture.id, 0.0f, m_color, m_body->GetAngle()); 60 | } 61 | 62 | -------------------------------------------------------------------------------- /NinjaPlatformer/Box.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class Box { 10 | public: 11 | Box(); 12 | ~Box(); 13 | 14 | void init(b2World* world, 15 | const glm::vec2& position, 16 | const glm::vec2& dimensions, 17 | Bengine::GLTexture texture, 18 | Bengine::ColorRGBA8 color, 19 | bool fixedRotation, 20 | bool isDynamic, 21 | float angle = 0.0f, 22 | glm::vec4 uvRect = glm::vec4(0.0f, 0.0f, 1.0f, 1.0f)); 23 | void destroy(b2World* world); 24 | 25 | void draw(Bengine::SpriteBatch& spriteBatch); 26 | 27 | bool isDynamic() const { return m_body->GetType() == b2_dynamicBody;} 28 | 29 | // Test if a point is inside the box 30 | bool testPoint(float x, float y) const { return m_fixture->TestPoint(b2Vec2(x, y)); } 31 | 32 | // Beautiful accessors 33 | b2Body* getBody() const { return m_body; } 34 | b2Fixture* getFixture() const { return m_fixture; } 35 | const glm::vec2& getDimensions() const { return m_dimensions; } 36 | glm::vec2 getPosition() const { return glm::vec2(m_body->GetPosition().x, m_body->GetPosition().y); } 37 | glm::vec4 getUvRect() const { return m_uvRect; } 38 | const Bengine::ColorRGBA8& getColor() const { return m_color; } 39 | float getAngle() const { return m_body->GetAngle(); } 40 | const Bengine::GLTexture& getTexture() const { return m_texture; } 41 | const bool& getFixedRotation() const { return m_fixedRotation; } 42 | const bool& getIsDynamic() const { return m_isDynamic; } 43 | private: 44 | glm::vec4 m_uvRect; 45 | b2Body* m_body = nullptr; 46 | b2Fixture* m_fixture = nullptr; 47 | glm::vec2 m_dimensions; 48 | Bengine::ColorRGBA8 m_color; 49 | Bengine::GLTexture m_texture; 50 | bool m_fixedRotation; 51 | bool m_isDynamic; 52 | }; 53 | 54 | -------------------------------------------------------------------------------- /NinjaPlatformer/Capsule.cpp: -------------------------------------------------------------------------------- 1 | #include "Capsule.h" 2 | 3 | void Capsule::init(b2World* world, 4 | const glm::vec2& position, 5 | const glm::vec2& dimensions, 6 | float density, 7 | float friction, 8 | bool fixedRotation) { 9 | m_dimensions = dimensions; 10 | 11 | // Make the body 12 | b2BodyDef bodyDef; 13 | bodyDef.type = b2_dynamicBody; 14 | bodyDef.position.Set(position.x, position.y); 15 | bodyDef.fixedRotation = fixedRotation; 16 | m_body = world->CreateBody(&bodyDef); 17 | 18 | // Create the box 19 | b2PolygonShape boxShape; 20 | boxShape.SetAsBox(dimensions.x / 2.0f, (dimensions.y - dimensions.x) / 2.0f); 21 | 22 | b2FixtureDef fixtureDef; 23 | fixtureDef.shape = &boxShape; 24 | fixtureDef.density = density; 25 | fixtureDef.friction = friction; 26 | m_fixtures[0] = m_body->CreateFixture(&fixtureDef); 27 | 28 | // Create the circles 29 | b2CircleShape circleShape; 30 | circleShape.m_radius = dimensions.x / 2.0f; 31 | 32 | b2FixtureDef circleDef; 33 | circleDef.shape = &circleShape; 34 | circleDef.density = density; 35 | circleDef.friction = friction; 36 | 37 | // Bottom circle 38 | circleShape.m_p.Set(0.0f, (-m_dimensions.y + dimensions.x) / 2.0f); 39 | m_fixtures[1] = m_body->CreateFixture(&circleDef); 40 | 41 | // Top Circle 42 | circleShape.m_p.Set(0.0f, (m_dimensions.y - dimensions.x) / 2.0f); 43 | m_fixtures[1] = m_body->CreateFixture(&circleDef); 44 | } 45 | 46 | void Capsule::destroy(b2World* world) { 47 | if (m_body) { 48 | world->DestroyBody(m_body); 49 | m_body = nullptr; 50 | } 51 | } 52 | 53 | void Capsule::drawDebug(Bengine::DebugRenderer& debugRenderer) { 54 | Bengine::ColorRGBA8 color(255, 255, 255, 255); 55 | // Draw box 56 | glm::vec4 destRect; 57 | destRect.x = m_body->GetPosition().x - m_dimensions.x / 2.0f; 58 | destRect.y = m_body->GetPosition().y - (m_dimensions.y - m_dimensions.x) / 2.0f; 59 | destRect.z = m_dimensions.x; 60 | destRect.w = m_dimensions.y - m_dimensions.x; 61 | debugRenderer.drawBox(destRect, color, m_body->GetAngle()); 62 | 63 | // Draw Circle 64 | debugRenderer.drawCircle(glm::vec2(destRect.x + m_dimensions.x / 2.0f, destRect.y), color, m_dimensions.x / 2.0f); 65 | debugRenderer.drawCircle(glm::vec2(destRect.x + m_dimensions.x / 2.0f, destRect.y + destRect.w), color, m_dimensions.x / 2.0f); 66 | } -------------------------------------------------------------------------------- /NinjaPlatformer/Capsule.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class Capsule { 8 | public: 9 | void init(b2World* world, 10 | const glm::vec2& position, 11 | const glm::vec2& dimensions, 12 | float density, 13 | float friction, 14 | bool fixedRotation); 15 | void destroy(b2World* world); 16 | 17 | void drawDebug(Bengine::DebugRenderer& debugRenderer); 18 | 19 | b2Body* getBody() const { return m_body; } 20 | b2Fixture* getFixture(int index) const { return m_fixtures[index]; } 21 | const glm::vec2& getDimensions() const { return m_dimensions; } 22 | private: 23 | b2Body* m_body = nullptr; 24 | b2Fixture* m_fixtures[3]; 25 | glm::vec2 m_dimensions; 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /NinjaPlatformer/Fonts/chintzy.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/Fonts/chintzy.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/animations/example.anims: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/Batang-18.font: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/DejaVuSans-10-NoScale.font: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/DejaVuSans-10.font: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/DejaVuSans-12-NoScale.font: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/DejaVuSans-12.font: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/DejaVuSans-14-NoScale.font: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/DejaVuSans-14.font: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/DejaVuSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/DejaVuSans.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/DejaVuSerif.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/DejaVuSerif.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/FairChar-30.font: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/FetteClassicUNZFraktur.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/FetteClassicUNZFraktur.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/Futhark Adapted.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/Futhark Adapted.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/GreatVibes-16.font: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/GreatVibes-22.font: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/GreatVibes-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/GreatVibes-Regular.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/IMFePIrm29P.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/IMFePIrm29P.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/Junicode-13.font: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/Junicode.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/Junicode.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/Jura-10.font: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/Jura-13.font: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/Jura-18.font: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/Jura-DemiBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/Jura-DemiBold.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/Jura-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/Jura-Light.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/Jura-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/Jura-Medium.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/Jura-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/Jura-Regular.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/Klingon-pIqaD-HaSta.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/Klingon-pIqaD-HaSta.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/Legal.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/Legal.txt -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/LicenseMIT.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/LicenseUbuntuFont.txt: -------------------------------------------------------------------------------- 1 | ------------------------------- 2 | UBUNTU FONT LICENCE Version 1.0 3 | ------------------------------- 4 | 5 | PREAMBLE 6 | This licence allows the licensed fonts to be used, studied, modified and 7 | redistributed freely. The fonts, including any derivative works, can be 8 | bundled, embedded, and redistributed provided the terms of this licence 9 | are met. The fonts and derivatives, however, cannot be released under 10 | any other licence. The requirement for fonts to remain under this 11 | licence does not require any document created using the fonts or their 12 | derivatives to be published under this licence, as long as the primary 13 | purpose of the document is not to be a vehicle for the distribution of 14 | the fonts. 15 | 16 | DEFINITIONS 17 | "Font Software" refers to the set of files released by the Copyright 18 | Holder(s) under this licence and clearly marked as such. This may 19 | include source files, build scripts and documentation. 20 | 21 | "Original Version" refers to the collection of Font Software components 22 | as received under this licence. 23 | 24 | "Modified Version" refers to any derivative made by adding to, deleting, 25 | or substituting -- in part or in whole -- any of the components of the 26 | Original Version, by changing formats or by porting the Font Software to 27 | a new environment. 28 | 29 | "Copyright Holder(s)" refers to all individuals and companies who have a 30 | copyright ownership of the Font Software. 31 | 32 | "Substantially Changed" refers to Modified Versions which can be easily 33 | identified as dissimilar to the Font Software by users of the Font 34 | Software comparing the Original Version with the Modified Version. 35 | 36 | To "Propagate" a work means to do anything with it that, without 37 | permission, would make you directly or secondarily liable for 38 | infringement under applicable copyright law, except executing it on a 39 | computer or modifying a private copy. Propagation includes copying, 40 | distribution (with or without modification and with or without charging 41 | a redistribution fee), making available to the public, and in some 42 | countries other activities as well. 43 | 44 | PERMISSION & CONDITIONS 45 | This licence does not grant any rights under trademark law and all such 46 | rights are reserved. 47 | 48 | Permission is hereby granted, free of charge, to any person obtaining a 49 | copy of the Font Software, to propagate the Font Software, subject to 50 | the below conditions: 51 | 52 | 1) Each copy of the Font Software must contain the above copyright 53 | notice and this licence. These can be included either as stand-alone 54 | text files, human-readable headers or in the appropriate machine- 55 | readable metadata fields within text or binary files as long as those 56 | fields can be easily viewed by the user. 57 | 58 | 2) The font name complies with the following: 59 | (a) The Original Version must retain its name, unmodified. 60 | (b) Modified Versions which are Substantially Changed must be renamed to 61 | avoid use of the name of the Original Version or similar names entirely. 62 | (c) Modified Versions which are not Substantially Changed must be 63 | renamed to both (i) retain the name of the Original Version and (ii) add -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/RichStyle.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/RichStyle.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/Tnua-Libre.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/Tnua-Libre.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/batang.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/batang.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/fonts/mizufalp.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/fonts/mizufalp.ttf -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/AlfiskoSkin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/imagesets/AlfiskoSkin.png -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/Aliasing.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/imagesets/Aliasing.jpg -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/BackgroundSampleBrowser.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/imagesets/BackgroundSampleBrowser.jpg -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/DriveIcons.imageset: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/DriveIcons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/imagesets/DriveIcons.png -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/FairChar.imageset: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/FairChar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/imagesets/FairChar.png -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/GameMenu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/imagesets/GameMenu.png -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/HUDDemo.imageset: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/HUDDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/imagesets/HUDDemo.png -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/HUDDemoGameOver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/imagesets/HUDDemoGameOver.png -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/OgreTrayImages.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/imagesets/OgreTrayImages.png -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/ReadMe.txt: -------------------------------------------------------------------------------- 1 | The images in this directory were obtained from various sources... 2 | 3 | SpaceBackground.jpg - Image Credit: NASA/JPL-Caltech (http://www.nasa.gov/multimedia/imagegallery/iotd.html) 4 | Aliasing.jpg - Aliasing test image created by Lukas "Ident" Meindl. 5 | TaharezLook.tga - Original Taharez imagery created by Lars "Taharez" Rinde. 6 | WindowsLook.tga - Windows look imagery created by Paul "CrazyEddie" Turner. 7 | vanilla.tga - Original "Vanilla GUI" imagery created by Shane Parker, used with permission. 8 | HUDDemo.png - Interface graphics created by "syg". Food objects created by Lukas "Ident" Meindl, images mostly taken from http://openclipart.org/ and edited. 9 | GameMenu.png - Created and provided by "syg". Modified by Lukas "Ident" Meindl 10 | BackgroundSampleBrowser.jpg - Taken from NASA images http://nssdc.gsfc.nasa.gov/photo_gallery/photogallery-mars.html -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/SampleBrowser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/imagesets/SampleBrowser.png -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/SpaceBackground.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/imagesets/SpaceBackground.jpg -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/TaharezLook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/imagesets/TaharezLook.png -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/WindowsLook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/imagesets/WindowsLook.png -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/imagesets/logo.png -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/imagesets/vanilla.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/GUI/imagesets/vanilla.png -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/layouts/Console.wnd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/layouts/EffectsDemo.layout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | This text is a multiline text: 13 | Line 1 14 | You can insert text anywhere, for example, here in line 2 15 | or maybe even in line 3? 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/layouts/HUDDemoGameOver.layout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/layouts/SampleBrowserLoadScreen.layout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/layouts/TabControlDemo.layout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/layouts/TabPage.layout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/layouts/TabPage2.layout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/layouts/TreeDemoTaharez.layout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/layouts/VanillaConsole.layout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | CEGUI Demo Console - F12 toggles this window 38 | 39 | It's now easy to add multiline text property. 40 | Line 1 41 | 42 | You can now put <xml>stuff</xml> in your property easly " " " 43 | 44 | Line 2 45 | Line 3 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/schemes/GameMenu.scheme: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/schemes/Generic.scheme: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/schemes/HUDDemo.scheme: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/schemes/SampleBrowser.scheme: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/schemes/VanillaCommonDialogs.scheme: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/schemes/VanillaCommonDialogs.scheme.orig: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/schemes/VanillaSkin.scheme: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/xml_schemas/Font.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/xml_schemas/GUIScheme.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/xml_schemas/Imageset.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /NinjaPlatformer/GUI/xml_schemas/Samples.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /NinjaPlatformer/GameplayScreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Box.h" 4 | #include "Player.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | // Our custom gameplay screen that inherits from the IGameScreen 18 | class GameplayScreen : public Bengine::IGameScreen { 19 | public: 20 | GameplayScreen(Bengine::Window* window); 21 | ~GameplayScreen(); 22 | 23 | virtual int getNextScreenIndex() const override; 24 | 25 | virtual int getPreviousScreenIndex() const override; 26 | 27 | virtual void build() override; 28 | 29 | virtual void destroy() override; 30 | 31 | virtual void onEntry() override; 32 | 33 | virtual void onExit() override; 34 | 35 | virtual void update() override; 36 | 37 | virtual void draw() override; 38 | 39 | private: 40 | void initUI(); 41 | void checkInput(); 42 | 43 | bool onExitClicked(const CEGUI::EventArgs& e); 44 | 45 | Bengine::SpriteBatch m_spriteBatch; 46 | Bengine::GLSLProgram m_textureProgram; 47 | Bengine::GLSLProgram m_lightProgram; 48 | Bengine::Camera2D m_camera; 49 | Bengine::GLTexture m_texture; 50 | Bengine::Window* m_window; 51 | Bengine::DebugRenderer m_debugRenderer; 52 | Bengine::GUI m_gui; 53 | 54 | bool m_renderDebug = false; 55 | 56 | Player m_player; 57 | std::vector m_boxes; 58 | std::unique_ptr m_world; 59 | }; 60 | 61 | -------------------------------------------------------------------------------- /NinjaPlatformer/LevelReaderWriter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Player.h" 6 | #include "Box.h" 7 | #include "Light.h" 8 | 9 | class LevelReaderWriter { 10 | public: 11 | static bool saveAsText(const std::string& filePath, const Player& player, const std::vector& boxes, const std::vector& lights); 12 | static bool saveAsBinary(const std::string& filePath, const Player& player, const std::vector& boxes, const std::vector& lights); 13 | static bool loadAsText(const std::string& filePath, b2World* world, Player& player, std::vector& boxes, std::vector& lights); 14 | static bool loadAsBinary(const std::string& filePath, b2World* world, Player& player, std::vector& boxes, std::vector& lights); 15 | private: 16 | static bool saveAsTextV0(const std::string& filePath, const Player& player, const std::vector& boxes, const std::vector& lights); 17 | static bool loadAsTextV0(std::ifstream& file, b2World* world, Player& player, std::vector& boxes, std::vector& lights); 18 | }; 19 | 20 | -------------------------------------------------------------------------------- /NinjaPlatformer/Levels/DumbLevel.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/NinjaPlatformer/Levels/DumbLevel.txt -------------------------------------------------------------------------------- /NinjaPlatformer/Light.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class Light { 8 | public: 9 | void draw(Bengine::SpriteBatch& spriteBatch) { 10 | glm::vec4 destRect; 11 | destRect.x = position.x - size / 2.0f; 12 | destRect.y = position.y - size / 2.0f; 13 | destRect.z = size; 14 | destRect.w = size; 15 | spriteBatch.draw(destRect, glm::vec4(-1.0f, -1.0f, 2.0f, 2.0f), 0, 0.0f, color, 0.0f); 16 | } 17 | 18 | Bengine::ColorRGBA8 color; 19 | glm::vec2 position; 20 | float size; 21 | }; 22 | -------------------------------------------------------------------------------- /NinjaPlatformer/MainMenuScreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Player.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include "ScreenIndices.h" 16 | 17 | class MainMenuScreen : public Bengine::IGameScreen { 18 | public: 19 | MainMenuScreen(Bengine::Window* window); 20 | ~MainMenuScreen(); 21 | 22 | virtual int getNextScreenIndex() const override; 23 | 24 | virtual int getPreviousScreenIndex() const override; 25 | 26 | virtual void build() override; 27 | 28 | virtual void destroy() override; 29 | 30 | virtual void onEntry() override; 31 | 32 | virtual void onExit() override; 33 | 34 | virtual void update() override; 35 | 36 | virtual void draw() override; 37 | 38 | private: 39 | void initUI(); 40 | void checkInput(); 41 | 42 | bool onNewGameClicked(const CEGUI::EventArgs& e); 43 | bool onEditorClicked(const CEGUI::EventArgs& e); 44 | bool onExitClicked(const CEGUI::EventArgs& e); 45 | 46 | int m_nextScreenIndex = SCREEN_INDEX_GAMEPLAY; 47 | Bengine::Camera2D m_camera; 48 | Bengine::Window* m_window; 49 | Bengine::GUI m_gui; 50 | }; -------------------------------------------------------------------------------- /NinjaPlatformer/NinjaPlatformer.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files 73 | 74 | 75 | Header Files 76 | 77 | 78 | -------------------------------------------------------------------------------- /NinjaPlatformer/Player.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Capsule.h" 4 | #include 5 | #include 6 | #include 7 | 8 | enum class PlayerMoveState {STANDING, RUNNING, PUNCHING, IN_AIR }; 9 | 10 | class Player { 11 | public: 12 | void init(b2World* world, 13 | const glm::vec2& position, 14 | const glm::vec2& drawDims, 15 | glm::vec2& collisionDims, 16 | Bengine::ColorRGBA8 color); 17 | void destroy(b2World* world); 18 | 19 | void draw(Bengine::SpriteBatch& spriteBatch); 20 | void drawDebug(Bengine::DebugRenderer& debugRenderer); 21 | 22 | void update(Bengine::InputManager& inputManager); 23 | 24 | const Capsule& getCapsule() const { return m_capsule; } 25 | 26 | glm::vec2 getPosition() const { 27 | glm::vec2 rv; 28 | rv.x = m_capsule.getBody()->GetPosition().x; 29 | rv.y = m_capsule.getBody()->GetPosition().y; 30 | return rv; 31 | } 32 | 33 | const glm::vec2& getDrawDims() const { return m_drawDims; } 34 | const glm::vec2& getCollisionDims() const { return m_collisionDims; } 35 | const Bengine::ColorRGBA8& getColor() const { return m_color; } 36 | 37 | private: 38 | glm::vec2 m_drawDims; 39 | glm::vec2 m_collisionDims; 40 | Bengine::ColorRGBA8 m_color; 41 | Bengine::TileSheet m_texture; 42 | Capsule m_capsule; 43 | PlayerMoveState m_moveState = PlayerMoveState::STANDING; 44 | float m_animTime = 0.0f; 45 | int m_direction = 1; // 1 or -1 46 | bool m_onGround = false; 47 | bool m_isPunching = false; 48 | }; 49 | 50 | -------------------------------------------------------------------------------- /NinjaPlatformer/ScreenIndices.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | const int SCREEN_INDEX_MAINMENU = 0; 4 | const int SCREEN_INDEX_GAMEPLAY = 1; 5 | const int SCREEN_INDEX_EDITOR = 2; -------------------------------------------------------------------------------- /NinjaPlatformer/Shaders/color.frag: -------------------------------------------------------------------------------- 1 | #version 130 2 | //The fragment shader operates on each pixel in a given polygon 3 | 4 | in vec2 fragmentPosition; 5 | in vec4 fragmentColor; 6 | 7 | //This is the 3 component float vector that gets outputted to the screen 8 | //for each pixel. 9 | out vec4 color; 10 | 11 | void main() { 12 | 13 | color = fragmentColor; 14 | } -------------------------------------------------------------------------------- /NinjaPlatformer/Shaders/color.vert: -------------------------------------------------------------------------------- 1 | #version 130 2 | //The vertex shader operates on each vertex 3 | 4 | //input data from the VBO. Each vertex is 2 floats 5 | in vec2 vertexPosition; 6 | in vec4 vertexColor; 7 | 8 | out vec2 fragmentPosition; 9 | out vec4 fragmentColor; 10 | 11 | uniform mat4 P; 12 | 13 | void main() { 14 | //Set the x,y position on the screen 15 | gl_Position.xy = (P * vec4(vertexPosition, 0.0, 1.0)).xy; 16 | //the z position is zero since we are in 2D 17 | gl_Position.z = 0.0; 18 | 19 | //Indicate that the coordinates are normalized 20 | gl_Position.w = 1.0; 21 | 22 | fragmentPosition = vertexPosition; 23 | 24 | fragmentColor = vertexColor; 25 | } -------------------------------------------------------------------------------- /NinjaPlatformer/Shaders/lightShading.frag: -------------------------------------------------------------------------------- 1 | #version 130 2 | //The fragment shader operates on each pixel in a given polygon 3 | 4 | in vec2 fragmentPosition; 5 | in vec4 fragmentColor; 6 | in vec2 fragmentUV; 7 | 8 | //This is the 3 component float vector that gets outputted to the screen 9 | //for each pixel. 10 | out vec4 color; 11 | 12 | void main() { 13 | float distance = length(fragmentUV); 14 | color = vec4(fragmentColor.rgb, fragmentColor.a * (pow(0.01, distance) - 0.01)); 15 | } -------------------------------------------------------------------------------- /NinjaPlatformer/Shaders/lightShading.vert: -------------------------------------------------------------------------------- 1 | #version 130 2 | //The vertex shader operates on each vertex 3 | 4 | //input data from the VBO. Each vertex is 2 floats 5 | in vec2 vertexPosition; 6 | in vec4 vertexColor; 7 | in vec2 vertexUV; 8 | 9 | out vec2 fragmentPosition; 10 | out vec4 fragmentColor; 11 | out vec2 fragmentUV; 12 | 13 | uniform mat4 P; 14 | 15 | void main() { 16 | //Set the x,y position on the screen 17 | gl_Position.xy = (P * vec4(vertexPosition, 0.0, 1.0)).xy; 18 | //the z position is zero since we are in 2D 19 | gl_Position.z = 0.0; 20 | 21 | //Indicate that the coordinates are normalized 22 | gl_Position.w = 1.0; 23 | 24 | fragmentPosition = vertexPosition; 25 | 26 | fragmentColor = vertexColor; 27 | 28 | fragmentUV = vertexUV; 29 | } -------------------------------------------------------------------------------- /NinjaPlatformer/Shaders/textureShading.frag: -------------------------------------------------------------------------------- 1 | #version 130 2 | //The fragment shader operates on each pixel in a given polygon 3 | 4 | in vec2 fragmentPosition; 5 | in vec4 fragmentColor; 6 | in vec2 fragmentUV; 7 | 8 | //This is the 3 component float vector that gets outputted to the screen 9 | //for each pixel. 10 | out vec4 color; 11 | 12 | uniform sampler2D mySampler; 13 | 14 | void main() { 15 | 16 | //cos(x) returns a number between -1 and 1. To convert it into the range 0 to 1 17 | //you simply do (cos(x) + 1.0) * 0.5 18 | 19 | vec4 textureColor = texture(mySampler, fragmentUV); 20 | 21 | //Make crazy colors using time and position! 22 | color = fragmentColor * textureColor; 23 | } -------------------------------------------------------------------------------- /NinjaPlatformer/Shaders/textureShading.vert: -------------------------------------------------------------------------------- 1 | #version 130 2 | //The vertex shader operates on each vertex 3 | 4 | //input data from the VBO. Each vertex is 2 floats 5 | in vec2 vertexPosition; 6 | in vec4 vertexColor; 7 | in vec2 vertexUV; 8 | 9 | out vec2 fragmentPosition; 10 | out vec4 fragmentColor; 11 | out vec2 fragmentUV; 12 | 13 | uniform mat4 P; 14 | 15 | void main() { 16 | //Set the x,y position on the screen 17 | gl_Position.xy = (P * vec4(vertexPosition, 0.0, 1.0)).xy; 18 | //the z position is zero since we are in 2D 19 | gl_Position.z = 0.0; 20 | 21 | //Indicate that the coordinates are normalized 22 | gl_Position.w = 1.0; 23 | 24 | fragmentPosition = vertexPosition; 25 | 26 | fragmentColor = vertexColor; 27 | 28 | fragmentUV = vec2(vertexUV.x, 1.0 - vertexUV.y); 29 | } -------------------------------------------------------------------------------- /NinjaPlatformer/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "App.h" 4 | 5 | int main(int argc, char** argv) { 6 | App app; 7 | app.run(); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GraphicsTutorials 2 | 3 | This is the repository for the Advanced C++/Graphics tutorial series on the youtube channel MakingGamesWithBen. 4 | 5 | Dependencies can be downloaded at https://github.com/Barnold1953/GraphicsTutorialsDeps 6 | -------------------------------------------------------------------------------- /ZombieGame/Agent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | const float AGENT_WIDTH = 60.0f; 7 | const float AGENT_RADIUS = AGENT_WIDTH / 2.0f; 8 | 9 | class Zombie; 10 | class Human; 11 | 12 | class Agent 13 | { 14 | public: 15 | Agent(); 16 | virtual ~Agent(); 17 | 18 | virtual void update(const std::vector& levelData, 19 | std::vector& humans, 20 | std::vector& zombies, 21 | float deltaTime) = 0; 22 | 23 | bool collideWithLevel(const std::vector& levelData); 24 | 25 | bool collideWithAgent(Agent* agent); 26 | 27 | void draw(Bengine::SpriteBatch& _spriteBatch); 28 | 29 | // Return true if we died 30 | bool applyDamage(float damage); 31 | 32 | glm::vec2 getPosition() const { return _position; } 33 | 34 | protected: 35 | 36 | void checkTilePosition(const std::vector& levelData, 37 | std::vector& collideTilePositions, 38 | float x, 39 | float y); 40 | 41 | void collideWithTile(glm::vec2 tilePos); 42 | 43 | glm::vec2 _position; 44 | glm::vec2 m_direction = glm::vec2(1.0f, 0.0f); 45 | Bengine::ColorRGBA8 _color; 46 | float _speed; 47 | float _health; 48 | GLuint m_textureID; 49 | }; 50 | 51 | -------------------------------------------------------------------------------- /ZombieGame/Bullet.cpp: -------------------------------------------------------------------------------- 1 | #include "Bullet.h" 2 | #include 3 | 4 | #include "Agent.h" 5 | #include "Human.h" 6 | #include "Zombie.h" 7 | #include "Level.h" 8 | 9 | Bullet::Bullet(glm::vec2 position, glm::vec2 direction, float damage, float speed) : 10 | _position(position), 11 | _direction(direction), 12 | _damage(damage), 13 | _speed(speed) { 14 | // Empty 15 | } 16 | 17 | 18 | Bullet::~Bullet() { 19 | // Empty 20 | } 21 | 22 | 23 | bool Bullet::update(const std::vector& levelData, float deltaTime) { 24 | _position += _direction * _speed * deltaTime; 25 | return collideWithWorld(levelData); 26 | } 27 | 28 | void Bullet::draw(Bengine::SpriteBatch& spriteBatch) { 29 | glm::vec4 destRect(_position.x, 30 | _position.y, 31 | BULLET_RADIUS * 2, 32 | BULLET_RADIUS * 2); 33 | const glm::vec4 uvRect(0.0f, 0.0f, 1.0f, 1.0f); 34 | 35 | Bengine::ColorRGBA8 color; 36 | color.r = 75; 37 | color.g = 75; 38 | color.b = 75; 39 | color.a = 255; 40 | 41 | spriteBatch.draw(destRect, uvRect, Bengine::ResourceManager::getTexture("Textures/circle.png").id, 0.0f, color); 42 | } 43 | 44 | bool Bullet::collideWithAgent(Agent* agent) { 45 | const float MIN_DISTANCE = AGENT_RADIUS + BULLET_RADIUS; 46 | 47 | glm::vec2 centerPosA = _position; 48 | glm::vec2 centerPosB = agent->getPosition() + glm::vec2(AGENT_RADIUS); 49 | 50 | glm::vec2 distVec = centerPosA - centerPosB; 51 | 52 | float distance = glm::length(distVec); 53 | 54 | float collisionDepth = MIN_DISTANCE - distance; 55 | if (collisionDepth > 0) { 56 | return true; 57 | } 58 | return false; 59 | } 60 | 61 | bool Bullet::collideWithWorld(const std::vector& levelData) { 62 | glm::ivec2 gridPosition; 63 | gridPosition.x = floor(_position.x / (float)TILE_WIDTH); 64 | gridPosition.y = floor(_position.y / (float)TILE_WIDTH); 65 | 66 | // If we are outside the world, just return 67 | if (gridPosition.x < 0 || gridPosition.x >= levelData[0].size() || 68 | gridPosition.y < 0 || gridPosition.y >= levelData.size()) { 69 | return true; 70 | } 71 | 72 | return (levelData[gridPosition.y][gridPosition.x] != '.'); 73 | } -------------------------------------------------------------------------------- /ZombieGame/Bullet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class Human; 8 | class Zombie; 9 | class Agent; 10 | 11 | const int BULLET_RADIUS = 5; 12 | 13 | class Bullet 14 | { 15 | public: 16 | Bullet(glm::vec2 position, glm::vec2 direction, float damage, float speed); 17 | ~Bullet(); 18 | 19 | // When update returns true, delete bullet 20 | bool update(const std::vector& levelData, float deltaTime); 21 | 22 | void draw(Bengine::SpriteBatch& spriteBatch); 23 | 24 | bool collideWithAgent(Agent* agent); 25 | 26 | float getDamage() const { return _damage; } 27 | 28 | glm::vec2 getPosition() const { return _position; } 29 | 30 | private: 31 | 32 | bool collideWithWorld(const std::vector& levelData); 33 | 34 | glm::vec2 _position; 35 | glm::vec2 _direction; 36 | float _damage; 37 | float _speed; 38 | }; 39 | 40 | -------------------------------------------------------------------------------- /ZombieGame/Fonts/chintzy.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/ZombieGame/Fonts/chintzy.ttf -------------------------------------------------------------------------------- /ZombieGame/Gun.cpp: -------------------------------------------------------------------------------- 1 | #include "Gun.h" 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | Gun::Gun(std::string name, int fireRate, int bulletsPerShot, 8 | float spread, float bulletDamage, float bulletSpeed, Bengine::SoundEffect fireEffect) : 9 | _name(name), 10 | _fireRate(fireRate), 11 | _bulletsPerShot(bulletsPerShot), 12 | _spread(spread), 13 | _bulletDamage(bulletDamage), 14 | _bulletSpeed(bulletSpeed), 15 | _frameCounter(0), 16 | m_fireEffect(fireEffect) { 17 | // Empty 18 | } 19 | 20 | 21 | Gun::~Gun() { 22 | // Empty 23 | } 24 | 25 | void Gun::update(bool isMouseDown, const glm::vec2& position, const glm::vec2& direction, std::vector& bullets, float deltaTime) { 26 | _frameCounter += 1.0f * deltaTime; 27 | // After a certain number of frames has passed we fire our gun 28 | if (_frameCounter >= _fireRate && isMouseDown) { 29 | fire(direction, position, bullets); 30 | _frameCounter = 0; 31 | } 32 | } 33 | 34 | void Gun::fire(const glm::vec2& direction, const glm::vec2& position, std::vector& bullets) { 35 | 36 | static std::mt19937 randomEngine(time(nullptr)); 37 | // For offsetting the accuracy 38 | std::uniform_real_distribution randRotate(-_spread, _spread); 39 | 40 | m_fireEffect.play(); 41 | 42 | for (int i = 0; i < _bulletsPerShot; i++) { 43 | // Add a new bullet 44 | bullets.emplace_back(position - glm::vec2(BULLET_RADIUS), 45 | glm::rotate(direction, randRotate(randomEngine)), 46 | _bulletDamage, 47 | _bulletSpeed); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /ZombieGame/Gun.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Bullet.h" 8 | 9 | class Gun 10 | { 11 | public: 12 | Gun(std::string name, int fireRate, int bulletsPerShot, 13 | float spread, float bulletDamage, float bulletSpeed, Bengine::SoundEffect fireEffect); 14 | ~Gun(); 15 | 16 | void update(bool isMouseDown, const glm::vec2& position, const glm::vec2& direction, std::vector& bullets, float deltaTime); 17 | 18 | private: 19 | 20 | Bengine::SoundEffect m_fireEffect; 21 | 22 | void fire(const glm::vec2& direction, const glm::vec2& position, std::vector& bullets); 23 | 24 | std::string _name; 25 | 26 | int _fireRate; ///< Fire rate in terms of frames 27 | 28 | int _bulletsPerShot; ///< How many bullets are fired at at time 29 | 30 | float _spread; ///< Accuracy 31 | 32 | float _bulletSpeed; 33 | 34 | int _bulletDamage; 35 | 36 | float _frameCounter; ///< Counts frames so we know when to shoot bullets 37 | 38 | }; 39 | 40 | -------------------------------------------------------------------------------- /ZombieGame/Human.cpp: -------------------------------------------------------------------------------- 1 | #include "Human.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | Human::Human() : 8 | _frames(0) 9 | { 10 | } 11 | 12 | 13 | Human::~Human() 14 | { 15 | } 16 | 17 | void Human::init(float speed, glm::vec2 pos) { 18 | 19 | static std::mt19937 randomEngine(time(nullptr)); 20 | static std::uniform_real_distribution randDir(-1.0f, 1.0f); 21 | 22 | _health = 20; 23 | 24 | _color.r = 255; 25 | _color.g = 255; 26 | _color.b = 255; 27 | _color.a = 255; 28 | 29 | _speed = speed; 30 | _position = pos; 31 | // Get random direction 32 | m_direction = glm::vec2(randDir(randomEngine), randDir(randomEngine)); 33 | // Make sure direction isn't zero 34 | if (m_direction.length() == 0) m_direction = glm::vec2(1.0f, 0.0f); 35 | 36 | m_direction = glm::normalize(m_direction); 37 | 38 | m_textureID = Bengine::ResourceManager::getTexture("Textures/human.png").id; 39 | } 40 | 41 | void Human::update(const std::vector& levelData, 42 | std::vector& humans, 43 | std::vector& zombies, 44 | float deltaTime) { 45 | 46 | static std::mt19937 randomEngine(time(nullptr)); 47 | static std::uniform_real_distribution randRotate(-40.0f, 40.0f); 48 | 49 | _position += m_direction * _speed * deltaTime; 50 | 51 | // Randomly change direction every 20 frames 52 | if (_frames == 20) { 53 | m_direction = glm::rotate(m_direction, randRotate(randomEngine)); 54 | _frames = 0; 55 | } else { 56 | _frames++; 57 | } 58 | 59 | if (collideWithLevel(levelData)) { 60 | m_direction = glm::rotate(m_direction, randRotate(randomEngine)); 61 | } 62 | } -------------------------------------------------------------------------------- /ZombieGame/Human.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Agent.h" 4 | 5 | class Human : public Agent 6 | { 7 | public: 8 | Human(); 9 | virtual ~Human(); 10 | 11 | void init(float speed, glm::vec2 pos); 12 | 13 | virtual void update(const std::vector& levelData, 14 | std::vector& humans, 15 | std::vector& zombies, 16 | float deltaTime) override; 17 | 18 | private: 19 | int _frames; 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /ZombieGame/Level.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | const int TILE_WIDTH = 64; 9 | 10 | class Level 11 | { 12 | public: 13 | // Load the level 14 | Level(const std::string& fileName); 15 | ~Level(); 16 | 17 | void draw(); 18 | 19 | // Getters 20 | int getWidth() const { return _levelData[0].size(); } 21 | int getHeight() const { return _levelData.size(); } 22 | int getNumHumans() const { return _numHumans; } 23 | const std::vector& getLevelData() const { return _levelData; } 24 | glm::vec2 getStartPlayerPos() const { return _startPlayerPos; } 25 | const std::vector& getZombieStartPositions() const { return _zombieStartPositions; } 26 | 27 | private: 28 | std::vector _levelData; 29 | int _numHumans; 30 | Bengine::SpriteBatch _spriteBatch; 31 | 32 | glm::vec2 _startPlayerPos; 33 | std::vector _zombieStartPositions; 34 | }; 35 | 36 | -------------------------------------------------------------------------------- /ZombieGame/MainGame.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "Player.h" 14 | #include "Level.h" 15 | #include "Bullet.h" 16 | 17 | class Zombie; 18 | 19 | enum class GameState { 20 | PLAY, 21 | EXIT 22 | }; 23 | 24 | class MainGame 25 | { 26 | public: 27 | MainGame(); 28 | ~MainGame(); 29 | 30 | /// Runs the game 31 | void run(); 32 | 33 | private: 34 | /// Initializes the core systems 35 | void initSystems(); 36 | 37 | /// Initializes the level and sets up everything 38 | void initLevel(); 39 | 40 | /// Initializes the shaders 41 | void initShaders(); 42 | 43 | /// Main game loop for the program 44 | void gameLoop(); 45 | 46 | /// Updates all agents 47 | void updateAgents(float deltaTime); 48 | 49 | /// Updates all bullets 50 | void updateBullets(float deltaTim); 51 | 52 | /// Checks the victory condition 53 | void checkVictory(); 54 | 55 | /// Handles input processing 56 | void processInput(); 57 | 58 | /// Renders the game 59 | void drawGame(); 60 | 61 | /// Draws the HUD 62 | void drawHud(); 63 | 64 | /// Adds blood to the particle engine 65 | void addBlood(const glm::vec2& position, int numParticles); 66 | 67 | /// Member Variables 68 | Bengine::Window m_window; ///< The game window 69 | 70 | Bengine::GLSLProgram m_textureProgram; ///< The shader program 71 | 72 | Bengine::InputManager m_inputManager; ///< Handles input 73 | 74 | Bengine::Camera2D m_camera; ///< Main Camera 75 | Bengine::Camera2D m_hudCamera; ///< Hud Camera 76 | 77 | Bengine::SpriteBatch m_agentSpriteBatch; ///< Draws all agents 78 | Bengine::SpriteBatch m_hudSpriteBatch; 79 | 80 | Bengine::ParticleEngine2D m_particleEngine; 81 | Bengine::ParticleBatch2D* m_bloodParticleBatch; 82 | 83 | std::vector m_levels; ///< vector of all levels 84 | 85 | int m_screenWidth = 1024; 86 | int m_screenHeight = 768; 87 | 88 | float m_fps; 89 | 90 | int m_currentLevel; 91 | 92 | Player* m_player; 93 | std::vector m_humans; ///< Vector of all humans 94 | std::vector m_zombies; ///< Vector of all zombies 95 | std::vector m_bullets; 96 | 97 | int m_numHumansKilled; ///< Humans killed by player 98 | int m_numZombiesKilled; ///< Zombies killed by player 99 | 100 | Bengine::SpriteFont* m_spriteFont; 101 | 102 | Bengine::AudioEngine m_audioEngine; 103 | 104 | GameState m_gameState; 105 | }; 106 | 107 | -------------------------------------------------------------------------------- /ZombieGame/Player.cpp: -------------------------------------------------------------------------------- 1 | #include "Player.h" 2 | #include 3 | #include 4 | 5 | #include "Gun.h" 6 | 7 | Player::Player() : 8 | _currentGunIndex(-1) { 9 | // Empty 10 | } 11 | 12 | Player::~Player() { 13 | // Empty 14 | } 15 | 16 | void Player::init(float speed, glm::vec2 pos, Bengine::InputManager* inputManager, Bengine::Camera2D* camera, std::vector* bullets) { 17 | _speed = speed; 18 | _position = pos; 19 | _inputManager = inputManager; 20 | _bullets = bullets; 21 | _camera = camera; 22 | _color.r = 255; 23 | _color.g = 255; 24 | _color.b = 255; 25 | _color.a = 255; 26 | _health = 150; 27 | m_textureID = Bengine::ResourceManager::getTexture("Textures/player.png").id; 28 | } 29 | 30 | void Player::addGun(Gun* gun) { 31 | // Add the gun to his inventory 32 | _guns.push_back(gun); 33 | 34 | // If no gun equipped, equip gun. 35 | if (_currentGunIndex == -1) { 36 | _currentGunIndex = 0; 37 | } 38 | } 39 | 40 | void Player::update(const std::vector& levelData, 41 | std::vector& humans, 42 | std::vector& zombies, 43 | float deltaTime) { 44 | 45 | if (_inputManager->isKeyDown(SDLK_w)) { 46 | _position.y += _speed * deltaTime; 47 | } else if (_inputManager->isKeyDown(SDLK_s)) { 48 | _position.y -= _speed * deltaTime; 49 | } 50 | if (_inputManager->isKeyDown(SDLK_a)) { 51 | _position.x -= _speed * deltaTime; 52 | } else if (_inputManager->isKeyDown(SDLK_d)) { 53 | _position.x += _speed * deltaTime; 54 | } 55 | 56 | if (_inputManager->isKeyDown(SDLK_1) && _guns.size() >= 0) { 57 | _currentGunIndex = 0; 58 | } else if (_inputManager->isKeyDown(SDLK_2) && _guns.size() >= 1) { 59 | _currentGunIndex = 1; 60 | } else if (_inputManager->isKeyDown(SDLK_3) && _guns.size() >= 2) { 61 | _currentGunIndex = 2; 62 | } 63 | 64 | glm::vec2 mouseCoords = _inputManager->getMouseCoords(); 65 | mouseCoords = _camera->convertScreenToWorld(mouseCoords); 66 | 67 | 68 | glm::vec2 centerPosition = _position + glm::vec2(AGENT_RADIUS); 69 | 70 | m_direction = glm::normalize(mouseCoords - centerPosition); 71 | 72 | if (_currentGunIndex != -1) { 73 | 74 | _guns[_currentGunIndex]->update(_inputManager->isKeyDown(SDL_BUTTON_LEFT), 75 | centerPosition, 76 | m_direction, 77 | *_bullets, 78 | deltaTime); 79 | 80 | 81 | } 82 | 83 | collideWithLevel(levelData); 84 | } 85 | -------------------------------------------------------------------------------- /ZombieGame/Player.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Human.h" 4 | #include 5 | #include 6 | #include "Bullet.h" 7 | 8 | class Gun; 9 | 10 | class Player : public Human 11 | { 12 | public: 13 | Player(); 14 | ~Player(); 15 | 16 | void init(float speed, glm::vec2 pos, Bengine::InputManager* inputManager, Bengine::Camera2D* camera, std::vector* bullets); 17 | 18 | void addGun(Gun* gun); 19 | 20 | void update(const std::vector& levelData, 21 | std::vector& humans, 22 | std::vector& zombies, 23 | float deltaTime) override; 24 | private: 25 | Bengine::InputManager* _inputManager; 26 | 27 | std::vector _guns; 28 | int _currentGunIndex; 29 | 30 | Bengine::Camera2D* _camera; 31 | std::vector* _bullets; 32 | 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /ZombieGame/Shaders/textureShading.frag: -------------------------------------------------------------------------------- 1 | #version 130 2 | //The fragment shader operates on each pixel in a given polygon 3 | 4 | in vec2 fragmentPosition; 5 | in vec4 fragmentColor; 6 | in vec2 fragmentUV; 7 | 8 | //This is the 3 component float vector that gets outputted to the screen 9 | //for each pixel. 10 | out vec4 color; 11 | 12 | uniform sampler2D mySampler; 13 | 14 | void main() { 15 | 16 | //cos(x) returns a number between -1 and 1. To convert it into the range 0 to 1 17 | //you simply do (cos(x) + 1.0) * 0.5 18 | 19 | vec4 textureColor = texture(mySampler, fragmentUV); 20 | 21 | //Make crazy colors using time and position! 22 | color = fragmentColor * textureColor; 23 | } -------------------------------------------------------------------------------- /ZombieGame/Shaders/textureShading.vert: -------------------------------------------------------------------------------- 1 | #version 130 2 | //The vertex shader operates on each vertex 3 | 4 | //input data from the VBO. Each vertex is 2 floats 5 | in vec2 vertexPosition; 6 | in vec4 vertexColor; 7 | in vec2 vertexUV; 8 | 9 | out vec2 fragmentPosition; 10 | out vec4 fragmentColor; 11 | out vec2 fragmentUV; 12 | 13 | uniform mat4 P; 14 | 15 | void main() { 16 | //Set the x,y position on the screen 17 | gl_Position.xy = (P * vec4(vertexPosition, 0.0, 1.0)).xy; 18 | //the z position is zero since we are in 2D 19 | gl_Position.z = 0.0; 20 | 21 | //Indicate that the coordinates are normalized 22 | gl_Position.w = 1.0; 23 | 24 | fragmentPosition = vertexPosition; 25 | 26 | fragmentColor = vertexColor; 27 | 28 | fragmentUV = vec2(vertexUV.x, 1.0 - vertexUV.y); 29 | } -------------------------------------------------------------------------------- /ZombieGame/Sound/XYZ.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/ZombieGame/Sound/XYZ.ogg -------------------------------------------------------------------------------- /ZombieGame/Sound/credits.txt: -------------------------------------------------------------------------------- 1 | Kistol: XYZ.ogg 2 | Michel Baradari: Shots -------------------------------------------------------------------------------- /ZombieGame/Sound/shots/cg1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/ZombieGame/Sound/shots/cg1.wav -------------------------------------------------------------------------------- /ZombieGame/Sound/shots/info.txt: -------------------------------------------------------------------------------- 1 | Sounds (c) by Michel Baradari apollo-music.de 2 | 3 | Licensed under CC BY 3.0 http://creativecommons.org/licenses/by/3.0/ 4 | 5 | Hosted on opengameart.org 6 | -------------------------------------------------------------------------------- /ZombieGame/Sound/shots/pistol.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/ZombieGame/Sound/shots/pistol.wav -------------------------------------------------------------------------------- /ZombieGame/Sound/shots/rifle.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/ZombieGame/Sound/shots/rifle.wav -------------------------------------------------------------------------------- /ZombieGame/Sound/shots/shotgun.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/ZombieGame/Sound/shots/shotgun.wav -------------------------------------------------------------------------------- /ZombieGame/Textures/circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/ZombieGame/Textures/circle.png -------------------------------------------------------------------------------- /ZombieGame/Textures/credits.txt: -------------------------------------------------------------------------------- 1 | The following textures are from Seed of Andromeda: 2 | glass.png 3 | light_bricks.png 4 | red_bricks.png 5 | 6 | Artist: Andreas Ressl -------------------------------------------------------------------------------- /ZombieGame/Textures/glass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/ZombieGame/Textures/glass.png -------------------------------------------------------------------------------- /ZombieGame/Textures/human.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/ZombieGame/Textures/human.png -------------------------------------------------------------------------------- /ZombieGame/Textures/light_bricks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/ZombieGame/Textures/light_bricks.png -------------------------------------------------------------------------------- /ZombieGame/Textures/particle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/ZombieGame/Textures/particle.png -------------------------------------------------------------------------------- /ZombieGame/Textures/player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/ZombieGame/Textures/player.png -------------------------------------------------------------------------------- /ZombieGame/Textures/red_bricks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/ZombieGame/Textures/red_bricks.png -------------------------------------------------------------------------------- /ZombieGame/Textures/zombie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/ZombieGame/Textures/zombie.png -------------------------------------------------------------------------------- /ZombieGame/Zombie.cpp: -------------------------------------------------------------------------------- 1 | #include "Zombie.h" 2 | #include 3 | 4 | #include "Human.h" 5 | 6 | Zombie::Zombie() 7 | { 8 | } 9 | 10 | Zombie::~Zombie() 11 | { 12 | } 13 | 14 | void Zombie::init(float speed, glm::vec2 pos) { 15 | _speed = speed; 16 | _position = pos; 17 | _health = 50; 18 | // Set Green Color 19 | _color = Bengine::ColorRGBA8(255, 255, 255, 255); 20 | m_textureID = Bengine::ResourceManager::getTexture("Textures/zombie.png").id; 21 | } 22 | 23 | void Zombie::update(const std::vector& levelData, 24 | std::vector& humans, 25 | std::vector& zombies, 26 | float deltaTime) { 27 | 28 | // Find the closest human 29 | Human* closestHuman = getNearestHuman(humans); 30 | 31 | // If we found a human, move towards him 32 | if (closestHuman != nullptr) { 33 | // Get the direction vector twoards the player 34 | m_direction = glm::normalize(closestHuman->getPosition() - _position); 35 | _position += m_direction * _speed * deltaTime; 36 | } 37 | 38 | // Do collision 39 | collideWithLevel(levelData); 40 | } 41 | 42 | Human* Zombie::getNearestHuman(std::vector& humans) { 43 | Human* closestHuman = nullptr; 44 | float smallestDistance = 9999999.0f; 45 | 46 | for (int i = 0; i < humans.size(); i++) { 47 | // Get the direction vector 48 | glm::vec2 distVec = humans[i]->getPosition() - _position; 49 | // Get distance 50 | float distance = glm::length(distVec); 51 | 52 | // If this person is closer than the closest person, this is the new closest 53 | if (distance < smallestDistance) { 54 | smallestDistance = distance; 55 | closestHuman = humans[i]; 56 | } 57 | } 58 | 59 | return closestHuman; 60 | } -------------------------------------------------------------------------------- /ZombieGame/Zombie.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Agent.h" 4 | 5 | class Zombie : public Agent 6 | { 7 | public: 8 | Zombie(); 9 | ~Zombie(); 10 | 11 | void init(float speed, glm::vec2 pos); 12 | 13 | virtual void update(const std::vector& levelData, 14 | std::vector& humans, 15 | std::vector& zombies, 16 | float deltaTime) override; 17 | private: 18 | 19 | Human* getNearestHuman(std::vector& humans); 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /ZombieGame/ZombieGame.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | -------------------------------------------------------------------------------- /ZombieGame/main.cpp: -------------------------------------------------------------------------------- 1 | #include "MainGame.h" 2 | 3 | int main(int argc, char** argv) { 4 | 5 | MainGame mainGame; 6 | mainGame.run(); 7 | 8 | return 0; 9 | } -------------------------------------------------------------------------------- /graphicsTutorials/Bullet.cpp: -------------------------------------------------------------------------------- 1 | #include "Bullet.h" 2 | #include 3 | 4 | 5 | Bullet::Bullet(glm::vec2 pos, glm::vec2 dir, float speed, int lifeTime) 6 | { 7 | _lifeTime = lifeTime; 8 | _position = pos; 9 | _direction = dir; 10 | _speed = speed; 11 | } 12 | 13 | 14 | Bullet::~Bullet() 15 | { 16 | } 17 | 18 | void Bullet::draw(Bengine::SpriteBatch& spriteBatch) { 19 | glm::vec4 uv(0.0f, 0.0f, 1.0f, 1.0f); 20 | static Bengine::GLTexture texture = Bengine::ResourceManager::getTexture("Textures/jimmyJump_pack/PNG/Bullet.png"); 21 | Bengine::ColorRGBA8 color; 22 | color.r = 255; 23 | color.g = 255; 24 | color.b = 255; 25 | color.a = 255; 26 | 27 | glm::vec4 posAndSize = glm::vec4(_position.x, _position.y, 30, 30); 28 | 29 | spriteBatch.draw(posAndSize, uv, texture.id, 0.0f, color); 30 | } 31 | 32 | bool Bullet::update() { 33 | _position += _direction * _speed; 34 | _lifeTime--; 35 | if (_lifeTime == 0) { 36 | return true; 37 | } 38 | return false; 39 | } -------------------------------------------------------------------------------- /graphicsTutorials/Bullet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class Bullet 7 | { 8 | public: 9 | Bullet(glm::vec2 pos, glm::vec2 dir, float speed, int lifeTime); 10 | ~Bullet(); 11 | 12 | void draw(Bengine::SpriteBatch& spriteBatch); 13 | // Returns true when we are out of life 14 | bool update(); 15 | 16 | private: 17 | int _lifeTime; 18 | float _speed; 19 | glm::vec2 _direction; 20 | glm::vec2 _position; 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /graphicsTutorials/MainGame.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | 18 | #include "Bullet.h" 19 | 20 | #include 21 | 22 | enum class GameState {PLAY, EXIT}; 23 | 24 | //Our example game class, just for testing purposes right now 25 | class MainGame 26 | { 27 | public: 28 | MainGame(); 29 | ~MainGame(); 30 | 31 | void run(); 32 | 33 | private: 34 | void initSystems(); 35 | void initShaders(); 36 | void gameLoop(); 37 | void processInput(); 38 | void drawGame(); 39 | 40 | Bengine::Window _window; 41 | int _screenWidth; 42 | int _screenHeight; 43 | GameState _gameState; 44 | 45 | Bengine::GLSLProgram _colorProgram; 46 | Bengine::Camera2D _camera; 47 | 48 | Bengine::SpriteBatch _spriteBatch; 49 | 50 | Bengine::InputManager _inputManager; 51 | Bengine::FpsLimiter _fpsLimiter; 52 | 53 | std::vector _bullets; 54 | 55 | float _maxFPS; 56 | float _fps; 57 | float _time; 58 | }; 59 | 60 | -------------------------------------------------------------------------------- /graphicsTutorials/Shaders/colorShading.frag: -------------------------------------------------------------------------------- 1 | #version 130 2 | //The fragment shader operates on each pixel in a given polygon 3 | 4 | in vec2 fragmentPosition; 5 | in vec4 fragmentColor; 6 | in vec2 fragmentUV; 7 | 8 | //This is the 3 component float vector that gets outputted to the screen 9 | //for each pixel. 10 | out vec4 color; 11 | 12 | uniform sampler2D mySampler; 13 | 14 | void main() { 15 | 16 | //cos(x) returns a number between -1 and 1. To convert it into the range 0 to 1 17 | //you simply do (cos(x) + 1.0) * 0.5 18 | 19 | vec4 textureColor = texture(mySampler, fragmentUV); 20 | 21 | //Make crazy colors using time and position! 22 | color = fragmentColor * textureColor; 23 | } -------------------------------------------------------------------------------- /graphicsTutorials/Shaders/colorShading.vert: -------------------------------------------------------------------------------- 1 | #version 130 2 | //The vertex shader operates on each vertex 3 | 4 | //input data from the VBO. Each vertex is 2 floats 5 | in vec2 vertexPosition; 6 | in vec4 vertexColor; 7 | in vec2 vertexUV; 8 | 9 | out vec2 fragmentPosition; 10 | out vec4 fragmentColor; 11 | out vec2 fragmentUV; 12 | 13 | uniform mat4 P; 14 | 15 | void main() { 16 | //Set the x,y position on the screen 17 | gl_Position.xy = (P * vec4(vertexPosition, 0.0, 1.0)).xy; 18 | //the z position is zero since we are in 2D 19 | gl_Position.z = 0.0; 20 | 21 | //Indicate that the coordinates are normalized 22 | gl_Position.w = 1.0; 23 | 24 | fragmentPosition = vertexPosition; 25 | 26 | fragmentColor = vertexColor; 27 | 28 | fragmentUV = vec2(vertexUV.x, 1.0 - vertexUV.y); 29 | } -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/AngryCloud.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/AngryCloud.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Background.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/BrokenLandPiece_Beige.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/BrokenLandPiece_Beige.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/BrokenLandPiece_Blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/BrokenLandPiece_Blue.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/BrokenLandPiece_Gray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/BrokenLandPiece_Gray.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/BrokenLandPiece_Green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/BrokenLandPiece_Green.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/BrokenLandPiece_Multicolored.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/BrokenLandPiece_Multicolored.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/BrokenLandPiece_Pink.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/BrokenLandPiece_Pink.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Bubble_Big.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Bubble_Big.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Bubble_Small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Bubble_Small.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Bullet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Bullet.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterLeft_Jump.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterLeft_Jump.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterLeft_Standing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterLeft_Standing.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterLeft_Walk1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterLeft_Walk1.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterLeft_Walk2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterLeft_Walk2.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterRight_Jump.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterRight_Jump.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterRight_Standing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterRight_Standing.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterRight_Walk1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterRight_Walk1.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterRight_Walk2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/CharacterRight_Walk2.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/CloudWind.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/CloudWind.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Coin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Coin.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Left_Beige.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Left_Beige.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Left_Blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Left_Blue.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Left_Gray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Left_Gray.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Left_Green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Left_Green.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Left_Multicolored.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Left_Multicolored.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Left_Pink.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Left_Pink.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Right_Beige.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Right_Beige.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Right_Blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Right_Blue.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Right_Gray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Right_Gray.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Right_Green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Right_Green.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Right_Multicolored.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Right_Multicolored.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Right_Pink.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/HalfLandPiece_Right_Pink.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/HappyCloud.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/HappyCloud.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/HearthEnemy1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/HearthEnemy1.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/HearthEnemy2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/HearthEnemy2.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/JetFire1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/JetFire1.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/JetFire2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/JetFire2.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Jetpack_Big.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Jetpack_Big.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Jetpack_Small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Jetpack_Small.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_DarkBeige.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_DarkBeige.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_DarkBlue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_DarkBlue.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_DarkGray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_DarkGray.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_DarkGreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_DarkGreen.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_DarkMulticolored.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_DarkMulticolored.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_DarkPing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_DarkPing.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_LightBeige.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_LightBeige.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_LightBlue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_LightBlue.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_LightGray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_LightGray.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_LightGreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_LightGreen.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_LightMulticolored.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_LightMulticolored.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_LightPing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/LandPiece_LightPing.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Lightning1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Lightning1.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Lightning2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Lightning2.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Mushroom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Mushroom.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_0.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_1.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_2.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_3.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_4.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_5.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_6.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_7.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_8.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_9.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_Point.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Number_Point.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Pistol.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Pistol.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/PNG/Spring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Barnold1953/GraphicsTutorials/f5f6e1f37170344c560a50300f0dd4db72619c48/graphicsTutorials/Textures/jimmyJump_pack/PNG/Spring.png -------------------------------------------------------------------------------- /graphicsTutorials/Textures/jimmyJump_pack/license.txt: -------------------------------------------------------------------------------- 1 | Credit goes to: 1001.com 2 | 3 | All assets in this package are licensed CC-BY-SA 4.0 4 | 5 | Read more about CC-BY-SA 4.0 here: 6 | https://creativecommons.org/licenses/by-sa/4.0 -------------------------------------------------------------------------------- /graphicsTutorials/graphicsTutorials.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | 29 | 30 | Header Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | -------------------------------------------------------------------------------- /graphicsTutorials/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "MainGame.h" 3 | 4 | int main(int argc, char** argv) { 5 | MainGame mainGame; 6 | mainGame.run(); 7 | 8 | return 0; 9 | } --------------------------------------------------------------------------------