From 1a908eb656af6bf164dcc9e41f9d2aac912efd69 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 18 Oct 2021 09:57:13 +0200 Subject: [PATCH] Bugs --- app.rb | 77 +++++++++++++++++++++++++++++++------------------------ config.rb | 3 +++ ui.rb | 31 +++++++++++++++++----- 3 files changed, 71 insertions(+), 40 deletions(-) diff --git a/app.rb b/app.rb index 45e4759..a1d1df7 100755 --- a/app.rb +++ b/app.rb @@ -3,13 +3,14 @@ require "matrix" require "gosu" load "gosu_plugin.rb" +load "ui.rb" load "config.rb" load "physobj.rb" load "objects.rb" load "controller.rb" class Window < Gosu::Window - attr_accessor :freeze, :caption, :physobjs, :planets, :controller, :camera + attr_accessor :freeze, :caption, :physobjs, :planets, :controller, :camera, :ui attr_reader :width, :height, :fonts def initialize(title, width, height, physobjs = [], planets = []) @@ -28,10 +29,44 @@ class Window < Gosu::Window big: @font2 } - @freeze = false + @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 + + cube2 = PhysCube.new("Beta", self, 8, 8) + cube2.pos = Vector[800, 450 + 300] + cube2.vel = Vector[2, 0] + cube2.show_info = true + + 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.vel = Vector[-2, 0] + planet.show_info = true + + sol_orbiters = [cube, cube2, planet] + sol.orbit(sol_orbiters) + + self.planets << sol + self.planets << planet + self.planets << cube + + self.physobjs << cube + self.physobjs << cube2 + self.physobjs << planet end def button_up(id) @@ -91,12 +126,15 @@ class Window < Gosu::Window end def draw + @ui.each do |u| + u.render + end + if( @controller != nil ) then @camera = Vector[self.width/2, self.height/2] - @controller.pos @font.draw_text(@controller.debug_string, 0, 32, 1, 1.0, 1.0, Gosu::Color::WHITE) end camx, camy = @camera[0], @camera[1] - p @camera @font2.draw_text("Frozen: #{@freeze}", 0, 0, 1, 1.0, 1.0, Gosu::Color::WHITE) @@ -115,36 +153,9 @@ class Window < Gosu::Window end -window = Window.new("Physics!", 1600, 900) - -cube = Player.new("Alpha", window, 8, 8) -cube.show_info = false -cube.thrust = 0.0075 -cube.pos = Vector[800, 450 + 500] -cube.vel = Vector[1, 0] -window.controller = cube - -cube2 = PhysCube.new("Beta", window, 8, 8) -cube2.pos = Vector[800, 450 + 300] -cube2.vel = Vector[2, 0] -cube2.show_info = true - -sol = Planet.new("Sol", window, 0xff_ffffaa, 1e2, 15, 1) -sol.pos = Vector[800, 450] - -planet = Planet.new("Planet", window, 0xff_cccccc, 1e1, 8, 1) -planet.pos = Vector[800, 450 + 300] -planet.vel = Vector[-2, 0] -planet.show_info = true - -sol_orbiters = [cube, cube2, planet] -sol.orbit(sol_orbiters) - -window.planets << sol -window.planets << planet +window = Window.new("Hohmann Miner", WINDOW_WIDTH, WINDOW_HEIGHT) +window.fullscreen = WINDOW_FULLSCREEN -window.physobjs << cube -window.physobjs << cube2 -window.physobjs << planet +mainmenu = MainMenu.new(window, true) window.show diff --git a/config.rb b/config.rb index b91b6d8..7f9e3ea 100644 --- a/config.rb +++ b/config.rb @@ -1,4 +1,7 @@ # UI +WINDOW_WIDTH = 1600 +WINDOW_HEIGHT = 900 +WINDOW_FULLSCREEN = false MAIN_FONT = "monospace" # Keybinds diff --git a/ui.rb b/ui.rb index bdc542c..f559500 100644 --- a/ui.rb +++ b/ui.rb @@ -1,11 +1,14 @@ class UI attr_accessor :x, :y - attr_reader :width, :height, :zindex, :uiscale - def initialize(x, y, width, height, zindex=1, uiscale=1) + attr_reader :window, :width, :height, :zindex, :uiscale + def initialize(window, x, y, width, height, zindex=1, uiscale=1) + @window = window @x, @y = x, y @width, @height = width, height @zindex = zindex @uiscale = uiscale + + @window.ui << self end private def pos @@ -25,15 +28,29 @@ class UI end def draw_rect(x, y, width, height, color=0xff_ffffff, z=0, mode=:default) - v1 = Vector[0, 0, color] + self.pos + Vector[x, y] - v2 = Vector[width, 0, color] + self.pos + Vector[x, y] - v3 = Vector[0, height, color] + self.pos + Vector[x, y] - v4 = Vector[width, height, color] + self.pos + Vector[x, y] + v1 = Vector[x, y, color] + self.pos + v2 = Vector[width + x, y, color] + self.pos + v3 = Vector[x, height + y, color] + self.pos + v4 = Vector[width + x, height + y, color] + self.pos self.draw_quad(v1, v2, v3, v4, z, mode) end def draw_circle(x, y, r, c, z = 0, thickness = 1, sides = nil, mode = :default) - Gosu::draw_circle(x, y, r, c z, thickness, sides, mode) + Gosu::draw_circle(x, y, r, c, z, thickness, sides, mode) end +end +class MainMenu < UI + attr_accessor :show + def initialize(window, show=false) + super window, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 99 + @show = show + end + + def render + if( @show ) then + self.draw_rect(0, 0, self.width, self.height, 0x99_aaaaaa) + self.draw_text("Hohmann Miner", self.window.fonts[:big], self.width/2, self.height/2) + end + end end