Skip to content

Commit

Permalink
PRINCE: Second hero implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslw committed Jul 31, 2014
1 parent 6088198 commit 34f496c
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 101 deletions.
66 changes: 49 additions & 17 deletions engines/prince/hero.cpp
Expand Up @@ -35,25 +35,22 @@ namespace Prince {

Hero::Hero(PrinceEngine *vm, GraphicsMan *graph) : _vm(vm), _graph(graph)
, _number(0), _visible(false), _state(kHeroStateStay), _middleX(0), _middleY(0)
, _boreNum(1), _currHeight(0), _moveDelay(0), _shadMinus(0), _moveSetType(0)
, _boreNum(1), _currHeight(0), _moveDelay(0), _shadMinus(0), _moveSetType(0), _zoomedHeroSurface(nullptr)
, _lastDirection(kHeroDirDown), _destDirection(kHeroDirDown), _talkTime(0), _boredomTime(0), _phase(0)
, _specAnim(nullptr), _drawX(0), _drawY(0), _drawZ(0), _zoomFactor(0), _scaleValue(0)
, _shadZoomFactor(0), _shadScaleValue(0), _shadLineLen(0), _shadDrawX(0), _shadDrawY(0)
, _frameXSize(0), _frameYSize(0), _scaledFrameXSize(0), _scaledFrameYSize(0), _color(0)
, _coords(nullptr), _dirTab(nullptr), _currCoords(nullptr), _currDirTab(nullptr), _step(0)
, _maxBoredom(200), _turnAnim(0), _leftRightMainDir(0), _upDownMainDir(0), _animSetNr(0)
{
_zoomBitmap = (byte *)malloc(kZoomBitmapLen);
_shadowBitmap = (byte *)malloc(2 * kShadowBitmapSize);
_shadowLine = new byte[kShadowLineArraySize];
}

Hero::~Hero() {
free(_zoomBitmap);
free(_shadowBitmap);
delete[] _shadowLine;
freeHeroAnim();
freeOldMove();
freeZoomedSurface();
}

bool Hero::loadAnimSet(uint32 animSetNr) {
Expand Down Expand Up @@ -238,6 +235,7 @@ static void plot(int x, int y, int color, void *data) {
shadowLine->_shadLineLen++;
}

// TODO - fix me
void Hero::showHeroShadow(Graphics::Surface *heroFrame) {
Graphics::Surface *makeShadow = new Graphics::Surface();
makeShadow->create(_frameXSize, _frameYSize, Graphics::PixelFormat::createFormatCLUT8());
Expand All @@ -258,16 +256,16 @@ void Hero::showHeroShadow(Graphics::Surface *heroFrame) {
int destX = _middleX - _scaledFrameXSize / 2;
int destY = _middleY - _shadMinus - 1;

if (destY > 1 && destY < kMaxPicHeight) {
if (destY > 1 && destY < _vm->kMaxPicHeight) {
int shadDirection;
if (_lightY > destY) {
if (_vm->_lightY > destY) {
shadDirection = 1;
} else {
shadDirection = 0;
}

_shadLineLen = 0;
Graphics::drawLine(_lightX, _lightY, destX, destY, 0, &plot, this);
Graphics::drawLine(_vm->_lightX, _vm->_lightY, destX, destY, 0, &plot, this);

byte *sprShadow = (byte *)_graph->_shadowTable70;

Expand All @@ -276,7 +274,7 @@ void Hero::showHeroShadow(Graphics::Surface *heroFrame) {

int shadPosX = _shadDrawX;
int shadPosY = _shadDrawY;
int shadBitAddr = destY * kMaxPicWidth / 8 + destX / 8;
int shadBitAddr = destY * _vm->kMaxPicWidth / 8 + destX / 8;
int shadBitMask = 128 >> (destX % 8);

int shadZoomY2 = _shadScaleValue;
Expand Down Expand Up @@ -401,9 +399,9 @@ void Hero::showHeroShadow(Graphics::Surface *heroFrame) {
shadZoomX += _scaleValue;
} else {
if (*shadowHero == _graph->kShadowColor) {
if ((shadBitMaskCopyTrans & _shadowBitmap[shadBitAddrCopyTrans]) != 0) {
if ((shadBitMaskCopyTrans & _vm->_shadowBitmap[shadBitAddrCopyTrans]) != 0) {
if (shadWallDown == 0) {
if ((shadBitMaskCopyTrans & _shadowBitmap[shadBitAddrCopyTrans + kShadowBitmapSize]) != 0) {
if ((shadBitMaskCopyTrans & _vm->_shadowBitmap[shadBitAddrCopyTrans + _vm->kShadowBitmapSize]) != 0) {
shadWDFlag = true;
//shadow
*background = *(sprShadow + *background);
Expand Down Expand Up @@ -459,7 +457,7 @@ void Hero::showHeroShadow(Graphics::Surface *heroFrame) {
} else {
//point_ok:
if (*shadowHero == _graph->kShadowColor) {
if ((shadBitMaskWallCopyTrans & _shadowBitmap[shadBitAddrWallCopyTrans + kShadowBitmapSize]) != 0) {
if ((shadBitMaskWallCopyTrans & _vm->_shadowBitmap[shadBitAddrWallCopyTrans + _vm->kShadowBitmapSize]) != 0) {
*background = *(sprShadow + *background);
}
}
Expand All @@ -480,19 +478,19 @@ void Hero::showHeroShadow(Graphics::Surface *heroFrame) {
}
//krap2
shadWallDestAddr -= kScreenWidth;
shadWallBitAddr -= kMaxPicWidth / 8;
shadWallBitAddr -= _vm->kMaxPicWidth / 8;
shadWallPosY--;
}
}
//skip_line
//next_line
if (*(shadowLineStart + 2) < *(shadowLineStart - 2)) {
//minus_y
shadBitAddr -= kMaxPicWidth / 8;
shadBitAddr -= _vm->kMaxPicWidth / 8;
shadPosY--;
diffY--;
} else if (*(shadowLineStart + 2) > *(shadowLineStart - 2)) {
shadBitAddr += kMaxPicWidth / 8;
shadBitAddr += _vm->kMaxPicWidth / 8;
shadPosY++;
diffY++;
}
Expand Down Expand Up @@ -546,7 +544,7 @@ void Hero::setScale(int8 zoomBitmapValue) {
}

void Hero::selectZoom() {
int8 zoomBitmapValue = *(_zoomBitmap + _middleY / 4 * kZoomBitmapWidth + _middleX / 4);
int8 zoomBitmapValue = *(_vm->_zoomBitmap + _middleY / 4 * _vm->kZoomBitmapWidth + _middleX / 4);
setScale(zoomBitmapValue);
}

Expand Down Expand Up @@ -879,9 +877,34 @@ void Hero::showHero() {
}
}
}

countDrawPosition();
}
}

void Hero::drawHero() {
if (_visible && !_vm->_flags->getFlagValue(Flags::NOHEROATALL)) {
freeZoomedSurface();
Graphics::Surface *mainHeroSurface = getSurface();
if (mainHeroSurface) {
//showHeroShadow(mainHeroSurface);
DrawNode newDrawNode;
newDrawNode.posX = _drawX;
newDrawNode.posY = _drawY;
newDrawNode.posZ = _drawZ;
newDrawNode.width = 0;
newDrawNode.height = 0;
newDrawNode.originalRoomSurface = nullptr;
newDrawNode.data = nullptr;
newDrawNode.drawFunction = &_graph->drawTransparentDrawNode;

if (_zoomFactor) {
_zoomedHeroSurface = zoomSprite(mainHeroSurface);
newDrawNode.s = _zoomedHeroSurface;
} else {
newDrawNode.s = mainHeroSurface;
}
_vm->_drawNodeList.push_back(newDrawNode);
}
}
}

Expand Down Expand Up @@ -966,6 +989,7 @@ void Hero::scrollHero() {
if (position < difference) {
destValue = position - _vm->kNormalWidth / 2;
}

if(destValue < 0) {
destValue = 0;
}
Expand Down Expand Up @@ -995,6 +1019,14 @@ void Hero::freeHeroAnim() {
}
}

void Hero::freeZoomedSurface() {
if (_zoomedHeroSurface != nullptr) {
_zoomedHeroSurface->free();
delete _zoomedHeroSurface;
_zoomedHeroSurface = nullptr;
}
}

}

/* vim: set tabstop=4 noexpandtab: */
16 changes: 4 additions & 12 deletions engines/prince/hero.h
Expand Up @@ -39,15 +39,8 @@ struct InventoryItem;

class Hero {
public:
static const int16 kMaxPicWidth = 1280;
static const int16 kMaxPicHeight = 480;
static const uint32 kMoveSetSize = 26;
static const int16 kZoomStep = 4;
static const int32 kZoomBitmapLen = kMaxPicHeight / kZoomStep * kMaxPicWidth / kZoomStep;
static const int16 kZoomBitmapWidth = kMaxPicWidth / kZoomStep;
static const int16 kZoomBitmapHeight = kMaxPicHeight / kZoomStep;
static const int16 kShadowLineArraySize = 2 * 1280 * 4;
static const int32 kShadowBitmapSize = kMaxPicWidth * kMaxPicHeight / 8;
static const int16 kScreenWidth = 640;
static const int16 kStepLeftRight = 8;
static const int16 kStepUpDown = 4;
Expand Down Expand Up @@ -119,6 +112,8 @@ class Hero {
void setVisible(bool flag) { _visible = flag; }

void showHero();
void drawHero();
void freeZoomedSurface();
void heroStanding();
void heroMoveGotIt(int x, int y, int dir);
int rotateHero(int oldDirection, int newDirection);
Expand Down Expand Up @@ -155,9 +150,7 @@ class Hero {
int16 _drawX;
int16 _drawY;
int16 _drawZ;

int16 _lightX; // for hero's shadow
int16 _lightY;

int32 _shadZoomFactor;
int32 _shadScaleValue;
int32 _shadLineLen;
Expand All @@ -179,6 +172,7 @@ class Hero {
uint16 _boreNum; // Bore anim frame
int16 _talkTime; // TalkTime time of talk anim
Animation *_specAnim; // additional anim
Graphics::Surface *_zoomedHeroSurface;

uint16 _currHeight; // height of current anim phase

Expand All @@ -189,8 +183,6 @@ class Hero {
uint32 _animSetNr; // number of animation set
Common::Array<Animation *> _moveSet; // MoveAnims MoveSet
int16 _turnAnim;
byte *_zoomBitmap;
byte *_shadowBitmap;
byte *_shadowLine;

uint32 _moveDelay;
Expand Down

0 comments on commit 34f496c

Please sign in to comment.