Skip to content

Instantly share code, notes, and snippets.

View kim366's full-sized avatar

Kim Schmider kim366

  • Sydney
View GitHub Profile
@kim366
kim366 / WindowSize.cpp
Last active October 20, 2016 18:04
Window Size from Grid
windowSize = boardSize * (tileSize + border) - border;
@kim366
kim366 / TilePosition.cpp
Last active October 20, 2016 18:03
Set the Tile Position of Each individual one when looping through the whole Grid
// For x
// For y
currentTile.setPosition((tileSize + border) * y, (tileSize + border) * x);
@kim366
kim366 / GridBox.cpp
Last active April 20, 2017 20:33
Box That snaps to Grid when moving Mouse Cursor
auto box_position{sf::Mouse::getPosition(window)};
for (auto& component : {box_position.x, box_position.y})
{
while (component % tileSize)
--component;
}
box.setPosition(box_position);
@kim366
kim366 / RotateToMouse.cpp
Created October 20, 2016 18:07
Rotate Player so he looks towards the cursor
sf::Vector2f delta(sf::Vector2f(sf::Mouse::getPosition(window)) - player.getPosition());
player.setRotation(atan(delta.y / delta.x) * 180 / PI);
@kim366
kim366 / MovePlayerToMouse.cpp
Created October 20, 2016 18:14
Move Background in Opposite Direction so it looks like Player is Moving to stop Player from going in a circle
// See RotateToMouse.cpp for definition of delta
sf::Vector2f normalizedDelta(delta / hypot(delta.x, delta.y));
if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
background.move(sf::Vector2f(-normalizedDelta.x, -normalizedDelta.y));
if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
background.move(sf::Vector2f(normalizedDelta.x, normalizedDelta.y));
@kim366
kim366 / new.cpp
Last active October 24, 2016 16:17
Dry SFML Event/Keyboard Poll code
sf::Event event;
while (window.pollEvent(event))
{
using k = sf::Keyboard;
using e = sf::Event;
auto kc = event.key.code;
auto et = event.type;
auto kp = e::KeyPressed;
//DIREKTER VERGLEICH/////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <stdio.h>
#include <set>
#include <vector>
#include <math.h>
#include <assert.h>
const sf::Vector2u window_size{1280, 720};
sf::CircleShape player{20.f};
@kim366
kim366 / Mix.frag
Created August 26, 2017 21:14
SFML Layer Mask
// Most credit to @fallahn
#version 120
uniform sampler2D tex1;
uniform sampler2D tex2;
uniform sampler2D maskTex;
void main()
{
#include <SFML/Graphics.hpp>
// #define CATCH_CONFIG_MAIN
// #include <catch.hpp>
void draw_lines(const std::vector<sf::Vector2f>& vector, sf::RenderWindow& window, sf::Color color = sf::Color::White)
{
for (auto it{vector.cbegin()}; it != vector.cend();)
{
auto current_it{it};
if (++it != vector.cend())
#include <SFML/Graphics.hpp>
#include <cassert>
#include <array>
#include <algorithm>
// #define CATCH_CONFIG_MAIN
// #include <catch.hpp>
void draw_lines(const std::vector<sf::Vector2f>& vector_, sf::RenderTarget& target_, sf::Color color_ = sf::Color::White)
{
for (auto it{vector_.cbegin()}; it != vector_.cend();)