Skip to content

Commit

Permalink
GOB: Handle Penetration shooting animations more cleverly
Browse files Browse the repository at this point in the history
Still no bullets, though :P
  • Loading branch information
DrMcCoy committed Jun 7, 2012
1 parent 95454ab commit 3d537e7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
4 changes: 4 additions & 0 deletions engines/gob/aniobject.cpp
Expand Up @@ -76,6 +76,10 @@ void ANIObject::rewind() {
_frame = 0;
}

void ANIObject::setFrame(uint16 frame) {
_frame = frame % _ani->getAnimationInfo(_animation).frameCount;
}

void ANIObject::setPosition() {
// CMP "animations" have no default position
if (_cmp)
Expand Down
3 changes: 3 additions & 0 deletions engines/gob/aniobject.h
Expand Up @@ -84,6 +84,9 @@ class ANIObject {
/** Rewind the current animation to the first frame. */
void rewind();

/** Set the animation to a specific frame. */
void setFrame(uint16 frame);

/** Return the current animation number. */
uint16 getAnimation() const;
/** Return the current frame number. */
Expand Down
2 changes: 1 addition & 1 deletion engines/gob/minigames/geisha/penetration.cpp
Expand Up @@ -823,7 +823,7 @@ void Penetration::subMove(int x, int y, Submarine::Direction direction) {
}

void Penetration::subShoot() {
if (!_sub->sub->canMove())
if (!_sub->sub->canMove() || _sub->sub->isShooting())
return;

_sub->sub->shoot();
Expand Down
27 changes: 21 additions & 6 deletions engines/gob/minigames/geisha/submarine.cpp
Expand Up @@ -51,7 +51,7 @@ enum Animation {
};


Submarine::Submarine(const ANIFile &ani) : ANIObject(ani), _state(kStateNone) {
Submarine::Submarine(const ANIFile &ani) : ANIObject(ani), _state(kStateMove) {
turn(kDirectionN);
}

Expand All @@ -63,13 +63,21 @@ void Submarine::turn(Direction to) {
if ((to == kDirectionNone) || ((_state == kStateMove) && (_direction == to)))
return;

_state = kStateMove;
_direction = to;

setAnimation(directionToMove(_direction));
setMode(kModeContinuous);
move();
}

void Submarine::move() {
uint16 frame = getFrame();
uint16 anim = (_state == kStateShoot) ? directionToShoot(_direction) : directionToMove(_direction);

setAnimation(anim);
setFrame(frame);
setPause(false);
setVisible(true);

setMode((_state == kStateShoot) ? kModeOnce : kModeContinuous);
}

void Submarine::shoot() {
Expand Down Expand Up @@ -104,8 +112,11 @@ void Submarine::advance() {

switch (_state) {
case kStateShoot:
if (isPaused())
turn(_direction);
if (isPaused()) {
_state = kStateMove;

move();
}
break;

case kStateExit:
Expand All @@ -132,6 +143,10 @@ bool Submarine::isDead() const {
return _state == kStateDead;
}

bool Submarine::isShooting() const {
return _state == kStateShoot;
}

bool Submarine::hasExited() const {
return _state == kStateExited;
}
Expand Down
5 changes: 5 additions & 0 deletions engines/gob/minigames/geisha/submarine.h
Expand Up @@ -68,6 +68,9 @@ class Submarine : public ANIObject {
/** Is the submarine dead? */
bool isDead() const;

/** Is the submarine shooting? */
bool isShooting() const;

/** Has the submarine finished exiting the level? */
bool hasExited() const;

Expand All @@ -91,6 +94,8 @@ class Submarine : public ANIObject {
uint16 directionToShoot(Direction direction) const;
/** Map the directions to explode animation indices. */
uint16 directionToExplode(Direction direction) const;

void move();
};

} // End of namespace Geisha
Expand Down

0 comments on commit 3d537e7

Please sign in to comment.