diff --git a/TheOneSDL/Application.cpp b/TheOneSDL/Application.cpp index 34f1643..7c62671 100644 --- a/TheOneSDL/Application.cpp +++ b/TheOneSDL/Application.cpp @@ -55,8 +55,8 @@ bool Application::init() SDL_Texture* temp_tex = NULL; //Create Player - temp_tex = IMG_LoadTexture(renderer, "VGB_Idle.png"); - player = new Player(temp_tex); + // renderer is passed in to load the texture + player = new Player(renderer); if (!player) { @@ -176,7 +176,7 @@ void Application::update() player->updateTexture(phys_eng, terrain_gen); //player->handleMovement(phys_eng, terrain_gen); terrain_gen->fillScreen(); - // system("pause"); // Frame by frame + //system("pause"); // Frame by frame } void Application::render() diff --git a/TheOneSDL/Physics.cpp b/TheOneSDL/Physics.cpp index 698b3fb..0ff0f57 100644 --- a/TheOneSDL/Physics.cpp +++ b/TheOneSDL/Physics.cpp @@ -22,7 +22,7 @@ void Physics::resetTime(){ } float Physics::getTime(){ - std::cout << "Time:" << time << std::endl; + // std::cout << "Time:" << time << std::endl; return time; } diff --git a/TheOneSDL/Player.cpp b/TheOneSDL/Player.cpp index 6014a54..96d5c53 100644 --- a/TheOneSDL/Player.cpp +++ b/TheOneSDL/Player.cpp @@ -1,7 +1,7 @@ #include "Player.h" #include -Player::Player(SDL_Texture* default_texture) +Player::Player(SDL_Renderer* renderer) { playerR.h = 32; playerR.w = 32; @@ -9,13 +9,36 @@ Player::Player(SDL_Texture* default_texture) tilemap_y = 16; playerR.x = tilemap_x*32; playerR.y = tilemap_y*32; - textureWidth = 1920; - textureHeight = 32; + // Defaults zero no texture loaded yet + textureWidth = 0; + textureHeight = 0; frameWidth = textureWidth / 60; frameHeight = textureHeight; frame_time = 0; + + // Check default file existance and load default texture + std::string idle_file = "textures\\VGB\\idle\\vgb_idle-Sheet.png"; + const char* filename = idle_file.c_str(); + SDL_Texture* default_texture = IMG_LoadTexture(renderer, filename); + SDL_QueryTexture(default_texture, NULL, NULL, &textureWidth, &textureHeight); + + // Load check + if ( textureWidth == 0 || textureHeight == 0) + { + std::cout << "Error Player.cpp: Texture not loaded " << filename << "with dims " << + textureWidth << " and " << textureHeight << std::endl; + exit(-1); + } + + texture = default_texture; // The current texture is the default texture + + // Test 2 + filename = idle_file2.c_str(); + texture2 = IMG_LoadTexture(renderer, filename); + SDL_QueryTexture(default_texture, NULL, NULL, &textureWidth, &textureHeight); + editMS(2); - setTexture(default_texture); + setTexture(texture); std::cout << "Player Created!\n"; } @@ -57,7 +80,7 @@ SDL_Texture* Player::getTexture() void Player::updateTexture(Physics* phys_eng, Terrain* terrain_eng) { - //std::cout << "[Type,F,TEX_X,X,Y]" << texture_name << "," << frame_time << "," << getTexX() + std::cout << "[Type,F,TEX_X,X,Y]" << idle_file << "," << frame_time << "," << getTexX() << std::endl; // << "," << getX() << "," << getY() << std::endl; xTexEdit(getTexX() + frameWidth); @@ -74,6 +97,8 @@ void Player::updateTexture(Physics* phys_eng, Terrain* terrain_eng) handleMovement(phys_eng,terrain_eng, 1); frame_time++; } + + } int Player::getY() @@ -109,11 +134,13 @@ void Player::yPathEdit(MovementDirection path) void Player::xEdit(int x) { playerR.x = x; + setTexture(texture2); } void Player::yEdit(int y) { playerR.y = y; + } void Player::wEdit(int w) @@ -129,6 +156,7 @@ void Player::hEdit(int h) void Player::xTexEdit(int x) { textureR.x = x; + } void Player::yTexEdit(int y) @@ -194,6 +222,7 @@ void Player::handleMovement(Physics* phys_eng, Terrain* terrain_eng, bool animat { case Up: { + setTexture(texture2); yEdit(getY() - getSpeed()); terrain_eng->background_tilemap[tilemap_y][tilemap_x] = '~'; tilemap_x = round(getX()/32); @@ -201,6 +230,10 @@ void Player::handleMovement(Physics* phys_eng, Terrain* terrain_eng, bool animat terrain_eng->background_tilemap[tilemap_y][tilemap_x] = '1'; break; } + case None: + { + setTexture(texture); + } // Case Down will be needed in future not currently // If Case down is needed implement collision check // case Down: diff --git a/TheOneSDL/Player.h b/TheOneSDL/Player.h index 2e04df7..00ea8a5 100644 --- a/TheOneSDL/Player.h +++ b/TheOneSDL/Player.h @@ -19,7 +19,7 @@ enum MovementDirection { class Player { public: - Player(SDL_Texture* default_texture); + Player(SDL_Renderer* default_texture); ~Player(); void updateTexture(Physics* phys_eng, Terrain* terrain_eng); @@ -80,7 +80,13 @@ class Player int textureWidth, textureHeight, frameWidth, frameHeight; - std::string texture_name = "VGB_Idle"; + //std::string texture_name = "VGB_Idle"; + std::string idle_file = "textures\\VGB\\idle\\vgb_idle-Sheet.png"; + std::string idle_file2 = "VGB_Idle.png"; + + //Textures stored + SDL_Texture* texture = NULL; + SDL_Texture* texture2 = NULL; int frame_time; diff --git a/TheOneSDL/TheOne.exe b/TheOneSDL/TheOne.exe index 9f9079d..01b5476 100644 Binary files a/TheOneSDL/TheOne.exe and b/TheOneSDL/TheOne.exe differ diff --git a/TheOneSDL/textures/VGB/idle/vgb_idle-Sheet.png b/TheOneSDL/textures/VGB/idle/vgb_idle-Sheet.png new file mode 100644 index 0000000..cda42d0 Binary files /dev/null and b/TheOneSDL/textures/VGB/idle/vgb_idle-Sheet.png differ diff --git a/TheOneSDL/textures/VGB/idle/vgb_idle.png b/TheOneSDL/textures/VGB/idle/vgb_idle2.png similarity index 100% rename from TheOneSDL/textures/VGB/idle/vgb_idle.png rename to TheOneSDL/textures/VGB/idle/vgb_idle2.png diff --git a/TheOneSDL/vgb_idle2.png b/TheOneSDL/vgb_idle2.png new file mode 100644 index 0000000..2e0aeaf Binary files /dev/null and b/TheOneSDL/vgb_idle2.png differ