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 / ext.c
Last active July 3, 2023 19:25
DragonRuby Game Toolkit - C Extensions Rendering Stars (https://youtu.be/OKcHsDxdbJg)
#include <dragonruby.h>
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/hash.h>
#include <time.h>
#include <stdlib.h>
#undef mrb_float
#undef Data_Wrap_Struct
#undef Data_Make_Struct
@amirrajan
amirrajan / ext-binding.c
Last active June 17, 2023 02:13
DragonRuby Game Toolkit - Stars Sample App Using C Extensions (https://youtu.be/OKcHsDxdbJg)
#include <dragonruby.h>
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/hash.h>
#include <time.h>
#include <stdlib.h>
#undef mrb_float
#undef Data_Wrap_Struct
#undef Data_Make_Struct
@amirrajan
amirrajan / main.rb
Created May 3, 2023 22:59
DragonRuby Game Toolkit - Bouncy Sample App https://youtu.be/Ps-4uzNf694
def tick args
# initalize a variable called ball within the game state
args.state.ball ||= {
x: 640 - 25,
y: 670,
w: 50,
h: 50,
path: "sprites/circle/blue.png",
dy: 0,
dx: 0
@amirrajan
amirrajan / main.py
Last active April 28, 2023 21:11
DragonRuby Game Toolkit vs PyGame - https://youtu.be/fuRGs6j6fPQ
import sys, pygame
import random
pygame.init()
size = width, height = 1280, 720
black = 0, 0, 0
screen = pygame.display.set_mode(size)
star_texture = pygame.image.load("tiny-star.png")
clock = pygame.time.Clock()
module GTK
class Runtime
module AsyncRequire
def async_require_init
@reload_list = []
# schema for reload_list_history
# { PATH: { current: { path: PATH,
# global_at: Fixnum,
# event: (:reload_queued|:processing|reload_completed) },
@amirrajan
amirrajan / main.rb
Created April 27, 2023 19:46
DragonRuby Game Toolkit - Square Fall
# game concept from: https://youtu.be/Tz-AinJGDIM
# This class encapsulates the logic of a button that pulses when clicked.
# It is used in the StartScene and GameOverScene classes.
class PulseButton
# a block is passed into the constructor and is called when the button is clicked,
# and after the pulse animation is complete
def initialize rect, text, &on_click
@rect = rect
@text = text
@amirrajan
amirrajan / main.rb
Created April 26, 2023 03:27
DragonRuby Game Toolkit - RubyConf 2022 source
class Game
attr_gtk
def tick
defaults
render
input
calc
end
@amirrajan
amirrajan / main.rb
Created April 22, 2023 23:52
DragonRuby Game Toolkit - Square Fall
class Game
attr_gtk
def tick
outputs.background_color = [237, 237, 237]
init_game
tick_start_scene
tick_game_scene
tick_game_over_scene
tick_next_scene
@amirrajan
amirrajan / main.rb
Created April 17, 2023 22:50
The Little Probe - physics
class Game
def calc_player_physics player, should_play_sound: true
return if !state.death_animation_completed_at
return if state.level.game_mode != :play
player.dx = player.dx.clamp(-10, 10)
player.dy = player.dy.clamp(-10, 10)
if player.on_floor
player.dx *= 0.8
@amirrajan
amirrajan / init.el
Created April 16, 2023 02:52
Init el for copilot
(use-package quelpa)
(use-package quelpa-use-package)
(use-package copilot
:quelpa (copilot.el :fetcher github
:repo "zerolfx/copilot.el"
:branch "main"
:files ("dist" "*.el")))