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 / 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
@amirrajan
amirrajan / main.rb
Last active August 25, 2024 16:19
DragonRuby Game Toolkit - Verlet Integration https://youtu.be/H6XF_MorweM
class Game
attr_gtk
def initialize
end
def defaults
state.objects ||= []
end
@amirrajan
amirrajan / readme.md
Last active November 10, 2024 14:28
xplat UI considerations for games

Things to consider when building a cross-platform game:

  1. Minimum button sizes for touch displays and small screen (eg steamdeck, mobile, nintendo switch hand held mode) is about 60 pixels. Anything smaller will fail lotcheck (Apple, Android, Nintendo).
  2. Visual feedback of UI interactions (Android, Apple -> they'll reject a feature/showcase of your game if you don't have this).
  3. Safe area/layout considerations. Avoid things like notches and app switch "chin". If you're making a game that can render edge to edge/without letter boxing, test at an aspect ratio of 21:12 (1680x960). Your safe are should be centered with an aspect ratio of 16:9 (placement of UI controls should always be in the safe area or they may be inaccesible because of notches and beveled edges).
  4. Button input detection with keyboard, touch, and gamepad. Navigation using keyboard, gamepad, mouse.
  5. Anything below 22px font size is pretty much unreadable on small screens (mobile, Steam Deck, Switch Lite).
  6. Text fields is a world of p
@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 July 24, 2024 11:46
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 / readme.md
Last active November 10, 2024 14:29
Minimal Emacs configuration for Windows and Mac (Vim bindings and leader key)

Here is a minimal setup that works on Windows and Mac (yes I use Emacs on Windows and it works well).

;; using an editor you are comfortable with
;; create c:/Users/USERNAME/AppData/Roaming/.emacs.d/init.el
;; and paste these contents in there:

;; NOTE: depending on how you start up emacs, your home directory may
;;       be different than the one above. Your initialization file 
;;       needs to be saved at ~/.emacs.d/init.el (however that is mapped
@amirrajan
amirrajan / player.rb
Last active July 2, 2024 21:46
DragonRuby Game Toolkit - Player State Machine
class Player
attr :x, :y, :w, :h, :action, :action_at,
:dx, :dy, :breathe_at, :facing, :run_speed, :on_ground_y, :on_ground,
:prev_on_ground
def initialize
@breathe_at = -100
@action = :idle
@action_at = 0
@x = 100