Skip to content

Instantly share code, notes, and snippets.

View emdeeeks's full-sized avatar

Gareth Griffiths emdeeeks

View GitHub Profile
@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
@julianrubisch
julianrubisch / main.rb
Last active February 2, 2026 17:39
DragonRuby "Async" Multiplayer Sync via HTTP
class Game < HttpRouter
def initialize(players: [])
@players = players
@http_debounce = 0
route do |routes|
@players.each do |player|
routes.get "/#{player.id}/progress" do |req|
if @current_scene_name == :host_scene
req.respond 200, "{ \"progress\": #{player.progress} }"
@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,
@amirrajan
amirrajan / main.rb
Last active October 9, 2025 17:13
DragonRuby Game Toolkit - Many to Many Collision Performance - https://youtu.be/cc3Sx2j85mM
def tick args
# initialize state
args.state.rects ||= []
args.state.rect_size ||= 8
args.state.move_squares ||= :no
if args.inputs.keyboard.key_down.tab
args.state.move_squares = args.state.move_squares == :yes ? :no : :yes
end
args.outputs.watch "FPS: #{GTK.current_framerate.to_sf}"
@amirrajan
amirrajan / main.rb
Created May 28, 2024 20:58
DragonRuby Game Toolkit - Scene Management With Fade To Black
class RootScene < Scene
attr :game
def initialize
@game = Game.new
$game = @game
@world_scene = WorldScene.new
@embark_scene = EmbarkScene.new
@world_event_scene = WorldEventScene.new
@battle_scene = BattleScene.new