[Scummvm-cvs-logs] SF.net SVN: scummvm:[44453] scummvm/trunk/engines/draci

dkasak13 at users.sourceforge.net dkasak13 at users.sourceforge.net
Tue Sep 29 01:10:12 CEST 2009


Revision: 44453
          http://scummvm.svn.sourceforge.net/scummvm/?rev=44453&view=rev
Author:   dkasak13
Date:     2009-09-28 23:10:08 +0000 (Mon, 28 Sep 2009)

Log Message:
-----------
draci: Added methods Game::positionAnimAsHero(), Game::getHeroX() and Game::getHeroY() and implemented correct positioning of all dragon animations. Fixed exiting the inventory by right-clicking outside it.

Modified Paths:
--------------
    scummvm/trunk/engines/draci/game.cpp
    scummvm/trunk/engines/draci/game.h
    scummvm/trunk/engines/draci/script.cpp

Modified: scummvm/trunk/engines/draci/game.cpp
===================================================================
--- scummvm/trunk/engines/draci/game.cpp	2009-09-28 23:02:39 UTC (rev 44452)
+++ scummvm/trunk/engines/draci/game.cpp	2009-09-28 23:10:08 UTC (rev 44453)
@@ -395,7 +395,7 @@
 				// If we are in inventory mode, all the animations except game items'
 				// images will necessarily be paused so we can safely assume that any
 				// animation under the cursor (a value returned by 
-				// AnimationManager::getTopAnimationID()) will be an item animation or.
+				// AnimationManager::getTopAnimationID()) will be an item animation or
 				// an overlay, for which we check. Item animations have their IDs 
 				// calculated by offseting their itemID from the ID of the last "special" 
 				// animation ID. In this way, we obtain its itemID. 
@@ -429,10 +429,8 @@
 				} else if (_vm->_mouse->rButtonPressed()) {
 					_vm->_mouse->rButtonSet(false);
 
-					Animation *inventoryAnim = _vm->_anims->getAnimation(kInventorySprite);
-					
 					// If we right-clicked outside the inventory, close it
-					if (!inventoryAnim->getFrame()->getRect().contains(x, y)) {
+					if (_animUnderCursor != kInventorySprite && _itemUnderCursor == kNoItem) {
 						inventoryDone();					
 
 					// If there is an inventory item under our cursor
@@ -992,17 +990,26 @@
 	x = p.x;
 	y = p.y;
 
-	debugC(4, kDraciLogicDebugLevel, "Walk to x: %d y: %d", x, y);
+	_heroX = p.x;
+	_heroY = p.y;
 
+	GameObject *dragon = getObject(kDragonObject); 
+
+	for (uint i = 0; i < dragon->_anims.size(); ++i) {
+		_vm->_anims->stop(dragon->_anims[i]);
+	}
+
+	debugC(3, kDraciLogicDebugLevel, "Walk to x: %d y: %d", x, y);
+
 	// Fetch dragon's animation ID
 	// FIXME: Need to add proper walking (this only warps the dragon to position)
-	int animID = getObject(kDragonObject)->_anims[0];
+	int animID = dragon->_anims[0];
 
 	Animation *anim = _vm->_anims->getAnimation(animID);
 
 	// Calculate scaling factors
-	double scaleX = _currentRoom._pers0 + _currentRoom._persStep * y;
-	double scaleY = scaleX;
+	const double scaleX = _vm->_game->getPers0() + _vm->_game->getPersStep() * y;
+	const double scaleY = scaleX;
 
 	// Set the Z coordinate for the dragon's animation
 	anim->setZ(y+1);
@@ -1385,6 +1392,58 @@
 	setExitLoop(false);
 }
 
+void Game::positionAnimAsHero(Animation *anim) {
+
+	// Fetch dragon's coordinates
+	int x = _heroX;
+	int y = _heroY;
+
+	// Calculate scaling factors
+	const double scaleX = getPers0() + getPersStep() * y;
+	const double scaleY = scaleX;
+
+	// Set the Z coordinate for the dragon's animation
+	anim->setZ(y+1);
+
+	// Fetch current frame
+	Drawable *frame = anim->getFrame();
+
+	// Fetch base dimensions of the frame
+	uint height = frame->getHeight();
+	uint width = frame->getWidth();
+
+	// Set the per-animation scaling factor
+	anim->setScaleFactors(scaleX, scaleY);
+
+  	_persons[kDragonObject]._x = x + (lround(scaleX) * width) / 2;
+	_persons[kDragonObject]._y = y - lround(scaleY) * height;
+
+	// We naturally want the dragon to position its feet to the location of the
+	// click but sprites are drawn from their top-left corner so we subtract
+	// the current height of the dragon's sprite
+	y -= (int)(scaleY * height);
+	x -= (int)(scaleX * width) / 2;
+
+	anim->setRelative(x, y);
+}
+
+int Game::getHeroX() {
+	return _heroX;
+}
+
+int Game::getHeroY() {
+	return _heroY;
+}
+
+double Game::getPers0() {
+	return _currentRoom._pers0;
+}
+
+double Game::getPersStep() {
+	return _currentRoom._persStep;
+}
+
+
 int Game::getRoomNum() const {
 	return _currentRoom._roomNum;
 }

Modified: scummvm/trunk/engines/draci/game.h
===================================================================
--- scummvm/trunk/engines/draci/game.h	2009-09-28 23:02:39 UTC (rev 44452)
+++ scummvm/trunk/engines/draci/game.h	2009-09-28 23:10:08 UTC (rev 44453)
@@ -260,6 +260,9 @@
 	}
 
 	void walkHero(int x, int y);
+	int getHeroX();
+	int getHeroY();
+	void positionAnimAsHero(Animation *anim);
 
 	void loadRoom(int roomNum);
 	int loadAnimation(uint animNum, uint z);
@@ -283,6 +286,9 @@
 	int getGateNum() const;
 	void setGateNum(int gate);
 
+	double getPers0();
+	double getPersStep();
+
 	int getItemStatus(int itemID) const;
 	void setItemStatus(int itemID, int status);
 	int getCurrentItem() const;
@@ -346,6 +352,8 @@
 
 	GameInfo _info;
 
+	int _heroX, _heroY;
+
 	int *_variables;
 	Person *_persons;
 	GameObject *_objects;

Modified: scummvm/trunk/engines/draci/script.cpp
===================================================================
--- scummvm/trunk/engines/draci/script.cpp	2009-09-28 23:02:39 UTC (rev 44452)
+++ scummvm/trunk/engines/draci/script.cpp	2009-09-28 23:10:08 UTC (rev 44453)
@@ -413,6 +413,10 @@
 	}
 
 	Animation *anim = _vm->_anims->getAnimation(animID);
+
+	if (objID == kDragonObject)
+		_vm->_game->positionAnimAsHero(anim);
+
 	anim->registerCallback(&Animation::stopAnimation);	
 
 	bool visible = (obj->_location == _vm->_game->getRoomNum() && obj->_visible);
@@ -439,6 +443,10 @@
 	}
 
 	Animation *anim = _vm->_anims->getAnimation(animID);
+
+	if (objID == kDragonObject)
+		_vm->_game->positionAnimAsHero(anim);
+
 	anim->registerCallback(&Animation::exitGameLoop);	
 
 	_vm->_game->setLoopSubstatus(kSubstatusStrange);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list