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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include "Entity.h"
namespace DarkMatter
{
Entity::Entity()
{
this -> texture = NULL;
this -> pos.x = 0; this -> pos.y = 0;
this -> health = 0;
this -> frame = 0;
this -> starttime = 0;
this -> width = 0;
this -> height = 0;
}
Entity::~Entity()
{
}
void Entity::LoadTexture(string filename, D3DCOLOR trans)
{
D3DXIMAGE_INFO info;
D3DXGetImageInfoFromFile(filename.c_str(), &info);
D3DXCreateTextureFromFileEx(
engine -> GetDevice(),
filename.c_str(),
info.Width, info.Height,
1,
D3DPOOL_DEFAULT,
D3DFMT_UNKNOWN,
D3DPOOL_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
trans,
&info,
NULL,
&this -> texture);
}
void Entity::DrawFrame(int width, int height, int columns)
{
D3DXVECTOR3 pos(this -> pos.x, this -> pos.y, 0);
D3DCOLOR white = D3DCOLOR_XRGB(255, 255, 255);
RECT rect;
rect.left = (this -> frame % columns) * width;
rect.top = (this -> frame / columns) * height;
rect.right = rect.left + width;
rect.bottom = rect.top + height;
engine -> GetSprite() -> Draw(this -> texture, &rect, NULL, &pos, white);
}
void Entity::Animate(int startframe, int endframe, int direction, int delay)
{
if ((int)GetTickCount() > this -> starttime + delay)
{
this -> starttime = GetTickCount();
this -> frame += direction;
if (this -> frame > endframe) this -> frame = startframe;
if (this -> frame < startframe) this -> frame = endframe;
}
}
void Entity::SetPos(float x, float y)
{
this -> pos.x = x;
this -> pos.y = y;
}
void Entity::SetDimensions(string filename)
{
D3DXIMAGE_INFO info;
D3DXGetImageInfoFromFile(filename.c_str(), &info);
this -> width = info.Width;
this -> height = info.Height;
}
};
|