Skip to content

Instantly share code, notes, and snippets.

@fallahn
fallahn / main.cpp
Created July 10, 2020 18:41
Following a path with SFML
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <array>
#include <cassert>
//dot product calculation
//https://relativity.net.au/gaming/java/DotProduct.html
float dot(const sf::Vector2f& lv, const sf::Vector2f& rv)
@fallahn
fallahn / main.cpp
Last active October 25, 2018 18:09
Build number generator
/*
Simple program which generates a header file containing a build number.
If the header file is found to exist then the number is incremented and file updated.
If the file is unparsable in some way then it is discarded and a new file starting
with the build number 0 is written.
Include the generated binary as part of your build chain - ie execute it in the
pre-compile stage - and include the resulting output in your source code.
*/
#include <fstream>
@fallahn
fallahn / PongExample2.cpp
Last active April 19, 2016 13:44
Pong collision example 2
///////////////////////////////////////////////////////////////////
// Source for Pong Collision Test example //
// http://trederia.blogspot.com/2016/02/2d-physics-101-pong.html //
// Released into the public domain //
// Example 2 //
///////////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
@fallahn
fallahn / PongExample1.cpp
Last active February 22, 2016 19:31
Pong collision example 1
///////////////////////////////////////////////////////////////////
// Source for Pong Collision Test example //
// http://trederia.blogspot.com/2016/02/2d-physics-101-pong.html //
// Released into the public domain //
// Example 1 //
///////////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
@fallahn
fallahn / VehicleExample
Created February 18, 2014 16:00
Sample vehicle handling in SFML
/*********************************************************************
Example code to accompany article at:
http://trederia.blogspot.com/2014/02/space-racers-breakdown-part-3-vehicle.html
*********************************************************************/
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
@fallahn
fallahn / gist:8316951
Last active July 26, 2017 15:53
2D water effect with GLSL and SFML
const char sinShader[] =
"#version 120\n"
"uniform float time = 1.0;"
"void main(void)"
"{"
"const float sinWidth = 0.08;"
"const float sinHeight = 0.04;"
"const float timeMulti = 10.0;"
"const float val = (sin(gl_FragCoord.x * sinWidth + time * timeMulti) + sin(gl_FragCoord.y * sinHeight + time * timeMulti)) * 0.3 + 0.5;"
@fallahn
fallahn / gist:8099202
Created December 23, 2013 15:42
rotational movement in SFML
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!");
sf::RectangleShape shape(sf::Vector2f(70.f, 10.f));
shape.setFillColor(sf::Color::Green);
shape.setOrigin(35.f, 5.f);
shape.setPosition(400.f, 300.f);