1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include "stdafx.h"
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <cmath>
#include <math.h>
#include <string>
#include <sstream>
#define pi 3.14145926535
int main()
{
reboot:
sf::RenderWindow App(sf::VideoMode(800, 600), "made by Jannes");
float x1=100;float x=x1;
float y1=100;float y=y1;
float x2=200;
float y2=100;
float length=sqrt(pow((x1-x2),2)+pow((y1-y2),2));
int a=0;
sf::Shape grapplerope=sf::Shape::Line(x1,y1,x2,y2,2.0f,sf::Color(128,128,128));
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::R)) {
App.Close();goto reboot;
}
}
// Clear screen
App.Clear(sf::Color(10,10,10));
// Draw shapes
App.Draw(grapplerope);
//elapsed time
float ElapsedTime = App.GetFrameTime();
float alpha=asin((y1-y2)/length)+0.001f;
if (x1<2*(length)+x-0.1f && a==0) {//change 0.1f to a bigger number if you want it to sling less at the left side
x1=x1+(100.f*alpha*App.GetFrameTime());
} else {
a=1;
x1=x1-(100.f*alpha*App.GetFrameTime());
if (x1-0.1f<=x) {//change the 0.1f to a bigger number if you want it to sling less to the right side.
a=0;
}
}
y1=sqrt(pow(length,2)-(pow((x1-x2),2)))+y2;
grapplerope=sf::Shape::Line(x1,y1,x2,y2,2.0f,sf::Color(128,128,128));
App.Display();
}
return EXIT_SUCCESS;
}
|