We have main components are:
- player
- enemy
Player implement as circular shape:
sf::CircleShape player(30);
player.setFillColor(sf::Color::Green);
player.setPosition(sf::Vector2f(screen.width/2,screen.height/4));
player.setOutlineThickness(3);
player.setOutlineColor(sf::Color::Blue);
Enemy ship implement as ConvexShape:
int numOfb=20;
sf::ConvexShape c[numOfb];
for(int i=0;i<numOfb;i++)
{
c[i].setPointCount(4);
c[i].setFillColor(sf::Color::Red);
c[i].setPoint(0,sf::Vector2f(100,100));
c[i].setPoint(1,sf::Vector2f(200,0));
c[i].setPoint(2,sf::Vector2f(0,0));
c[i].setPoint(3,sf::Vector2f(100,0));
c[i].setPosition(rang(ran)+screen.width,rang(ran));
}
When player collides with enemy ship will lost, else than will win after 30 sec.
for(int i=0;i<numOfb;i++)
{
if(player.getGlobalBounds().intersects(c[i].getGlobalBounds()))
{
ifLoss=true;
player.setOutlineColor(sf::Color::Red);
}
}
for linux :
$ sudo apt-get install libsfml-dev
- go to
app/src/main/jni/
$ g++ -c main.cpp
$ g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
$ ./sfml-app
for android:
- first should have: - android SDK [https://developer.android.com/studio] - android NDK [https://developer.android.com/ndk] - gradle [https://gradle.org/]
- build SFML for android [https://github.com/SFML/SFML/wiki/Tutorial%3A-Building-SFML-for-Android]
- go to root of project will see
local.properties
file open it in text editor, and change paths of SDK and NDK - open CLI and type
gradle build
- plug your android phone using USB.
- also on root folder of project open CLI and type
gradle installDebug
- you will see app install on your phone
2-avoid enemy
3-win after 30 sec
4-collided enemy
5-game over