diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-04-14 10:37:42 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-04-14 10:37:42 +0100 |
commit | 348cb17ccc87f85f014675d0aea849fd2c34e3c3 (patch) | |
tree | c237225e925fecdd84ed51e32fdebd865bdb1534 | |
parent | 09730bc689eee02bb4828ebc9d92f14793b78ebd (diff) | |
download | Arider-348cb17ccc87f85f014675d0aea849fd2c34e3c3.tar.gz Arider-348cb17ccc87f85f014675d0aea849fd2c34e3c3.zip |
Adding physics engine
-rw-r--r-- | .dir-locals.el | 9 | ||||
-rw-r--r-- | CMakeLists.txt | 7 | ||||
m--------- | YAGE | 0 | ||||
-rw-r--r-- | include/animation.hpp | 4 | ||||
-rw-r--r-- | include/block.hpp | 30 | ||||
-rw-r--r-- | include/game.hpp | 2 | ||||
-rw-r--r-- | include/level.hpp (renamed from include/levelloader.hpp) | 0 | ||||
-rw-r--r-- | include/physics.hpp | 10 | ||||
-rw-r--r-- | src/block.cpp | 21 | ||||
-rw-r--r-- | src/game.cpp | 2 | ||||
-rw-r--r-- | src/level.cpp (renamed from src/levelloader.cpp) | 2 |
11 files changed, 74 insertions, 13 deletions
diff --git a/.dir-locals.el b/.dir-locals.el index 223f1d6..2d4dbd5 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -1,15 +1,12 @@ -((nil . ((company-clang-arguments . ("-I../include/YAGE/" - "-I../include/" +((nil . ((company-clang-arguments . ("-I../include/" "-I../YAGE/include/" "-I/usr/include/" "-I/usr/include/SDL2/")) - (company-c-headers-path-user . ("../include/YAGE/" - "../include/" + (company-c-headers-path-user . ("../include/" "../YAGE/include/" "/usr/include/" "/usr/include/SDL2/")) - (flycheck-clang-include-path . ("../include/YAGE/" - "../include/" + (flycheck-clang-include-path . ("../include/" "../YAGE/include/" "/usr/include/" "/usr/include/SDL2/"))))) diff --git a/CMakeLists.txt b/CMakeLists.txt index 733df91..0034e05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ set(ARIDER_MAJOR_VERSION 0) set(ARIDER_MINOR_VERSION 1) set(ARIDER_PATCH_VERSION 0) set(ARIDER_VERSION - ${ARIDER_MAJOR_VERSION}.${ARIDERn_MINOR_VERSION}.${ARIDER_PATCH_VERSION}) + ${ARIDER_MAJOR_VERSION}.${ARIDERn_MINOR_VERSION}${ARIDER_PATCH_VERSION}) # set standard set(CMAKE_CXX_STANDARD 14) @@ -30,9 +30,10 @@ configure_file ( # adding my executable add_executable(${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/src/animation.cpp - ${CMAKE_SOURCE_DIR}/src/character.cpp + ${CMAKE_SOURCE_DIR}/src/block.cpp + ${CMAKE_SOURCE_DIR}/src/character.cpp ${CMAKE_SOURCE_DIR}/src/game.cpp - ${CMAKE_SOURCE_DIR}/src/levelloader.cpp + ${CMAKE_SOURCE_DIR}/src/level.cpp ${CMAKE_SOURCE_DIR}/src/main.cpp ${CMAKE_SOURCE_DIR}/src/player.cpp) diff --git a/YAGE b/YAGE -Subproject 6d410918675effd76c5b30f6dbe5b6f4b915470 +Subproject daa032e2f6c86da16902f654055d8b040d7670b diff --git a/include/animation.hpp b/include/animation.hpp index da24fd5..54eb71a 100644 --- a/include/animation.hpp +++ b/include/animation.hpp @@ -12,10 +12,12 @@ enum class AnimationState { + STILL, IDLE, MOVING, JUMPING, CROUCHING, + FALLING, }; class Animation @@ -25,7 +27,7 @@ private: AnimationState current_animation_; int current_index_=0; public: - Animation(); + Animation(); void pushFrame(AnimationState state, const std::string &texture_path); yage::Texture currentFrame() const; diff --git a/include/block.hpp b/include/block.hpp new file mode 100644 index 0000000..dd6d5d9 --- /dev/null +++ b/include/block.hpp @@ -0,0 +1,30 @@ +#ifndef BLOCK_HPP +#define BLOCK_HPP + +#include "animation.hpp" + +#include <YAGE/spritebatch.hpp> + +class Block +{ +private: + Animation animation_; + int x_; + int y_; + int width_; + int height_; + + // adding physics elements + double mass_=7850.0/*kg*/; + // assuming it's a 1mx1mx1m block of steel + double velocity_=0.0; + +public: + Block(const std::string &texture, int x, int y, int width=70, int height=70); + Block(Animation animation, int x, int y, int width=70, int height=70); + + void render(yage::SpriteBatch &sprite_batch, float depth) const; +}; + + +#endif diff --git a/include/game.hpp b/include/game.hpp index 3bcc14f..8f9f1fa 100644 --- a/include/game.hpp +++ b/include/game.hpp @@ -1,7 +1,7 @@ #ifndef GAME_HPP #define GAME_HPP -#include "levelloader.hpp" +#include "level.hpp" #include "player.hpp" #include <YAGE/camera2d.hpp> diff --git a/include/levelloader.hpp b/include/level.hpp index 07fb372..07fb372 100644 --- a/include/levelloader.hpp +++ b/include/level.hpp diff --git a/include/physics.hpp b/include/physics.hpp new file mode 100644 index 0000000..55267ca --- /dev/null +++ b/include/physics.hpp @@ -0,0 +1,10 @@ +#ifndef PHYSICS_HPP +#define PHYSICS_HPP + +class Physics +{ +public: + static void calculateNewPosition(); +}; + +#endif diff --git a/src/block.cpp b/src/block.cpp new file mode 100644 index 0000000..c1aeb68 --- /dev/null +++ b/src/block.cpp @@ -0,0 +1,21 @@ +#include "block.hpp" + +#include <YAGE/vertex.hpp> + +Block::Block(const std::string &texture, int x, int y, int width, int height): + x_(x), y_(y), + width_(width), height_(height) +{ + animation_.pushFrame(AnimationState::STILL, texture); +} + +Block::Block(Animation animation, int x, int y, int width, int height) : + animation_(animation), + x_(x), y_(y), + width_(width), height_(height) +{} + +void Block::render(yage::SpriteBatch &sprite_batch, float depth) const +{ + sprite_batch.draw(glm::vec4(x_, y_, width_, height_), glm::vec4(0.f, 0.f, 1.f, 1.f), animation_.currentFrame().id, yage::Color(255, 255, 255, 255), depth); +} diff --git a/src/game.cpp b/src/game.cpp index 3a34715..81f0fa6 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1,6 +1,6 @@ #include "animation.hpp" #include "game.hpp" -#include "levelloader.hpp" +#include "level.hpp" #include <GL/glew.h> #include <glm/glm.hpp> diff --git a/src/levelloader.cpp b/src/level.cpp index 88a2ba4..f3219a8 100644 --- a/src/levelloader.cpp +++ b/src/level.cpp @@ -1,4 +1,4 @@ -#include "levelloader.hpp" +#include "level.hpp" #include <YAGE/resourcemanager.hpp> #include <YAGE/vertex.hpp> |