2009-06-14 20:11:23 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-06-15 14:10:14 +00:00
|
|
|
#include "asylum/scene.h"
|
2009-06-14 20:11:23 +00:00
|
|
|
|
|
|
|
namespace Asylum {
|
|
|
|
|
2009-06-15 18:30:59 +00:00
|
|
|
#define SCREEN_EDGES 40
|
2009-06-15 20:38:12 +00:00
|
|
|
#define SCROLL_STEP 10
|
2009-06-15 18:30:59 +00:00
|
|
|
|
2009-06-15 14:10:14 +00:00
|
|
|
Scene::Scene(Screen *screen, Sound *sound, uint8 sceneIdx): _screen(screen), _sound(sound) {
|
2009-06-14 20:11:23 +00:00
|
|
|
_sceneIdx = sceneIdx;
|
2009-06-15 14:10:14 +00:00
|
|
|
_sceneResource = new SceneResource;
|
|
|
|
if (_sceneResource->load(_sceneIdx)) {
|
2009-06-14 20:11:23 +00:00
|
|
|
_text = new Text(_screen);
|
|
|
|
_resPack = new ResourcePack(sceneIdx);
|
2009-06-16 00:48:12 +00:00
|
|
|
|
2009-06-14 21:49:39 +00:00
|
|
|
char musPackFileName[10];
|
|
|
|
sprintf(musPackFileName, "mus.%03d", sceneIdx);
|
|
|
|
_musPack = new ResourcePack(musPackFileName);
|
2009-06-15 18:30:59 +00:00
|
|
|
|
|
|
|
_bgResource = new GraphicResource(_resPack, _sceneResource->getWorldStats()->_commonRes.backgroundImage);
|
2009-06-15 21:38:53 +00:00
|
|
|
|
|
|
|
// Statue animation, used for testing
|
2009-06-16 05:32:48 +00:00
|
|
|
_animResource = new GraphicResource(_resPack, _sceneResource->getWorldStats()->_actorsDef[0].graphicResId);
|
2009-06-14 20:11:23 +00:00
|
|
|
}
|
2009-06-15 13:06:06 +00:00
|
|
|
|
2009-06-15 20:38:12 +00:00
|
|
|
_cursorResource = new GraphicResource(_resPack, _sceneResource->getWorldStats()->_commonRes.curMagnifyingGlass);
|
2009-06-15 21:38:53 +00:00
|
|
|
|
2009-06-16 07:20:29 +00:00
|
|
|
_background = 0;
|
2009-06-16 05:32:48 +00:00
|
|
|
_animCurFrame = 0;
|
2009-06-15 18:30:59 +00:00
|
|
|
_startX = _startY = 0;
|
2009-06-15 20:38:12 +00:00
|
|
|
_leftClick = false;
|
2009-06-14 20:11:23 +00:00
|
|
|
}
|
|
|
|
|
2009-06-15 14:10:14 +00:00
|
|
|
Scene::~Scene() {
|
2009-06-16 05:32:48 +00:00
|
|
|
delete _animResource;
|
2009-06-15 13:06:06 +00:00
|
|
|
delete _cursorResource;
|
|
|
|
delete _bgResource;
|
2009-06-15 10:54:32 +00:00
|
|
|
delete _musPack;
|
|
|
|
delete _resPack;
|
|
|
|
delete _text;
|
2009-06-15 14:10:14 +00:00
|
|
|
delete _sceneResource;
|
2009-06-16 00:48:12 +00:00
|
|
|
}
|
2009-06-14 20:11:23 +00:00
|
|
|
|
2009-06-15 14:10:14 +00:00
|
|
|
void Scene::enterScene() {
|
|
|
|
_screen->setPalette(_resPack, _sceneResource->getWorldStats()->_commonRes.palette);
|
2009-06-15 12:28:19 +00:00
|
|
|
|
2009-06-16 07:20:29 +00:00
|
|
|
_background = _bgResource->getFrame(0);
|
2009-06-15 21:38:53 +00:00
|
|
|
_screen->copyToBackBuffer(((byte *)_background->surface.pixels) + _startY * _background->surface.w + _startX, _background->surface.w, 0, 0, 640, 480);
|
2009-06-15 13:06:06 +00:00
|
|
|
|
|
|
|
_cursorStep = 1;
|
|
|
|
_curMouseCursor = 0;
|
|
|
|
_screen->setCursor(_cursorResource, 0);
|
|
|
|
_screen->showCursor();
|
2009-06-16 00:48:12 +00:00
|
|
|
|
2009-06-16 07:20:29 +00:00
|
|
|
// Music testing: play the first music track
|
|
|
|
_sound->playMusic(_musPack, 0);
|
|
|
|
|
2009-06-16 00:48:12 +00:00
|
|
|
// TEST
|
2009-06-16 05:39:01 +00:00
|
|
|
// Draw the actor walking towards the north
|
2009-06-16 00:48:12 +00:00
|
|
|
_sceneResource->getMainActor()->setAction(_resPack, 6);
|
2009-06-16 10:11:24 +00:00
|
|
|
_sceneResource->getMainActor()->drawActorAt(_screen, 150, 150);
|
2009-06-15 12:28:19 +00:00
|
|
|
}
|
|
|
|
|
2009-06-15 14:10:14 +00:00
|
|
|
void Scene::handleEvent(Common::Event *event, bool doUpdate) {
|
2009-06-14 18:46:29 +00:00
|
|
|
_ev = event;
|
|
|
|
|
|
|
|
switch (_ev->type) {
|
|
|
|
case Common::EVENT_MOUSEMOVE:
|
|
|
|
_mouseX = _ev->mouse.x;
|
|
|
|
_mouseY = _ev->mouse.y;
|
|
|
|
break;
|
|
|
|
case Common::EVENT_LBUTTONUP:
|
2009-06-15 20:38:12 +00:00
|
|
|
//_leftClick = true; // TODO
|
2009-06-14 18:46:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doUpdate || _leftClick)
|
|
|
|
update();
|
2009-06-14 20:11:23 +00:00
|
|
|
}
|
|
|
|
|
2009-06-15 14:10:14 +00:00
|
|
|
void Scene::updateCursor() {
|
2009-06-15 13:06:06 +00:00
|
|
|
_curMouseCursor += _cursorStep;
|
|
|
|
if (_curMouseCursor == 0)
|
|
|
|
_cursorStep = 1;
|
|
|
|
if (_curMouseCursor == _cursorResource->getFrameCount() - 1)
|
|
|
|
_cursorStep = -1;
|
|
|
|
|
|
|
|
_screen->setCursor(_cursorResource, _curMouseCursor);
|
|
|
|
}
|
|
|
|
|
2009-06-15 14:10:14 +00:00
|
|
|
void Scene::update() {
|
2009-06-15 18:30:59 +00:00
|
|
|
bool scrollScreen = false;
|
|
|
|
GraphicFrame *bg = _bgResource->getFrame(0);
|
|
|
|
|
2009-06-16 00:48:12 +00:00
|
|
|
updateCursor();
|
2009-06-15 21:38:53 +00:00
|
|
|
|
|
|
|
// Proof of concept for animation showing
|
2009-06-16 05:32:48 +00:00
|
|
|
GraphicFrame *animFrame = _animResource->getFrame(_animCurFrame);
|
|
|
|
_animCurFrame++;
|
|
|
|
if (_animCurFrame >= _animResource->getFrameCount())
|
|
|
|
_animCurFrame = 0;
|
2009-06-15 21:38:53 +00:00
|
|
|
|
|
|
|
// Hardcoded coords
|
2009-06-16 05:32:48 +00:00
|
|
|
copyToSceneBackground(animFrame, 655, 0);
|
2009-06-15 21:38:53 +00:00
|
|
|
|
2009-06-15 18:30:59 +00:00
|
|
|
// Proof of concept for screen scrolling
|
|
|
|
|
2009-06-16 00:48:12 +00:00
|
|
|
// TESTING
|
|
|
|
// Main Actor
|
2009-06-16 10:11:24 +00:00
|
|
|
_sceneResource->getMainActor()->drawActorAt(_screen, 150, 150);
|
2009-06-16 00:48:12 +00:00
|
|
|
|
2009-06-15 18:30:59 +00:00
|
|
|
// Horizontal scrolling
|
2009-06-15 20:38:12 +00:00
|
|
|
if (_mouseX < SCREEN_EDGES && _startX >= SCROLL_STEP) {
|
|
|
|
_startX -= SCROLL_STEP;
|
2009-06-15 18:30:59 +00:00
|
|
|
scrollScreen = true;
|
2009-06-15 20:38:12 +00:00
|
|
|
} else if (_mouseX > 640 - SCREEN_EDGES && _startX <= bg->surface.w - 640 - SCROLL_STEP) {
|
|
|
|
_startX += SCROLL_STEP;
|
2009-06-15 18:30:59 +00:00
|
|
|
scrollScreen = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Vertical scrolling
|
2009-06-15 20:38:12 +00:00
|
|
|
if (_mouseY < SCREEN_EDGES && _startY >= SCROLL_STEP) {
|
|
|
|
_startY -= SCROLL_STEP;
|
2009-06-15 18:30:59 +00:00
|
|
|
scrollScreen = true;
|
2009-06-15 20:38:12 +00:00
|
|
|
} else if (_mouseY > 480 - SCREEN_EDGES && _startY <= bg->surface.h - 480 - SCROLL_STEP) {
|
|
|
|
_startY += SCROLL_STEP;
|
2009-06-15 18:30:59 +00:00
|
|
|
scrollScreen = true;
|
|
|
|
}
|
|
|
|
|
2009-06-15 21:38:53 +00:00
|
|
|
//if (scrollScreen)
|
2009-06-15 18:30:59 +00:00
|
|
|
_screen->copyToBackBuffer(((byte *)bg->surface.pixels) + _startY * bg->surface.w + _startX, bg->surface.w, 0, 0, 640, 480);
|
|
|
|
|
2009-06-15 13:06:06 +00:00
|
|
|
// TODO
|
2009-06-14 20:11:23 +00:00
|
|
|
}
|
|
|
|
|
2009-06-15 21:38:53 +00:00
|
|
|
void Scene::copyToSceneBackground(GraphicFrame *frame, int x, int y) {
|
|
|
|
int h = frame->surface.h;
|
|
|
|
int w = frame->surface.w;
|
|
|
|
byte *buffer = (byte *)frame->surface.pixels;
|
|
|
|
byte *dest = ((byte *)_background->surface.pixels) + y * _background->surface.w + x;
|
|
|
|
|
|
|
|
while (h--) {
|
|
|
|
memcpy(dest, buffer, w);
|
|
|
|
dest += _background->surface.w;
|
|
|
|
buffer += frame->surface.w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-14 20:11:23 +00:00
|
|
|
} // end of namespace Asylum
|