Skip to content

Commit

Permalink
Implement player underglow. Close #25
Browse files Browse the repository at this point in the history
  • Loading branch information
MMPetrov20 committed Mar 25, 2023
1 parent 6c30c0c commit 1f73dde
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
39 changes: 20 additions & 19 deletions _build/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ void Game()
const int screenHeight = 1080;

InitWindow(screenWidth, screenHeight, "Dev window");
//ToggleFullscreen();
ToggleFullscreen();
SetTargetFPS(60);

// Intialize player variables
Player* player = Player::getinstance();

Camera2D playerCam = { {screenWidth/2, screenHeight/2}, player->getPosition(), 0, 1};

// Intialize camera variables
Texture2D background = LoadTexture("./../assets/UI/background.png");
Rectangle boundaries[4] = {
{-50, 0, 50, 2160},
Expand All @@ -25,8 +27,6 @@ void Game()
{0, 2160, 3840, 50}
};

// float recY = 100;

while (!WindowShouldClose())
{
// Move the player
Expand All @@ -41,27 +41,28 @@ void Game()
// Draw
BeginDrawing();

ClearBackground(BLANK);
ClearBackground(BLANK);

BeginMode2D(playerCam);

BeginMode2D(playerCam);
// Draw background base
DrawRectangle(0, 0, 3840, 2160, WHITE);

DrawTexture(background, 0, 0, RAYWHITE);
// Draw texture underglow
DrawTexture(player->getUnderglowTexture(), player->getPosition().x - 400, player->getPosition().y - 400, RAYWHITE);

// Scrolls
// recY -= GetMouseWheelMove() * 4;
// Draw background
DrawTexture(background, 0, 0, RAYWHITE);

// DrawRectangle(100, recY, 100, 100, RED);
// Draw the player
DrawTexturePro(
player->getPlayerTexture(),
Rectangle{0, 0, float(player->getPlayerTexture().width), float(player->getPlayerTexture().height)},
Rectangle{player->getPosition().x, player->getPosition().y, float(player->getPlayerTexture().width), float(player->getPlayerTexture().height)},
Vector2{float(player->getPlayerTexture().width / 2), float(player->getPlayerTexture().height / 2)}, 0, RAYWHITE);

// Draw the player
DrawTexturePro(
player->getTexture(),
Rectangle{0, 0, float(player->getTexture().width), float(player->getTexture().height)},

Rectangle{player->getPosition().x, player->getPosition().y, float(player->getTexture().width), float(player->getTexture().height)},

Vector2{float(player->getTexture().width / 2), float(player->getTexture().height / 2)}, 0, RAYWHITE);
EndMode2D();

EndMode2D();
EndDrawing();
}
CloseWindow();
Expand Down
26 changes: 16 additions & 10 deletions _build/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ void Player::setPosition(Vector2 position)

// Getters
// Get player texture
Texture2D Player::getTexture()
Texture2D Player::getPlayerTexture()
{
return _texture;
}

// Get underglow texture
Texture2D Player::getUnderglowTexture()
{
return _underglow;
}

// Get player position
Vector2 Player::getPosition()
{
Expand All @@ -30,19 +36,19 @@ void Player::Move(Vector2 position)
// Process keyboard movement input
if (IsKeyDown(KEY_W))
{
yOffset -= 2;
yOffset -= 3;
}
if (IsKeyDown(KEY_S))
{
yOffset += 2;
yOffset += 3;
}
if (IsKeyDown(KEY_A))
{
xOffset -= 2;
xOffset -= 3;
}
if (IsKeyDown(KEY_D))
{
xOffset += 2;
xOffset += 3;
}

// Update player position
Expand All @@ -54,19 +60,19 @@ void Player::CheckMapBoundary(Rectangle boundaries[4])
{
if (CheckCollisionCircleRec(_position, 93, boundaries[0]))
{
_position.x += 2;
_position.x += 3;
}
if (CheckCollisionCircleRec(_position, 93, boundaries[1]))
{
_position.x -= 2;
_position.x -= 3;
}
if (CheckCollisionCircleRec(_position, 93, boundaries[2]))
{
_position.y += 2;
_position.y += 3;
}
if (CheckCollisionCircleRec(_position, 93, boundaries[2]))
if (CheckCollisionCircleRec(_position, 93, boundaries[3]))
{
_position.y -= 2;
_position.y -= 3;
}
}

4 changes: 3 additions & 1 deletion _build/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Player
{
private:
Texture2D _texture = LoadTexture("./../assets/player/player.png");
Texture2D _underglow = LoadTexture("./../assets/player/playerUnderglow.png");
Vector2 _position = {960, 540};

// Constructor
Expand All @@ -26,7 +27,8 @@ class Player
void setPosition(Vector2 position);

// Getters
Texture2D getTexture();
Texture2D getPlayerTexture();
Texture2D getUnderglowTexture();
Vector2 getPosition();

// Methods
Expand Down
Binary file modified assets/UI/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1f73dde

Please sign in to comment.