MyScene::MyScene(PContext *context) : PScene("my-scene", context) { m_nextSprite = 0; PResourceManager *resMgr = context->module<PResourceManager>("resource-manager"); const puint32 *rect = context->rect(); PCamera *camera = PNEW(PCamera("camera", this)); camera->setFixed(true); camera->transform().setLookAt(0.0f, 10.0f, 7.0f, 0.0f, 5.0f, 0.0f, 0.0f, 1.0f, 0.0f); camera->projection().perspective(60.0f, (pfloat32)rect[2] / (pfloat32)rect[3], 0.1f, 100.0f); setMainCamera(camera); m_plane = PNEW(PDrawable("plane", this)); m_plane->setGeometry(PNEW(PGeometryPlane(resMgr))); m_plane->setMaterial(PNEW(PMaterial("color.pmt", resMgr))); m_plane->material()->parameter("color") = P_COLOR_RED; PTexture* textures[1]; textures[0] = resMgr->getTexture("texture.png"); pchar name[] = "sprite0"; for (puint32 i = 0; i < NUM_SPRITES; ++i) { name[6]++; m_sprites[i] = PNEW(PSprite(name, this)); m_sprites[i]->setAnimationDuration(4, 2000); m_sprites[i]->setTextureAtlas(textures, 1, 2, 2, true); m_sprites[i]->transform().setScaling(pVector3(0.25f, 0.25f, 1.0f)); m_sprites[i]->transform().setTranslation(pVector3(-100000.0f, -100000.0f, -100000.0f)); } pfloat32 aspect = (pfloat32)rect[2] / (pfloat32)rect[3]; PSprite2D *legend = PNEW(PSprite2D("legend", this)); legend->transform().setScaling(pVector3(aspect * 0.25f, aspect * 0.0625f, 1.0f)); textures[0] = resMgr->getTexture("legend.png"); legend->setTextureAtlas(textures, 1, 1, 1, true); legend->setAnimationDuration(1, 10000); legend->transform().setTranslation(pVector3(0, 0.4f, -1.0f)); }
void LumpRemapper::ParseMap(Scanner &sc) { while(sc.TokensLeft()) { if(!sc.CheckToken(TK_Identifier)) sc.ScriptMessage(Scanner::ERROR, "Expected identifier in map.\n"); bool parseSprites = false; TArray<FString> *map = NULL; if(sc->str.Compare("graphics") == 0) map = &graphics; else if(sc->str.Compare("sprites") == 0) { parseSprites = true; map = &sprites; } else if(sc->str.Compare("sounds") == 0) map = &sounds; else if(sc->str.Compare("digitalsounds") == 0) { // Check for sample rate change if(sc.CheckToken('(')) { sc.MustGetToken(TK_Identifier); if(sc->str.Compare("timervalue") != 0) sc.ScriptMessage(Scanner::ERROR, "Expected timervalue.\n"); sc.MustGetToken('='); sc.MustGetToken(TK_IntConst); digiTimerValue = sc->number; sc.MustGetToken(')'); } map = &digitalsounds; } else if(sc->str.Compare("music") == 0) map = &music; else if(sc->str.Compare("textures") == 0) map = &textures; else sc.ScriptMessage(Scanner::ERROR, "Unknown map section '%s'.\n", sc->str.GetChars()); if(!sc.CheckToken('{')) sc.ScriptMessage(Scanner::ERROR, "Expected '{'."); if(!sc.CheckToken('}')) { while(true) { if(!sc.CheckToken(TK_StringConst)) sc.ScriptMessage(Scanner::ERROR, "Expected string constant.\n"); const FString spriteName = sc->str; map->Push(spriteName); if(parseSprites && sc.CheckToken(':')) { sc.MustGetToken(TK_Identifier); if(sc->str.Compare("pspr") == 0) psprites.Push(PSprite(spriteName, PSPR_NORMAL)); else if(sc->str.Compare("blakepspr") == 0) psprites.Push(PSprite(spriteName, PSPR_BLAKE)); else sc.ScriptMessage(Scanner::ERROR, "Expected pspr modifier.\n"); } if(sc.CheckToken('}')) break; if(!sc.CheckToken(',')) sc.ScriptMessage(Scanner::ERROR, "Expected ','.\n"); } } } }