aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/chewy/chewy.cpp28
-rw-r--r--engines/chewy/chewy.h27
-rw-r--r--engines/chewy/graphics.cpp62
-rw-r--r--engines/chewy/graphics.h14
4 files changed, 97 insertions, 34 deletions
diff --git a/engines/chewy/chewy.cpp b/engines/chewy/chewy.cpp
index 94cbee4559..35575e10b4 100644
--- a/engines/chewy/chewy.cpp
+++ b/engines/chewy/chewy.cpp
@@ -63,6 +63,9 @@ void ChewyEngine::initialize() {
_console = new Console(this);
_graphics = new Graphics();
_sound = new Sound();
+
+ _curCursor = 0;
+ _elapsedFrames = 0;
}
Common::Error ChewyEngine::run() {
@@ -86,29 +89,26 @@ Common::Error ChewyEngine::run() {
//_sound->playMusic(2);
// Run a dummy loop
- Common::Event event;
- uint curCursor = 0;
- const uint maxCursors = 41;
-
while (!shouldQuit()) {
- while (g_system->getEventManager()->pollEvent(event)) {
- if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP)
+ while (g_system->getEventManager()->pollEvent(_event)) {
+ if (_event.type == Common::EVENT_KEYDOWN && _event.kbd.keycode == Common::KEYCODE_ESCAPE)
g_engine->quitGame();
- if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_SPACE) || event.type == Common::EVENT_RBUTTONUP) {
- curCursor++;
- if (curCursor == maxCursors)
- curCursor = 0;
- _graphics->setCursor(curCursor);
- }
-
- if (event.type == Common::EVENT_KEYDOWN && event.kbd.flags & Common::KBD_CTRL && event.kbd.keycode == Common::KEYCODE_d)
+ if ((_event.type == Common::EVENT_KEYDOWN && _event.kbd.keycode == Common::KEYCODE_SPACE) || _event.type == Common::EVENT_RBUTTONUP)
+ _graphics->nextCursor();
+ if (_event.type == Common::EVENT_KEYDOWN && _event.kbd.flags & Common::KBD_CTRL && _event.kbd.keycode == Common::KEYCODE_d)
_console->attach();
}
_console->onFrame();
+ // Cursor animation
+ if (_elapsedFrames % 30 == 0)
+ _graphics->animateCursor();
+
g_system->updateScreen();
g_system->delayMillis(10);
+
+ _elapsedFrames++;
}
return Common::kNoError;
diff --git a/engines/chewy/chewy.h b/engines/chewy/chewy.h
index 2235d5f1cf..a3f5f9298d 100644
--- a/engines/chewy/chewy.h
+++ b/engines/chewy/chewy.h
@@ -25,6 +25,7 @@
#include "common/scummsys.h"
+#include "common/events.h"
#include "common/file.h"
#include "common/util.h"
#include "common/str.h"
@@ -42,18 +43,6 @@ class Graphics;
class Sound;
class ChewyEngine : public Engine {
-
-protected:
- // Engine APIs
- virtual Common::Error run();
- virtual bool hasFeature(EngineFeature f) const;
-
- void shutdown();
-
- void initialize();
-
- Console *_console;
-
public:
ChewyEngine(OSystem *syst, const ChewyGameDescription *gameDesc);
virtual ~ChewyEngine();
@@ -68,6 +57,20 @@ public:
Graphics *_graphics;
Sound *_sound;
+
+protected:
+ // Engine APIs
+ virtual Common::Error run();
+ virtual bool hasFeature(EngineFeature f) const;
+
+ void initialize();
+ void shutdown();
+
+ Console *_console;
+
+ Common::Event _event;
+ uint _curCursor;
+ uint _elapsedFrames;
};
} // End of namespace Chewy
diff --git a/engines/chewy/graphics.cpp b/engines/chewy/graphics.cpp
index 84e6002dc9..2b90ab7802 100644
--- a/engines/chewy/graphics.cpp
+++ b/engines/chewy/graphics.cpp
@@ -31,6 +31,34 @@
namespace Chewy {
+const byte _cursorFrames[] = {
+ 4, 1, 1, 1, // walk
+ 4, 1, 1, 1, // pick up / use
+ 1, 1, 1, 1, 1,
+ 4, 1, 1, 1, // look
+ 4, 1, 1, 1, // talk
+ 4, 1, 1, 1, // open
+ 1,
+ 1, 1, 1, 1, // left, right, up, down
+ 1, // save
+ 1,
+ 5, 1, 1, 1, 1,
+ 1,
+ 1, // use (inventory)
+ 1, // look (inventory)
+ 1 // gun
+};
+
+Graphics::Graphics() {
+ _curCursor = 0;
+ _curCursorFrame = 0;
+ _cursorSprites = new SpriteResource("cursor.taf");
+}
+
+Graphics::~Graphics() {
+ delete _cursorSprites;
+}
+
void Graphics::drawImage(Common::String filename, int imageNum) {
BackgroundResource *res = new BackgroundResource(filename);
TBFChunk *image = res->getImage(imageNum);
@@ -86,15 +114,15 @@ void Graphics::playVideo(uint num) {
cfoDecoder->close();
}
-void Graphics::setCursor(uint num) {
- SpriteResource *res = new SpriteResource("cursor.taf");
- TAFChunk *cursor = res->getSprite(num);
+void Graphics::setCursor(uint num, bool newCursor) {
+ TAFChunk *cursor = _cursorSprites->getSprite(num);
+ if (newCursor)
+ _curCursor = num;
CursorMan.replaceCursor(cursor->data, cursor->width, cursor->height, 0, 0, 0);
delete[] cursor->data;
delete cursor;
- delete res;
}
void Graphics::showCursor() {
@@ -105,4 +133,30 @@ void Graphics::hideCursor() {
CursorMan.showMouse(false);
}
+void Graphics::animateCursor() {
+ if (_cursorFrames[_curCursor] > 1) {
+ _curCursorFrame++;
+
+ if (_curCursorFrame >= _cursorFrames[_curCursor])
+ _curCursorFrame = 0;
+
+ setCursor(_curCursor + _curCursorFrame, false);
+ }
+}
+
+void Graphics::nextCursor() {
+ uint maxCursors = ARRAYSIZE(_cursorFrames);
+
+ if (_cursorFrames[_curCursor] > 0)
+ _curCursor += _cursorFrames[_curCursor];
+ else
+ _curCursor++;
+
+ if (_curCursor >= maxCursors)
+ _curCursor = 0;
+
+ _curCursorFrame = 0;
+ setCursor(_curCursor);
+}
+
} // End of namespace Chewy
diff --git a/engines/chewy/graphics.h b/engines/chewy/graphics.h
index 64c4255324..381e8f513c 100644
--- a/engines/chewy/graphics.h
+++ b/engines/chewy/graphics.h
@@ -27,18 +27,24 @@
namespace Chewy {
+class SpriteResource;
+
class Graphics {
public:
- Graphics() {}
- ~Graphics() {}
+ Graphics();
+ ~Graphics();
void drawImage(Common::String filename, int imageNum);
void playVideo(uint num);
- void setCursor(uint num);
+ void setCursor(uint num, bool newCursor = true);
void showCursor();
void hideCursor();
+ void animateCursor();
+ void nextCursor();
private:
-
+ uint _curCursor;
+ uint _curCursorFrame;
+ SpriteResource *_cursorSprites;
};
} // End of namespace Chewy