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 / repl.rb
Created February 29, 2024 11:39
Pure Ruby Marshal
class MarshalWriteBuffer
attr_reader :object, :data
def initialize(object)
@object = object
@data = "\x04\b" # '4.8' (version)
end
def write(current_object = object)
case current_object
# ./dragonruby mygame --eval bootstrap.rb
class GTK::Console
def eval_the_set_command
cmd = current_input_str.strip
if cmd == "1"
puts "hi"
prompt.clear
return
elsif cmd == "2"
@amirrajan
amirrajan / main.rb
Created February 10, 2024 17:13
DragonRuby Game Toolkit - Shader Sim https://youtu.be/JHkFI2VmKp8
def tick args
easing_perc = (args.state.tick_count % 600) / 600
offset_1 = 0 + easing_perc * 800
offset_2 = -800 + easing_perc * 800
# two sprites scrolling horizontally and vertically
args.outputs.background_color = [0, 0, 0]
args.outputs[:scene].background_color = [0, 0, 0, 0]
args.outputs[:scene].w = 800
args.outputs[:scene].h = 800
@amirrajan
amirrajan / main.rb
Created January 16, 2024 07:31
DragonRuby Game Toolkit - Bullet Hell
class ShopScene
attr_gtk
def activate
state.module_selected = nil
state.available_modules = state.modules.shuffle.take(3)
state.available_module_1 = state.available_modules[0]
state.available_module_2 = state.available_modules[1]
state.available_module_3 = state.available_modules[2]
end
class WebWrapperView < UIView
URL = NSBundle.mainBundle.URLForResource("index", withExtension: "html")
FALLBACK_USER_AGENT = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1'
def initWithFrame(frame)
super
create_web_view
load_url
self
end
@amirrajan
amirrajan / main.rb
Created November 21, 2023 07:13
DragonRuby Game Toolkit - Lowrez Kenobi Source
require 'app/lowrez.rb'
class Game
attr_gtk
def request_action name, at: nil
at ||= state.tick_count
state.player.requested_action = name
state.player.requested_action_at = at
end
@amirrajan
amirrajan / main.rb
Created November 21, 2023 04:00
DragonRuby Game Toolkit - Simple Dodging Game
def tick args
defaults args
input_player args
spawn_bullets args
calc_bullets args
render args
end
def defaults args
args.state.player ||= { x: 100, y: 100 + rand(520), w: 32, h: 32, path: "sprites/square/blue.png", hp: 10 }
@amirrajan
amirrajan / game.rbc
Created October 20, 2023 10:18
DragonRuby Game Toolkit bytecode compilation output example.
RITE0200£MATZ0000IREPI0300&
`b9kGamej c/h[dh[dh[dh[dh[dh[dh[dh[dh[d h[ d
h[
d  9 attr_gtktickcar_collision_rectget_map_data_files load_map! save_map!relative_to_car_camerarelative_to_carnew_prism_stonesnew_checkpoint_prism_stonescompleted_at_least_once?'completed_at_least_once_with_good_time?"Â5/////////'ô//''///'$QSQS//SQS/ //
'=//
// // //
////9_* SCENE TRANSITION ERROR: Do not set ~state.scene~ directly. Use ~state.next_scene~. Scene was
, but became .statescenedefaultsrenderinputcalcgame_is_resetting!!=raise
next_scenescene= next_scene=
tick_countscene_changed_at=game_is_resetting=i ;5//@//
@amirrajan
amirrajan / Program.cs
Created July 29, 2023 00:32
DragonRuby Game Toolkit vs Unity Performance - Collisions
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class CameraUtility
{
public static void GetCameraBounds(out float minX, out float minY, out float maxX, out float maxY, float padding)
{
Camera cam = Camera.main;
Vector3 camPos = cam.transform.position;