void Game::move(Direction d) { if (gameOver) { return UI::instance()->say("Game Over. Restart or quit."); } const int ny = player->getY() + d.dy(), nx = player->getX() + d.dx(); LevelObject* obj = level->objectAt(ny, nx); if (obj) { // Walked into an object. What to do? MoveIntoVisitor visitor(*this, d); obj->accept(visitor); if (!visitor.keepMoving) { // Something happened, so don't do anything more. return; } } if (player->moveRelative(d)) { // A player action happened, so step. step(); } else { UI::instance()->say("You can't pass that way."); } }
LevelObject* LevelObjectFactory::produceLvlObj(int objID){ switch(objID){ case OBJ1:{ LevelObject* lvlObj = new LevelObject(OBJ1, "Chair"); Dialog* dia = new Dialog(lvlObj); std::shared_ptr<Dialog> ptr = std::shared_ptr<Dialog>(dia); dia->setRunFunc( [ptr](){ LevelObject* parent = (*ptr).lvlObjParent; if(parent->isPresent()){ Tools::printMsg("Hello, I am a chair!"); bool choice = Tools::printQuestion("Do you want to pick me up?"); if(choice){ parent->setPresence(false); Game::instance()->getPlayer()->addItem(ItemFactory::produceItem(ItemFactory::ITEM1)); } } } ); lvlObj->setDialog(dia); return lvlObj; } default:break; } return 0; }
void MapView::dropEvent(QDropEvent *event) { qdbg << "dropEvent: text=" << event->mimeData()->formats().first() << endl; if (!event->mimeData()->hasFormat(levelObjectNameMimeType)) return; event->acceptProposedAction(); QPoint dragOffset; QByteArray nameData; QByteArray encodedData = event->mimeData()->data(levelObjectNameMimeType); QDataStream dataStream(&encodedData, QIODevice::ReadOnly); dataStream >> nameData >> dragOffset; QString name = QString::fromUtf8(nameData); LevelObject *obj = LevelObjectsModel::sharedInstance()->levelObjectByName(name); if (!obj) return; QSizeF objSize = obj->size(); QPoint dragOffsetShifted(dragOffset.x() - objSize.width() / 2, dragOffset.y() - objSize.height() / 2); QPoint viewportTargetPos(event->pos() - dragOffsetShifted); LevelObject *newObject = obj->clone(); newObject->setPosition(mapToScene(viewportTargetPos)); connect(newObject, SIGNAL(modified()), mapScene(), SLOT(setModified())); MapItem *item = new MapItem(newObject); MapScene *scene = mapScene(); //scene->addItem(item); scene->setModified(true); NewItemCommand *command = new NewItemCommand(scene, item); scene->undoStack()->push(command); }
void Level::renderDev( DevDrawMode mode ) { for( ObjectList::iterator iter = mObjects.begin() , itEnd = mObjects.end() ; iter != itEnd ; ++iter ) { LevelObject* obj = *iter; obj->renderDev( mode ); } }
void LevelFactory::generate() { enum directions { X_INC, X_DEC, Z_INC, Z_DEC }; for (int i = 0; i < 20; i++) { LevelObject obj = chooseNextObject(Block()); obj.setPosition(0, 0, 0); obj.setSize(10, 10, 10); level.addObject(obj); } }
static int setObjectEnable(lua_State* lua){ lua_settop(lua,2); string name(lua_tostring(lua, 1)); LevelObject* lo = RobotLevel::instance()->findObject(name); if(lo!=nullptr){ lo->setEnabled(lua_toboolean(lua,2)); return 0; } RobotLevel::instance()->getLogger().error("No object [%s] found ",name.c_str()); return 0; }
LevelObject* Level::spawnObjectByName( char const* name , Vec2f const& pos ) { LevelObject* obj = mObjectCreator->createObject( name ); if ( !obj ) return NULL; obj->init(); obj->setPos( pos ); if ( mSpwanDestroyFlag & SDF_SETUP_DEFAULT ) obj->setupDefault(); addObject( obj ); return obj; }
static int object_color(lua_State* lua){ lua_settop(lua,5); LevelObject* obj = RobotLevel::instance()->findObject(lua_tostring(lua, 1)); vec4 color(lua_tonumber(lua, 2), lua_tonumber(lua, 3), lua_tonumber(lua, 4), lua_tonumber(lua, 5)); if(obj){ obj->setColor(color); } return 0; }
void Level::addObject(std::string className, ValueMap& prop){ LevelObject* obj = nullptr; if (className == "Player"){ obj = new Player; setGamePanelOnPlayer((Player*)obj); } //else if (className == "Monster") // obj = new Monster; if (obj != nullptr){ obj->setProperties(prop); obj->addSpriteToLevel(this); obj->addBody(); } }
QString Level::xml () { QString rv; rv.append(QString("<Level name=\"%1\">").arg(levelName())); QHashIterator<int, LevelObject*> o (this->levelObjects); o.toFront (); while (o.hasNext ()) { o.next (); LevelObject* obj = o.value (); int id = o.key (); rv.append(obj->xml (id)); } rv.append("</Level>"); return rv; }
LevelObject* Level::hitObjectTest( Vec2f const& pos ) { for( ObjectList::iterator iter = mObjects.begin() , itEnd = mObjects.end() ; iter != itEnd ; ++iter ) { LevelObject* obj = *iter; Rect bBox; obj->calcBoundBox( bBox ); if ( bBox.hitTest( pos ) ) return obj; } return NULL; }
void Mob::onBodyCollision( ColBody& self , ColBody& other ) { LevelObject* obj = other.getClient(); switch( obj->getType() ) { case OT_BULLET: { Bullet* bullet = obj->cast< Bullet >(); if ( bullet->team == TEAM_PLAYER ) { takeDamage( bullet ); } } break; } }
QJsonArray MapScene::toJsonArray(bool selectedOnly) const { QJsonArray objects; foreach (QGraphicsItem *item, items()) { MapItem *mapItem = dynamic_cast<MapItem *>(item); if (!mapItem) continue; if (selectedOnly &&!mapItem->selected()) continue; LevelObject *obj = mapItem->levelObject(); if (!obj) continue; QJsonObject json = obj->toJsonObject(); objects.append(json); }
void Level::tick() { for( ObjectList::iterator iter = mObjects.begin() , itEnd = mObjects.end(); iter != itEnd; ++iter ) { LevelObject* obj = *iter; obj->tick(); } mColManager.update(); for( ObjectList::iterator iter = mObjects.begin() , itEnd = mObjects.end(); iter != itEnd; ) { LevelObject* obj = *iter; ++iter; if( obj->mNeedDestroy ) { obj->onDestroy( mSpwanDestroyFlag ); delete obj; } else { obj->postTick(); } } if ( mTopMessage == NULL ) { if ( !mMsgQueue.empty() ) { mTopMessage = mMsgQueue.front(); mTopMessage->nodifyShow(); } } if ( mTopMessage ) { mTopMessage->tick(); if ( mTopMessage->unisten ) { delete mTopMessage; mMsgQueue.erase(mMsgQueue.begin()); mTopMessage = NULL; } } }
void Selector::checkSelection(EditorLevel& level, GOIterator* objects) { if (!sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) clearSelection(); level.checkSelection(selectionRect); GOIterator* it = objects; for(; it; it = it->next) { LevelObject* object = (LevelObject*)it->object; object->checkSelection(selectionRect); } }
void Level::updateRender( float dt ) { for( ObjectList::iterator iter = mObjects.begin() ; iter != mObjects.end(); ++iter ) { LevelObject* obj = *iter; obj->updateRender( dt ); } RenderLightList& lights = getRenderLights(); for( RenderLightList::iterator iter = lights.begin() , itEnd = lights.end(); iter != itEnd ; ++iter ) { Light* light = *iter; light->cachePos = light->offset; if ( light->host ) light->cachePos += light->host->getPos(); } if ( mTopMessage ) mTopMessage->updateRender( dt ); }
void Level::renderObjects( RenderPass pass ) { for( ItemList::iterator iter = mItems.begin() , itEnd = mItems.end(); iter != itEnd ; ++iter ) { LevelObject* obj = *iter; IObjectRenderer* renderer = obj->getRenderer(); renderer->render( pass , obj ); } for( MobList::iterator iter = mMobs.begin() , itEnd = mMobs.end(); iter != itEnd ; ++iter ) { LevelObject* obj = *iter; IObjectRenderer* renderer = obj->getRenderer(); renderer->render( pass , obj ); } for( PlayerVec::iterator iter = mPlayers.begin() , itEnd = mPlayers.end(); iter != itEnd ; ++iter ) { Player* player = *iter; IObjectRenderer* renderer = player->getRenderer(); renderer->render( pass , player ); } for( BulletList::iterator iter = mBullets.begin() , itEnd = mBullets.end(); iter != itEnd ; ++iter ) { LevelObject* obj = *iter; IObjectRenderer* renderer = obj->getRenderer(); renderer->render( pass , obj ); } for( ParticleList::iterator iter = mParticles.begin() , itEnd = mParticles.end(); iter != itEnd ; ++iter ) { LevelObject* obj = *iter; IObjectRenderer* renderer = obj->getRenderer(); renderer->render( pass , obj ); } }
int main() { initializeCrap(); install_int_ex(increment_speed_counter,BPS_TO_TIMER(120)); int screenMode = 0; //0 for windowed, 1 for fullscreen srand((unsigned)time(NULL)); BITMAP *buffer = create_bitmap(800,600); BITMAP *titleimg = load_bitmap("quiximgTitle.bmp",NULL); BITMAP *imgPlayers = load_bitmap("quiximgPlayerSet.bmp",NULL); MIDI *song = load_midi("quixsong.mid"); PlayerObject poPlayer[4]; LaserObject loLaser[4]; LevelObject Level; MenuObject Menu; float scrollerX = -150.0, scrollerY = 5.0; int winner; poPlayer[0].setControlScheme(0); poPlayer[1].setControlScheme(1); poPlayer[2].setControlScheme(2); poPlayer[3].setControlScheme(3); poPlayer[0].samSound = load_sample("quixp1Death.wav"); poPlayer[1].samSound = load_sample("quixp2Death.wav"); poPlayer[2].samSound = load_sample("quixp3Death.wav"); poPlayer[3].samSound = load_sample("quixp4Death.wav"); poPlayer[0].setX(32); poPlayer[0].setY(32); poPlayer[0].setDir('l'); poPlayer[1].setX(32); poPlayer[1].setY(544); poPlayer[1].setDir('l'); poPlayer[2].setX(736); poPlayer[2].setY(544); poPlayer[2].setDir('r'); poPlayer[3].setX(736); poPlayer[3].setY(32); poPlayer[3].setDir('r'); int mouseDown[21]; //Kind of a crappy array --- Each button is a # //and it's set to true if that button was clicked. for (int i = 0; i < 20; i++) { mouseDown[i] = false; } while ( !Menu.isDone() ) { while (speed_counter > 0) { /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~ MENU SCREEN ~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ if ( Menu.getEnabled() == true ) { if (key[KEY_Z]) { if (Menu.getFullscreen() == true) { Menu.changeScreenSize(0); Menu.setFullscreen(false); } else { Menu.changeScreenSize(1); Menu.setFullscreen(true); } } if (mouse_b & 1) { mouseDownClick(&Menu, mouseDown); } else { mouseUp(&Menu, mouseDown, poPlayer, &Level, song); } } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~~~ IN-GAME ~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ else { //Player Input1 if (key[KEY_ESC]) { play_midi(NULL, false); if (Menu.fragLimitHit == true) { Menu.fragLimitHit == false; for (int i=0; i<4; i++) { poPlayer[i].resetScore(); poPlayer[i].resetDeaths(); } poPlayer[0].setX(32); poPlayer[0].setY(32); poPlayer[0].setDir('l'); poPlayer[1].setX(32); poPlayer[1].setY(544); poPlayer[1].setDir('l'); poPlayer[2].setX(736); poPlayer[2].setY(544); poPlayer[2].setDir('r'); poPlayer[3].setX(736); poPlayer[3].setY(32); poPlayer[3].setDir('r'); Menu.fragLimitHit = false; Menu.resetPressed = false; mouseDown[19] = false; } Level.setEnabled(false); Menu.setEnabled(true); } for (int i=0; i<4; i++) { if (poPlayer[i].getControlScheme() == 0) { if (key[KEY_W]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_A]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_S]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_D]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_F]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if (poPlayer[i].getControlScheme() == 1) { if (key[KEY_I]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_J]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_K]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_L]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_H]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if (poPlayer[i].getControlScheme() == 2) { if (key[KEY_UP]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_LEFT]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_DOWN]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_RIGHT]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_RCONTROL]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if (poPlayer[i].getControlScheme() == 3) { if (key[KEY_8_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_4_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_2_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_6_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_PLUS_PAD]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 4) { //Joystick #1 poll_joystick(); if (joy[0].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[0].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[0].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[0].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[0].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 5) { //Joystick #2 poll_joystick(); if (joy[1].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[1].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[1].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[1].stick[0].axis[0].d2) {moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[1].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 6) { //Joystick #3 poll_joystick(); if (joy[2].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[2].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[2].stick[0].axis[1].d2) {moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[2].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[2].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 7) { //Joystick #4 poll_joystick(); if (joy[3].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[3].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[3].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[3].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[3].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } } if (Level.timeForAPowerupTimer >= 60) { Level.timeForAPowerupTimer = 0; } else { Level.timeForAPowerupTimer++; } } if ( Level.getFrame() < 32 ) { Level.setFrame( Level.getFrame() + 1 ); } else { Level.setFrame(0); } //Score Bar if (Level.getFragLimit() != 0 && Level.getEnabled() == true) { scrollerX += 0.5; if (scrollerX >= 1200.0) { scrollerX = -150.0; } } for (int i=0; i<4; i++) { //Res circle if (poPlayer[i].getRespawnCounter() >= 0) { poPlayer[i].setRespawnCounter( poPlayer[i].getRespawnCounter() + 1); } //"Laser" movement if (loLaser[i].getEnabled() == true) { if (loLaser[i].getDir() == 'u') { loLaser[i].moveUp('l'); } else if (loLaser[i].getDir() == 'd') { loLaser[i].moveDown('l'); } else if (loLaser[i].getDir() == 'l') { loLaser[i].moveLeft('l'); } else if (loLaser[i].getDir() == 'r') { loLaser[i].moveRight('l'); } checkCollision(&loLaser[i], poPlayer, i, Level); } if ((poPlayer[i].returnScore() == Level.getFragLimit()) && (Level.getFragLimit() > 0)) { //Frag Limit hit Menu.fragLimitHit = true; winner = i; } } speed_counter--; }//while (speed_counter > 0) if ( Menu.getEnabled() == true ) { drawMenuStuff(buffer, Menu, titleimg, imgPlayers, Level); } else if (Menu.fragLimitHit == true) { //Show win window! floodfill (buffer, 0, 0, makecol(0,0,0)); textprintf(buffer,font,348,203,makecol(100,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,347,202,makecol(150,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,346,201,makecol(200,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,345,200,makecol(255,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,330,250,makecol(255,0,0), "Player 1 score: %i", poPlayer[0].returnScore() ); textprintf(buffer,font,330,260,makecol(255,0,0), "Player 2 score: %i", poPlayer[1].returnScore() ); textprintf(buffer,font,330,270,makecol(255,0,0), "Player 3 score: %i", poPlayer[2].returnScore() ); textprintf(buffer,font,330,280,makecol(255,0,0), "Player 4 score: %i", poPlayer[3].returnScore() ); textprintf(buffer,font,330,249,makecol(255,255,255), "Player 1 score: %i", poPlayer[0].returnScore() ); textprintf(buffer,font,330,259,makecol(255,255,255), "Player 2 score: %i", poPlayer[1].returnScore() ); textprintf(buffer,font,330,269,makecol(255,255,255), "Player 3 score: %i", poPlayer[2].returnScore() ); textprintf(buffer,font,330,279,makecol(255,255,255), "Player 4 score: %i", poPlayer[3].returnScore() ); textout_centre(buffer, font, "Hit esc to continue", 400, 300, makecol(255,255,255)); } else { generateBackground(buffer, Level); drawCharacters(poPlayer, Level, buffer); drawScoreBar(buffer, poPlayer, scrollerX, scrollerY, Level); if (loLaser[0].getEnabled() == true) { drawLaser(loLaser[0], buffer, Level, 0); } if (loLaser[1].getEnabled() == true) { drawLaser(loLaser[1], buffer, Level, 1); } if (loLaser[2].getEnabled() == true) { drawLaser(loLaser[2], buffer, Level, 2); } if (loLaser[3].getEnabled() == true) { drawLaser(loLaser[3], buffer, Level, 3); } } acquire_screen(); blit(buffer, screen, 0, 0, 0, 0, 800, 600); clear_bitmap(buffer); release_screen(); }//while ( !Menu.isDone() ) return 0; return 0; }