Skip to content

Instantly share code, notes, and snippets.

#include "arrlist.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define EXTRA_CAPACITY 4
#define RESZ_NUMER 5
#define RESZ_DENOM 3
#define MAX(x, y) ((x) > (y) ? (x) : (y))
@awsumpwner27
awsumpwner27 / resolve_object_tile_collision.cpp
Last active April 15, 2016 21:29
Resolve the collision between a tilemap and a box as long as a tile and the box are both 64x64 units. Unnecessarily dependant on SFML.
void resolve_object_tile_collision(sf::Vector2f& tl_object_position, sf::Vector2f& tl_object_velocity, std::uint8_t* tile_data, std::uint32_t tiles_width, std::uint32_t tiles_height) {
//Using a method of AABB collision detection that handles the response between the tile it most intersects first.
std::vector<std::pair<float, sf::Vector2i>> tile_intersections; //Pairs consisting of the intersection area of a tile with its relative position
//Populate tile_intersections
sf::Vector2i prime_tile_pos( //Tile the object's top left corner rests within
int(std::floor(tl_object_position.x / 64.f)),
int(std::floor(tl_object_position.y / 64.f))
);
for (int8_t y = 0; y <= 1; ++y) {
for (int8_t x = 0; x <= 1; ++x) {
@awsumpwner27
awsumpwner27 / Tilemap.cpp
Created April 13, 2016 11:44
2015 version of my SFML tilemap implementation.
#include <stdint.h>
#include "Tilemap.hpp"
Tilemap::Tilemap(const sf::Vector2u& map_dimensions, const sf::Vector2u& tile_dimensions, sf::Texture* texture, uint8_t* tile_data_pointer) :
_vertices(sf::Triangles, map_dimensions.x * map_dimensions.y * 6u),
_map_dimensions(map_dimensions),
_tile_dimensions(tile_dimensions),
_texture(texture),
_tile_data_pointer(tile_data_pointer)
{
#include <SFML/Graphics.hpp>
int main(){
sf::RenderWindow window(sf::VideoMode(1024u, 576u), "LD31");{
window.setFramerateLimit(60u);
}
sf::CircleShape circle(32.f);
while(window.isOpen()){
sf::Event event;
while(window.pollEvent(event)){
@awsumpwner27
awsumpwner27 / TileMap.h
Created July 18, 2014 07:38
SFML Tile Map Code
#ifndef H_TILEMAP
#define H_TILEMAP
#include <array>
#include <SFML/Graphics.hpp>
class TexBoxCoords : public sf::Rect<int> {
public:
TexBoxCoords(void) :
sf::Rect<int>()