/****************************************** THIRSTY NELLAN An 3D Animated Adventure Game for children Copyright (C) 2002 Geoffrey M. Draper This file is part of Thirsty Nellan. Thirsty Nellan 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. Thirsty Nellan 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 Thirsty Nellan; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA As a special exception, the copyright holder (Geoffrey M. Draper) gives permission to link this program with Qt non-commercial edition, and distribute the resulting executable, without including the source code for the Qt non-commercial edition in the source distribution. (This clause applies only to Windows and MacOS versions of the software.) ******************************************/ #include "mycanvas.h" #include "gamedata.h" #include "infobox.h" #include extern GameData *gd; MyCanvas::MyCanvas(QObject *parent, const char *name) : QCanvas (parent, name) { connect(this, SIGNAL(roomChanged()), this, SLOT(refreshScene())); resize(800, 510); setAdvancePeriod(50); } void MyCanvas::hideAllSprites() { for (int i=0; iobjectData[i].largeIcon->hide(); } gd->catSprite->hide(); gd->flashingSign->hide(); gd->blackDoor->hide(); gd->carrotSprite->hide(); gd->banker->hide(); } void MyCanvas::refreshScene() { InfoBox *ib; setBackgroundPixmap(*(gd->roomData[gd->currentRoom].roomImage)); hideAllSprites(); for (int i=0; iobjectData[i].location == gd->currentRoom) { gd->objectData[i].largeIcon->show(); } } switch(gd->currentRoom) { case gd->BANK: gd->banker->strikeAPose(); break; case gd->GREEN_ROOM: break; case gd->CAT_ROOM: gd->catSprite->show(); if (!gd->roomData[gd->CAT_ROOM].visited) { gd->playSound("audio/Ncat.WAV"); ib = new InfoBox("images/squares/nellan_hello.png", " Wow! Non hai mai visto un gatto così grande\n" " prima d'ora. Lei ti sorride e dice, \"Ciao,\n" " amico mio. Mi chiamo Nella. Ho tanta sete.\n" " Non saresti così gentile da portarmi un po' di \n" " latte fresco? Ti avverto, non sarà facile,\n" " ma forse tu sei abbastanza bravo e ci riuscirai.\"", (QWidget*)parent()); ib->exec(); } break; case gd->WHITE_ROOM: if (gd->roomData[gd->OFFICE].visited) { gd->blackDoor->show(); } if (!gd->roomData[gd->WHITE_ROOM].visited) { gd->playSound("audio/HiCulla.WAV"); ib = new InfoBox("images/squares/chula_hello.png", " Un bel coniglio bianco ti si avvivina\n" " e dice, \"Ciao, mi chiamo Celeste! Benvenuto\n" " nella Casa Incantata, amico!\"\n" " Ti da un buffetto e dice, \"Se mi prendi\n" " su e mi porti nella stanza che c'è\n" " a destra, ti darò un regalo che\n" " ho tenuto da parte per te.\"", (QWidget*)parent()); ib->exec(); } break; case gd->GOLD_ROOM: if (gd->objectData[gd->CHULA].location == -1) { //if we're carrying the rabbit if (gd->objectData[gd->EGG].location == -2 && //and the egg is still hidden... gd->objectData[gd->EGG].pointsAwarded == 0) { //and we haven't picked up the egg yet gd->playSound("audio/Nchulaegg.WAV"); ib = new InfoBox("images/squares/chula_egg.png", " Celeste salta giù dal tuo braccio e corre\n" " via. Un attimo dopo ritorna con un\n" " grosso uovo d'oro.", (QWidget*)parent()); ib->exec(); gd->objectData[gd->EGG].location = gd->GOLD_ROOM; gd->objectData[gd->EGG].largeIcon->move(gd->avatar->x() + 200, gd->avatar->y()); gd->objectData[gd->EGG].largeIcon->setZ(2); gd->objectData[gd->CHULA].location = gd->GOLD_ROOM; gd->objectData[gd->CHULA].largeIcon->move(gd->avatar->x() + 100, gd->avatar->y()-50); gd->objectData[gd->CHULA].largeIcon->setZ(2); emit inventoryItemRemoved(gd->CHULA); } } break; case gd->HOT_ROOM: if (!gd->roomData[gd->HOT_ROOM].visited) { gd->playSound("audio/nhotinhere.WAV"); ib = new InfoBox("images/squares/thermometer.png", " Wow! Che caldo che c'è qui! ", (QWidget*)parent()); ib->exec(); } if (gd->objectData[gd->COLD_MILK].location == -1) { emit milkWarmed(); gd->playSound("audio/Nwarmmilk.WAV"); ib = new InfoBox("images/squares/milk_warmed.png", " Questa stanza è così torrida che il\n" " latte nella tua tazza si riscalda. ", (QWidget*)parent()); ib->exec(); } break; case gd->OFFICE: if (!gd->roomData[gd->OFFICE].visited) { gd->playSound("audio/Noffice.WAV"); ib = new InfoBox("images/squares/sitting_in_office.png", " WOW! Quella sedia doveva essere magica!\n" " Ti ritrovi in un vecchio ufficio polveroso.\n" " Hai l'impressione che nessuno abbia messo\n" " piede in questa stanza da parecchi anni.", (QWidget*)parent()); ib->exec(); gd->roomData[gd->WHITE_ROOM].perimeter->setPoint(7, 398, 341); } break; case gd->MILK_ROOM: if (!gd->carrotsEaten) { gd->carrotSprite->show(); } break; case gd->STORE: gd->flashingSign->show(); break; } gd->roomData[gd->currentRoom].visited = true; update(); } void MyCanvas::emitRoomChanged() { emit roomChanged(); } void MyCanvas::emitScoreChanged() { emit scoreChanged(); } void MyCanvas::emitInventoryItemAdded(int id) { emit inventoryItemAdded(id); } void MyCanvas::emitInventoryItemRemoved(int id) { emit inventoryItemRemoved(id); } void MyCanvas::emitEndgame() { emit endgame(); } void MyCanvas::showInfoBox(QString filename, QString msg) { InfoBox *ib; ib = new InfoBox(filename, msg, (QWidget*)parent()); ib->exec(); }