diff --git a/.gitignore b/.gitignore index b1a77ba..8bd99fc 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ TheOneSDL/.vscode/c_cpp_properties.json TheOneSDL/.vscode/settings.json TheOneSDL/.vscode/tasks.json TheOneSDL/.vscode/launch.json +*.mp4 diff --git a/TheOneSDL/Application.h b/TheOneSDL/Application.h index 2869f08..74784f3 100644 --- a/TheOneSDL/Application.h +++ b/TheOneSDL/Application.h @@ -86,7 +86,7 @@ class Application //Constants for reference - const char* windowTitle = "C23 Engine: The One SDL v.0.18.1 FPS:"; + const char* windowTitle = "C23 Engine: The One SDL v.0.19 FPS:"; int textureWidth = 1920; int textureHeight = 32; diff --git a/TheOneSDL/Player.cpp b/TheOneSDL/Player.cpp index fb67510..79009bd 100644 --- a/TheOneSDL/Player.cpp +++ b/TheOneSDL/Player.cpp @@ -9,6 +9,8 @@ Player::Player(SDL_Renderer* renderer) tilemap_y = 16; playerR.x = tilemap_x*32; playerR.y = tilemap_y*32; + // Set default speed + playerSpeed = 3; // Defaults zero no texture loaded yet textureWidth = 0; textureHeight = 0; @@ -30,20 +32,24 @@ Player::Player(SDL_Renderer* renderer) exit(-1); } - texture = default_texture; // The current texture is the default texture + // Load Textures + // Load filenames - // Test 2 - filename = idle_file2.c_str(); - texture2 = IMG_LoadTexture(renderer, filename); - SDL_QueryTexture(texture2, NULL, NULL, &textureWidth, &textureHeight); - - // Load Run Left - filename = run_left_file.c_str(); - run_left = IMG_LoadTexture(renderer, filename); - SDL_QueryTexture(run_left, NULL, NULL, &textureWidth, &textureHeight); + std::list tex_files = {idle, run_left, run_right}; + std::list tex_names = {"idle", "run_left","run_right"}; + - editMS(2); - setTexture(texture); + while (tex_files.size() > 0) { + filename = tex_files.front().c_str(); // Reference from front + std::string name = tex_names.front(); + tex_names.pop_front(); // pop + tex_files.pop_front(); + textures[name] = IMG_LoadTexture(renderer,filename); + std::cout << name << "loaded with " << textures[name] << std::endl; + } + + editMS(3); // push default speed + setTexture(textures["idle"]); std::cout << "Player Created!\n"; } @@ -85,7 +91,7 @@ SDL_Texture* Player::getTexture() void Player::updateTexture(Physics* phys_eng, Terrain* terrain_eng) { - std::cout << "[Frame]" << frame_time << std::endl; + //std::cout << "[Frame]" << frame_time << std::endl; // << "," << getX() << "," << getY() << std::endl; xTexEdit(getTexX() + frameWidth); @@ -101,6 +107,7 @@ void Player::updateTexture(Physics* phys_eng, Terrain* terrain_eng) { handleMovement(phys_eng,terrain_eng, 1); frame_time++; + } @@ -205,10 +212,10 @@ void Player::handleMovement(Physics* phys_eng, Terrain* terrain_eng, bool animat { case Left: { - std::cout << "Left\n"; + // std::cout << "Left\n"; if (!inAnimation) { - setTexture(run_left); + setTexture(textures["run_left"]); inAnimation = true; } xEdit(getX() - getSpeed()); @@ -220,8 +227,11 @@ void Player::handleMovement(Physics* phys_eng, Terrain* terrain_eng, bool animat } case Right: { - std::cout << "Right\n"; - setTexture(texture); + if (!inAnimation) + { + setTexture(textures["run_right"]); + inAnimation = true; + } xEdit(getX() + getSpeed()); terrain_eng->background_tilemap[tilemap_y][tilemap_x] = '~'; tilemap_x = round(getX()/32); @@ -231,7 +241,7 @@ void Player::handleMovement(Physics* phys_eng, Terrain* terrain_eng, bool animat } default: { - setTexture(texture); + setTexture(textures["idle"]); inAnimation = false; } } @@ -239,7 +249,7 @@ void Player::handleMovement(Physics* phys_eng, Terrain* terrain_eng, bool animat { case Up: { - std::cout << "Up\n"; + // std::cout << "Up\n"; yEdit(getY() - getSpeed()); terrain_eng->background_tilemap[tilemap_y][tilemap_x] = '~'; tilemap_x = round(getX()/32); diff --git a/TheOneSDL/Player.h b/TheOneSDL/Player.h index 254eaec..f5cbc1f 100644 --- a/TheOneSDL/Player.h +++ b/TheOneSDL/Player.h @@ -4,6 +4,8 @@ #include "Terrain.h" #include +#include +#include class Terrain; class Physics; @@ -72,6 +74,9 @@ class Player int tilemap_x; int tilemap_y; + //Speed + int playerSpeed; + SDL_Texture* player_texture = NULL; MovementDirection currentDirectionX = None; @@ -80,16 +85,16 @@ class Player int textureWidth, textureHeight, frameWidth, frameHeight; - //std::string texture_name = "VGB_Idle"; - std::string idle_file = "textures\\VGB\\idle\\vgb_idle-Sheet.png"; - std::string idle_file2 = "VGB_Idle.png"; - std::string run_left_file = "textures\\VGB\\run\\vgb_run_left-Sheet.png"; + // Filenames + std::string idle = "textures\\VGB\\idle\\vgb_idle-Sheet.png"; + std::string run_left = "textures\\VGB\\run\\vgb_run_left-Sheet.png"; + std::string run_right = "textures\\VGB\\run\\vgb_run_right-Sheet.png"; + std::list tex_files; //Textures stored - SDL_Texture* texture = NULL; - SDL_Texture* texture2 = NULL; - SDL_Texture* run_left = NULL; + std::map textures; + int frame_time; bool inAnimation = false; // toggle to lock animation canceling diff --git a/TheOneSDL/TheOne.exe b/TheOneSDL/TheOne.exe index 43484ab..56378a9 100644 Binary files a/TheOneSDL/TheOne.exe and b/TheOneSDL/TheOne.exe differ diff --git a/TheOneSDL/textures/VGB/run/vgb_run_right-Sheet.png b/TheOneSDL/textures/VGB/run/vgb_run_right-Sheet.png new file mode 100644 index 0000000..700d57e Binary files /dev/null and b/TheOneSDL/textures/VGB/run/vgb_run_right-Sheet.png differ