Skip to content

Instantly share code, notes, and snippets.

@sojastar
sojastar / keymap.rb
Created May 26, 2020 07:52
Key mapping swap for DragonRuby
module KeyMap
def self.set(mapping)
mapping.each_pair do |command,key|
GTK::KeyboardKeys.send :alias_method, command, key
end
end
def self.unset(mapping)
mapping.each_pair do |command,key|
GTK::KeyboardKeys.send :undef_method, command
CC=gcc
CFLAGS=-std=c99 -lm
MRUBY_INCLUDE=../../mruby-3.1.0/include
MRUBY_LIB=../../mruby-3.1.0/build/host/lib/libmruby.a
SOURCE=c_from_ruby
all:
$(CC) $(CFLAGS) -I$(MRUBY_INCLUDE) $(SOURCE).c -o $(SOURCE) $(MRUBY_LIB)
clean:
@sojastar
sojastar / haskell_sdl2_setup.md
Created February 19, 2024 10:28
Setting up a basic Haskell SDL2 application on MacOS

1. Install SDL2 with homebrew:

$> brew install sdl2

and optionally:

$> brew install sdl2_image
$> brew install sdl2_mixer
$> brew install sdl2_gfx
$> brew install sdl2_ttf
@sojastar
sojastar / collisions.rb
Created September 4, 2024 11:17
AABB collision detection in Ruby
module Collisions
def self.aabb_rect_vs_rect(rect1,rect2)
rect1[0] < rect2[0] + rect2[2] &&
rect1[0] + rect1[2] > rect2[0] &&
rect1[1] < rect2[1] + rect2[3] &&
rect1[1] + rect1[3] > rect2[1]
end
def self.resolve_collisions_with_rects(position,size,velocity,rects)
# First round of collision testing that will teel us ...