Skip to content

Instantly share code, notes, and snippets.

View amirrajan's full-sized avatar
💭
Working on DragonRuby Game Toolkit and RubyMotion

Amir Rajan amirrajan

💭
Working on DragonRuby Game Toolkit and RubyMotion
View GitHub Profile
@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:21
DragonRuby Game Toolkit - Vista (https://amirrajan.itch.io/vista)
class Game
attr :args
def initialize args
@args = args
end
def new_game(rng_seed)
puts "New Game: #{rng_seed}"
self.state ||= {}
@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
Created December 3, 2024 20:08
DragonRuby Game Toolkit - FF8 Rinoa
def tick args
if Kernel.tick_count == 0
r = read_obj_raw 'models/rinoa.obj'
end
args.grid.origin_center!
args.state.obj ||= read_obj_raw 'models/rinoa.obj'
args.state.triangles ||= read_obj 'models/rinoa.obj'
args.state.target_triangles_start ||= 0
args.state.target_triangles_end ||= 952
@amirrajan
amirrajan / 00_demo.md
Last active November 10, 2024 14:28
DragonRuby Game Toolkit - Ramp Collisions and Jumping
ramp-collision.mp4
class Game
  attr :args

  def defaults
    args.state.terrain ||= [
      { x: 0,  y: 0, w: 128, h: 128, left_perc: 0, right_perc: 0.5 },
      { x: 128,  y: 64, w: 128, h: 128, left_perc: 0, right_perc: 1.0 },
@amirrajan
amirrajan / slides.rb
Created October 6, 2024 08:31
DragonRuby Game Toolkit PowerPoint
def tick_intro args
[
Layout.rect(row: 0, col: 12)
.merge(text: "DragonRuby Game Toolkit: Lessons Learned",
alignment_enum: 1,
vertical_alignment_enum: 1,
size_enum: 10, **white),
Layout.rect(row: 1, col: 12)
.merge(text: "Amir Rajan", **centered_white_label),
Layout.rect(row: 1.6, col: 12)
@amirrajan
amirrajan / main.rb
Created September 9, 2024 05:02
DragonRuby Game Toolkit - Ramp Collisions
class Game
attr :args
def defaults
args.state.terrain ||= [
{ x: 0, y: 0, w: 128, h: 128, left_perc: 0, right_perc: 0.5 },
{ x: 128, y: 64, w: 128, h: 128, left_perc: 0, right_perc: 1.0 },
{ x: 256, y: 64, w: 128, h: 128, left_perc: 0.5, right_perc: 0 },
{ x: 384, y: 64, w: 128, h: 128, left_perc: 0, right_perc: 0 },
]
@amirrajan
amirrajan / main.rb
Created September 1, 2024 17:35
DragonRuby Game Toolkit - Mario Style Jumping
class Game
attr_gtk
def tick
defaults
input
calc
render
end