void set_color() { int opaque{abs(static_cast<int>(m_strength*255.0f))}; if (opaque > 255) { opaque = 255; } if (m_strength < 0.0f) { sf::Color light_red{m_light_red}; light_red.a = opaque; m_sprite.setColor(light_red); } else { sf::Color light_blue{m_light_blue}; light_blue.a = opaque; m_sprite.setColor(light_blue); } }
void cursor::manageHit() { if(hit) { hitSprite.setColor(sf::Color(255, 255, 255, 255)); hit = false; } else if(hitSprite.getColor().a > 0) { int currentAlpha = hitSprite.getColor().a; a += timeModifier; while(a > 1) { currentAlpha -= 15; a -= 15; } if(a < 0) a = 0; if(currentAlpha < 0) currentAlpha = 0; hitSprite.setColor(sf::Color(255, 255, 255, currentAlpha)); } hitSprite.setPosition(sprite.getPosition()); hitSprite.setRotation(sprite.getRotation()); }
// Initialising functions // Detects if a mouse is hovering over a button based on the mouse position, and if it is, tints the button slightly grey. // If it isn't then the tint is removed. // This version of the function is for sprites void cScreen::buttonHighlightDetect(sf::Vector2i &mousePos, sf::Sprite &button) { // If the mouse's current position is within the bounds of the button if (button.getGlobalBounds().contains(mousePos.x, mousePos.y)) { // Set the tint of the button to RGB color 200,200,200 button.setColor(sf::Color(200, 200, 200)); } // If not set the tint of the button to white else button.setColor(sf::Color::White); }
void begin(sf::Sprite &s, float x, float y) { s.setColor(sf::Color(lightMap->valueAt(x, y),lightMap->valueAt(x, y),lightMap->valueAt(x, y),255)); /*; float dist = sqrtf(powf(std::abs(s.getPosition().x - x), 2) + powf(std::abs(s.getPosition().y - y), 2)); const int maxRadius = 6; const int lowestLight = 20; const int gradient = 200/maxRadius; for (int i = 1; i < maxRadius; i++) { int flicker = flickerSeed - TILESIZE*i; if (dist > i*TILESIZE && dist < (i+2)*TILESIZE) { int gray = abs((255-i*gradient)+flicker); gray = gray < lowestLight ? lowestLight : gray; s.setColor(sf::Color(gray,gray,gray,255)); } } if (dist > maxRadius*TILESIZE) { s.setColor(sf::Color(lowestLight,lowestLight,lowestLight,255)); } */ }
void cursor::setTexture(string cursorPass) { sprite.setTexture(textureManager.get(cursorPass)); sprite.setOrigin((Collision::GetSpriteSize(sprite).x / sprite.getScale().x / 2), (Collision::GetSpriteSize(sprite).y / sprite.getScale().y / 2)); sprite.rotate(-90); sprite.setColor(sf::Color(255, 255, 255, settings.getCursorAplha())); }
//Player sprite render. void update(float deltaTime, char** levelMap, struct config* config) { //Player controls (testing). if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) mMovement.y -= mSpeed; if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) mMovement.y += mSpeed; if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) mMovement.x -= mSpeed; if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) mMovement.x += mSpeed; mRect.left += mMovement.x * deltaTime; collision(0, levelMap, config); mRect.top += mMovement.y * deltaTime; collision(1, levelMap, config); //Player animation. mCurrentFrame += mAnimationSpeed * deltaTime; if(mCurrentFrame > mFrameCount) mCurrentFrame -= mFrameCount; if(mMovement.x > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 925, mRect.width, mRect.height)); if(mMovement.x < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 667, mRect.width, mRect.height)); if(mMovement.y > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 535, mRect.width, mRect.height)); if(mMovement.y < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 787, mRect.width, mRect.height)); mSprite.setPosition(mRect.left - offsetX, mRect.top - offsetY); //HP. if(mHP / mMaxHp >= 0.6) mHpSprite.setColor(sf::Color::Green); else if((mHP / mMaxHp >= 0.35) && (mHP / mMaxHp < 0.6)) mHpSprite.setColor(sf::Color::Yellow); else if(mHP / mMaxHp < 0.35) mHpSprite.setColor(sf::Color::Red); mHpSprite.setTextureRect(sf::IntRect(100 * (1 - mHP / mMaxHp), 0, 100, 10)); mHpSprite.setPosition(mRect.left - offsetX, mRect.top + mRect.height - offsetY); mTextName.setPosition(mRect.left - offsetX, mRect.top - mTextName.getCharacterSize() - offsetY); //- //Camera scrolling. if(mRect.left > config->screenWidth / 2 - mRect.width / 2) offsetX = mRect.left - (config->screenWidth / 2 - mRect.width / 2); if(mRect.top > config->screenHeight / 2 - mRect.height / 2) offsetY = mRect.top - (config->screenHeight / 2 - mRect.height / 2); //Stopping the player. mMovement.x = 0; mMovement.y = 0; }
int main() { sf::RenderWindow App(sf::VideoMode(imageWidth, imageHeight), "SFML Graphics",sf::Style::Fullscreen); // This is the SFML application initialization with the app's parameters cx[0] = 255; cx[1] = 0; cx[2] = 0; // The initial colors for the shifting kradius = 0.1; imagen.create(imageWidth,imageHeight); mandtex.create(imageWidth,imageHeight); // The scaling factor, defined by the ranges in Real and Imaginary axis, // divided by the respective axis real length. mandelb.setOrigin(imageWidth/2,imageHeight/2); mandelb.setPosition(640,400); mandelb.scale(1.5,1.5); // Set the image positioning, centering and scaling. k.real = 0; k.imag = 0; // Original K seed values. dir = false; // Direction of scan over the complex plane mandel = false; // false if painting Julia Set, true if Mandelbrot Set. draw = true; // To tell the application to pause or continue drawing, its switched by // pressing the right click. while (App.isOpen()) { sf::Event Event; while (App.pollEvent(Event)) { // SFML works with an event loop if (Event.type == sf::Event::Closed){ // If the window is closed, close the application App.close(); } if( Event.type == Event.MouseButtonReleased && Event.mouseButton.button == sf::Mouse::Left){ // If the left mouse is pressed and released, close the application App.close(); } if( Event.type == Event.MouseButtonReleased && Event.mouseButton.button == sf::Mouse::Right){ // If the right mouse is pressed and released, toggle randomness. draw = !draw; } } App.clear(); if(!draw) continue; // If false, then stop animating and freeze in the last generated frame. resolve(); //radialScan(); horizontalScan(); mandelb.setColor(sf::Color(cx[0], cx[1], cx[2])); // Shift the image hue. App.draw(mandelb); App.display(); } return EXIT_SUCCESS; }
void AnimatableSprite::setSprite(sf::Sprite sprite) { sf::Vector2f center = getCenterPosition(); sf::Vector2f scale = _sprite.getScale(); sf::Color color = _sprite.getColor(); sprite.setScale(scale); sprite.setColor(color); _sprite = sprite; setCenterPosition(center); }
void cursor::LowAmmo(int current, int maximum) { lowAmmoSprite.setPosition(sprite.getPosition()); lowAmmoSprite.setRotation(sprite.getRotation()); double ammoLimit = 0.3 * maximum; double ammoPseudoPercentage = static_cast <float> (current) / ammoLimit; ammoPseudoPercentage *= 255; lowAmmoSprite.setColor(sf::Color(255, 255, 255, 255 - ammoPseudoPercentage)); }
void SplashScreen::fadeSpriteIn(sf::RenderWindow & renderWindow, sf::Sprite& sprite) { if((int)sprite.getColor().a < 255) { sf::Color color = sprite.getColor(); color.a++; sprite.setColor(color); }else{ fadeIn = false; } }
void SplashScreen::fadeSpriteOut(sf::RenderWindow & renderWindow, sf::Sprite& sprite) { if(sprite.getColor().a > 0) { sf::Color color = sprite.getColor(); color.a--; sprite.setColor(color); }else{ stopSplash = true; } }
void Checkbox::update(Event event) { if(!event.type == sf::Event::MouseButtonPressed and !event.type == sf::Event::MouseMoved) return; sf::Vector2f mouseCoords = sf::Vector2f(sf::Mouse::getPosition().x * viewScale + screenCornerX, sf::Mouse::getPosition().y * viewScale + screenCornerY); if(event.type == sf::Event::MouseMoved) focus = box.getGlobalBounds().contains(mouseCoords); if(event.type == sf::Event::MouseButtonPressed and focus) state = !state; if(state) check.setColor(sf::Color(255, 255, 255, 255)); else if(focus) check.setColor(sf::Color(255, 255, 255, 127)); else check.setColor(sf::Color(255, 255, 255, 0)); }
void GraphicEngine::transformSprite(sf::Sprite& sprite, const Transformation& t, const Color& color) { if (t.hasPosition()) sprite.setPosition((float)t.getX(), (float)t.getY()); if (t.hasRotation()) sprite.rotate(t.getRotation()); if (color.isUsed()) sprite.setColor(sf::Color(color.getColor())); if (t.hasScale()) sprite.setScale(t.getScaleX(), t.getScaleY()); }
void cursor::HighAmmo(int current, int maximum) { highAmmoSprite.setPosition(sprite.getPosition()); highAmmoSprite.setRotation(sprite.getRotation()); double pseudoAmmo = current - (0.7 * maximum); double pseudoAmmoMax = maximum - (0.7 * maximum); double ammoPseudoPercentage = static_cast <float> (pseudoAmmo) / pseudoAmmoMax; ammoPseudoPercentage *= 255; highAmmoSprite.setColor(sf::Color(255, 255, 255, ammoPseudoPercentage)); }
void Warp::updateWarp(Player* p, sf::Sprite& s){ static int _alpha = 0; s.setColor(sf::Color(0, 0, 0, 255)); if (!playerWarped){ _alpha = transition.get_ticks() / 10; s.setColor(sf::Color(0, 0, 0, _alpha)); if (_alpha >= 255){ _alpha = 255; s.setColor(sf::Color(0, 0, 0, _alpha)); p->setHardPosition(warpToX, warpToY); playerWarped = true; transition.stop(); transition.start(); } } if (playerWarped){ _alpha = -75 + (transition.get_ticks() / 10); if (_alpha > 0){ s.setColor(sf::Color(0, 0, 0, 255 - _alpha)); if (255 - _alpha <= 0){ _alpha = 255; s.setColor(sf::Color(0, 0, 0, 255 - _alpha)); transition.stop(); playerWarped = false; bIsActive = false; } } } s.setPosition(p->getX() - SCREEN_WIDTH / 2, p->getY() - SCREEN_HEIGHT / 2); p->setXVel(0); p->setYVel(0); return; }
void setup() { window = new sf::RenderWindow(sf::VideoMode(800, 600), "Untitled"); window->setFramerateLimit(60); clock = new sf::Clock(); // textures are apparently stored in the graphic card's memory rather than RAM tile_texture = new sf::Texture(); tile_texture->loadFromFile("assets/gfx/tiles/basic1.png"); // sprites are used to position and draw textures tile_sprite = new sf::Sprite(); tile_sprite->setTexture(*tile_texture); tile_sprite->setColor(sf::Color(255, 255, 255, 255)); }
sf::Sprite Missile::ajouterMissileVaisseau(sf::Sprite sp, float posMissileX, float posMissileY) { if (!missile.loadFromFile("ressource/missile.png", sf::IntRect(0, 0, 100,100))) { std::cout<<"Erreur durant le chargement de l'image missile"<<std::endl; return sp; // On ferme le programme } else { sp.setTexture(missile); sp.setScale(0.5f, 0.5f); //setScale peut changer la taille sp.setColor(sf::Color(0, 255, 0)); sp.setPosition(posMissileX, posMissileY); return sp; } }
inline void set_color(const sf::Color& color) { sprite.setColor(color); }
void rysuj_hud( sf::RenderWindow & okno ) { if( bonusik->zwroc_timer() > 0 ) alphaPaskaBonusu = 1; // else // if( bonusik->zwroc_timer() == 0 ) // alphaPaskaBonusu = 0; if( bonusik->zwroc_timer() == 0 ){ if( alphaPaskaBonusu > 0 ) alphaPaskaBonusu -= 0.01; } spr_paskaBonusu.setColor( sf::Color( 255, 255, 255, 255*alphaPaskaBonusu)); /// GDY HP DOJDZIE DO STANU KRYTYCZNEGO, ZAMIEN NA CZERWONY KOLOR // if( gracz->zwroc_hp() < 20 ) // spr_paskaHp.setColor( sf::Color( 255, 255, 255, 255 ) ); // else // spr_paskaHp.setColor( sf::Color( 255, 255, 255, 255 ) ); // gracz->ustaw_hp( 10 ); for( int i = 0 ; i < 2 ; i++ ) { spr_paskaHp.setTexture( tex_paskaHp[ i ] ); spr_paskaBonusu.setTexture( tex_paskaBonusu[ i ] ); // spr_paskaBonusu.setScale( 1.5, 1 ); if( i == 0 ) { spr_paskaHp.setTextureRect( sf::IntRect( 0, 0, 153, 18 ) ); spr_paskaBonusu.setTextureRect( sf::IntRect( 0, 0, 578, 31 ) ); } else { spr_paskaHp.setTextureRect( sf::IntRect( 0, 0, (gracz->zwroc_hp()/gracz->zwroc_maxHP())*153, 18 ) ); spr_paskaBonusu.setTextureRect( sf::IntRect( 0, 0, (bonusik->zwroc_timer() / bonusik->zwroc_maxTimer() )*578, 31 ) ); } okno.draw( spr_paskaHp ); if( alphaPaskaBonusu > 0 ) { okno.draw( spr_paskaBonusu ); } } rysuj_tekst( okno, "Poziom: ", ::lvl, 170, 5 ); // rysuj_tekst( okno, "Score: ", ::score ); rysuj_tekst( okno, L"Pozostało: ", ::potrzeba_zabitych - ::ilosc_zabitych, 520, 110 ); /// rysuj jaki lvl /// rysuj ile punktow /// rysuj jaki bonus if( bonusik->x != -500 && bonusik->typ == -1 ) rysuj_tekst( okno, L"Szybko, bonus jest na mapie\n\tmusisz go znaleźć!", 200, 100 ); if( bonusik->zwroc_timer() > 0 ) rysuj_tekst( okno, "Czas bonusu: ", bonusik->zwroc_timer() + 1, 285, 410 ); if( bonusik->typ != -1 ) { ustaw_timer( 1, 2 ); typ_bonusu = bonusik->typ; } if( zwroc_timer( 1 ) != 0 ) { switch( typ_bonusu ) { case bonus_dmgUp: rysuj_tekst( okno, L"Wylosowałes bonus: Zwiększenie ataku!", 200, 100 ); break; case bonus_hpUp: rysuj_tekst( okno, L"Wylosowałes bonus: Całkowite wyleczenie!", 200, 100 ); break; case bonus_spdUp: rysuj_tekst( okno, L"Wylosowałes bonus: Przyśpieszenie!", 200, 100 ); break; case bonus_hpDown: rysuj_tekst( okno, L"Co, ale że co?! HP ci spadło !", 200, 100 ); break; case bonus_spdDown: rysuj_tekst( okno, L"Chodzisz powooooli jak zółw...", 200, 100 ); break; case bonus_immune: rysuj_tekst( okno, L"Muahahaha! Nieśmiertelny! (czasowo ^^)", 200, 100 ); break; case 6: rysuj_tekst( okno, L"Nięęęęęę", 300, 10 ); break; case -1: break; default: rysuj_tekst( okno, L"Nięę", 300, 10 ); break; } } }
void end(sf::Sprite &s) { s.setColor(sf::Color::White); }
void setColor(sf::Color color) { sprite.setColor(color); }
void set_color() { m_sprite.setColor(m_light_orange); }
void set_color() { m_sprite.setColor(m_light_purple); }
void update(sf::Time time) { MusicManager::instance().update(time); system.update(time); sm.update(); oTweener.step(time.asMilliseconds() / 1000.f); if ((int)(rand() % 90) == 3 && first) sm.setCurrentEffect("distortion", sf::seconds(0.05)); if ((int)(rand() % 100) == 3 && !first) sm.setCurrentEffect("inversion", sf::seconds(1)); if (first) { logo.setColor(sf::Color(255,255,255,interpolateLinear(logo.getColor().a, 255, 0.05f))); logo.setPosition(0, newLogoY); if (!pressFading) { press.setColor(sf::Color(255,255,255,interpolateLinear(press.getColor().a, 0,pressFactor))); if (press.getColor().a < 7) { pressFading = true; } } else { press.setColor(sf::Color(255,255,255,interpolateLinear(press.getColor().a, 255, pressFactor))); if (press.getColor().a > 243) { pressFading = false; } } sprite.update(time); if (transition && timer.getElapsedTime().asSeconds() > 0.5) { press.setColor(sf::Color(255,255,255,0)); } if (transition && timer.getElapsedTime().asSeconds() > 0.5) { transition = false; oTweener.addTween(&CDBTweener::TWEQ_BACK, CDBTweener::TWEA_INOUT, 2.f, &newLogoY, -800.0f); } if (!transition && logo.getPosition().y <= -800 && !check) { sm.setCurrentEffect("rgb", sf::seconds(1)); check = true; timer.restart();SoundManager::instance().playNoiseSound(); } if (check && timer.getElapsedTime().asSeconds() > 1) { first = false; MusicManager::instance().playMusicFast("battle"); pressFading = true; } } else { pressFactor = 0.2; if (!pressFading) { pointer.setColor(sf::Color(255,255,255,interpolateLinear(pointer.getColor().a, 0,pressFactor))); if (pointer.getColor().a < 7) { pressFading = true; } } else { pointer.setColor(sf::Color(255,255,255,interpolateLinear(pointer.getColor().a, 255, pressFactor))); if (pointer.getColor().a > 243) { pressFading = false; } } switch (selection) { case 0: pointer.setPosition(1183, 415); break; case 1: pointer.setPosition(1183, 531); break; case 2: pointer.setPosition(1183, 645); break; default: break; } } };
MainMenu() : system(TextureManager::instance().getTexture("assets/rticle.png")) { pointer.setTexture(TextureManager::instance().getTexture("assets/two_pointer.png")); //pointer.setPosition(1183, 427); //system = new thor::ParticleSystem(); emitter.setEmissionRate(0.5f); emitter.setParticleLifetime( sf::seconds(40) ); emitter.setParticleRotation( thor::Distributions::uniform(0.f, 360.f) ); emitter.setParticlePosition( sf::Vector2f(1260,740) ); emitter.setParticleScale(sf::Vector2f(0.1,0.1)); system.addEmitter(thor::refEmitter(emitter)); thor::ColorGradient gradient; gradient[0.0f] = sf::Color::Magenta; gradient[0.1f] = sf::Color::Red; gradient[0.2f] = sf::Color::Blue; gradient[0.3f] = sf::Color::Cyan; gradient[0.4f] = sf::Color::Green; gradient[0.5f] = sf::Color::Red; gradient[0.6f] = sf::Color::Magenta; gradient[0.7f] = sf::Color::Cyan; gradient[0.8f] = sf::Color::Red; gradient[0.9f] = sf::Color::Blue; gradient[1.0f] = sf::Color::Red; thor::ColorAnimation colorizer(gradient); thor::FadeAnimation fader(0.1f, 0.1f); system.addAffector( thor::ScaleAffector(sf::Vector2f(0.1f,0.1))); system.addAffector( thor::AnimationAffector(fader) ); system.addAffector( thor::AnimationAffector(colorizer) ); sprite = AnimatedSprite(sf::seconds(0.3)); v.setTexture(TextureManager::instance().getTexture("assets/one_upper.png")); back2.setTexture(TextureManager::instance().getTexture("assets/two_menu.png")); logo.setTexture(TextureManager::instance().getTexture("assets/one_logo.png")); press.setTexture(TextureManager::instance().getTexture("assets/one_anybutton.png")); anim.setSpriteSheet(TextureManager::instance().getTexture("assets/one_animooted.jpg")); for (int i = 0; i < 5; i++) { anim.addFrame(sf::IntRect(0, 800 * i, WIDTH, HEIGHT)); } sprite.setAnimation(anim); sprite.setLooped(true); sprite.play(); logo.setColor(sf::Color(255,255,255,0)); press.setColor(sf::Color(255,255,255,0)); pointer.setColor(sf::Color(255,255,255,0)); press.setPosition(WIDTH/2 - press.getTextureRect().width/2, HEIGHT/2 - press.getTextureRect().height/2 + 100); pressFading = true; newLogoY = 800; oTweener.addTween(&CDBTweener::TWEQ_BACK, CDBTweener::TWEA_INOUT, 2.f, &newLogoY, 0.0f); first = true; pressFactor = 0.2; transition = false; check = false; sm.init(sf::Vector2f(WIDTH, HEIGHT)); rt.create(WIDTH, HEIGHT); MusicManager::instance().playMusicFast("low"); selection = 1; };