1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include <iostream>
#include <string>
#include <vector>
#include "SDL.h"
#include "SDL_image.h"
#include "enemy.h"
#include "asset.h"
Enemy::Enemy(bool active, int x_ini, int y_ini, int x, int y, int h, int w, int frame_count, int frame_flag , int state, int xdisp, int id)
: _isActive(active), _x_ini(x_ini), _y_ini(y_ini), _x(x), _y(y), _h(h), _w(w), _frame_count(frame_count), _frame_flag(frame_flag), _state(state), _xDisplacement(xdisp), _enemy_ID(id)
{
_x_target = _x_ini;
_y_target = _y_ini;
}
Enemy::~Enemy()
{
// blank destructor
}
void Enemy::draw(SDL_Texture *enemy_image_texture) const // draw the Enemy to the render buffer
{
SDL_Rect source{ 0, ((_h / _frame_count) * _frame_flag), _w, (_h / _frame_count) }; // Source sprite sheet x, sprite sheet y, Image Texture width, Image Texture height
SDL_Rect destination{ _x - _xDisplacement,_y,_w,(_h / _frame_count)}; // destination rectagle x & y Window coordinates, width, height
if (enemy_image_texture)
{
SDL_RenderCopy(Window::renderer, enemy_image_texture, &source, &destination);
}
else if (!enemy_image_texture)
{
std::cerr << "Failed to pass texture to Enemy::draw. \n";
}
}
bool Enemy::rectVsRect(Asset &hero)
{
return((_x + _w) >= hero._x && _x <= (hero._x + hero._w) && (_y + _h) >= hero._y && _y <= (hero._y + (hero._h / 8)));
}
bool Enemy::enemiesVsBullets(Bullet& shot)
{
return((_x + _w) >= shot._x && _x <= (shot._x + shot._w) && (_y + _h) >= shot._y && _y <= (shot._y + (shot._h / 2)));
}
|