Skip to content

Instantly share code, notes, and snippets.

View emdeeeks's full-sized avatar

Gareth Griffiths emdeeeks

View GitHub Profile
@amirrajan
amirrajan / shared_controller.rb
Created June 7, 2025 00:05
two controllers, one game
class SharedKeyDown
attr :args
def inputs
@args.inputs
end
def start
inputs.controllers.any? { |c| c.key_down.start }
end
@amirrajan
amirrajan / main.rb
Last active June 9, 2025 22:56
camera with rotation matrix and circle based collision
class Game
attr_gtk
def initialize
@player = { x: 30,
y: -16,
w: 32,
h: 32,
dx: 0,
dy: 0,
@amirrajan
amirrajan / main.rb
Last active June 9, 2025 23:01
DragonRuby Game Toolkit: Slay the Card Game Example
class Game
attr_gtk
attr :enemy
def tick
defaults
calc
render
end
@amirrajan
amirrajan / main.rb
Created March 9, 2025 00:22
DragonRuby Game Toolkit - Endurance The Probe
class Game
attr_gtk
def current_level_name
# used by level editor to figure out which data file to save/load
state.levels[state.current_level_index] || :todo
end
# helper method to move rect within the camera
def to_screen_space target
@amirrajan
amirrajan / main.rb
Created January 15, 2025 14:01
Legion Story Progression Concept
class Probe
def queue_story!(predicate: nil, entries:, completion_action: nil, completion_checkpoint:, completion: nil)
raise "Either completion_action or completion must be provided." if !completion_action && !completion
return if @action == :story
return if @current_story_items.length > 0
return if checkpoint_reached?(completion_checkpoint)
should_queue = if predicate.is_a? Proc
predicate.call
elsif predicate.is_a? FalseClass
# this file sets up the main game loop (no need to modify it)
# play game here: https://samples.dragonruby.org/samples/99_genre_lowrez/nokia_3310_snake/index.html
require "app/nokia_emulation.rb"
class Game
attr :args, :nokia_mouse_position
def tick
# create a new game on frame zero
new_game if Kernel.tick_count == 0
@amirrajan
amirrajan / main.rb
Last active February 26, 2025 15:13
DragonRuby Game Toolkit - Towers of Hanoi implementation (https://amirrajan.itch.io/hanoi)
class Game
attr_gtk
# get solution for hanoi tower
# https://youtu.be/rf6uf3jNjbo
def solve count, from, to, other
solve_recur(count, from, to, other).flatten
end
# recursive function for getting solution
@amirrajan
amirrajan / main.rb
Created December 7, 2024 21:06
DragonRuby Game Toolkit - Advanced Scene Management
# representation of a game that has a healing mechanic
class Game
# game has access to args and hp
attr :args, :hp
# initialize game with 100 hp
def initialize
@hp = 100
end
@amirrajan
amirrajan / main.rb
Last active June 9, 2025 23:06
DragonRuby Game Toolkit - Verlet Integration https://youtu.be/H6XF_MorweM
class Game
attr_gtk
def initialize
end
def defaults
state.objects ||= []
end
@amirrajan
amirrajan / player.rb
Created August 10, 2024 23:27
DragonRuby Game Toolkit - Animation State Machine
class Player
def initialize
@action_lookup = {
idle: {
frame_count: 7,
dir: "sprites/player/idle",
repeat: true
},
attack: {
frame_count: 6,