From 559d0c7dea5bedf939a74e822421035a9e35041f Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 25 Oct 2021 09:14:52 +0200 Subject: [PATCH] File restruc & refactor --- README.md | 2 +- preview.png => media/preview.png | Bin app.rb => src/app.rb | 29 ++++++++++------------- config.rb => src/config.rb | 0 controller.rb => src/lib/controller.rb | 0 gosu_plugin.rb => src/lib/gosu_plugin.rb | 0 objects.rb => src/lib/objects.rb | 0 physobj.rb => src/lib/physobj.rb | 0 ui.rb => src/lib/ui.rb | 10 ++++---- src/lib/universe.rb | 16 +++++++++++++ 10 files changed, 34 insertions(+), 23 deletions(-) rename preview.png => media/preview.png (100%) rename app.rb => src/app.rb (86%) rename config.rb => src/config.rb (100%) rename controller.rb => src/lib/controller.rb (100%) rename gosu_plugin.rb => src/lib/gosu_plugin.rb (100%) rename objects.rb => src/lib/objects.rb (100%) rename physobj.rb => src/lib/physobj.rb (100%) rename ui.rb => src/lib/ui.rb (88%) create mode 100644 src/lib/universe.rb diff --git a/README.md b/README.md index eef2f71..5cba3e4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # Hohmann Miner Mine stuff and then get more stuff but in space. -![](preview.png) +![](media/preview.png) diff --git a/preview.png b/media/preview.png similarity index 100% rename from preview.png rename to media/preview.png diff --git a/app.rb b/src/app.rb similarity index 86% rename from app.rb rename to src/app.rb index 86b021d..744da15 100755 --- a/app.rb +++ b/src/app.rb @@ -10,16 +10,17 @@ load "objects.rb" load "controller.rb" class Window < Gosu::Window - attr_accessor :freeze, :caption, :physobjs, :planets, :controller, :camera, :ui + attr_accessor :caption, attr_reader :width, :height, :fonts - def initialize(title, width, height, physobjs = [], planets = []) + def initialize(title, width, height, universe) super width, height @width, @height = width, height self.caption = "#{title}| #{width}x#{height}" - @physobjs = physobjs - @planets = planets + #@physobjs = physobjs + #@planets = planets + @universe = universe @font = Gosu::Font.new(self, MAIN_FONT, 18) @font2 = Gosu::Font.new(self, MAIN_FONT, 20) @@ -33,20 +34,15 @@ class Window < Gosu::Window button: @font_button } - @freeze = true - @controller = nil - - @camera = Vector[0, 0] - @ui = [] end def start_game - cube = Player.new("Alpha", self, 8, 8) - cube.show_info = false - cube.thrust = 0.0075 - cube.pos = Vector[800, 450 + 500] - cube.vel = Vector[1, 0] - self.controller = cube + ply = Player.new("Player", self, 8, 8) + ply.show_info = false + ply.thrust = 0.0075 + ply.pos = Vector[800, 450 + 500] + ply.vel = Vector[1, 0] + self.controller = ply cube2 = PhysCube.new("Beta", self, 8, 8) cube2.pos = Vector[800, 450 + 300] @@ -66,9 +62,8 @@ class Window < Gosu::Window self.planets << sol self.planets << planet - self.planets << cube - self.physobjs << cube + self.physobjs << ply self.physobjs << cube2 self.physobjs << planet end diff --git a/config.rb b/src/config.rb similarity index 100% rename from config.rb rename to src/config.rb diff --git a/controller.rb b/src/lib/controller.rb similarity index 100% rename from controller.rb rename to src/lib/controller.rb diff --git a/gosu_plugin.rb b/src/lib/gosu_plugin.rb similarity index 100% rename from gosu_plugin.rb rename to src/lib/gosu_plugin.rb diff --git a/objects.rb b/src/lib/objects.rb similarity index 100% rename from objects.rb rename to src/lib/objects.rb diff --git a/physobj.rb b/src/lib/physobj.rb similarity index 100% rename from physobj.rb rename to src/lib/physobj.rb diff --git a/ui.rb b/src/lib/ui.rb similarity index 88% rename from ui.rb rename to src/lib/ui.rb index 9062956..3b99605 100644 --- a/ui.rb +++ b/src/lib/ui.rb @@ -80,7 +80,7 @@ class Button < UI def render sel = self.hover? ? :selected : :default - # self.draw_rect(self.x, self.y, self.width, self.height, self.colors[:background][sel]) + self.draw_rect(self.x, self.y, self.width, self.height, self.colors[:background][sel]) self.draw_text(self.text, self.font, self.width/2 - self.text_width/2, self.height/2 - self.text_height/2, self.colors[:text][sel]) end @@ -102,12 +102,12 @@ class MainMenu < UI self.draw_text(titletext, self.window.fonts[:title], self.width/2 - titlewidth/2, self.height/4) playbtn = Button.new(self.window, self, "Play", self.window.fonts[:button]) - #playbtn.x, playbtn.y = self.width/2 - playbtn.width/2, self.height/2 - playbtn.height/2 + playbtn.x, playbtn.y = self.width/2 - playbtn.width/2, self.height/2 - playbtn.height/2 playbtn.render -# quitbtn = Button.new(self.window, self, "Quit", self.window.fonts[:button]) -# quitbtn.x, quitbtn.y = self.width/2 - quitbtn.width/2, quitbtn.height + playbtn.y + 16 -# quitbtn.render + quitbtn = Button.new(self.window, self, "Quit", self.window.fonts[:button]) + quitbtn.x, quitbtn.y = self.width/2 - quitbtn.width/2, quitbtn.height + playbtn.y + 16 + quitbtn.render end end end diff --git a/src/lib/universe.rb b/src/lib/universe.rb new file mode 100644 index 0000000..5992ee0 --- /dev/null +++ b/src/lib/universe.rb @@ -0,0 +1,16 @@ +class Universe + attr_accessor :freeze, :physobjs, :planets, :controller, :camera, :ui + def initialize(seed, window) + @seed = seed + @window = window + + @physobjs = [] + @planets = [] + + @freeze = true + @controller = nil + + @camera = Vector[0, 0] + @ui = [] + end +end