void Bee::drawOn(sf::RenderTarget& target) const { //if (!isInHive_) //{ auto beeSprite = buildSprite(centre, rayon, texture_); if (( speed_.angle() >= M_PI/2) or (speed_.angle() <= -M_PI/2)) { beeSprite.scale(1, -1); } beeSprite.rotate(speed_.angle()/DEG_TO_RAD); target.draw(beeSprite); if(isDebugOn()) { //couleur et épaisseur du cercle dependent de l'état de mouvement de l'abeille sf::Color color = (getMoveMode()==Random) ? sf::Color::Black : sf::Color::Blue; double size (rayon+1); double thickness = (getMoveMode()==Random) ? 5 : 3; auto shape = buildAnnulus(centre, size, color, thickness); target.draw(shape); Vec2d affiche (centre.x,centre.y +20); auto const text = buildText(statestring_, affiche , getAppFont(), 10, sf::Color::White); target.draw(text); } //} }
Bonfire::Bonfire(float startX, float startY) : AnimatedObject(startX, startY, 1), basicShape(startX, startY) { buildSprite(); Sprite::update(); }
//----------------------------------------------------------------------------- int SDL_main(int argc, char *argv[]) { // NOTE: check for the correct number of arguements if(argc<2) { fprintf(stderr, "Error: need a level name.\n"); return -1; } // NOTE: add the sqlite db to the levels directory char filename[0xFF]; sprintf(filename, "levels/%s.db", argv[1]); // NOTE: open database connection if(sqlite3_open_v2(filename, &db, SQLITE_OPEN_READONLY, NULL)) { fprintf(stderr, "sqlite3_open: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); return -1; } /* === */ start(); /* === */ int wallSprite00Inds[2*3] = { 03, 04, 35, 36, 67, 68 }; SDL_Color wall00Color = {0xFF,0xFF,0xFF,0xFF}; SDL_Surface *wallSprite00 = buildSprite(2, 3, wall00Color, wallSprite00Inds); int floorSprite00Inds[2*3] = { 17, 18, 49, 50, 81, 82 }; SDL_Color floorSprite00Color = {0x33,0x33,0x33,0xFF}; SDL_Surface *floorSprite00 = buildSprite(2, 3, floorSprite00Color, floorSprite00Inds); int doorSprite00Inds[2*3] = { 29, 30, 61, 62, 93, 94 }; SDL_Color doorSprite00Color = {0xFF,0xFF,0xFF,0xFF}; SDL_Surface *doorSprite00 = buildSprite(2, 3, doorSprite00Color, doorSprite00Inds); int wallSprite01Inds[2*3] = { 97, 98, 129, 130, 161, 162 }; SDL_Color wall01Color = {0xFF,0xFF,0xFF,0xFF}; SDL_Surface *wallSprite01 = buildSprite(2, 3, wall01Color, wallSprite01Inds); int wallSprite02Inds[2*3] = { 105, 106, 137, 138, 169, 170 }; SDL_Color wallSprite02Color = {0xFF,0xFF,0xFF,0xFF}; SDL_Surface *wallSprite02 = buildSprite(2, 3, wallSprite02Color, wallSprite02Inds); /* === */ while(running) { /* === */ pollInput(); SDL_RenderClear(renderer); SDL_FillRect(screen, 0, 0x00); /* === */ loadTiles(); SDL_Rect tempRect = { 0, 0, SPRITE_W*2, SPRITE_H*3 }; int i, j; for(j=0; j<12; j++) { for(i=0; i<30; i++) { tempRect.x = SPRITE_W*2*i; tempRect.y = SPRITE_H*3*j; switch(lvl.tiles[j][i]) { case 0x01: { SDL_BlitSurface(wallSprite00, NULL, screen, &tempRect); } break; case 0x02: { SDL_BlitSurface(doorSprite00, NULL, screen, &tempRect); } break; case 0x03: { SDL_BlitSurface(wallSprite01, NULL, screen, &tempRect); } break; case 0x04: { SDL_BlitSurface(wallSprite02, NULL, screen, &tempRect); } break; default: { SDL_BlitSurface(floorSprite00, NULL, screen, &tempRect); } break; } } } /* === */ int pitch; void *pixels; // NOTE: get the pixels for the screen texture SDL_LockTexture(texture, NULL, &pixels, &pitch); // NOTE: set the pixels for the screen texture SDL_ConvertPixels( screen->w, screen->h, screen->format->format, screen->pixels, screen->pitch, SDL_PIXELFORMAT_RGBA8888, pixels, pitch ); // NOTE: lock the texture so that it may be presented SDL_UnlockTexture(texture); // NOTE: present the texture SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderPresent(renderer); SDL_Delay(10); /* === */ } /* === */ SDL_FreeSurface(wallSprite00); wallSprite00 = NULL; SDL_FreeSurface(floorSprite00); floorSprite00 = NULL; SDL_FreeSurface(doorSprite00); doorSprite00 = NULL; SDL_FreeSurface(wallSprite01); wallSprite01 = NULL; SDL_FreeSurface(wallSprite02); wallSprite02 = NULL; /* === */ quit(); /* === */ // NTOE: close the database connection sqlite3_close(db); db = NULL; fclose(stderr); return 0; }
PpuSnapshot::PpuSnapshot(N3sRawPpu * rawPPU) { // Copy register options ctrl.spriteNameTable = getBit(rawPPU->ctrl, 3); ctrl.backgroundNameTable = getBit(rawPPU->ctrl, 4); ctrl.spriteSize16x8 = getBit(rawPPU->ctrl, 5); mask.greyscale = getBit(rawPPU->mask, 0); mask.renderBackgroundLeft8 = getBit(rawPPU->mask, 1); mask.renderSpritesLeft8 = getBit(rawPPU->mask, 2); mask.renderBackground = getBit(rawPPU->mask, 3); mask.renderSprites = getBit(rawPPU->mask, 4); mask.emphasizeRed = getBit(rawPPU->mask, 5); mask.emphasizeGreen = getBit(rawPPU->mask, 6); mask.emphasizeBlue = getBit(rawPPU->mask, 7); // Build sprites for (int i = 0; i < 64; i++) { unsigned char *spritePtr = (unsigned char*)(&rawPPU->oam[0] + (i*4)); sprites.push_back(buildSprite(spritePtr)); } // Grab pattern table patternTable = &rawPPU->patternTable.data[0]; // Grab background quadrants background.addQuadrant((char*)&rawPPU->nameTables[0], ctrl.backgroundNameTable); background.addQuadrant((char*)&rawPPU->nameTables[1], ctrl.backgroundNameTable); background.addQuadrant((char*)&rawPPU->nameTables[2], ctrl.backgroundNameTable); background.addQuadrant((char*)&rawPPU->nameTables[3], ctrl.backgroundNameTable); // Set mirroring type switch (rawPPU->mirroring) { case 12: background.mirrorType = horizontal; break; case 10: background.mirrorType = vertical; break; case 0: background.mirrorType = vertical; break; case 1: background.mirrorType = vertical; break; } // Copy background color palette.backgroundColorIndex = (int)rawPPU->palette[0]; // Copy palette for (int p = 0; p < 8; p++) { for (int c = 0; c < 3; c++) { palette.colorIndices[(p * 3) + c] = (int)rawPPU->palette[(p * 4) + 1 + c]; } } // Create variables to track most recent scroll variables int lastX = 0; int lastY = 0; int lastNametable = 0; int lastScanline = 0; bool lastPatternSelect = false; bool sectionAdded = false; // Create "sections" of screen where scroll has changed for (auto kv : rawPPU->scrollSnapshots) { // Read current values int currentX = kv.second.getTrueX(); int currentY = kv.second.getTrueY(); int currentNametable = kv.second.v.nametable; bool currentPatternSelect = kv.second.patternSelect; // Measure if the change in Y matches change in scanline, which would indicate Y wasn't changed in way we'll see int currentScanline = kv.first; int scanlineDelta = currentScanline - lastScanline; int yDelta = currentY - lastY; // Push to list only if different from last snapshot and Y change hasn't matched scanline change if (!sectionAdded || currentX != lastX || scanlineDelta != yDelta || currentNametable != lastNametable || currentPatternSelect != lastPatternSelect) { ScrollSection s = ScrollSection(); s.top = currentScanline; s.x = currentX; s.y = currentY; s.nameTable = currentNametable; s.patternSelect = currentPatternSelect; scrollSections.push_back(s); lastX = currentX; lastY = currentY; lastNametable = currentNametable; lastScanline = currentScanline; lastPatternSelect = currentPatternSelect; sectionAdded = true; } } // Create sections where OAM pattern is different oamPatternSelect = rawPPU->oamPatternSelect; // Make sure first and last scroll sections take up the full screen if (scrollSections.size() > 0) { scrollSections.front().top = 0; scrollSections.back().bottom = 239; // Change the bottom of all scroll sections to be top of next if needed if (scrollSections.size() > 1) { for (int i = 0; i < scrollSections.size()-1; i++) { scrollSections[i].bottom = scrollSections[i + 1].top - 1; } } } }