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" source "https://rubygems.org"
gem "gosu" gem "gosu"
gem "matrix"

@ -1,13 +1,15 @@
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
gosu (1.2.0) gosu (1.3.0)
matrix (0.4.2)
PLATFORMS PLATFORMS
x86_64-linux x86_64-linux
DEPENDENCIES DEPENDENCIES
gosu gosu
matrix
BUNDLED WITH 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 # Hohmann Miner
Mine stuff and then get more stuff but in space. Mine stuff and then get more stuff but in space.
![](media/preview.png) ![](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" require_relative "ui/mainmenu.rb"
class Window < Gosu::Window 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 attr_reader :width, :height, :fonts
def initialize(title, width, height) def initialize(title, width, height)
@ -40,6 +40,7 @@ class Window < Gosu::Window
@ui = [] @ui = []
@fonts = { @fonts = {
small: Gosu::Font.new(self, MAIN_FONT, 8),
normal: Gosu::Font.new(self, MAIN_FONT, 18), normal: Gosu::Font.new(self, MAIN_FONT, 18),
big: Gosu::Font.new(self, MAIN_FONT, 20), big: Gosu::Font.new(self, MAIN_FONT, 20),
title: Gosu::Font.new(self, MAIN_FONT, 64), title: Gosu::Font.new(self, MAIN_FONT, 64),
@ -54,7 +55,7 @@ class Window < Gosu::Window
ply.show_info = false ply.show_info = false
ply.thrust = 0.0075 ply.thrust = 0.0075
ply.pos = Vector[800, 450 + 500] ply.pos = Vector[800, 450 + 500]
ply.vel = Vector[1, 0] ply.vel = Vector[1.2, 0]
@world.controller = ply @world.controller = ply
cube2 = PhysCube.new("Beta", self, 8, 8) 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 = Planet.new("Sol", self, 0xff_ffffaa, 1e2, 15, 1)
sol.pos = Vector[800, 450] sol.pos = Vector[800, 450]
planet = Planet.new("Planet", self, 0xff_cccccc, 1e1, 8, 1) planet = Planet.new("Planet", self, 0xff_cccccc, 1e2, 8, 1)
planet.pos = Vector[800, 450 + 300] planet.pos = Vector[800, 450 + 800]
planet.vel = Vector[-2, 0] planet.vel = Vector[-2, 0]
planet.show_info = true planet.show_info = true
@ -81,7 +82,7 @@ class Window < Gosu::Window
@world.physobjs << planet @world.physobjs << planet
@world.freeze = false @world.freeze = false
self.mainmenu.show = false # self.mainmenu.show = false
end end
def button_up(id) def button_up(id)
@ -93,9 +94,11 @@ class Window < Gosu::Window
@up_keyhook.call(KEY_EVENTS[id]) @up_keyhook.call(KEY_EVENTS[id])
@key_events[:down].delete(id) # when the key is released: stop holding it @key_events[:down].delete(id) # when the key is released: stop holding it
# if( @world && @world.controller ) then =begin
# @world.controller.button_up(id) if( @world && @world.controller ) then
# end @world.controller.button_up(id)
end
=end
end end
def button_down(id) def button_down(id)
@ -105,13 +108,13 @@ class Window < Gosu::Window
@key_events[:down] << id @key_events[:down] << id
# if( id == BIND_PAUSE ) then if( id == BIND_PAUSE ) then
# @freeze = !@freeze @freeze = !@freeze
# end end
#
# if( @world && @world.controller ) then if( @world && @world.controller ) then
# @world.controller.button_down(id) @world.controller.button_down(id)
# end end
end end
private def broadcast_event(event) private def broadcast_event(event)
@ -144,7 +147,7 @@ end
window = Window.new("Hohmann Miner", WINDOW_WIDTH, WINDOW_HEIGHT) window = Window.new("Hohmann Miner", WINDOW_WIDTH, WINDOW_HEIGHT)
window.fullscreen = WINDOW_FULLSCREEN window.fullscreen = WINDOW_FULLSCREEN
window.mainmenu = MainMenu.new(window, true) # window.mainmenu = MainMenu.new(window, true)
window.start_game
window.show window.show
# window.start_game

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

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

@ -27,6 +27,8 @@ class PhysObj
end end
def tick def tick
self.apply_accel_vecs
@x, @y = @pos[0], @pos[1] @x, @y = @pos[0], @pos[1]
@angle %= 360 @angle %= 360
@ -44,9 +46,9 @@ class PhysObj
end end
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| @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
end end
@ -56,7 +58,7 @@ class PhysObj
def render(x_offset=0, y_offset=0, color=Gosu::Color.argb(0xaa_2222ff)) def render(x_offset=0, y_offset=0, color=Gosu::Color.argb(0xaa_2222ff))
if( @show_info ) then 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
end end

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

Loading…
Cancel
Save