Reworked the dialouge system. Now the main.rb function can register and delete the dialouges.

This commit is contained in:
2026-06-17 10:50:14 -06:00
parent 564c600150
commit 931773fb12
4 changed files with 87 additions and 66 deletions
+8 -23
View File
@@ -1,11 +1,8 @@
## Nathan Hinton
## A number producer that will create numbers when an extractor is placed on it.
require './dialouge_box.rb'
PRODUCER_DEBUG = false
BORDER = 2
HOVER_TIME = 500 # ms
class Producer
attr_reader :draw_x, :draw_y
@@ -14,9 +11,10 @@ class Producer
# @param y [Integer] Y position to start at
# @param number [Integer] The number to produce
# @param rate [Integer] The speed in numbers per second to produce
def initialize(x, y, number, rate, box_size, screen_width, screen_height)
def initialize(parent, x, y, number, rate, box_size, screen_width, screen_height)
@x = x
@y = y
@parent = parent
@number = [number, 1].max
@rate = rate
@box_size = box_size
@@ -28,8 +26,10 @@ class Producer
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")
puts "X: #{@x}, Y: #{@y}"
@tooltip = @parent.register_dialouge(@x, @y, @box_size, @box_size, "Produces #{@rate} number per second", 500)
end
# Creates numbers depending on the rate. This is done with knowing that the
# game is 30 fps so we use that for a counter
@@ -38,23 +38,12 @@ 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, mouse_used)
def update(delta_mult, camera_x, camera_y, camera_zoom)
@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 !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
@tooltip.update(@draw_x, @draw_y, @camera_zoom)
end
else
@tooltip_timer = 0
@tooltip.show = false
end
if @extractor
@extractor.update()
end
@tooltip.move(@draw_x, @draw_y)
end
# Draw the producer. Uses the camera x and y to shift where it should draw
@@ -63,9 +52,5 @@ class Producer
puts "Drawing at #{@x - camera_x}, #{@y - camera_y}"
end
@image.draw(@draw_x, @draw_y, 0, @camera_zoom, @camera_zoom)
@tooltip.draw()
if @extractor
@extractor.update()
end
end
end