5
« on: December 16, 2009, 04:50:15 am »
Any Ideas?
#include <SFML/Graphics.hpp>
#include <math.h>
#include <iostream>
using namespace std;
bool checkCollision(int x1, int x2, int y1, int y2);
int main()
{
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
sf::Image Gah;
sf::Input input;
if(!Gah.LoadFromFile("Arrow.png"))
{return 1;}
sf::Sprite sprite;
sprite.SetImage(Gah);
sprite.SetPosition(100.0, 100.0);
// Start game loop
while (App.IsOpened())
{
sf::Event Event;
// Process events
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
sprite.FlipX(true);
}
// Clear the screen (fill it with black color)
App.Clear();
cout<< "drawing sprite"<<endl;
App.Draw(sprite);
// Display window contents on screen
App.Display();
}
return EXIT_SUCCESS;
}
bool checkCollision(int x1, int x2, int y1, int y2)
{
float dis;
dis = sqrt((float)( ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1))) );
if(dis <= 30)
{
cout << "collide!" << endl;
return true;
}
if(dis >= 31)
{
cout<< "not collide" << endl;
return false;
}
return false;
}