void Brixpath::init() { //Init system stuff Iw2DInit(); IwResManagerInit(); IwGxFontInit(); //read resources IwGetResManager()->LoadGroup("brixpath.group"); _backgroundImage = Iw2DCreateImageResource("3px"); // Initialize evil classes g_Input.Init(); g_ColorManager.initialize(); g_FontManager.initialize(); g_GameStateManager.initialize(); //Load leveles g_LevelsManager.initializeFromFile("test.json"); _gameStateData.gameLevel = 0; _gameStateData.currentScene = MAIN_MENU_SCENE; _gameStateData.switchToScene = MAIN_MENU_SCENE; //levels should be initialize only after Iw2d and similar stuff is initialized; _sceneManager = new ScenesManager(&_gameStateData); _scene = _sceneManager->getActiveScene(); //and start drawing scene _scene->capture(); };
bool CIwGameImage::Load(bool blocking) { // If already loaded return true if (Image2D != NULL || Texture != NULL) return true; // Image is file based if (File != NULL) { File->setFileAvailableCallback(CIwGameImage_FileRetrievedAsyncCallback, this); if (File->Open(NULL, "rb", blocking)) return true; else return false; } if (ResourceGroup != NULL) { // Create image from the resource group IwGetResManager()->SetCurrentGroup(ResourceGroup); Image2D = Iw2DCreateImageResource(NameHash); if (Image2D != NULL) { Width = Image2D->GetWidth(); Height = Image2D->GetHeight(); State = State_Loaded; return true; } } return false; }
void Button::Load(char * imagename,CIwSVec2 pos) { _image=Iw2DCreateImageResource(imagename); m_ImgSize=CIwSVec2(_image->GetWidth(),_image->GetHeight()); m_BGSize=CIwSVec2(_image->GetWidth(),_image->GetHeight()); m_ImgPos=pos; m_BGPos=pos; btn_type=IMAGE; }
void Panel::Load(char * imagename,CIwSVec2 pos) { m_images.append(Iw2DCreateImageResource(imagename)); m_BGPos=pos; m_BGSize=CIwSVec2(m_images[m_images.size()-1]->GetWidth(),m_images[m_images.size()-1]->GetHeight()); isMusicPlay=false; isDisplay=false; m_text=""; }
//load resource and initialize void CGame::LoadRes() { _currentLevel=0; lastPlayedMusic=-1; //conditions of tutorial _firstLaunch=true; _firstLaunchLevel1=true; _enterDoor=false; _enterDoorDisplayed=false; _mazeFinish=false; _mazeFinishDisplayed=false; _levelFinish=false; _setEndingText=false; _imageTut.append(Iw2DCreateImageResource("tuttext_1")); _imageTut.append(Iw2DCreateImageResource("tuttext_2")); _imageTut.append(Iw2DCreateImageResource("tuttext_3")); _imageTut.append(Iw2DCreateImageResource("tuttext_4")); _timeLevelCost=0; _timeElapsed=0; _Character=new Character; _Music_1=new Music; _Music_2=new Music; _SE=new SE; _UI=new UI; //IwMemBucketDebugSetBreakpoint(331) ; _MapLevel.append(new Map); _MapLevel[0]->Load(0); _MapLevel[0]->Init(); //load character img _Character->Load(); currentMap=_MapLevel[_currentLevel]; _Character->Init(currentMap->_StartPos); currentMap->Init(); _Music_1->Init("audios/music1.mp3"); _Music_2->Init("audios/music2.mp3"); _SE->Init(); _SE->AddSFX("footstep_L1"); _SE->AddSFX("footstep_R1"); _SE->AddSFX("noise_2"); _SE->AddSFX("button_1"); _UI->Load(); _GS=GS_Playing; }
void Anima::Load(char * filename,int frameCount,int aniSpeed) { timeElapsed=0; _frameIndex=0; _aniSpeed=aniSpeed; _frameCount=frameCount; _image=Iw2DCreateImageResource(filename); _frameSize=CIwSVec2(_image->GetWidth()/_frameCount,_image->GetHeight()); for(int i=0;i!=frameCount;i++) { _framePos.append(CIwSVec2(_frameSize.x*i,_frameSize.y)); } }
CIw2DImage* IGResourceManager::getImage(std::string name) { // see if the resource has been loaded already CIw2DImage* ret = (CIw2DImage*)this->getResource(name); if(ret != NULL) return (CIw2DImage*)ret; // resource doesn't exist, so load it IGResourceManager::Resource* r = new IGResourceManager::Resource; r->name = name; r->data = (void*)Iw2DCreateImageResource(name.c_str()); r->count = 1; r->type = IGResourceManagerTypeImage; resources.push_back(r); return (CIw2DImage*)r->data; }
uint32 ResourceManager::RegisterImage(std::string imageName) { CIw2DImage *image = Iw2DCreateImageResource(imageName.c_str()); if(image == null) { std::string errMsg = "Unknown image resource requested: '"; errMsg += imageName + "'"; s3eDebugAssertShow(S3E_MESSAGE_CONTINUE, errMsg.c_str()); return 0; } int handle = images->size(); images->push_back(image); return handle; }
void CInventory::Init() { inventory_image = Iw2DCreateImageResource("inventory"); int screen_width = Iw2DGetSurfaceWidth(); int screen_height = Iw2DGetSurfaceHeight(); // Create inventory sprite inventory_sprite = new CSprite(); inventory_sprite->Init(); inventory_sprite->setPosAngScale(screen_width/2, screen_height - (IMAGE_SIZE_HEIGHT / 2), 0, IW_GEOM_ONE); // center image vertically on screen inventory_sprite->setDestSize(IMAGE_SIZE_WIDTH, IMAGE_SIZE_HEIGHT); inventory_sprite->setImage(inventory_image, "inventory"); // initialize inventory storage Clear(); }
bool SpriteSheet::ParseAttribute(CIwTextParserITX* pParser, const char* pAttrName) { char line[0x100]; if (!strcmp(pAttrName, "name")) { pParser->ReadString(line, 0x100); name = line; image = Iw2DCreateImageResource(name.c_str()); } else { return CIwManaged::ParseAttribute(pParser, pAttrName); } return true; }
bool Iw2DSprite::LoadFromResource(CIwResGroup* pGroup, std::string pName, bool pDataFromFile) { bool sameName = ( pName.compare(m_ResourceName) > 0 ) ? true : false; bool emptyName = m_ResourceName.empty(); if( !sameName || m_ResourceGroup != pGroup || !m_Built || ( !emptyName && !m_ResourceGroup) ) { m_ResourceGroup = pGroup; m_ResourceName = pName; m_Built = false; IwGetResManager()->SetCurrentGroup(m_ResourceGroup); if( m_ResourceGroup->GetResNamed(m_ResourceName.c_str(),IW_GX_RESTYPE_TEXTURE) ) { m_Built = true; if(pDataFromFile) { std::string w,h,f; w = m_ResourceName + "_w" ; h = m_ResourceName + "_h" ; f = m_ResourceName + "_frames" ; int temp; s3eConfigGetInt("Sprites",w.c_str(),&temp); m_FrameSize.x = temp; s3eConfigGetInt("Sprites",h.c_str(),&temp); m_FrameSize.y = temp; s3eConfigGetInt("Sprites",f.c_str(),&temp); m_MaxFrames = temp; } m_SpriteSheet = Iw2DCreateImageResource(m_ResourceName.c_str()); m_Frames.x = m_SpriteSheet->GetWidth() / m_FrameSize.x; m_Frames.y = m_SpriteSheet->GetHeight() / m_FrameSize.y; m_Center.x = m_FrameSize.x / 2; m_Center.y = m_FrameSize.y / 2; m_Angle = 0; m_Flip = CIwSVec2::g_Zero; } } return m_Built; }
void TileSet::Init(cJSON* tileset) { _defaultTU=new TileUnit; bool b[4]={false,false,false,false};//non-blocking border _defaultTU->Init(b,false,false,false); m_firstGid=cJSON_GetObjectItem(tileset,"firstgid")->valueint; _filename=cJSON_GetObjectItem(tileset,"image")->valuestring; _imageHeight=cJSON_GetObjectItem(tileset,"imageheight")->valueint; _imageWidth=cJSON_GetObjectItem(tileset,"imagewidth")->valueint; _name=cJSON_GetObjectItem(tileset,"name")->valuestring; _tileheight=cJSON_GetObjectItem(tileset,"tileheight")->valueint; _tilewidth=cJSON_GetObjectItem(tileset,"tilewidth")->valueint; _image=Iw2DCreateImageResource(_name); _tilesPerRow=_imageWidth/_tilewidth; _tileSize= CIwSVec2(_tilewidth, _tileheight); cJSON * properties=cJSON_GetObjectItem(tileset,"tileproperties"); if(properties!=NULL) { int propSize=0; if(properties->child) propSize=cJSON_GetArraySize(properties); for(int i=0;i!=propSize;i++) { cJSON *tile=cJSON_GetArrayItem(properties,i); int index=atoi(tile->string); bool b[4]={false,false,false,false};//non-blocking border bool isDoor=false; bool isEndPoint=false; bool isNPC=false; int NPCindex=0; int properSize=cJSON_GetArraySize(tile); for(int j=0;j!=properSize;j++) { cJSON * proper=cJSON_GetArrayItem(tile,j); if(CharCMP(proper->string, "Border",sizeof("Border"))) { char* border=cJSON_GetArrayItem(tile,0)->valuestring; for(int i=0;i!=4;i++) if(border[i*2]=='0') b[i]=true;//blocking border } else if(CharCMP(proper->string, "Door",sizeof("Door"))) { isDoor=true; } else if(CharCMP(proper->string, "EndPoint",sizeof("EndPoint"))) { isEndPoint=true; } else if(CharCMP(proper->string, "NPC",sizeof("NPC"))) { isNPC=true; NPCindex=proper->valueint; } } TileUnit tu; if(isNPC) tu.Init(b,isDoor,isEndPoint,isNPC,NPCindex); else tu.Init(b,isDoor,isEndPoint,isNPC); m_TileUnitsKey.append(index); m_TileUnits.append(tu); } } }
void setupTextures() { IwGetResManager()->LoadGroup("tiles.group"); CIw2DImage* a = NULL; CIw2DImage* cutter = NULL; CIw2DImage* dpad_down = NULL; CIw2DImage* dpad_left = NULL; CIw2DImage* dpad_right = NULL; CIw2DImage* dpad_up = NULL; CIw2DImage* lb = NULL; CIw2DImage* lt = NULL; CIw2DImage* l_stick = NULL; CIw2DImage* o = NULL; CIw2DImage* rb = NULL; CIw2DImage* rt = NULL; CIw2DImage* r_stick = NULL; CIw2DImage* thumbl = NULL; CIw2DImage* thumbr = NULL; CIw2DImage* u = NULL; CIw2DImage* y = NULL; a = Iw2DCreateImageResource("a"); cutter = Iw2DCreateImageResource("cutter"); dpad_down = Iw2DCreateImageResource("dpad_down"); dpad_left = Iw2DCreateImageResource("dpad_left"); dpad_right = Iw2DCreateImageResource("dpad_right"); dpad_up = Iw2DCreateImageResource("dpad_up"); lb = Iw2DCreateImageResource("lb"); lt = Iw2DCreateImageResource("lt"); l_stick = Iw2DCreateImageResource("l_stick"); o = Iw2DCreateImageResource("o"); rb = Iw2DCreateImageResource("rb"); rt = Iw2DCreateImageResource("rt"); r_stick = Iw2DCreateImageResource("r_stick"); thumbl = Iw2DCreateImageResource("thumbl"); thumbr = Iw2DCreateImageResource("thumbr"); u = Iw2DCreateImageResource("u"); y = Iw2DCreateImageResource("y"); m_controllers[0].Position = CIwFVec2(400, 150); m_controllers[1].Position = CIwFVec2(1000, 150); m_controllers[2].Position = CIwFVec2(400, 550); m_controllers[3].Position = CIwFVec2(1000, 550); for (int index = 0; index < 4; ++index) { m_controllers[index].Initialize( a, cutter, dpad_down, dpad_left, dpad_right, dpad_up, lb, lt, l_stick, o, rb, rt, r_stick, thumbl, thumbr, u, y); } }
void CInventory::AddAtoms(char* i_strAtomSymbol, int i_nCount) { bool bMatchFound = false; int matchIndex = -1; if (inventoryCount == 0) { // HASAN - debug //s3eDebugOutputString("Adding inventory sprite to sprite manager."); // add the inventory to the sprite manager when the first atom is added g_Game.getSpriteManager()->addSprite(inventory_sprite); } if (inventoryCount > 0) { for (int i = 0; i < MAX_COUNT; i++) { if (!strcmp(atoms[i], i_strAtomSymbol)) { bMatchFound = true; matchIndex = i; break; } } } if (!bMatchFound) { // match strcpy(atoms[inventoryCount], i_strAtomSymbol); atomCount[inventoryCount] += i_nCount; CAtom* atom = new CAtom(); atom->Init(i_strAtomSymbol); // horizontal center, same as inventory graphic int posX = (Iw2DGetSurfaceWidth() / 2) - (IMAGE_SIZE_WIDTH / 2); int posY = Iw2DGetSurfaceHeight() - (IMAGE_SIZE_HEIGHT / 2); // offset inventory horizontally to fit in the container posX = posX + (10 + (64 / 2)); // NOTE: 64 = atom size, 10 = border + spacing if (inventoryCount > 0) { posX = posX + (inventoryCount * (64 + 15)); // NOTE: 64 = atom size, 15 = spacing + border + spacing } atom->setPosAngScale(posX, posY, 0, IW_GEOM_ONE); atom->setVelocity(0,0); // HASAN - new to create/show the inventory count images CIw2DImage* inventoryCountImage = Iw2DCreateImageResource("inventory_number"); CSprite* inventoryCountSprite = new CSprite(); inventoryCountSprite->setImage(inventoryCountImage, "inventory_number"); // NOTE: image width & height = 25 & font width & height = 30 inventoryCountSprite->setPosition(posX + 13 + (30 / 2), posY + (30 / 2) + 3); inventoryCountSprite->setDestSize(30, 30); // make larger than source to fit behind the text properly g_Game.getSpriteManager()->addSprite(inventoryCountSprite); atomCountImages[inventoryCount] = inventoryCountSprite; atomObjs[inventoryCount] = atom; inventoryCount++; } else { atomCount[matchIndex] += i_nCount; } }
void Character::Load() { _image=Iw2DCreateImageResource("character"); _Size=CIwSVec2(_image->GetWidth(),_image->GetHeight()); m_CollisionBox=CIwSVec2(_Size.x,_Size.y/2); }
void Map::ReadJsonFile(char * filename) { m_filename=filename; cJSON *root; char * jsonContent; s3eFile* fileHandler; fileHandler=s3eFileOpen(filename, "rb"); if (fileHandler != NULL) { // Allocate buffer to be filled with the files contents int32 fileSize = s3eFileGetSize(fileHandler); jsonContent = (char*)s3eMallocBase(fileSize+1); // Read data from file if (s3eFileRead(&jsonContent[0], fileSize+1, 1, fileHandler) != 1) { // An kError has occurred, retrieve information for display std::cout<<s3eFileGetErrorString()<<std::endl; } else { // Data reading has been successful jsonContent[fileSize] = '\0'; } } else { // Something went wrong during opening of the file retrieve error for display std::cout<<s3eFileGetErrorString()<<std::endl; } if (fileHandler) s3eFileClose(fileHandler); root = cJSON_Parse(jsonContent); s3eFileFlush(fileHandler); _height=cJSON_GetObjectItem(root,"height")->valueint; cJSON *layers = cJSON_GetObjectItem(root,"layers"); _tileHeight=cJSON_GetObjectItem(root,"tileheight")->valueint; _tileWidth=cJSON_GetObjectItem(root,"tilewidth")->valueint; _width=cJSON_GetObjectItem(root,"width")->valueint; _layer_base->Init(cJSON_GetArrayItem(layers,0)); _layer_middle->Init(cJSON_GetArrayItem(layers,1)); _layer_maze->Init(cJSON_GetArrayItem(layers,2)); cJSON *tilesets = cJSON_GetObjectItem(root,"tilesets"); _tileset_map->Init(cJSON_GetArrayItem(tilesets,0)); _tileset_maze->Init(cJSON_GetArrayItem(tilesets,1)); cJSON * properties=cJSON_GetObjectItem(root,"properties"); int propSize=cJSON_GetArraySize(properties); for(int i=propSize-1;i!=-1;i--) { cJSON * prop=cJSON_GetArrayItem(properties,i); char* propString=prop->valuestring; char* name=prop->string; char* chars_array = strtok(propString, ","); if(CharCMP(name,"Block",sizeof("Block"))) { while(chars_array) { _EventBlock.append(atoi(chars_array)); chars_array = strtok(NULL, ","); } } else if(CharCMP(name,"BG",sizeof("BG"))) { _BGImage=Iw2DCreateImageResource(propString); } else if(CharCMP(name,"Door",sizeof("Door"))) { while(chars_array) { m_doors.append(atoi(chars_array)); chars_array = strtok(NULL, ","); } } else if(CharCMP(name,"EndPoint",sizeof("EndPoint"))) { _EndPos[0]=atoi(chars_array); chars_array = strtok(NULL, ","); _EndPos[1]=atoi(chars_array); } else if(CharCMP(name,"StartPoint",sizeof("StartPoint"))) { _StartPos[0]=atoi(chars_array); chars_array = strtok(NULL, ","); _StartPos[1]=atoi(chars_array); } else if(CharCMP(name,"emaze",sizeof("emaze"))) { while(chars_array) { mapEndIndex.append(atoi(chars_array)); chars_array = strtok(NULL, ","); } } else if(CharCMP(name,"etmaze",sizeof("etmaze"))) { while(chars_array) { mazeEndIndex.append(atoi(chars_array)); chars_array = strtok(NULL, ","); } } else if(CharCMP(name,"smaze",sizeof("smaze"))) { while(chars_array) { mapStartIndex.append(atoi(chars_array)); chars_array = strtok(NULL, ","); } } else if(CharCMP(name,"stmaze",sizeof("stmaze"))) { while(chars_array) { mazeStartIndex.append(atoi(chars_array)); chars_array = strtok(NULL, ","); } } } _total=_height*_width; _size=CIwSVec2(_width*_tileWidth,_height*_tileHeight); }