master
E. Almqvist 3 years ago
commit 8a72edec77
  1. 1
      Gemfile
  2. 6
      Gemfile.lock
  3. 3
      Play_Game.sh
  4. 4
      README.md
  5. BIN
      media/orbit_of_orbit.png
  6. 37
      src/app.rb
  7. 6
      src/config.rb
  8. 3
      src/lib/controller.rb
  9. 8
      src/lib/physobj.rb
  10. 10
      src/lib/world.rb

@ -1,3 +1,4 @@
source "https://rubygems.org"
gem "gosu"
gem "matrix"

@ -1,13 +1,15 @@
GEM
remote: https://rubygems.org/
specs:
gosu (1.2.0)
gosu (1.3.0)
matrix (0.4.2)
PLATFORMS
x86_64-linux
DEPENDENCIES
gosu
matrix
BUNDLED WITH
2.2.26
2.2.28

@ -0,0 +1,3 @@
#!/usr/bin/bash
ruby src/app.rb

@ -1,3 +1,7 @@
# Hohmann Miner
Mine stuff and then get more stuff but in space.
![](media/preview.png)
## Orbits!
![](media/orbit_of_orbit.png)
You can now orbit stuff that orbits other stuff!

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

@ -18,7 +18,7 @@ require_relative "lib/world.rb"
require_relative "ui/mainmenu.rb"
class Window < Gosu::Window
attr_accessor :caption, :ui, :world, :mainmenu, :key_events
attr_accessor :caption, :ui, :world, :mainmenu, :key_events, :up_keyhook, :down_keyhook
attr_reader :width, :height, :fonts
def initialize(title, width, height)
@ -40,6 +40,7 @@ class Window < Gosu::Window
@ui = []
@fonts = {
small: Gosu::Font.new(self, MAIN_FONT, 8),
normal: Gosu::Font.new(self, MAIN_FONT, 18),
big: Gosu::Font.new(self, MAIN_FONT, 20),
title: Gosu::Font.new(self, MAIN_FONT, 64),
@ -54,7 +55,7 @@ class Window < Gosu::Window
ply.show_info = false
ply.thrust = 0.0075
ply.pos = Vector[800, 450 + 500]
ply.vel = Vector[1, 0]
ply.vel = Vector[1.2, 0]
@world.controller = ply
cube2 = PhysCube.new("Beta", self, 8, 8)
@ -65,8 +66,8 @@ class Window < Gosu::Window
sol = Planet.new("Sol", self, 0xff_ffffaa, 1e2, 15, 1)
sol.pos = Vector[800, 450]
planet = Planet.new("Planet", self, 0xff_cccccc, 1e1, 8, 1)
planet.pos = Vector[800, 450 + 300]
planet = Planet.new("Planet", self, 0xff_cccccc, 1e2, 8, 1)
planet.pos = Vector[800, 450 + 800]
planet.vel = Vector[-2, 0]
planet.show_info = true
@ -81,7 +82,7 @@ class Window < Gosu::Window
@world.physobjs << planet
@world.freeze = false
self.mainmenu.show = false
# self.mainmenu.show = false
end
def button_up(id)
@ -93,9 +94,11 @@ class Window < Gosu::Window
@up_keyhook.call(KEY_EVENTS[id])
@key_events[:down].delete(id) # when the key is released: stop holding it
# if( @world && @world.controller ) then
# @world.controller.button_up(id)
# end
=begin
if( @world && @world.controller ) then
@world.controller.button_up(id)
end
=end
end
def button_down(id)
@ -105,13 +108,13 @@ class Window < Gosu::Window
@key_events[:down] << id
# if( id == BIND_PAUSE ) then
# @freeze = !@freeze
# end
#
# if( @world && @world.controller ) then
# @world.controller.button_down(id)
# end
if( id == BIND_PAUSE ) then
@freeze = !@freeze
end
if( @world && @world.controller ) then
@world.controller.button_down(id)
end
end
private def broadcast_event(event)
@ -144,7 +147,7 @@ end
window = Window.new("Hohmann Miner", WINDOW_WIDTH, WINDOW_HEIGHT)
window.fullscreen = WINDOW_FULLSCREEN
window.mainmenu = MainMenu.new(window, true)
# window.mainmenu = MainMenu.new(window, true)
window.start_game
window.show
# window.start_game

@ -5,9 +5,9 @@ ENABLE_DEBUG = true
WORLD_SEED = 123456789
# UI
WINDOW_WIDTH = 640
WINDOW_HEIGHT = 480
WINDOW_FULLSCREEN = false
WINDOW_WIDTH = 1600
WINDOW_HEIGHT = 900
WINDOW_FULLSCREEN = false
MAIN_FONT = "monospace"
# Keybinds

@ -8,9 +8,6 @@ class Player < PhysCube
# Bind all the binds to all the functions stuff
# world.down_keyhook.add()
# world.down_keyhook.add(:player, :toggle_engine, {
# puts("ENGINE TOGGLE :D")
# })
end

@ -27,6 +27,8 @@ class PhysObj
end
def tick
self.apply_accel_vecs
@x, @y = @pos[0], @pos[1]
@angle %= 360
@ -44,9 +46,9 @@ class PhysObj
end
end
def render_path(x_offset=0, y_offset=0)
def render_path(x_offset=0, y_offset=0, color=0xaa_ccccff)
@saved_pos.each do |pos|
Gosu.draw_rect(pos[0] + x_offset, pos[1] + y_offset, 1, 1, Gosu::Color.argb(0xaa_ccccff))
Gosu.draw_rect(pos[0] + x_offset, pos[1] + y_offset, 1, 1, Gosu::Color.argb(color))
end
end
@ -56,7 +58,7 @@ class PhysObj
def render(x_offset=0, y_offset=0, color=Gosu::Color.argb(0xaa_2222ff))
if( @show_info ) then
self.world.fonts[:normal].draw_text(self.inspect, self.pos[0] + x_offset, self.pos[1] + y_offset, 1, 1.0, 1.0, color)
self.world.fonts[:small].draw_text(self.inspect, self.pos[0] + x_offset, self.pos[1] + y_offset, 1, 1.0, 1.0, color)
end
end

@ -1,5 +1,5 @@
class World
attr_accessor :freeze, :physobjs, :planets, :controller, :camera
attr_accessor :freeze, :physobjs, :planets, :controller, :camera, :window
def initialize(seed, window)
@seed = seed
@window = window
@ -22,19 +22,19 @@ class World
orbiters += @physobjs # append each element
orbiters += @planets
orbiters.delete(planet) # dont orbit yourself, it is bad for your health.
planet.orbit(planets)
planet.orbit(orbiters)
end
end
end
def render
if( @controller != nil ) then
self.camera = Vector[self.width/2, self.height/2] - self.controller.pos
@font.draw_text(self.controller.inspect, 0, 32, 1, 1.0, 1.0, Gosu::Color::WHITE)
self.camera = Vector[self.window.width/2, self.window.height/2] - self.controller.pos
self.window.fonts[:normal].draw_text(self.controller.inspect, 0, 32, 1, 1.0, 1.0, Gosu::Color::WHITE)
end
camx, camy = self.camera[0], self.camera[1]
@font2.draw_text("Frozen: #{@freeze}", 0, 0, 1, 1.0, 1.0, Gosu::Color::WHITE)
self.window.fonts[:normal].draw_text("Frozen: #{@freeze}", 0, 0, 1, 1.0, 1.0, Gosu::Color::WHITE)
@physobjs.each do |obj|
obj.render(camx, camy)

Loading…
Cancel
Save