How can the code below be refactored to remove the set and get methods? And more importantly should they be and why?
// Code taken from somewhere
#include "app.h"
#include "enemy.h"
Enemy::Enemy(App* app, const char* file,int screenWidth, int screenHeight, SDL_Renderer* renderer) {
x = 0;
y = 0;
w = 0;
h = 0;
fireTicks = 0;
fireRate = 400;
velocity = 250;
alive = false;
enemyBulletTex = NULL;
this->app = app;
if((enemyTex = gfxManager::loadTexture(renderer,file)) == 0) {
throw std::invalid_argument("err, could not load the enemy texture!");
}
if((enemyBulletTex = gfxManager::loadTexture(renderer, "../gfx/enemyBullet_1.png")) == 0) {
throw std::invalid_argument("err, could not load the enemyBullet texture!");
}
SDL_QueryTexture(enemyTex, NULL, NULL, &w, &h);
x = (screenWidth - w) /2;
y = 150;
}
Enemy::~Enemy() {
}
void Enemy::think(float elapsedSeconds) {
if(isAlive()) {
shoot();
// boundaries detection
if(x < 0) {
x -= x;
}
if(x + w > app->getWidth()) {
x -= (x + w - app->getWidth());
}
}
}
void Enemy::render(SDL_Renderer *renderer) {
if(isAlive())
gfxManager::drawTexture(renderer,enemyTex,x,y);
}
void Enemy::shoot() {
int currentTime = SDL_GetTicks();
if(fireTicks + fireRate < currentTime) {
for(int i = 0; i < app->getBulletPoolSize(); i++) {
if(app->getBulletPool()[i]->getActive() == false) {
app->getBulletPool()[i]->setActive(true);
app->getBulletPool()[i]->setTexture(enemyBulletTex);
app->getBulletPool()[i]->setX((x + w / 2)-app->getBulletPool()[i]->getW()/2);
app->getBulletPool()[i]->setY(y + h / 2);
app->getBulletPool()[i]->setOwner(-1);
break;
}
}
fireTicks = currentTime;
}
}
void Enemy::setAlive(bool status) {
alive = status;
}
bool Enemy::isAlive() {
return alive;
}
int Enemy::getX() {
return x;
}
int Enemy::getY() {
return y;
}
int Enemy::getW() {
return w;
}
int Enemy::getH() {
return h;
}