diff --git a/README.md b/README.md index 6f2d77d..c2f10c6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,36 @@ # number_factory A game where you create combinations of numbers! + +# UI elements + +If you hover over the producers you will see the speed at which it produces. + +If you hover over the consumer, you can see your next goal or quest + +## tools + +### Extractor + +Extracts numbers. It is a three by three square and populates numbers from any +side (max 12) every time the producer ticks. + +### Conveyer belt + +Can move numbers around. + +### Adder + +Can output to either side but will only output to one space. Prefers the slot +on the left. If it is full though it will use the slots to the right + + +### Multiplier + +### Subtractor + +### Divider + +### Exponent + +### Logarithm diff --git a/assets/images/adder.png b/assets/images/adder.png new file mode 100644 index 0000000..2bbf7fb Binary files /dev/null and b/assets/images/adder.png differ diff --git a/assets/images/adder.xcf b/assets/images/adder.xcf new file mode 100644 index 0000000..6f6bd10 Binary files /dev/null and b/assets/images/adder.xcf differ diff --git a/assets/images/background_square.png b/assets/images/background_square.png index 7f70173..56623a0 100644 Binary files a/assets/images/background_square.png and b/assets/images/background_square.png differ diff --git a/assets/images/background_square.xcf b/assets/images/background_square.xcf index f5ee3ff..4302437 100644 Binary files a/assets/images/background_square.xcf and b/assets/images/background_square.xcf differ diff --git a/assets/images/belt.png b/assets/images/belt.png new file mode 100644 index 0000000..1edd967 Binary files /dev/null and b/assets/images/belt.png differ diff --git a/assets/images/belt.xcf b/assets/images/belt.xcf new file mode 100644 index 0000000..320a918 Binary files /dev/null and b/assets/images/belt.xcf differ diff --git a/assets/images/extrtactor.png b/assets/images/extrtactor.png new file mode 100644 index 0000000..e4b2f78 Binary files /dev/null and b/assets/images/extrtactor.png differ diff --git a/assets/images/extrtactor.xcf b/assets/images/extrtactor.xcf new file mode 100644 index 0000000..2ebf3ce Binary files /dev/null and b/assets/images/extrtactor.xcf differ diff --git a/assets/images/producer.png b/assets/images/producer.png new file mode 100644 index 0000000..690638b Binary files /dev/null and b/assets/images/producer.png differ diff --git a/assets/images/producer.xcf b/assets/images/producer.xcf new file mode 100644 index 0000000..13a44f0 Binary files /dev/null and b/assets/images/producer.xcf differ diff --git a/consumer.rb b/consumer.rb index 0f09068..836a7db 100644 --- a/consumer.rb +++ b/consumer.rb @@ -37,11 +37,11 @@ class Consumer # @param camera_x [Integer] The camera X position # @param camera_y [Integer] The camera Y position # @param camera_zoom [Float] The camera zoom - def update(delta_mult, camera_x, camera_y, camera_zoom, mouse_x, mouse_y) + def update(delta_mult, camera_x, camera_y, camera_zoom, mouse_x, mouse_y, mouse_used) @draw_x = (((((@screen_width / @box_size.to_f) / 2.0) + (@x - camera_x) * camera_zoom) * @box_size) + BORDER * camera_zoom) @draw_y = (((((@screen_height / @box_size.to_f) / 2.0) + (@y - camera_y) * camera_zoom) * @box_size) + BORDER * camera_zoom) @camera_zoom = camera_zoom - if 0 < mouse_x - @draw_x && mouse_x - @draw_x < (SIZE * @box_size * @camera_zoom) && 0 < mouse_y - @draw_y && mouse_y - @draw_y < (SIZE * @box_size * @camera_zoom) + if !mouse_used && 0 < mouse_x - @draw_x && mouse_x - @draw_x < (SIZE * @box_size * @camera_zoom) && 0 < mouse_y - @draw_y && mouse_y - @draw_y < (SIZE * @box_size * @camera_zoom) @tooltip_timer += 60.0 * delta_mult if @tooltip_timer > HOVER_TIME @tooltip.show = true diff --git a/extractor.rb b/extractor.rb new file mode 100644 index 0000000..38d7dba --- /dev/null +++ b/extractor.rb @@ -0,0 +1,26 @@ +# Nathan Hinton +# +# When placed it will extract numbers at a specified rate and place them on any +# conveyer belts that are adjacent to it. + +class Extractor + def initialize(x, y, box_size) + @x = x + @y = y + @box_size = box_size + @image = Gosu.render(@box_size - (2 * BORDER), @box_size - (2 * BORDER)) { + Gosu::Image.new('assets/images/producer.png').draw(0, 0, 0, @box_size / 32.0, @box_size / 32.0) + Gosu::Image.from_text("#{@number}", 20, font: FONT_PATH).draw(10 / 32.0 * @box_size, (8 / 32.0 * @box_size), 1, 2, 2, 0xFFFA32C0) + } + end + + def update(delta_mult, camera_x, camera_y) + @draw_x = (((((@screen_width / @box_size.to_f) / 2.0) + (@x - camera_x) * camera_zoom) * @box_size) + BORDER * camera_zoom) + @draw_y = (((((@screen_height / @box_size.to_f) / 2.0) + (@y - camera_y) * camera_zoom) * @box_size) + BORDER * camera_zoom) + @camera_zoom = camera_zoom + end + + def draw() + @image.draw(@draw_x, @draw_y, 0, @camera_zoom, @camera_zoom) + end +end diff --git a/main.rb b/main.rb index 2a32501..fa86428 100644 --- a/main.rb +++ b/main.rb @@ -7,7 +7,7 @@ require 'yaml' require './producer.rb' require './consumer.rb' -require './dialouge_box.rb' +require './ui.rb' FONT_PATH = 'assets/font/Cousine-Regular.ttf' @@ -45,9 +45,8 @@ class NumFactory < Gosu::Window @camera_x_zoom_offset = WIDTH.to_f / (@camera_boxes * BOX_SIZE * 2).to_f @camera_y_zoom_offset = HEIGHT.to_f / (@camera_boxes * BOX_SIZE * 2).to_f - @dd = DialougeBox.new(0, 0, WIDTH, HEIGHT, "This is a really really really really really really really really really really string\nof test text!") - @dialouges = [] - + @ui = UI.new(WIDTH, HEIGHT) + # Load from file or initialize a new game begin game_save_data = YAML.load_file("#{GAME_SAVE_DIRECTORY}/positions.yaml") @@ -188,8 +187,10 @@ class NumFactory < Gosu::Window @camera_y = [@camera_y, @game_width].min ### ITEMS ### + mouse_used = @ui.update(self.mouse_x, self.mouse_y) + @producers.each do |producer| - producer.update(delta_mult, @camera_x, @camera_y, @camera_zoom, self.mouse_x, self.mouse_y) + producer.update(delta_mult, @camera_x, @camera_y, @camera_zoom, self.mouse_x, self.mouse_y, mouse_used) end @belts.each do |belt| @@ -197,10 +198,7 @@ class NumFactory < Gosu::Window end @consumers.each do |consumer| - consumer.update(delta_mult, @camera_x, @camera_y, @camera_zoom, self.mouse_x, self.mouse_y) - end - @dialouges.each do |dialouge| - dialouge.update(0, 0, newtext: "My new text is: #{delta_mult}") + consumer.update(delta_mult, @camera_x, @camera_y, @camera_zoom, self.mouse_x, self.mouse_y, mouse_used) end end @@ -209,9 +207,11 @@ class NumFactory < Gosu::Window def draw # Draw mouse coords: onscreen_items = 0 + # TODO: The background does *not* actually need to move. It can just stay + # in one spot and scale... This would make the program load so much faster + # as well as allow for larger maps. @background.draw( (((((WIDTH / BOX_SIZE.to_f) / 2.0) - (@camera_x * @camera_zoom)) * (BOX_SIZE))), - ((((HEIGHT / BOX_SIZE.to_f) / 2.0) - (@camera_y * @camera_zoom)) * (BOX_SIZE)), 0, @camera_zoom, @@ -236,9 +236,7 @@ class NumFactory < Gosu::Window end end - @dialouges.each do |dialouge| - dialouge.draw() - end + @ui.draw() Gosu::Image.from_text("#{width}, #{height}", 20, font: FONT_PATH).draw(1600, 0, 1) Gosu::Image.from_text("#{mouse_x}, #{mouse_y}", 20, font: FONT_PATH).draw(1600, 100, 1) diff --git a/producer.rb b/producer.rb index 610e98f..97229f7 100644 --- a/producer.rb +++ b/producer.rb @@ -7,7 +7,6 @@ PRODUCER_DEBUG = false BORDER = 2 HOVER_TIME = 500 # ms - class Producer attr_reader :draw_x, :draw_y # Create producer at a position with the number and rate specified @@ -25,8 +24,8 @@ class Producer @screen_height = screen_height @image = Gosu.render(@box_size - (2 * BORDER), @box_size - (2 * BORDER)) { # Render the item - Gosu.draw_rect(0, 0, @box_size - (2 * BORDER), @box_size - (2 * BORDER), Gosu::Color::RED, 0) - Gosu::Image.from_text("#{@number}", 20, font: FONT_PATH).draw(5, 5, 1) + Gosu::Image.new('assets/images/producer.png').draw(0, 0, 0, @box_size / 32.0, @box_size / 32.0) + Gosu::Image.from_text("#{@number}", 20, font: FONT_PATH).draw(10 / 32.0 * @box_size, (8 / 32.0 * @box_size), 1, 2, 2, 0xFFFA32C0) } @tooltip = DialougeBox.new(@x, @y, WIDTH, HEIGHT, "Produces #{@rate} number per second") @@ -39,11 +38,11 @@ class Producer # @param camera_x [Integer] The camera X position # @param camera_y [Integer] The camera Y position # @param camera_zoom [Float] The camera zoom - def update(delta_mult, camera_x, camera_y, camera_zoom, mouse_x, mouse_y) + def update(delta_mult, camera_x, camera_y, camera_zoom, mouse_x, mouse_y, mouse_used) @draw_x = (((((@screen_width / @box_size.to_f) / 2.0) + (@x - camera_x) * camera_zoom) * @box_size) + BORDER * camera_zoom) @draw_y = (((((@screen_height / @box_size.to_f) / 2.0) + (@y - camera_y) * camera_zoom) * @box_size) + BORDER * camera_zoom) @camera_zoom = camera_zoom - if 0 < mouse_x - @draw_x && mouse_x - @draw_x < (@box_size * @camera_zoom) && 0 < mouse_y - @draw_y && mouse_y - @draw_y < (@box_size * @camera_zoom) + if !mouse_used && 0 < mouse_x - @draw_x && mouse_x - @draw_x < (@box_size * @camera_zoom) && 0 < mouse_y - @draw_y && mouse_y - @draw_y < (@box_size * @camera_zoom) @tooltip_timer += 60.0 * delta_mult if @tooltip_timer > HOVER_TIME @tooltip.show = true @@ -53,6 +52,9 @@ class Producer @tooltip_timer = 0 @tooltip.show = false end + if @extractor + @extractor.update() + end end # Draw the producer. Uses the camera x and y to shift where it should draw @@ -62,5 +64,8 @@ class Producer end @image.draw(@draw_x, @draw_y, 0, @camera_zoom, @camera_zoom) @tooltip.draw() + if @extractor + @extractor.update() + end end end diff --git a/ui.rb b/ui.rb new file mode 100644 index 0000000..8039b4e --- /dev/null +++ b/ui.rb @@ -0,0 +1,39 @@ +# Nathan Hinton +# This is the UI for the game and will contain all of the sub elements required. + +# There will be three main areas that we will be in charge of. First, the +# bottom bar has the selector of item types. There will be a menu in the top +# right as well as any store things that we need/ +class UI + # Setup for the UI + # @param width [Integer] Width of screen in pixels + # @param height [Integer] Height of the screen in pixels + def initialize(width, height) + @width = width + @height = height + @tool_selector = [] + @toolbar_width = width / 2 + @toolbar_height = height / 9 + @tool_selector_image = Gosu.render(@toolbar_width, @toolbar_height) { + Gosu.draw_rect( + 0, + 0, + @toolbar_width, + @toolbar_height, + Gosu::Color.new(0xC0, 0xFF, 0xFF, 0xFF), + 0) + Gosu::Image.from_text('tool selector', TEXT_SIZE, font: FONT_PATH).draw(TEXT_MARGIN, TEXT_MARGIN) + } + @x = (@width / 2) - (@toolbar_width / 2) + @y = @height - @toolbar_height + + end + + def update(mouse_x, mouse_y) + false + end + + def draw() + @tool_selector_image.draw(@x, @y) + end +end