Hohmann Miner, a sandbox physics game where you mine stuff.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hohmann-miner/app.rb

54 lines
982 B

3 years ago
#!/usr/bin/ruby -w
require "gosu"
load "physobj.rb"
class Window < Gosu::Window
3 years ago
attr_accessor :caption, :physobjs, :planets
3 years ago
attr_reader :width, :height
3 years ago
def initialize(title, width, height, physobjs = [], planets = [])
3 years ago
super width, height
@width, @height = width, height
self.caption = "#{title}| #{width}x#{height}"
@physobjs = physobjs
3 years ago
@planets = planets
3 years ago
end
def update
@physobjs.each do |obj|
obj.physics
end
3 years ago
@planets.each do |planet|
planet.orbit(@physobjs)
end
3 years ago
end
def draw
@physobjs.each do |obj|
obj.render
3 years ago
obj.draw_vector(obj.vel, 10)
obj.draw_vector(obj.accel, 500, 0xff_aaffaa)
3 years ago
end
3 years ago
@planets.each do |planet|
planet.render
end
3 years ago
end
end
window = Window.new("Physics!", 1600, 900)
3 years ago
planet = Planet.new("Earth", window, 0xff_aaffaa)
3 years ago
planet.pos = Vector[800, 450]
3 years ago
3 years ago
cube = PhysCube.new("Cube", window, 8, 8)
cube.vel = Vector[10, 0]
3 years ago
planet.orbit([cube])
3 years ago
3 years ago
window.planets << planet
3 years ago
window.physobjs << cube
window.show