Reworked the dialouge system. Now the main.rb function can register and delete the dialouges.
This commit is contained in:
@@ -7,6 +7,7 @@ require 'yaml'
|
||||
|
||||
require './producer.rb'
|
||||
require './consumer.rb'
|
||||
require './dialouge_box.rb'
|
||||
require './ui.rb'
|
||||
|
||||
FONT_PATH = 'assets/font/Cousine-Regular.ttf'
|
||||
@@ -46,6 +47,9 @@ class NumFactory < Gosu::Window
|
||||
@camera_y_zoom_offset = HEIGHT.to_f / (@camera_boxes * BOX_SIZE * 2).to_f
|
||||
|
||||
@ui = UI.new(WIDTH, HEIGHT)
|
||||
@dialouges = [
|
||||
#DialougeBox.new(0, 5, BOX_SIZE, BOX_SIZE, WIDTH, HEIGHT, 'this is some really good test text!', BOX_SIZE, 500)
|
||||
]
|
||||
|
||||
# Load from file or initialize a new game
|
||||
begin
|
||||
@@ -75,7 +79,7 @@ class NumFactory < Gosu::Window
|
||||
center_y = ((@game_height - 1) / 2).to_i
|
||||
|
||||
@consumers.append(
|
||||
Consumer.new(center_x, center_y, BOX_SIZE, WIDTH, HEIGHT),
|
||||
Consumer.new(self, center_x, center_y, BOX_SIZE, WIDTH, HEIGHT),
|
||||
)
|
||||
|
||||
# The value of the producer is proportional to the distance from the center
|
||||
@@ -85,6 +89,7 @@ class NumFactory < Gosu::Window
|
||||
# Place a producer:
|
||||
@producers.append(
|
||||
Producer.new(
|
||||
self,
|
||||
xx,
|
||||
yy,
|
||||
(Math.sqrt((xx - center_x)**2 + (yy - center_y) ** 2) * GAME_PRODUCER_VALUE_MULT).to_i,
|
||||
@@ -159,6 +164,24 @@ class NumFactory < Gosu::Window
|
||||
end
|
||||
|
||||
|
||||
## Register a dialouge into the game
|
||||
# @param x [Integer] The x position that the dialouge should be drawn at.
|
||||
# @param y [Integer] The y position that the dialouge should be drawn at.
|
||||
# @param size_x [Integer] The pixel width
|
||||
# @param size_y [Integer] The pixel width
|
||||
# @param text [String] The text for the dialouge box
|
||||
def register_dialouge(x, y, size_x, size_y, text, popup_time)
|
||||
dialouge = DialougeBox.new(x, y, size_x, size_y, WIDTH, HEIGHT, text, BOX_SIZE, popup_time)
|
||||
@dialouges.append(dialouge)
|
||||
return dialouge
|
||||
end
|
||||
|
||||
## Remove a dialouge from the game
|
||||
# @param dialouge [DialougeBox] The dialouge to remove
|
||||
def deregister_dialouge(dialouge)
|
||||
@dialouges.delete(dialouge)
|
||||
end
|
||||
|
||||
## Called every frame
|
||||
def update
|
||||
@delta_time = Time.now() - @tick_time
|
||||
@@ -190,7 +213,7 @@ class NumFactory < Gosu::Window
|
||||
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, mouse_used)
|
||||
producer.update(delta_mult, @camera_x, @camera_y, @camera_zoom)
|
||||
end
|
||||
|
||||
@belts.each do |belt|
|
||||
@@ -200,7 +223,10 @@ class NumFactory < Gosu::Window
|
||||
@consumers.each do |consumer|
|
||||
consumer.update(delta_mult, @camera_x, @camera_y, @camera_zoom, self.mouse_x, self.mouse_y, mouse_used)
|
||||
end
|
||||
|
||||
|
||||
@dialouges.each do |dialouge|
|
||||
dialouge.update(delta_mult, @camera_zoom, self.mouse_x, self.mouse_y)
|
||||
end
|
||||
end
|
||||
|
||||
## Called when OS wants to update window.
|
||||
@@ -236,6 +262,11 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user