51 lines
1.7 KiB
C++
51 lines
1.7 KiB
C++
//
|
|
// Created by bruno on 28.10.2023.
|
|
//
|
|
|
|
#include "Player.h"
|
|
|
|
void Player::processInput(SDL_Event *event){
|
|
|
|
};
|
|
|
|
int Player::render(SDL_Renderer* renderer){
|
|
this->playerSprite->moveTo(this->x, this->y);
|
|
return this->playerSprite->render(renderer);
|
|
}
|
|
|
|
void Player::renderHUD(SDL_Renderer* renderer) {
|
|
// Determine the dimensions and positions for the HUD
|
|
SDL_Rect hudRect = { 0, screenRect.h - hudHeight, screenRect.w, hudHeight };
|
|
|
|
// Set the HUD background color
|
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
|
SDL_RenderFillRect(renderer, &hudRect);
|
|
|
|
// Set the colors for the health and energy bars
|
|
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); // Red for health
|
|
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255); // Green for energy
|
|
|
|
// Calculate the width of the health and energy bars based on player's values
|
|
int healthBarWidth = (health / maxHealth) * (160 / 2); // Half of the screen width
|
|
int energyBarWidth = (energy / maxEnergy) * (160 / 2); //TODO, replace with logicalWidth
|
|
|
|
// Define the position and size of the health bar
|
|
SDL_Rect healthBarRect = { 10, screenRect.h - hudHeight + 10, healthBarWidth, hudHeight - 20 };
|
|
|
|
// Define the position and size of the energy bar
|
|
SDL_Rect energyBarRect = { screenRect.w / 2, screenRect.h - hudHeight + 10, energyBarWidth, hudHeight - 20 };
|
|
|
|
// Render the health bar
|
|
SDL_RenderFillRect(renderer, &healthBarRect);
|
|
|
|
// Render the energy bar
|
|
SDL_RenderFillRect(renderer, &energyBarRect);
|
|
}
|
|
|
|
Player::Player(int initialX, int initialY, Sprite *sprite, int hudHeight, SDL_Rect *screenRect){
|
|
this->x = initialX;
|
|
this->y = initialY;
|
|
this->screenRect = *screenRect;
|
|
this->playerSprite = sprite;
|
|
this->hudHeight = hudHeight;
|
|
} |