Skip to content

Instantly share code, notes, and snippets.

// Map scrolling functions
auto panMap = [&mapView, &minimapView] (float speed, int dir) {
float timeValue = TimePerFrame.asSeconds();
float moveValue = speed * timeValue;
if (dir == 0) { mapView.move(-moveValue, 0.f); minimapView.move(-moveValue, 0.f); }
if (dir == 1) { mapView.move(moveValue, 0.f); minimapView.move(moveValue, 0.f); }
if (dir == 2) { mapView.move(0.f, -moveValue); minimapView.move(0.f, -moveValue); }
if (dir == 3) { mapView.move(0.f, moveValue); minimapView.move(0.f, moveValue); }
};
// Map edge scrolling
if (mousePosition.x < mapScrollTreshold && mousePosition.x >= 0) {
mapScrollSpeed += (mapScrollSpeed - mousePosition.x) * 1.5f;
panMapLeft(mapScrollSpeed, TimePerFrame);
}
if (mousePosition.x >= window.getSize().x - mapScrollTreshold
&& mousePosition.x <= window.getSize().x) {
mapScrollSpeed += (window.getSize().x - mousePosition.x) * 1.5f;
panMapRight(mapScrollSpeed, TimePerFrame);
void Game::run()
{
sf::Clock clock;
sf::Time timeSinceLastUpdate = sf::Time::Zero;
while (mWindow.isOpen())
{
sf::Time elapsedTime = clock.restart();
timeSinceLastUpdate += elapsedTime;
while (timeSinceLastUpdate > TimePerFrame)
{
@clooth
clooth / mapscroll.cpp
Created September 23, 2013 10:51
map scroll
auto panMapLeft = [&mapView] (float speed, float time) { mapView.move(-speed * time, 0.f); };
auto panMapRight = [&mapView] (float speed, float time) { mapView.move(speed * time, 0.f); };
auto panMapUp = [&mapView] (float speed, float time) { mapView.move(0.f, -speed * time); };
auto panMapDown = [&mapView] (float speed, float time) { mapView.move(0.f, speed * time); };
// Map scroll
float mapScrollSpeed = 1000.f; // The speed of the scrolling
if (event.type == sf::Event::KeyPressed)
{
// Pan left
//
// TextureManager.h
// Grand
//
// Created by Nico Hämäläinen on 9/21/13.
// Copyright (c) 2013 Nico Hämäläinen. All rights reserved.
//
#ifndef __Grand__TextureManager__
#define __Grand__TextureManager__
@clooth
clooth / process_manager.h
Created September 20, 2013 09:36
example
struct Process
{
Process* next_;
Process* previous_;
void (*function_)(void* caller_ptr, Purpose purpose);
unsigned int id;
long colorFromHexString(std::string hexString)
{
return strtol(hexString.c_str(), NULL, 16);
}
std::vector<Uint32> rgbFromColor(long colorValue)
{
std::vector<Uint32> rgb;
// Red, Green, Blue
@clooth
clooth / dl.js
Created September 18, 2013 23:55
var downloadURL = function(a) {
var b = "hiddenDownloader" + (+new Date()),
c = document.getElementById(b);
null === c && (c = document.createElement("iframe"), c.id = b, c.style.display = "none", document.body.appendChild(c)), c.src = a
};
window.zips = document.querySelectorAll('a.tutLink[href$=zip]');
var i = 0;
for (var i; i < window.zips.length; i++) {
var zip = window.zips[i];
downloadURL(zip.href);
/**
Loads a BMP image into a texture on the rendering device
@param file The BMP image file to load
@param renderer The renderer to load the texture onto
@return the loaded texture, or nullptr if something went wrong.
*/
SDL_Texture *loadTexture(const std::string &file, SDL_Renderer *renderer)
{
SDL_Surface *loadedImage = SDL_LoadBMP(file.c_str());
#include <SDL2/SDL.h>
#include <stdio.h>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
int main(int argc, char* args[])
{
// Main rendering window
SDL_Window* window = NULL;