Files
number_factory/consumer.rb
T

57 lines
2.0 KiB
Ruby

## Nathan Hinton
## A number consumer that will create numbers when an extractor is placed on it.
require './dialouge_box.rb'
CONSUMER_DEBUG = false
BORDER = 2
SIZE = 3
HOVER_TIME = 500 # ms
# This actually should be stored somewhere else. This is the goals/quests for the game
TASKS = [
"Collect 10 1's"
]
class Consumer
attr_reader :draw_x, :draw_y, :size_x, :size_y
# Create consumer at a position with the number and rate specified
# @param x [Integer] X position to start at
# @param y [Integer] Y position to start at
def initialize(parent, x, y, box_size, screen_width, screen_height)
@parent = parent
@x = x - SIZE / 2
@y = y - SIZE / 2
@box_size = box_size
@screen_width = screen_width
@screen_height = screen_height
@image = Gosu.render((SIZE * @box_size) - (2 * BORDER), (SIZE * @box_size) - (2 * BORDER)) {
Gosu.draw_rect(0, 0, (SIZE * @box_size) - (2 * BORDER), (SIZE * @box_size) - (2 * BORDER), Gosu::Color::GREEN, 0)
}
@task_index = 0
@tooltip = @parent.register_dialouge(@x, @y, @box_size * SIZE, @box_size * SIZE, TASKS[@task_index], 500)
@size_x = @size_y = 3
end
# Consumes numbers created
# @param delta_mult [Float] The delta multiplier for any actions
# @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)
@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
@tooltip.move(@draw_x, @draw_y)
end
# Draw the consumer. Uses the camera x and y to shift where it should draw
def draw()
if PRODUCER_DEBUG
puts "Drawing at #{@x - camera_x}, #{@y - camera_y}"
end
@image.draw(@draw_x, @draw_y, 0, @camera_zoom, @camera_zoom)
end
end