This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RAD2DEG = 180.0 / Math::PI | |
TIME_STEP = 0.2 / 60 # delta time isn't required in DragonRuby but it really handy for tuning and debugging physics | |
COLLISION_BIAS = 0.05 # adds some energy into the collision to get objects to separate. tune this in steps of 0.01 | |
COLLISION_SLOP = 0.1 # amount shapes are allowed to overlap without triggering correction. helps avoid position jitter | |
COLLISION_ITERATIONS = 10 # how many times to run the solver. a good range is between 5 and 15 | |
def tick args | |
args.gtk.reset if args.inputs.keyboard.r | |
# Create some circles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tick args | |
# Create some circles | |
args.state.circles ||= 10.map_with_ys 2 do |x, y| | |
radius = 32 | |
diameter = radius * 2 | |
# for static objects use mass = Float::INFINITY | |
mass = Math::PI * radius * radius | |
path = 'sprites/circle/blue.png' | |
offset_x = (1280 - ((diameter + radius) * 10)) / 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module GTK | |
class Runtime | |
def draw_circle c | |
radius = c.radius.to_i || 0 | |
xc = c.x.to_i + radius | |
yc = c.y.to_i + radius | |
t = c.thickness || 1 | |
r = c.r || 0 | |
g = c.g || 0 | |
b = c.b || 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_vertices rect | |
x = rect.x; y = rect.y | |
w = rect.w; h = rect.h | |
cx = x + w * 0.5; cy = y + h * 0.5 | |
sin = Math.sin (rect.angle || 0.0).to_radians; cos = Math.cos (rect.angle || 0.0).to_radians | |
[ | |
[(x - cx) * cos - (y + h - cy) * sin + cx, (x - cx) * sin + (y + h - cy) * cos + cy], # Top Left | |
[(x + w - cx) * cos - (y + h - cy) * sin + cx, (x + w - cx) * sin + (y + h - cy) * cos + cy], # Top Right | |
[(x + w - cx) * cos - (y - cy) * sin + cx, (x + w - cx) * sin + (y - cy) * cos + cy], # Bottom Right | |
[(x - cx) * cos - (y - cy) * sin + cx, (x - cx) * sin + (y - cy) * cos + cy] # Bottom Left |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEG2RAD=Math::PI/180 | |
RAD2DEG=180/Math::PI | |
class Vector2 | |
attr_accessor(:x,:y) | |
def initialize(x=0.0,y=0.0) @x=x;@y=y; end | |
def serialize; {x:@x,y:@y} end | |
def inspect; serialize.to_s end | |
def to_a; serialize.values end | |
def to_s; serialize.to_s end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SCALE = 175.0 | |
LOD = 0.005 | |
MAX_Z_FAR = 600.0 | |
MIN_Z_FAR = 175.0 | |
MIN_SCREEN_W = 70 | |
MIN_SCREEN_H = 60 | |
MAX_SCREEN_W = 360 | |
MAX_SCREEN_H = 120 | |
DRS_FRAME_WINDOW = 10 | |
Z_FAR_ADJUST_SPEED = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include MatrixFunctions | |
# Math constants | |
K_INV_6 = 1.0 / 6.0 | |
K_2_OVER_3 = 2.0 / 3.0 | |
K_2_PI = Math::PI * 2.0 | |
K_SQRT_3 = Math.sqrt 3.0 | |
K_NEG_1_OVER_3 = -1.0 / 3.0 | |
K_DEG2RAD = Math::PI / 180.0 | |
K_RAD2DEG = 360.0 / (2.0 * Math::PI) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
args.gtk.method(:write_file).parameters.map(&:last).map { |p| p.to_s } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Vec2Extensions | |
def + other | |
return super other if other.is_a? Vec2 | |
vec2 x + other, y + other if other.is_a? Numeric | |
end | |
def - other | |
return vec2 x - other.x, y - other.y if other.is_a? Vec2 | |
vec2 x - other, y - other if other.is_a? Numeric | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.21) | |
include(CMakeRC.cmake) | |
project(test) | |
file(GLOB_RECURSE ENGINE_SOURCES "${CMAKE_SOURCE_DIR}/engine/*.cpp") | |
file(GLOB_RECURSE GAME_SOURCES "${CMAKE_SOURCE_DIR}/game/*.cpp") | |
# Resource compiler | |
file(GLOB_RECURSE ASSETS "${CMAKE_SOURCE_DIR}/assets/*.*") | |
cmrc_add_resource_library(game-resources ALIAS game::resources NAMESPACE resources ${ASSETS}) |