2 Commits 842b1f5bbe ... d91d24e295

Author SHA1 Message Date
  Brigham Henry Keys, Esq d91d24e295 Added guid system 1 year ago
  Brigham Henry Keys, Esq 0a54683cd9 The player moves around a lot more like paperboy now 1 year ago
10 changed files with 54 additions and 18 deletions
  1. 0 1
      CMake/Dependencies/SDL2.cmake
  2. 16 0
      CMake/Dependencies/SDL2_image.cmake
  3. 6 6
      CMakeLists.txt
  4. BIN
      assets/grass.bmp
  5. 11 1
      src/Entity.cpp
  6. 2 0
      src/Entity.hpp
  7. 8 3
      src/Main.cpp
  8. 10 7
      src/Player.cpp
  9. 1 0
      src/Player.hpp
  10. 0 0
      src/uuid4.cpp

+ 0 - 1
CMake/Dependencies/SDL2.cmake

@@ -13,5 +13,4 @@ include_directories(SYSTEM ${SDL2_INCLUDE_DIR})
 set(GAME_DEPENDENCY_LIBRARIES
     ${GAME_DEPENDENCY_LIBRARIES}
     ${SDL2_LIBRARY}
-    dl
     )

+ 16 - 0
CMake/Dependencies/SDL2_image.cmake

@@ -0,0 +1,16 @@
+ExternalProject_Add(sdl2_image
+  DOWNLOAD_NO_PROGRESS 1
+  URL https://notabug.org/bkeys/uploads/raw/master/SDL_image_2.0.3.tar.gz
+  PREFIX ${CMAKE_CURRENT_BINARY_DIR}/sdl2
+  CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/  -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
+)
+
+set(SDL2_IMAGE_INCLUDE_DIR "${CMAKE_BINARY_DIR}/")
+set(SDL2_IMAGE_LIBRARY "${CMAKE_BINARY_DIR}/")
+
+include_directories(SYSTEM ${_INCLUDE_DIR})
+
+set(GAME_DEPENDENCY_LIBRARIES
+    ${GAME_DEPENDENCY_LIBRARIES}
+    ${SDL2_IMAGE_LIBRARY}
+    )

+ 6 - 6
CMakeLists.txt

@@ -8,32 +8,32 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Dependencies)
 include(ExternalProject)
 
 set(CMAKE_CXX_FLAGS "-std=c++1z -fno-elide-constructors -pedantic-errors -Werror -Wextra -Wall -Wpedantic -Winit-self -Wmissing-declarations -Wuninitialized -Woverloaded-virtual -Wold-style-cast -Wfatal-errors -O3 -pthread")
-add_definitions(${CMAKE_CXX_FLAGS})
 
 set(SRC 
 src/Main.cpp
 src/Sprite.cpp
 src/Player.cpp
 src/Entity.cpp
+src/uuid4.cpp
 )
 
 include(SDL2)
 
 find_package(OpenGL REQUIRED)
 
-include_directories(
-    ${OpenGL_INCLUDE_DIR}
-    ${SDL2_INCLUDE_DIR}
-)
+include_directories(${OpenGL_INCLUDE_DIR})
 
 # Create the binary
 add_executable(${CMAKE_PROJECT_NAME} ${SRC})
 
 # Link the libraries
-add_dependencies(${CMAKE_PROJECT_NAME} sdl2)
+add_dependencies(${CMAKE_PROJECT_NAME} sdl2 crossguid)
 
 target_link_libraries(${CMAKE_PROJECT_NAME}
   ${OPENGL_LIBRARIES}
   ${SDL2_LIBRARY}
+  ${GAME_DEPENDENCY_LIBRARIES}
+  ${CROSSGUID_LIBRARY}
+  uuid
   dl
 )

BIN
assets/grass.bmp


+ 11 - 1
src/Entity.cpp

@@ -7,12 +7,15 @@ You can read more about this license by opening the LICENSE
 file that should have been included with this software.
 */
 #include <SDL2/SDL.h>
+
+#include "uuid4.hpp"
 #include "Entity.hpp"
 
 std::vector<Entity*> Entity::entity_collection = std::vector<Entity*>();
 
 Entity::Entity(const std::string &file_path_, SDL_Renderer *ren, float nx, float ny, int nw, int nh) :
-Sprite(file_path_, ren, nx, ny, nw, nh) {
+Sprite(file_path_, ren, nx, ny, nw, nh),
+id(uuid4_generate()) {
   // entity_collection.push_back(this);
 }
 
@@ -20,4 +23,11 @@ void Entity::process_entities() {
   for(const auto &entity : entity_collection) {
     entity->process();
   }
+}
+
+bool Entity::is_colliding() {
+  // for(const auto &entity : entity_collection) {
+        
+  // }
+  return false;
 }

+ 2 - 0
src/Entity.hpp

@@ -19,7 +19,9 @@ public:
 Entity(const std::string &file_path_, SDL_Renderer *ren, float nx = 0, float ny = 0, int nw = 0, int nh = 0);
 static std::vector<Entity*> entity_collection;
 static void process_entities();
+bool is_colliding();
 private:
 virtual void process() = 0;
+std::string id;
 };
 

+ 8 - 3
src/Main.cpp

@@ -14,6 +14,7 @@ file that should have been included with this software.
 #include <string>
 #include <vector>
 #include <SDL2/SDL.h>
+#include "uuid4.hpp"
 #include "Sprite.hpp"
 #include "Player.hpp"
 
@@ -21,7 +22,7 @@ const int SCREEN_WIDTH = 640;
 const int SCREEN_HEIGHT = 480;
 
 int main(void) {
-
+  uuid4_init();
   SDL_Init(SDL_INIT_VIDEO);
   // std::map<std::string, Sprite> sprites;// = std::map<std::string, Sprite>();
   std::vector<Sprite*> sprites;
@@ -40,9 +41,9 @@ int main(void) {
     return 1;
   }
   
-  Player p("assets/bike.bmp", ren, 50, 50, 32, 383 / 8);
+  Player p("assets/bike.bmp", ren, 200, 350, 32, 383 / 8);
   sprites.push_back(&p);
-  sprites.push_back(new Sprite("assets/trash_can.bmp", ren, 100, 100, 51 * .75, 64 * .75));
+  sprites.push_back(new Sprite("assets/trash_can.bmp", ren, 400, 150, 51 * .75, 64 * .75));
 
   bool quit = false;
   SDL_Event e;
@@ -63,6 +64,10 @@ int main(void) {
     std::sort(sprites.rbegin(), sprites.rend(), PointerCompare());
     for(const auto &s : sprites) {
       s->render();
+      if(s->file_path != "assets/bike.bmp") {
+        s->x -= (1.f / 2.f) * p.acceleration;
+        s->y += (.75 / 2.f) * p.acceleration;
+      }
     }
     p.process();
     // Entity::process_entities();

+ 10 - 7
src/Player.cpp

@@ -10,7 +10,8 @@ file that should have been included with this software.
 #include "Player.hpp"
 
 Player::Player(const std::string &file_path_, SDL_Renderer *ren, float nx, float ny, int nw, int nh) :
-Entity(file_path_, ren, nx, ny, nw, nh) {
+Entity(file_path_, ren, nx, ny, nw, nh),
+acceleration(1.f) {
 
 }
 
@@ -18,19 +19,21 @@ void Player::process() {
   const Uint8 *keystates = SDL_GetKeyboardState(nullptr);
 
     if (keystates[SDL_SCANCODE_W]) {
-      y -= .5;
-      x += .5;
+      acceleration += .005f;
     }
     if (keystates[SDL_SCANCODE_A]) {
       x -= .5;
-      y -= .25;
     }
     if (keystates[SDL_SCANCODE_S]) {
-      y += .5;
-      x -= .5;
+      acceleration -= .005f;
     }
     if (keystates[SDL_SCANCODE_D]) {
       x += .5;
-      y += .25;
+    }
+
+    if (acceleration <= .8f) {
+      acceleration = .8f;
+    } else if(acceleration >= 1.2f) {
+      acceleration = 1.2f;
     }
 }

+ 1 - 0
src/Player.hpp

@@ -16,5 +16,6 @@ class Player : public Entity {
 public:
 Player(const std::string &file_path_, SDL_Renderer *ren, float nx = 0, float ny = 0, int nw = 0, int nh = 0);
 void process() override;
+float acceleration;
 private:
 };

+ 0 - 0
src/uuid4.cpp


Some files were not shown because too many files changed in this diff