~ubuntu-branches/ubuntu/raring/scummvm/raring

« back to all changes in this revision

Viewing changes to engines/toon/flux.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Moritz Muehlenhoff
  • Date: 2011-05-25 19:02:23 UTC
  • mto: (21.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: james.westby@ubuntu.com-20110525190223-fiqm0oaec714xk31
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ScummVM - Graphic Adventure Engine
 
2
*
 
3
* ScummVM is the legal property of its developers, whose names
 
4
* are too numerous to list here. Please refer to the COPYRIGHT
 
5
* file distributed with this source distribution.
 
6
*
 
7
* This program is free software; you can redistribute it and/or
 
8
* modify it under the terms of the GNU General Public License
 
9
* as published by the Free Software Foundation; either version 2
 
10
* of the License, or (at your option) any later version.
 
11
 
 
12
* This program is distributed in the hope that it will be useful,
 
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
* GNU General Public License for more details.
 
16
 
 
17
* You should have received a copy of the GNU General Public License
 
18
* along with this program; if not, write to the Free Software
 
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
20
*
 
21
* $URL$
 
22
* $Id$
 
23
*
 
24
*/
 
25
 
 
26
#include "common/debug.h"
 
27
 
 
28
#include "toon/flux.h"
 
29
 
 
30
namespace Toon {
 
31
 
 
32
CharacterFlux::CharacterFlux(ToonEngine *vm) : Character(vm) {
 
33
        _id = 1;
 
34
        _animationInstance = vm->getAnimationManager()->createNewInstance(kAnimationCharacter);
 
35
        _animationInstance->setUseMask(true);
 
36
        vm->getAnimationManager()->addInstance(_animationInstance);
 
37
}
 
38
 
 
39
CharacterFlux::~CharacterFlux() {
 
40
}
 
41
 
 
42
void CharacterFlux::playStandingAnim() {
 
43
        debugC(4, kDebugCharacter, "playStandingAnim()");
 
44
 
 
45
        _animationInstance->setAnimation(_walkAnim);
 
46
        _animationInstance->setFrame(_facing * 3);
 
47
        _animationInstance->setAnimationRange(_facing * 3, _facing * 3);
 
48
        _animationInstance->stopAnimation();
 
49
        _animationInstance->setLooping(true);
 
50
 
 
51
        //s/etVisible(true);
 
52
}
 
53
 
 
54
void CharacterFlux::setVisible(bool visible) {
 
55
        if (_vm->state()->_currentChapter == 2) {
 
56
                Character::setVisible(false);
 
57
        } else {
 
58
                Character::setVisible(visible);
 
59
        }
 
60
}
 
61
 
 
62
void CharacterFlux::playWalkAnim(int32 start, int32 end) {
 
63
        debugC(4, kDebugCharacter, "playWalkAnim(%d, %d)", start, end);
 
64
 
 
65
        _animationInstance->setAnimation(_walkAnim);
 
66
        _animationInstance->setAnimationRange(24 + _facing * 10, 24 + _facing * 10 + 9);
 
67
        _animationInstance->playAnimation();
 
68
        _animationInstance->setFps(16);
 
69
        _animationInstance->setLooping(true);
 
70
}
 
71
 
 
72
int32 CharacterFlux::fixFacingForAnimation(int32 originalFacing, int32 animationId) {
 
73
 
 
74
        static const byte fixFluxAnimationFacing[] = {
 
75
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
 
76
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xee, 0xff, 0xff, 0xff,
 
77
                0xff, 0xff, 0xff, 0xff, 0xee, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x55,
 
78
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 
79
 
 
80
        byte animFacingFlag = fixFluxAnimationFacing[animationId];
 
81
        int32 v5 = 1 << originalFacing;
 
82
        int32 v6 = 1 << originalFacing;
 
83
        int32 facingMask = 0;
 
84
        do {
 
85
                if (v6 & animFacingFlag) {
 
86
                        facingMask = v6;
 
87
                } else if (v5 & animFacingFlag) {
 
88
                        facingMask = v5;
 
89
                }
 
90
                v5 >>= 1;
 
91
                v6 <<= 1;
 
92
        }
 
93
        while (!facingMask);
 
94
 
 
95
        int32 finalFacing = 0;
 
96
        for (finalFacing = 0; ; ++finalFacing) {
 
97
                facingMask >>= 1;
 
98
                if (!facingMask)
 
99
                        break;
 
100
        }
 
101
 
 
102
        return finalFacing;
 
103
}
 
104
 
 
105
void CharacterFlux::setPosition(int32 x, int32 y) {
 
106
        debugC(5, kDebugCharacter, "setPosition(%d, %d)", x, y);
 
107
 
 
108
        _z = _vm->getLayerAtPoint(x, y);
 
109
        _scale = _vm->getScaleAtPoint(x, y);
 
110
        int32 width = _walkAnim->getWidth() * _scale / 1024;
 
111
        int32 height = 165 * _scale / 1024;
 
112
        _animationInstance->setPosition(x - width / 2, y - height, _z , false);
 
113
        _animationInstance->setScale(_scale);
 
114
 
 
115
        // in original code, flux shadow scale is 3/4 of real scale
 
116
        int32 shadowScale = _scale * 3 / 4;
 
117
 
 
118
        // work out position and scale of the shadow below character
 
119
        int32 shadowWidth = _shadowAnim->getWidth() * shadowScale / 1024;
 
120
        int32 shadowHeight = _shadowAnim->getHeight() * shadowScale / 1024;
 
121
        _shadowAnimationInstance->setPosition(x - shadowWidth / 2, y - shadowHeight / 2 , _z , false);
 
122
        _shadowAnimationInstance->setScale(shadowScale);
 
123
        _x = x;
 
124
        _y = y;
 
125
        _finalX = x;
 
126
        _finalY = y;
 
127
        _animationInstance->setLayerZ(_y);
 
128
}
 
129
 
 
130
void CharacterFlux::update(int32 timeIncrement) {
 
131
        debugC(5, kDebugCharacter, "update(%d)", timeIncrement);
 
132
        Character::update(timeIncrement);
 
133
        setPosition(_x, _y);
 
134
}
 
135
 
 
136
int32 CharacterFlux::getRandomIdleAnim() {
 
137
        debugC(3, kDebugCharacter, "getRandomIdleAnim()");
 
138
        static const int32 idle[] = { 0xe, 0xf, 0x21, 0x22, 0x24, 0x25, 0x27 };
 
139
        return idle[_vm->randRange(0, 6)];
 
140
}
 
141
 
 
142
} // End of namespace Toon