Skip to content

Instantly share code, notes, and snippets.

View kim366's full-sized avatar

Kim Schmider kim366

  • Sydney
View GitHub Profile
@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 / 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 / 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 / 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 / WindowSize.cpp
Last active October 20, 2016 18:04
Window Size from Grid
windowSize = boardSize * (tileSize + border) - border;