void IS::Map::setAt(unitPos const &p, TileType type) { if (!_config) return; if (_tiles.find(p) == _tiles.end() || _config->getTile(type) == nullptr) return; putTile(p, type); }
void IS::Map::createStaticBlock() { for (uint16_t i = 0; i < (_config->getDimension().first + 2) * (_config->getDimension().second + 2); i++) { unitPos pos(i % (_config->getDimension().first + 2), i / (_config->getDimension().first + 2)); if (!pos.first || pos.first == _config->getDimension().first + 1 || !pos.second || pos.second == _config->getDimension().second + 1) putTile(pos, Border); else if (!(pos.first % 2) && !(pos.second % 2)) putTile(pos, UnbreakBlock); else { putTile(pos, None); _walkable.push_back(std::make_shared<unitPos>(pos)); } } }
void HydroFlowProducer::putTile(TileCache::Tile *t) { TileProducer::putTile(t); if (t->level > 0) { TileCache::Tile *t2 = findTile(t->level - 1, t->tx / 2, t->ty / 2); assert(t2 != NULL); putTile(t2); } TileCache::Tile *t2 = graphs->findTile(t->level, t->tx, t->ty); graphs->putTile(t2); }
void HydroFlowProducer::stopCreateTile(int level, int tx, int ty) { TileProducer::stopCreateTile(level, tx, ty); if (level > 0) { TileCache::Tile *t = findTile(level - 1, tx / 2, ty / 2); assert(t != NULL); putTile(t); } TileCache::Tile *t = graphs->findTile(level, tx, ty); assert(t != NULL); graphs->putTile(t); }
void CPUElevationProducer::stopCreateTile(int level, int tx, int ty) { if (level > 0) { TileCache::Tile *t = findTile(level - 1, tx / 2, ty / 2); assert(t != NULL); putTile(t); } int tileSize = getCache()->getStorage()->getTileSize() - 5; int residualTileSize = residualTiles->getCache()->getStorage()->getTileSize() - 5; int mod = residualTileSize / tileSize; if (residualTiles->hasTile(level, tx / mod, ty / mod)) { TileCache::Tile *t = residualTiles->findTile(level, tx / mod, ty / mod); assert(t != NULL); residualTiles->putTile(t); } }
void IS::Map::createBreakableBlock() { int16_t i; std::random_shuffle(_walkable.begin(), _walkable.end()); i = 0; for (auto empty : _walkable) { i++; if (std::find(_config->getSpawns().begin(), _config->getSpawns().end(), *empty - unitPos(1, 1)) == _config->getSpawns().end()) putTile(*empty, BreakBlock); else i--; if (i > (_walkable.size() * _config->getBlockRate())) break; } _walkable.clear(); }
int main() { int width,height; FILE *pf; pf = fopen("./ex2.data.txt","r"); char buf[256]; fgets(buf,256,pf); puts(buf); char *pTemp = strtok(buf,","); //puts(pTemp); width = atoi(pTemp); pTemp = strtok(NULL,","); //puts(pTemp); height = atoi(pTemp); pMapBuf = (char *)malloc(width*height); int ix,iy; for(iy=0;iy<height;iy++) { fgets(buf,256,pf); pTemp = strtok(buf,","); pMapBuf[iy*width + 0] = atoi(pTemp); for(ix=1;ix<width;ix++) { pTemp = strtok(NULL,","); pMapBuf[iy*width + ix] = atoi(pTemp); } } putTile(0,height,0,width,width,pMapBuf,chrTable); free(pMapBuf); fclose(pf); }
int main() { int bLoop=1; MapObject.m_header.m_nSkima = 1; MapObject.m_pBuf = NULL; char TilePalette[] = {'.','#','@','%'}; while(bLoop) { char szCmd[32]; gets(szCmd); char *pTemp = strtok(szCmd," "); if(!strcmp(pTemp,"exit")) { bLoop = 0; if( MapObject.m_pBuf ) { free(MapObject.m_pBuf); } } else if( !strcmp(pTemp,"dump") ){ putTile( 0,MapObject.m_header.m_nHeight, 0,MapObject.m_header.m_nWidth, MapObject.m_header.m_nWidth, MapObject.m_pBuf, TilePalette ); } else if(!strcmp(pTemp,"new")) { //new 8 4 if(MapObject.m_pBuf !=NULL) {free(MapObject.m_pBuf); } MapObject.m_header.m_nWidth = atoi(strtok(NULL," ")); MapObject.m_header.m_nHeight = atoi(strtok(NULL," ")); MapObject.m_pBuf = malloc( MapObject.m_header.m_nHeight * MapObject.m_header.m_nWidth ); for(int i=0;i< MapObject.m_header.m_nHeight * MapObject.m_header.m_nWidth;i++) { MapObject.m_pBuf[i] = 0; } } else if(!strcmp(pTemp,"put")) { //put 1 2 1 (x y tile_index) int x,y,tile_index; x = atoi(strtok(NULL, " ")); y = atoi(strtok(NULL, " ")); tile_index = atoi(strtok(NULL," ")); MapObject.m_pBuf[ y*MapObject.m_header.m_nWidth + x ] = tile_index; } else if( !strcmp(pTemp,"hline") ) { //hline 1 2 int xpos,tile_index; xpos = atoi( strtok(NULL," ") ); tile_index = atoi( strtok(NULL," ") ); for(int iy=0;iy<MapObject.m_header.m_nHeight;iy++) { MapObject.m_pBuf[iy* MapObject.m_header.m_nWidth + xpos] = tile_index; } } else if( !strcmp(pTemp,"vline")) { int ypos,tile_index; ypos = atoi( strtok(NULL," ") ); tile_index = atoi( strtok(NULL," " )); for(int ix = 0;ix < MapObject.m_header.m_nWidth;ix++) { MapObject.m_pBuf[ix + ypos*MapObject.m_header.m_nWidth] = tile_index; } } else if( !strcmp(pTemp,"save")) { //save filename int } else if( !strcmp(pTemp,"load")) { //load filename } } return 0; }
void BrushPreview::updatePreview() { #ifndef DESIGNER_PLUGIN if(!m_preview) { m_preview = new paintcore::LayerStack; m_previewCache = new paintcore::LayerStackPixmapCacheObserver(this); m_previewCache->attachToLayerStack(m_preview); } auto layerstack = m_preview->editor(0); if(m_preview->width() == 0) { const QSize size = contentsRect().size(); layerstack.resize(0, size.width(), size.height(), 0); layerstack.createLayer(0, 0, QColor(0,0,0), false, false, QString()); } else if(m_preview->width() != contentsRect().width() || m_preview->height() != contentsRect().height()) { layerstack.resize(0, contentsRect().width() - m_preview->width(), contentsRect().height() - m_preview->height(), 0); } QRectF previewRect( m_preview->width()/8, m_preview->height()/4, m_preview->width()-m_preview->width()/4, m_preview->height()-m_preview->height()/2 ); paintcore::PointVector pointvector; switch(_shape) { case Stroke: pointvector = brushes::shapes::sampleStroke(previewRect); break; case Line: pointvector << paintcore::Point(previewRect.left(), previewRect.top(), 1.0) << paintcore::Point(previewRect.right(), previewRect.bottom(), 1.0); break; case Rectangle: pointvector = brushes::shapes::rectangle(previewRect); break; case Ellipse: pointvector = brushes::shapes::ellipse(previewRect); break; case FloodFill: case FloodErase: pointvector = brushes::shapes::sampleBlob(previewRect); break; } QColor bgcolor = m_bg; brushes::ClassicBrush brush = m_brush; // Special handling for some blending modes // TODO this could be implemented in some less ad-hoc way if(brush.blendingMode() == paintcore::BlendMode::MODE_BEHIND) { // "behind" mode needs a transparent layer for anything to show up brush.setBlendingMode(paintcore::BlendMode::MODE_NORMAL); } else if(brush.blendingMode() == paintcore::BlendMode::MODE_COLORERASE) { // Color-erase mode: use fg color as background bgcolor = m_color; } if(_shape == FloodFill) { brush.setColor(bgcolor); } auto layer = layerstack.getEditableLayerByIndex(0); layer.putTile(0, 0, 99999, isTransparentBackground() ? paintcore::Tile() : paintcore::Tile(bgcolor)); brushes::BrushEngine brushengine; brushengine.setBrush(1, 1, brush); for(int i=0;i<pointvector.size();++i) brushengine.strokeTo(pointvector[i], layer.layer()); brushengine.endStroke(); const auto dabs = brushengine.takeDabs(); for(int i=0;i<dabs.size();++i) brushes::drawBrushDabsDirect(*dabs.at(i), layer); layer.mergeSublayer(1); if(_shape == FloodFill || _shape == FloodErase) { paintcore::FillResult fr = paintcore::floodfill(m_preview, previewRect.center().toPoint(), _shape == FloodFill ? m_color : QColor(), _fillTolerance, 0, false, 360000); if(_fillExpansion>0) fr = paintcore::expandFill(fr, _fillExpansion, m_color); if(!fr.image.isNull()) layer.putImage(fr.x, fr.y, fr.image, _shape == FloodFill ? (_underFill ? paintcore::BlendMode::MODE_BEHIND : paintcore::BlendMode::MODE_NORMAL) : paintcore::BlendMode::MODE_ERASE); } m_needupdate=false; #endif }
void editLevelScreen() { int currentType = TILE_RED; showType(currentType); Tile *tiles[TOTAL_TILES]; if(loadTiles(tiles) == false) { cleanUp(); exit(0); } while(true) { fps.start(); while(SDL_PollEvent(&event)) { //When the user clicks if( event.type == SDL_MOUSEBUTTONDOWN ) { //Put the tile putTile( tiles, currentType ); } if (event.type == SDL_KEYDOWN) { switch(event.key.keysym.sym) { case SDLK_1: case SDLK_q: { //Scroll forward through tiles currentType--; if( currentType < TILE_RED ) currentType = TILE_TOPLEFT; //Show the current tile type showType( currentType ); break; } case SDLK_2: case SDLK_w: { //Scroll backward through tiles currentType++; if( currentType > TILE_TOPLEFT ) currentType = TILE_RED; //Show the current tile type showType( currentType ); break; } case SDLK_s: { // save the tiles and display a "saved" message saveTiles(tiles); SDL_Color savedMessageColor = {255, 255, 255}; SDL_Surface* savedMessage = NULL; savedMessage = load_font("eva.ttf", "SAVED", savedMessageColor, 24); apply_surface(1, 1, savedMessage, screen); SDL_Delay(500); SDL_FreeSurface(savedMessage); break; } case SDLK_BACKSPACE: { deleteTiles(tiles); startScreen(); break; } default:; } } myWindow.handle_window(); handleMusic(); if( event.type == SDL_QUIT ) { //Quit the program deleteTiles(tiles); cleanUp(); exit(0); } } if (myWindow.error()) { cleanUp(); exit(0); } setEditorCamera(); for (int t = 0; t < TOTAL_TILES; t++) tiles[t]->show(); if (SDL_Flip(screen) == -1) { cleanUp(); exit(0); } //Cap the frame rate if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) { SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); } } }