1
SFML projects / Re: sfml space invaders type of game
« on: November 14, 2014, 04:32:50 am »
yes, an menu and a 'tutorial' level are the next thing to do
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
sf::Event event;
sf::Texture texture_patrat;
sf::Texture texture_background;
texture_patrat.loadFromFile("Patrat.png");
texture_background.loadFromFile("Background.png");
sf::Sprite patrat;
sf::Sprite background;
patrat.setTexture(texture_patrat);
background.setTexture(texture_background);
sf::VideoMode screen=sf::VideoMode::getDesktopMode();
sf::RenderWindow window(sf::VideoMode(800,600), "SFML window",sf::Style::Fullscreen);
window.setFramerateLimit(30);
sf::Vector2f dimensiuni;
float newsizea,newsizeb;
newsizea=screen.width/1680;
newsizeb=screen.height/1050;
sf::Vector2f x,y;
x=patrat.getScale();
y=background.getScale();
background.setScale(x.x*newsizea,x.y*newsizeb);
patrat.setScale(y.x*newsizea,y.y*newsizeb);
dimensiuni=patrat.getPosition();
while(window.isOpen())
{
while(window.pollEvent(event))
{
if(event.type == sf::Event::KeyPressed)
{
if(event.key.code==sf::Keyboard::Escape)
{
window.close();
}
if(event.key.code==sf::Keyboard::Up&&dimensiuni.y-20>=0)
{
dimensiuni.y-=20;
patrat.setPosition(dimensiuni.x,dimensiuni.y);
}
if(event.key.code==sf::Keyboard::Up&&dimensiuni.y-20<0)
{
dimensiuni.y=0;
patrat.setPosition(dimensiuni.x,dimensiuni.y);
}
if(event.key.code==sf::Keyboard::Down&&dimensiuni.y+20<=screen.height-200)
{
dimensiuni.y+=20;
patrat.setPosition(dimensiuni.x,dimensiuni.y);
}
if(event.key.code==sf::Keyboard::Down&&dimensiuni.y+20>screen.height-200)
{
dimensiuni.y=screen.height-200;
patrat.setPosition(dimensiuni.x,dimensiuni.y);
}
if(event.key.code==sf::Keyboard::Right&&dimensiuni.x+20<=screen.width-200)
{
dimensiuni.x+=20;
patrat.setPosition(dimensiuni.x,dimensiuni.y);
}
if(event.key.code==sf::Keyboard::Right&&dimensiuni.x+20>screen.width-200)
{
dimensiuni.x=screen.width-200;
patrat.setPosition(dimensiuni.x,dimensiuni.y);
}
if(event.key.code==sf::Keyboard::Left&&dimensiuni.x-20>=0)
{
dimensiuni.x-=20;
patrat.setPosition(dimensiuni.x,dimensiuni.y);
}
if(event.key.code==sf::Keyboard::Left&&dimensiuni.x-20<0)
{
dimensiuni.x=0;
patrat.setPosition(dimensiuni.x,dimensiuni.y);
}
}
}
window.draw(background);
window.draw(patrat);
window.display();
}
return 0;
}