Coś ewidentnie spier****
main:
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include "test.hpp"
#include "sterowanie.hpp"
enum Stan
{
Menu, Wybor, Gra
};
void move();
void setPosition();
int main()
{
sf::RenderWindow aplikacja( sf::VideoMode( 820, 720 ), "GRA" );
aplikacja.setFramerateLimit( 30 );
Stan stan = Menu;
Obiekt pdl;
sf::Texture menu_textura;
sf::Texture wybor_textura;
sf::Texture gra_textura;
sf::Texture player_texture;
sf::Texture drzewo_texture;
menu_textura.loadFromFile( "tekstura-menu.png" );
wybor_textura.loadFromFile( "wybor-tekstura.png" );
gra_textura.loadFromFile( "gra-tekstura.png" );
player_texture.loadFromFile( "tekstura-gracza.png" );
drzewo_texture.loadFromFile( "tekstura-drzewo.png" );
sf::Sprite menu( menu_textura );
sf::Sprite wybor( wybor_textura );
sf::Sprite gra( gra_textura );
sf::Sprite player( player_texture, sf::IntRect( 0, 0, 100, 200 ) );
sf::Sprite drzewo( drzewo_texture );
drzewo.setPosition( 200, 200 );
player.setPosition( 100, 100 );
while( aplikacja.isOpen() )
{
sf::Event event;
while( aplikacja.pollEvent( event ) )
{
if( event.type == sf::Event::Closed )
aplikacja.close();
}
switch( stan )
{
case Menu:
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Enter ) )
{
stan = Gra;
}
break;
case Wybor:
break;
case Gra:
Ruch_postaci( player );
break;
}
aplikacja.clear();
switch( stan )
{
case Menu:
aplikacja.draw( menu );
aplikacja.draw( pdl );
break;
case Wybor:
aplikacja.draw( wybor );
break;
case Gra:
aplikacja.draw( gra );
aplikacja.draw( drzewo );
aplikacja.draw( player );
break;
}
aplikacja.display();
}
return 0;
}
sterowanie.cpp i .hpp
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include "sterowanie.hpp"
void Ruch_postaci( sf::Sprite player )
{
if( sf::Keyboard::isKeyPressed( sf::Keyboard::W ) )
{
int top = player.getTextureRect().top;
player.setTextureRect( sf::IntRect( 200,( top + 200 ) % 600, 100, 200 ) );
player.move( 0, - 5 );
}
if( sf::Keyboard::isKeyPressed( sf::Keyboard::S ) )
{
int top = player.getTextureRect().top;
player.setTextureRect( sf::IntRect( 100,( top + 200 ) % 600, 100, 200 ) );
player.move( 0, 5 );
}
if( sf::Keyboard::isKeyPressed( sf::Keyboard::A ) )
{
int top = player.getTextureRect().top;
player.setTextureRect( sf::IntRect( 100,( top + 200 ) % 600, - 100, 200 ) );
player.move( - 5, 0 );
}
if( sf::Keyboard::isKeyPressed( sf::Keyboard::D ) )
{
int top = player.getTextureRect().top;
player.setTextureRect( sf::IntRect( 0,( top + 200 ) % 600, 100, 200 ) );
player.move( 5, 0 );
}
if( sf::Keyboard::isKeyPressed( sf::Keyboard::E ) )
{
int top = player.getTextureRect().top;
player.setTextureRect( sf::IntRect( 300,( top + 200 ) % 600, 100, 200 ) );
}
}
#ifndef sterowanie.hpp
#define sterowanie.hpp
void Ruch_postaci( sf::Sprite player )
#endif
test.cpp i .hpp
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include "test.hpp"
class Obiekt
: public sf::Drawable
{
private:
virtual void draw( sf::RenderTarget & target, sf::RenderStates states ) const
{
sf::VertexArray kwadrat( sf::Quads, 4 );
kwadrat[ 0 ].position = sf::Vector2f( 100, 100 );
kwadrat[ 1 ].position = sf::Vector2f( 300, 100 );
kwadrat[ 2 ].position = sf::Vector2f( 300, 300 );
kwadrat[ 3 ].position = sf::Vector2f( 100, 300 );
sf::Texture textura;
textura.loadFromFile( "podloga.jpg" );
kwadrat[ 0 ].texCoords = sf::Vector2f( 0, 0 );
kwadrat[ 1 ].texCoords = sf::Vector2f( 0, 100 );
kwadrat[ 2 ].texCoords = sf::Vector2f( 100, 100 );
kwadrat[ 3 ].texCoords = sf::Vector2f( 100, 0 );
states.texture = & textura;
target.draw( kwadrat, states );
}
};
#ifndef test.hpp
#define test.hpp
class Obiekt
: public sf::Drawable
{
private:
virtual void draw( sf::RenderTarget & target, sf::RenderStates states ) const;
};
#endif
BŁĄD:
||=== Build: Debug in platformowka (compiler: GNU GCC Compiler) ===|
C:\Users\Routa\Desktop\platformowka\sterowanie.hpp|1|warning: extra tokens at end of #ifndef directive|
C:\Users\Routa\Desktop\platformowka\sterowanie.hpp|2|warning: missing whitespace after the macro name|
C:\Users\Routa\Desktop\platformowka\test.hpp|1|warning: extra tokens at end of #ifndef directive|
C:\Users\Routa\Desktop\platformowka\test.hpp|1|warning: extra tokens at end of #ifndef directive|
C:\Users\Routa\Desktop\platformowka\test.hpp|2|warning: missing whitespace after the macro name|
C:\Users\Routa\Desktop\platformowka\sterowanie.hpp|1|warning: extra tokens at end of #ifndef directive|
C:\Users\Routa\Desktop\platformowka\sterowanie.hpp|2|warning: missing whitespace after the macro name|
C:\Users\Routa\Desktop\platformowka\test.hpp|2|warning: missing whitespace after the macro name|
C:\Users\Routa\Desktop\platformowka\sterowanie.cpp|5|error: expected initializer before 'void'|
C:\Users\Routa\Desktop\platformowka\test.cpp|5|error: redefinition of 'class Obiekt'|
C:\Users\Routa\Desktop\platformowka\test.hpp|4|error: previous definition of 'class Obiekt'|
C:\Users\Routa\Desktop\platformowka\main.cpp|6|error: expected initializer before 'enum'|
C:\Users\Routa\Desktop\platformowka\main.cpp||In function 'int main()':|
C:\Users\Routa\Desktop\platformowka\main.cpp|18|error: 'Stan' was not declared in this scope|
C:\Users\Routa\Desktop\platformowka\main.cpp|53|error: 'stan' was not declared in this scope|
C:\Users\Routa\Desktop\platformowka\main.cpp|55|error: 'Menu' was not declared in this scope|
C:\Users\Routa\Desktop\platformowka\main.cpp|59|error: 'Gra' was not declared in this scope|
C:\Users\Routa\Desktop\platformowka\main.cpp|63|error: 'Wybor' was not declared in this scope|
C:\Users\Routa\Desktop\platformowka\main.cpp|67|error: 'Gra' was not declared in this scope|
C:\Users\Routa\Desktop\platformowka\main.cpp|98|error: 'Ruch_postaci' was not declared in this scope|
C:\Users\Routa\Desktop\platformowka\main.cpp|104|error: 'stan' was not declared in this scope|
C:\Users\Routa\Desktop\platformowka\main.cpp|106|error: 'Menu' was not declared in this scope|
C:\Users\Routa\Desktop\platformowka\main.cpp|112|error: 'Wybor' was not declared in this scope|
C:\Users\Routa\Desktop\platformowka\main.cpp|116|error: 'Gra' was not declared in this scope|
||=== Build failed: 15 error(s), 8 warning(s) (0 minute(s), 0 second(s)) ===|