arczi14 Temat założony przez niniejszego użytkownika |
SFML 2.0 Spadek wydajności » 2014-07-01 15:21:08 Witam, To znowu ja z kolejnym problemem... Zastanawiam się czy SFML nadaje się do dość dużych projektów ~10000 linii? Otóż mam sobie menu z którego można wybrać opcje jak graj, konto, itp. Tzn. jak klikam graj uruchamia się funkcja graj() I tak samo do innych opcji uruchamiają się inne funkcje. Ale gdy uruchamiam gra() działa ona normalnie, natomiast gdy uruchomię inną opcje(kod poniżej) i nastepnie ponownie z menu uruchamiam gra() ilość FPS z około 100 spada do 40 i gra staje się niegrywalna... Wklejam wam kod funkcji, przez który funkcja gra() spada z wydajnością... #include "engine.h" #include "lang.h" #include "account.h"
void Gra::account() { Language lang( lang_file ); Account account; sf::Sprite body[ 63 ]; sf::RectangleShape bodyR; sf::Text header( lang.lg( 8 ), f_header, 50 ); sf::Clock clock; sf::RectangleShape login_box( sf::Vector2f( 200, 30 ) ); sf::RectangleShape password_box( sf::Vector2f( 200, 30 ) ); sf::Text header_login( lang.lg( 11 ), f_normal, 60 ); sf::Text login_text( lang.lg( 12 ), f_normal, 30 ); sf::Text password_text( lang.lg( 13 ), f_normal, 30 ); sf::Text password_pressed_text; sf::Text login_pressed_text; sf::Text box_text; sf::Sprite box_rect; int for_mod = 0; float accumulate = 0; string login = "LPM"; string password = "LPM"; bool comunicat = false; bool password_pressing = false; bool login_pressing = false; bool log_try = true; bodyR.setSize( sf::Vector2f( 800, 550 ) ); bodyR.setFillColor( sf::Color( 0, 0, 0, 125 ) ); bodyR.setOutlineColor( sf::Color::Black ); bodyR.setOutlineThickness( 3 ); bodyR.setPosition( 240, 80 ); header.setPosition( 265, 75 ); for( int i = 0; i < 9; i++ ) { for( int x = 0; x < 7; x++ ) { body[ for_mod ].setPosition( 175 *( i ), 175 *( x ) ); body[ for_mod ].setTexture( t_back ); body[ for_mod ].setTextureRect( sf::IntRect( 0, 0, 175, 175 ) ); for_mod++; } } while( STATE == ACCOUNT ) { sf::Event event; sf::Vector2f mouse( sf::Mouse::getPosition( * WindowApp ) ); accumulate += clock.restart().asSeconds(); while( WindowApp->pollEvent( event ) ) { if( event.type == sf::Event::Closed ) STATE = END; if( event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape ) STATE = MENU; if( event.type == sf::Event::MouseButtonReleased && event.key.code == sf::Mouse::Left ) { if( login_box.getGlobalBounds().contains( mouse ) && password_pressing != true ) { login_pressing = true; login = ""; } else if( password_box.getGlobalBounds().contains( mouse ) && login_pressing != true ) { password_pressing = true; password = ""; } else if( box_rect.getGlobalBounds().contains( mouse ) ) { if( account.logIn( login, password ) ) { LOGSTATE = LOGIN; CLIENT_ID = account.client_id; CLIENT_LOGIN = account.client_login; } else log_try = false; } } if( event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return ) { if( password_pressing == true ) password_pressing = false; else if( login_pressing == true ) login_pressing = false; else { if( account.logIn( login, password ) ) { LOGSTATE = LOGIN; CLIENT_ID = account.client_id; CLIENT_LOGIN = account.client_login; } else log_try = false; } } if( event.type == sf::Event::TextEntered ) { if( password_pressing == true ) { if( password.length() < 16 && event.text.unicode > 8 && event.text.unicode < 256 ) password +=( char ) event.text.unicode; else if( password.length() <= 10 && password.length() > 0 && event.text.unicode == 8 ) password.erase(( password.length() - 1 ), 1 ); } else if( login_pressing == true ) { if( login.length() < 16 && event.text.unicode > 8 && event.text.unicode < 256 ) login +=( char ) event.text.unicode; else if( login.length() <= 10 && login.length() > 0 && event.text.unicode == 8 ) login.erase(( login.length() - 1 ), 1 ); } } } if( accumulate >= 0.010 ) { accumulate = 0; for( int i = 0; i < 63; i++ ) { body[ i ].move( - 0.5, 1 ); if( body[ i ].getPosition().x < - 175 ) { double tempY = body[ i ].getPosition().y; body[ i ].setPosition( 1290, tempY ); } if( body[ i ].getPosition().y > 768 ) { double tempX = body[ i ].getPosition().x; body[ i ].setPosition( tempX, - 174 ); } } WindowApp->clear(); for( int i = 0; i < 63; i++ ) WindowApp->draw( body[ i ] ); WindowApp->draw( bodyR ); WindowApp->draw( header ); switch( LOGSTATE ) { case LOGOUT: { if( comunicat == false ) { if( messageBox( 1, 0, lang.Dlg( 9, 10 ), ACCOUNT ) ) comunicat = true; } if( !log_try ) { if( messageBox( 1, 0, lang.lg( 16 ), ACCOUNT ) ) log_try = true; } header_login.setPosition( 600, 100 ); login_box.setPosition( 750, 207 ); login_text.setPosition( 600, 200 ); password_box.setPosition( 750, 307 ); password_text.setPosition( 600, 300 ); box_text.setCharacterSize( 24 ); box_text.setFont( f_normal ); box_text.setString( lang.lg( 14 ) ); box_text.setColor( sf::Color( 255, 206, 173 ) ); box_text.setPosition( 650 +( 80 - 5 * 6 ), 402 ); box_text.setStyle( sf::Text::Bold ); box_rect.setTexture( t_pressed ); box_rect.setPosition( 640, 400 ); box_rect.setColor( sf::Color( 20, 20, 20, 150 ) ); login_pressed_text.setPosition( 752, 204 ); login_pressed_text.setCharacterSize( 26 ); login_pressed_text.setFont( f_normal ); login_pressed_text.setString( login ); password_pressed_text.setPosition( 752, 304 ); password_pressed_text.setCharacterSize( 26 ); password_pressed_text.setFont( f_normal ); string temp = ""; for( int i = 0; i < password.length(); i++ ) temp += "*"; password_pressed_text.setString( temp ); if( box_rect.getGlobalBounds().contains( mouse ) ) box_rect.setColor( sf::Color( 50, 50, 50, 150 ) ); else box_rect.setColor( sf::Color( 20, 20, 20, 200 ) ); if( !password_pressing && !password_box.getGlobalBounds().contains( mouse ) ) password_box.setFillColor( sf::Color( 214, 133, 22, 200 ) ); else password_box.setFillColor( sf::Color::Black ); if( !login_pressing && !login_box.getGlobalBounds().contains( mouse ) ) login_box.setFillColor( sf::Color( 214, 133, 22, 200 ) ); else login_box.setFillColor( sf::Color::Black ); WindowApp->draw( header_login ); WindowApp->draw( login_box ); WindowApp->draw( login_text ); WindowApp->draw( password_box ); WindowApp->draw( password_text ); WindowApp->draw( box_rect ); WindowApp->draw( box_text ); WindowApp->draw( password_pressed_text ); WindowApp->draw( login_pressed_text ); } break; } WindowApp->display(); } } }
Co z tą funkcją może być nie tak( Już kilkanaście godzin szukam jakiś błędów i nic znaleźć nie mogę...)? Osobiście wydaje mi się to nie możliwe, żeby funkcja powyżej mogła w jakikolwiek sposób wpłynąć na szybkość gry no ale gra faktycznie zwalnia... Podaję wam mój program na dowód: (Wejdz w "Graj", wyjdz, wejdz w "Konto", wyjdz i ponownie wejdz w "Graj" i zobaczysz że gra strasznie zwolniła). http://www.sendspace.pl/file/95cbd3c70802133ffa621cdBędę potwornie wdzięczny za jakąkolwiek pomoc, wskazówkę. |
|
DejaVu |
» 2014-07-01 16:17:44 Żadna biblioteka ani żaden silnik nie poradzi sobie z błędami programisty. Renderowanie SFML-a jest oparte o bibliotekę OpenGL, a więc masz sprzętowe wsparcie renderowania czegokolwiek na scenie. |
|
arczi14 Temat założony przez niniejszego użytkownika |
» 2014-07-01 16:42:58 W takim razie mógłbyś rzucić okiem na kod który wrzuciłem ? |
|
pekfos |
» 2014-07-01 17:31:00 (Wejdz w "Graj", wyjdz, wejdz w "Konto", wyjdz i ponownie wejdz w "Graj" i zobaczysz że gra strasznie zwolniła). |
Nie dałeś kodu do "graj". Zastanawiam się czy SFML nadaje się do dość dużych projektów ~10000 linii? |
Co ma piernik do wiatraka? |
|
arczi14 Temat założony przez niniejszego użytkownika |
» 2014-07-01 17:48:03 Gra: #include "engine.h" #include "objects.h"
#define SKILL_Q 0 #define SKILL_W 1 #define SKILL_E 2 #define SKILL_R 3
using namespace std;
void Gra::game() { sf::Sprite lowTexture[ 40 ]; sf::Sprite wall[ 40 ][ 2 ]; sf::Clock clock; sf::Clock game; sf::Time game_time; sf::Sprite cursor; sf::Text Tpoints[ 2 ]; sf::Text Tvs( " VS ", f_header, 50 ); sf::Text Ttime; Language lang( lang_file ); Player player( hero_info, f_normal ); Player enemy_player( hero_info, f_normal ); Cursor_click cursor_click( sf::Color( 74, 205, 31, 200 ) ); float zoom = 1.0f; float x = 0; float y = 0; int wavenumber = 1; int minion_respawn = 1; int SKILL = SKILL_Q; float accumulate = 0; WindowApp->setMouseCursorVisible( false ); for( int i = 0; i < 40; i++ ) { lowTexture[ i ].setTexture( t_game_01 ); lowTexture[ i ].setTextureRect( sf::IntRect( 0, 0, 32, 720 ) ); lowTexture[ i ].setPosition( i * 32, 0 ); wall[ i ][ 0 ].setPosition( i * 32, 0 ); wall[ i ][ 0 ].setTexture( t_wall_01 ); wall[ i ][ 1 ].setPosition( i * 32, 660 ); wall[ i ][ 1 ].setTexture( t_wall_01 ); } player.setTexture( t_player_01 ); enemy_player.setTexture( t_player_01 ); enemy_player.setBorderColor( sf::Color( 255, 25, 31, 230 ) ); sf::View view; sf::View minimapView; view.reset( sf::FloatRect( 0, 0, 1280, 720 ) ); view.setViewport( sf::FloatRect( 0, 0, 1.0f, 1.0f ) ); sf::Vector2f view_position( 0, 720 / 2 ); Tpoints[ 0 ].setFont( f_header ); Tpoints[ 1 ].setFont( f_header ); Tpoints[ 0 ].setCharacterSize( 50 ); Tpoints[ 1 ].setCharacterSize( 50 ); Tpoints[ 0 ].setPosition( 550, 9 ); Tpoints[ 1 ].setPosition( 700, 9 ); Tpoints[ 0 ].setColor( player.color ); Tpoints[ 1 ].setColor( enemy_player.color ); Tvs.setPosition( 600, 9 ); Ttime.setCharacterSize( 40 ); Ttime.setFont( f_normal ); Ttime.setColor( sf::Color::Magenta ); Ttime.setPosition( 1150, 9 ); cursor.setTexture( t_c_normal ); while( STATE == GAME ) { sf::Event event; sf::Vector2f mouse( sf::Mouse::getPosition( * WindowApp ) ); sf::Vector2i pixelPos = sf::Mouse::getPosition( * WindowApp ); sf::Vector2f worldPos = WindowApp->mapPixelToCoords( pixelPos ); cursor.setPosition( mouse.x - 8, mouse.y ); accumulate += clock.restart().asSeconds(); stringstream points[ 2 ]; stringstream SStime[ 2 ]; string Stime; points[ 0 ] << player.death_number; points[ 1 ] << enemy_player.death_number; int Itime = game_time.asSeconds(); SStime[ 0 ] << int( Itime / 60 ); SStime[ 1 ] << int( Itime % 60 ); Stime = SStime[ 0 ].str() + " : " + SStime[ 1 ].str() + "s"; Ttime.setString( Stime ); Tpoints[ 0 ].setString( points[ 0 ].str() ); Tpoints[ 1 ].setString( points[ 1 ].str() ); if( enemy_player.player.getGlobalBounds().contains( worldPos ) ) cursor.setTexture( t_c_enemy ); else cursor.setTexture( t_c_normal ); if( game.getElapsedTime().asMilliseconds() > 1000 ) { game_time += sf::milliseconds( game.restart().asMilliseconds() ); player.setRegen(); } while( WindowApp->pollEvent( event ) ) { if( event.type == sf::Event::MouseWheelMoved ) { zoom = 1.f + event.mouseWheel.delta * 0.1f; view.zoom( zoom ); } if( event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape ) STATE = MENU; if( event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Q ) enemy_player.castAttack( player.position, 0, game_time, mouse ); if( event.type == sf::Event::Closed ) STATE = END; if( event.type == sf::Event::MouseButtonPressed && event.key.code == sf::Mouse::Right ) { x = worldPos.x - player.position.x - 16; y = worldPos.y - player.position.y - 32; player.update( x, y ); cursor_click.setColor( sf::Color( 74, 205, 31, 200 ) ); cursor_click.setCircle( mouse ); } if( event.type == sf::Event::MouseButtonPressed && event.key.code == sf::Mouse::Left ) { cursor_click.setColor( sf::Color( 255, 70, 30, 200 ) ); cursor_click.setCircle( mouse ); if( player.skill_follow[ SKILL ] == 1 ) { if( enemy_player.player.getGlobalBounds().contains( worldPos ) ) player.castAttack( enemy_player.position, SKILL, game_time, mouse ); } else player.castAttack( enemy_player.position, SKILL, game_time, mouse ); } if( event.type == sf::Event::KeyPressed ) { switch( event.key.code ) { case sf::Keyboard::Q: { SKILL = SKILL_Q; break; } case sf::Keyboard::W: { SKILL = SKILL_W; break; } case sf::Keyboard::E: { SKILL = SKILL_E; break; } case sf::Keyboard::R: { SKILL = SKILL_R; break; } } } } if( accumulate >= 0.010 ) { accumulate = 0; player.move( game_time ); player.skill_able(); if( player.position.y < 60 ) player.position.y = 60; if( player.position.y > 640 ) player.position.y = 640; int temp_damage = player.skills_move( enemy_player ); if( temp_damage > 0 ) { enemy_player.hp -= temp_damage * player.attack_damage; } int temp_damage_enemy = enemy_player.skills_move( player ); if( temp_damage_enemy > 0 ) { if( player.hp > temp_damage_enemy * enemy_player.attack_damage ) player.hp -= temp_damage_enemy * enemy_player.attack_damage; else player.killPlayer( game_time ); } WindowApp->clear(); for( int i = 0; i < 40; i++ ) { WindowApp->draw( lowTexture[ i ] ); WindowApp->draw( wall[ i ][ 0 ] ); WindowApp->draw( wall[ i ][ 1 ] ); } if( cursor_click.steps > 0 ) cursor_click.Draw( * WindowApp ); enemy_player.Draw( * WindowApp ); player.Draw( * WindowApp ); player.drawSkill(); WindowApp->draw( Tpoints[ 0 ] ); WindowApp->draw( Tpoints[ 1 ] ); WindowApp->draw( Tvs ); WindowApp->draw( Ttime ); WindowApp->draw( cursor ); WindowApp->display(); } } }
I klasa player którą wykorzystuje funkcja gra: #include "objects.h"
int Player::getInt( string tab[], string to_f ) { string to_ret; string temp; for( int i = 0; i < 100; i++ ) { size_t pos = tab[ i ].find( to_f ); if( pos != string::npos ) { temp = tab[ i ]; for( int j = 0; j <( tab[ i ].length() - pos ); j++ ) { to_ret += temp[ j + pos + to_f.length() ]; } break; } } return atoi( to_ret.c_str() ); }
float Player::getFloat( string tab[], string to_f ) { string to_ret; string temp; for( int i = 0; i < 100; i++ ) { size_t pos = tab[ i ].find( to_f ); if( pos != string::npos ) { temp = tab[ i ]; for( int j = 0; j <( tab[ i ].length() - pos ); j++ ) { to_ret += temp[ j + pos + to_f.length() ]; } break; } } return atof( to_ret.c_str() ); }
Player::Player( string date[], sf::Font font ) { hp = getInt( date, "HP:" ); mana = getInt( date, "MANA:" ); attack_damage = getFloat( date, "AD:" ); movement_speed = getFloat( date, "Movement:" ); mana_cost[ 0 ] = getInt( date, "Q_cost:" ); mana_cost[ 1 ] = getInt( date, "W_cost:" ); mana_cost[ 2 ] = getInt( date, "E_cost:" ); mana_cost[ 3 ] = getInt( date, "R_cost:" ); cd_time[ 0 ] = getInt( date, "Q_cd:" ); cd_time[ 1 ] = getInt( date, "W_cd:" ); cd_time[ 2 ] = getInt( date, "E_cd:" ); cd_time[ 3 ] = getInt( date, "R_cd:" ); skill_speed[ 0 ] = getFloat( date, "Q_speed:" ); skill_speed[ 1 ] = getFloat( date, "W_speed:" ); skill_speed[ 2 ] = getFloat( date, "E_speed:" ); skill_speed[ 3 ] = getFloat( date, "R_speed:" ); skill_follow[ 0 ] = getInt( date, "Q_Follow:" ); skill_follow[ 1 ] = getInt( date, "W_Follow:" ); skill_follow[ 2 ] = getInt( date, "E_Follow:" ); skill_follow[ 3 ] = getInt( date, "R_Follow:" ); skill_grow[ 0 ] = getFloat( date, "Q_Grow:" ); skill_grow[ 1 ] = getFloat( date, "W_Grow:" ); skill_grow[ 2 ] = getFloat( date, "E_Grow:" ); skill_grow[ 3 ] = getFloat( date, "R_Grow:" ); skill_grow_step[ 0 ] = getFloat( date, "Q_Grow_Step:" ); skill_grow_step[ 1 ] = getFloat( date, "W_Grow_Step:" ); skill_grow_step[ 2 ] = getFloat( date, "E_Grow_Step:" ); skill_grow_step[ 3 ] = getFloat( date, "R_Grow_Step:" ); hp_regen = getFloat( date, "HP_regen:" ); mana_regen = getFloat( date, "Mana_regen:" ); string Sskills[ 4 ] = { "Q", "W", "E", "R" }; death_number = 0; f_normal = font; gold = 1000; position.x = 30; position.y = 350; steps = 0; DIRECTION = RIGHT; max_hp = hp; max_mana = mana; color = sf::Color( 74, 205, 31, 230 ); for( int i = 0; i < 4; i++ ) { Tskill[ i ].setPosition( 540 +( i * 50.5 ), 680 ); Tskill[ i ].setFont( f_normal ); Tskill[ i ].setCharacterSize( 22 ); Tskill[ i ].setString( Sskills[ i ] ); skills[ i ].setPosition( 530 +( i * 50 ), 675 ); skills[ i ].setRadius( 20 ); } R_frame.setSize( sf::Vector2f( 82, 14 ) ); R_frame.setFillColor( sf::Color( 0, 0, 0, 0 ) ); R_frame.setOutlineColor( sf::Color( 243, 211, 29 ) ); R_frame.setOutlineThickness( 1 ); }
void Player::update( float x, float y ) { getVector.x = x; getVector.y = y; steps = sqrt( x * x + y * y ) / movement_speed; animations_steps = 1; conststeps = steps; switch( getDirection( x, y ) ) { case 0: DIRECTION = DOWN; break; case 1: DIRECTION = LEFT; break; case 2: DIRECTION = RIGHT; break; case 3: DIRECTION = UP; break; } }
int Player::getDirection( float x, float y ) { float sin = atan2( x, y ); if( sin >= - 0.75 && sin <= 0.75 ) return 0; if( sin >= 0.75 && sin <= 2.25 ) return 2; if( sin >= 2.25 || sin < - 2.25 ) return 3; return 1; }
void Player::setTexture( sf::Texture name ) { t_player = name; }
void Player::Draw( sf::RenderWindow & win ) { if( death != true ) { double hp_value =( hp * 100 ) / max_hp * 0.8; float mana_value =( mana * 100 ) / max_mana * 0.8; R_frame.setPosition( position.x - 25, position.y - 27 ); R_hp.setSize( sf::Vector2f( hp_value, 6 ) ); R_hp.setFillColor( color ); R_hp.setPosition( position.x - 24, position.y - 26 ); R_mana.setSize( sf::Vector2f( mana_value, 6 ) ); R_mana.setFillColor( sf::Color( 32, 118, 204, 230 ) ); R_mana.setPosition( position.x - 24, position.y - 20 ); player.setTexture( t_player ); sf::Vector2f temp_texture( t_player.getSize().x / 3, t_player.getSize().y / 4 ); player.setTextureRect( sf::IntRect( temp_texture.x * animations_steps, DIRECTION * temp_texture.y, temp_texture.x, temp_texture.y ) ); player.setPosition( position ); App = & win; App->draw( R_frame ); App->draw( R_hp ); App->draw( R_mana ); for( int i = 0; i < AA_sprite.size(); i++ ) App->draw( AA_sprite[ i ] ); App->draw( player ); } else { sf::RectangleShape black_screen( sf::Vector2f( 1280, 720 ) ); black_screen.setFillColor( sf::Color( 0, 0, 0, 170 ) ); black_screen.setPosition( 0, 0 ); App->draw( black_screen ); } }
void Player::drawSkill() { for( int i = 0; i < 4; i++ ) { if( death != true ) { if( skills_able[ i ] == false ) skills[ i ].setFillColor( sf::Color::Red ); else if( mana < mana_cost[ i ] ) skills[ i ].setFillColor( sf::Color::Blue ); else skills[ i ].setFillColor( sf::Color::Green ); App->draw( skills[ i ] ); App->draw( Tskill[ i ] ); } else { skills[ i ].setFillColor( sf::Color( 255, 0, 0, 128 ) ); App->draw( skills[ i ] ); App->draw( Tskill[ i ] ); } } }
void Player::move( sf::Time time ) { game_time = time; if( steps > 0 && death != true ) { steps--; position.x += getVector.x / conststeps; position.y += getVector.y / conststeps; if( t_player.getSize().x <=( t_player.getSize().x / 3 ) *( animations_steps + 1 ) ) animations_steps = 0; else animations_steps++; } if( death == true ) { if( time.asMilliseconds() >= death_time.asMilliseconds() ) { death = false; } } }
bool Player::collision( sf::Vector2f a, sf::Vector2f bP, sf::Vector2f b, float c ) { sf::Vector2f circleDistance; circleDistance.x = abs( a.x - bP.x - 8 +( b.x / 8 ) ); circleDistance.y = abs( a.y - bP.y - 16 +( b.y / 4 ) ); if( circleDistance.x >( b.x / 2 + c ) ) { return false; } if( circleDistance.y >( b.y / 2 + c ) ) { return false; } if( circleDistance.x <=( b.x / 2 ) ) { return true; } if( circleDistance.y <=( b.y / 2 ) ) { return true; } float cornerDistance_sq =( circleDistance.x - b.x / 2 ) *( circleDistance.x - b.x / 2 ) + ( circleDistance.y - b.y / 2 ) *( circleDistance.y - b.y / 2 ); return( cornerDistance_sq <=( c * c ) ); }
int Player::skills_move( Player enemy_player ) { int how_much = 0; for( int i = 0; i < AA_sprite.size(); i++ ) { sf::Vector2f temp( 32, 32 ); if( collision( AA_sprite[ i ].getPosition(), enemy_player.player.getPosition(), temp, AA_sprite[ i ].getRadius() ) == true && skill_grow[ AA_number[ i ] ] == 0 ) { AA_sprite.erase( AA_sprite.begin() + i ); AA_vector.erase( AA_vector.begin() + i ); AA_follow.erase( AA_follow.begin() + i ); AA_number.erase( AA_number.begin() + i ); how_much++; continue; } else if( skill_grow[ AA_number[ i ] ] != 0 && AA_sprite[ i ].getRadius() >= skill_grow[ AA_number[ i ] ] ) { if( collision( AA_sprite[ i ].getPosition(), enemy_player.player.getPosition(), temp, AA_sprite[ i ].getRadius() ) == true ) how_much++; AA_sprite.erase( AA_sprite.begin() + i ); AA_vector.erase( AA_vector.begin() + i ); AA_follow.erase( AA_follow.begin() + i ); AA_number.erase( AA_number.begin() + i ); continue; } else if( AA_sprite[ i ].getPosition().x > 1300 || AA_sprite[ i ].getPosition().x < - 20 || AA_sprite[ i ].getPosition().y > 750 || AA_sprite[ i ].getPosition().y < - 20 ) { AA_sprite.erase( AA_sprite.begin() + i ); AA_vector.erase( AA_vector.begin() + i ); AA_follow.erase( AA_follow.begin() + i ); AA_number.erase( AA_number.begin() + i ); continue; } else { if( AA_follow[ i ] == false ) AA_sprite[ i ].move( AA_vector[ i ].x, AA_vector[ i ].y ); else { sf::Vector2f move_vect; move_vect.x = enemy_player.position.x - AA_sprite[ i ].getPosition().x; move_vect.y = enemy_player.position.y - AA_sprite[ i ].getPosition().y; float temp_step = sqrt( move_vect.x * move_vect.x + move_vect.y * move_vect.y ) / skill_speed[ 0 ]; AA_vector[ i ].x = move_vect.x / temp_step; AA_vector[ i ].y = move_vect.y / temp_step; AA_sprite[ i ].move( AA_vector[ i ].x, AA_vector[ i ].y ); } if( skill_grow[ AA_number[ i ] ] != 0 && AA_sprite[ i ].getRadius() < skill_grow[ AA_number[ i ] ] ) { AA_sprite[ i ].setRadius( AA_sprite[ i ].getRadius() + skill_grow_step[ AA_number[ i ] ] ); AA_sprite[ i ].move( - skill_grow_step[ AA_number[ i ] ], - skill_grow_step[ AA_number[ i ] ] ); } } } return how_much; }
void Player::setBorderColor( sf::Color temp ) { color = temp; }
void Player::castAttack( sf::Vector2f vect, int attack_number, sf::Time time, sf::Vector2f mouse ) { if( death != true ) { sf::Vector2f move_vect; float temp_step; switch( attack_number ) { case 0: { if( mana >= mana_cost[ 0 ] && skill_time[ 0 ].asMilliseconds() <= time.asMilliseconds() ) { move_vect.x = vect.x - position.x; move_vect.y = vect.y - position.y; temp_step = sqrt( move_vect.x * move_vect.x + move_vect.y * move_vect.y ) / skill_speed[ 0 ]; AA_vector.push_back( sf::Vector2f( move_vect.x / temp_step, move_vect.y / temp_step ) ); AA_sprite.push_back( sf::CircleShape( 10 ) ); AA_follow.push_back( true ); AA_number.push_back( 0 ); AA_sprite[ AA_sprite.size() - 1 ].setFillColor( color ); AA_sprite[ AA_sprite.size() - 1 ].setPosition( position ); mana -= mana_cost[ 0 ]; skill_time[ 0 ] = sf::milliseconds( time.asMilliseconds() + cd_time[ 0 ] ); skills_able[ 0 ] = false; } } break; case 1: { if( mana >= mana_cost[ 1 ] && skill_time[ 1 ].asMilliseconds() <= time.asMilliseconds() ) { move_vect.x = mouse.x - position.x; move_vect.y = mouse.y - position.y; temp_step = sqrt( move_vect.x * move_vect.x + move_vect.y * move_vect.y ) / skill_speed[ 1 ]; AA_vector.push_back( sf::Vector2f( move_vect.x / temp_step, move_vect.y / temp_step ) ); AA_sprite.push_back( sf::CircleShape( 7 ) ); AA_follow.push_back( false ); AA_number.push_back( 1 ); AA_sprite[ AA_sprite.size() - 1 ].setFillColor( color ); AA_sprite[ AA_sprite.size() - 1 ].setPosition( position ); mana -= mana_cost[ 1 ]; skill_time[ 1 ] = sf::milliseconds( time.asMilliseconds() + cd_time[ 1 ] ); skills_able[ 1 ] = false; } } break; case 2: { if( mana >= mana_cost[ 2 ] && skill_time[ 2 ].asMilliseconds() <= time.asMilliseconds() ) { AA_vector.push_back( sf::Vector2f( 0, 0 ) ); AA_sprite.push_back( sf::CircleShape( 0 ) ); AA_follow.push_back( false ); AA_number.push_back( 2 ); AA_sprite[ AA_sprite.size() - 1 ].setFillColor( color ); AA_sprite[ AA_sprite.size() - 1 ].setPosition( mouse.x - 2, mouse.y - 2 ); mana -= mana_cost[ 2 ]; skill_time[ 2 ] = sf::milliseconds( time.asMilliseconds() + cd_time[ 2 ] ); skills_able[ 2 ] = false; } } break; case 3: { if( mana >= mana_cost[ 3 ] && skill_time[ 3 ].asMilliseconds() <= time.asMilliseconds() ) { move_vect.x = vect.x - mouse.x; move_vect.y = vect.y - mouse.y; temp_step = sqrt( move_vect.x * move_vect.x + move_vect.y * move_vect.y ) / skill_speed[ 1 ]; AA_vector.push_back( sf::Vector2f( move_vect.x / temp_step, move_vect.y / temp_step ) ); AA_sprite.push_back( sf::CircleShape( 15 ) ); AA_follow.push_back( true ); AA_number.push_back( 3 ); AA_sprite[ AA_sprite.size() - 1 ].setFillColor( color ); AA_sprite[ AA_sprite.size() - 1 ].setPosition( mouse ); mana -= mana_cost[ 3 ]; skill_time[ 3 ] = sf::milliseconds( time.asMilliseconds() + cd_time[ 3 ] ); skills_able[ 3 ] = false; } } break; } } }
void Player::setRegen() { if( death != true ) { if( max_hp >= hp + hp_regen ) hp += hp_regen; else hp = max_hp; if( max_mana >= mana + mana_regen ) mana += mana_regen; else mana = max_mana; } else { mana = max_mana; hp = max_hp; } }
void Player::killPlayer( sf::Time clock ) { if( death != true ) { death = true; death_time = sf::seconds( clock.asSeconds() +( clock.asSeconds() / 15 ) ); death_number++; } }
void Player::skill_able() { for( int i = 0; i < 4; i++ ) { if( skills_able[ i ] == false ) { if( skill_time[ i ].asMilliseconds() <= game_time.asMilliseconds() ) skills_able[ i ] = true; } } }
|
|
DejaVu |
» 2014-07-01 18:01:49 Pierwszy lepszy przykład: player.setTexture( t_player );
Kopiujesz teksturę co każde jej wyświetlenie. |
|
pekfos |
» 2014-07-01 18:03:14 Gdzie tworzysz okno i gdzie to wszystko wywołujesz? |
|
arczi14 Temat założony przez niniejszego użytkownika |
» 2014-07-01 18:04:52
Pierwszy lepszy przykład:
player.setTexture( t_player );
Kopiujesz teksturę co każde jej wyświetlenie.
|
Ta tekstura kopiuje się przed pętlą while gry więc wykonuje się raz. |
|
« 1 » 2 3 |