Created
September 26, 2021 02:48
-
-
Save JustinJohnWilliams/18326a97372a63596157ab252cae34ac to your computer and use it in GitHub Desktop.
This file contains hidden or 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_game args | |
args.outputs.background_color = [0,0,0] | |
args.grid.origin_center! | |
args.state.magnitude ||= 20 | |
args.state.angle_of_stars ||= 0 | |
args.state.stars ||= 750.map do | |
{ | |
w: 10, | |
h: 10, | |
b: 255, | |
xr: 1.randomize(:sign, :ratio), | |
yr: 1.randomize(:sign, :ratio), | |
zr: 1.randomize(:sign, :ratio) | |
} | |
end | |
if args.inputs.controller_one.a | |
$gtk.console.show | |
puts $gtk.read_file("app/tick.rb") | |
end | |
if args.inputs.controller_one.b | |
$gtk.console.close | |
end | |
args.state.magnitude += ((args.inputs.controller_one.right_analog_y_perc * 0.025) ** 2) * args.inputs.controller_one.right_analog_y_perc.sign | |
if args.state.magnitude < 0 | |
args.state.magnitude = 0 | |
end | |
args.state.angle_of_stars += args.inputs.controller_one.left_analog_y_perc | |
args.outputs.solids << args.state.stars.map do |s| | |
{ | |
x: 120 * s[:xr] * args.state.magnitude, | |
y: 55 + 120 * s[:yr] * args.state.magnitude, | |
z: 55 + 20 * s[:zr] * args.state.magnitude, | |
w: (10 * args.state.magnitude).clamp(1, 10), | |
h: (10 * args.state.magnitude).clamp(1, 10), | |
b: 255 | |
} | |
end.map! do |star| | |
rotate_point(star, args.state.angle_of_stars, { x: 20, y: 0 } ) | |
end | |
#defaults args | |
#render args | |
#calc args | |
end | |
def rotate_point point, a, around = nil | |
s = Math.sin a.to_radians | |
c = Math.cos a.to_radians | |
px = point.x | |
pz = point.z | |
cx = 0 | |
cz = 0 | |
if around | |
cx = around.x | |
cz = around.z | |
end | |
point.merge(x: ((px - cx) * c - (pz - cz) * s) + cx, | |
z: ((px - cx) * s + (pz - cz) * c) + cz) | |
end | |
$gtk.reset | |
#$gtk.console.show | |
#puts $gtk.read_file("app/tick.rb") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment