diff --git a/include/object/entity.hpp b/include/object/entity.hpp index d7fae92..658833d 100644 --- a/include/object/entity.hpp +++ b/include/object/entity.hpp @@ -48,6 +48,7 @@ namespace Game::Object { std::string mName; std::shared_ptr mTex; Transform mTransform; + bool mIsFlipped = false; // Whether the texture should be rendered flipped horizontally or not bool mIsActive; int mZIndex = 0; // For rendering order; higher zIndex renders on top of lower zIndex float mTiledScale = 1.f; // Only used if the texture is tiled, to determine how much to scale the texture when rendering (since the entire texture is rendered as a single tile, this is necessary to be able to have different sized tiles) diff --git a/resources/l3ladja.png b/resources/l3ladja.png new file mode 100644 index 0000000..1bf4595 Binary files /dev/null and b/resources/l3ladja.png differ diff --git a/src/game/agame/player.cpp b/src/game/agame/player.cpp index 9a39381..16e376c 100644 --- a/src/game/agame/player.cpp +++ b/src/game/agame/player.cpp @@ -15,6 +15,9 @@ namespace Game::AGame { int w, h; SDL_GetWindowSizeInPixels(Window::Window::getSDLWindowBackend(), &w, &h); + mTransform.scaleX = 8.f; + mTransform.scaleY = 8.f; + mTransform.x -= mTex->getWidth() * mTransform.adjustedScaleX() / 2.f; mTransform.y -= mTex->getHeight() * mTransform.adjustedScaleY() / 2.f; @@ -30,10 +33,10 @@ namespace Game::AGame { //Object::Camera::getInstance().move(1.f, 0.f); // Simple movement - if (Input::isKeyPressed(SDL_SCANCODE_W)) mTransform.y -= mSpeed * deltaTime; - if (Input::isKeyPressed(SDL_SCANCODE_S)) mTransform.y += mSpeed * deltaTime; - if (Input::isKeyPressed(SDL_SCANCODE_A)) mTransform.x -= mSpeed * deltaTime; - if (Input::isKeyPressed(SDL_SCANCODE_D)) mTransform.x += mSpeed * deltaTime; + if (Input::isKeyPressed(SDL_SCANCODE_W)) { mTransform.y -= mSpeed * deltaTime; } + if (Input::isKeyPressed(SDL_SCANCODE_S)) { mTransform.y += mSpeed * deltaTime; } + if (Input::isKeyPressed(SDL_SCANCODE_A)) { mTransform.x -= mSpeed * deltaTime; mIsFlipped = false; } + if (Input::isKeyPressed(SDL_SCANCODE_D)) { mTransform.x += mSpeed * deltaTime; mIsFlipped = true; } mSpeed = Input::isKeyPressed(SDL_SCANCODE_LSHIFT) ? 400.f : 200.f; } } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 66e4393..b1c5464 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,7 +22,7 @@ int main() { //Object::Transform t1{100.f, 100.f, 0.f, 1.f, 1.f}; State::GameState::getInstance().addEntity(std::make_unique("BG", std::make_shared("../resources/bgtest.png", window.getRenderer()->getSDLRenderer()), Object::DEFAULT_TRANSFORM)); - State::GameState::getInstance().addEntity(std::make_unique("Player", std::make_shared("../resources/missing_texture.png", window.getRenderer()->getSDLRenderer()), Object::DEFAULT_TRANSFORM)); + State::GameState::getInstance().addEntity(std::make_unique("Player", std::make_shared("../resources/l3ladja.png", window.getRenderer()->getSDLRenderer()), Object::DEFAULT_TRANSFORM)); //State::GameState::getInstance().addEntity(std::make_unique("Player2", std::make_shared("../resources/roboto.ttf", window.getRenderer()->getSDLRenderer(), 128, "Roboto"), t1)); window.run(); diff --git a/src/object/entity.cpp b/src/object/entity.cpp index b9edb2f..bb7029f 100644 --- a/src/object/entity.cpp +++ b/src/object/entity.cpp @@ -64,7 +64,7 @@ namespace Game::Object { &dst, mTransform.rotation, ¢er, - SDL_FLIP_NONE + mIsFlipped ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE ); } else { // Tiled rendering - render the texture repeatedly to fill the area defined by the entity's transform @@ -89,7 +89,7 @@ namespace Game::Object { &dst, mTransform.rotation, nullptr, // No rotation center since each tile is rendered independently - SDL_FLIP_NONE + mIsFlipped ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE ); dst.y += dst.h; // Move down for the next tile in the column } diff --git a/src/renderer/texture.cpp b/src/renderer/texture.cpp index 47b3abe..fc71349 100644 --- a/src/renderer/texture.cpp +++ b/src/renderer/texture.cpp @@ -20,6 +20,11 @@ namespace Game::Renderer { mTex = SDL_CreateTextureFromSurface(renderer, surf); SDL_DestroySurface(surf); + + // Apply a more pixelated scaling mode, since this is a pixel art game and the default linear filtering causes unwanted blurring when textures are scaled up + if (mTex && !SDL_SetTextureScaleMode(mTex, SDL_SCALEMODE_NEAREST)) { + WARN("Failed to set texture scale mode to NEAREST for '" << mId << "': " << SDL_GetError()); + } } Texture::Texture(const Texture& other) {